2023-01-04 13:47:37 +01:00
|
|
|
import { createStyles, PasswordInput, TextInput } from '@mantine/core';
|
2022-08-27 15:58:36 +02:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2023-01-03 18:55:02 +01:00
|
|
|
import React, { useEffect } from 'react';
|
2022-10-27 14:22:15 +02:00
|
|
|
import { IInput } from '../../../../interfaces/dialog';
|
2023-01-03 18:55:02 +01:00
|
|
|
import { UseFormRegisterReturn } from 'react-hook-form';
|
2022-05-03 15:08:28 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
2023-01-03 18:55:02 +01:00
|
|
|
register: UseFormRegisterReturn;
|
2022-08-09 23:50:14 +02:00
|
|
|
row: IInput;
|
2022-05-03 15:08:28 +02:00
|
|
|
index: number;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 13:47:37 +01:00
|
|
|
const useStyles = createStyles((theme) => ({
|
|
|
|
|
eyeIcon: {
|
|
|
|
|
color: theme.colors.dark[2],
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
2022-05-03 15:08:28 +02:00
|
|
|
const InputField: React.FC<Props> = (props) => {
|
2023-01-04 13:47:37 +01:00
|
|
|
const { classes } = useStyles();
|
|
|
|
|
|
2022-05-03 15:08:28 +02:00
|
|
|
return (
|
2023-01-04 13:47:37 +01:00
|
|
|
<>
|
|
|
|
|
{!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}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<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}
|
|
|
|
|
visibilityToggleIcon={({ reveal, size }) => (
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
icon={reveal ? 'eye-slash' : 'eye'}
|
|
|
|
|
fontSize={size}
|
|
|
|
|
cursor="pointer"
|
|
|
|
|
className={classes.eyeIcon}
|
|
|
|
|
fixedWidth
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2022-05-03 15:08:28 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default InputField;
|