Files
ox_lib/web/src/features/dialog/components/fields/input.tsx

61 lines
1.7 KiB
TypeScript
Raw Normal View History

import { createStyles, PasswordInput, TextInput } from '@mantine/core';
2022-08-27 15:58:36 +02:00
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React, { useEffect } from 'react';
import { IInput } from '../../../../interfaces/dialog';
import { UseFormRegisterReturn } from 'react-hook-form';
interface Props {
register: UseFormRegisterReturn;
row: IInput;
index: number;
}
const useStyles = createStyles((theme) => ({
eyeIcon: {
color: theme.colors.dark[2],
},
}));
const InputField: React.FC<Props> = (props) => {
const { classes } = useStyles();
return (
<>
{!props.row.password ? (
<TextInput
{...props.register}
defaultValue={props.row.default}
label={props.row.label}
description={props.row.description}
icon={props.row.icon && <FontAwesomeIcon icon={props.row.icon} fixedWidth />}
placeholder={props.row.placeholder}
disabled={props.row.disabled}
2023-01-08 11:35:30 +01:00
withAsterisk={props.row.required}
/>
) : (
<PasswordInput
{...props.register}
defaultValue={props.row.default}
label={props.row.label}
description={props.row.description}
icon={props.row.icon && <FontAwesomeIcon icon={props.row.icon} fixedWidth />}
placeholder={props.row.placeholder}
disabled={props.row.disabled}
2023-01-08 11:35:30 +01:00
withAsterisk={props.row.required}
visibilityToggleIcon={({ reveal, size }) => (
<FontAwesomeIcon
icon={reveal ? 'eye-slash' : 'eye'}
fontSize={size}
cursor="pointer"
className={classes.eyeIcon}
fixedWidth
/>
)}
/>
)}
</>
);
};
export default InputField;