2023-01-04 13:47:37 +01:00
|
|
|
import { createStyles, PasswordInput, TextInput } from '@mantine/core';
|
2023-02-13 21:24:33 +01:00
|
|
|
import React from 'react';
|
2023-02-15 13:00:09 +01:00
|
|
|
import { IInput } from '../../../../typings/dialog';
|
2023-01-03 18:55:02 +01:00
|
|
|
import { UseFormRegisterReturn } from 'react-hook-form';
|
2023-11-15 15:28:21 +01:00
|
|
|
import LibIcon from '../../../../components/LibIcon';
|
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}
|
2023-11-15 15:28:21 +01:00
|
|
|
icon={props.row.icon && <LibIcon icon={props.row.icon} fixedWidth />}
|
2023-01-04 13:47:37 +01:00
|
|
|
placeholder={props.row.placeholder}
|
2023-05-08 23:00:47 +01:00
|
|
|
minLength={props.row.min}
|
|
|
|
|
maxLength={props.row.max}
|
2023-01-04 13:47:37 +01:00
|
|
|
disabled={props.row.disabled}
|
2023-01-08 11:35:30 +01:00
|
|
|
withAsterisk={props.row.required}
|
2023-01-04 13:47:37 +01:00
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<PasswordInput
|
|
|
|
|
{...props.register}
|
|
|
|
|
defaultValue={props.row.default}
|
|
|
|
|
label={props.row.label}
|
|
|
|
|
description={props.row.description}
|
2023-11-15 15:28:21 +01:00
|
|
|
icon={props.row.icon && <LibIcon icon={props.row.icon} fixedWidth />}
|
2023-01-04 13:47:37 +01:00
|
|
|
placeholder={props.row.placeholder}
|
2023-05-08 23:00:47 +01:00
|
|
|
minLength={props.row.min}
|
|
|
|
|
maxLength={props.row.max}
|
2023-01-04 13:47:37 +01:00
|
|
|
disabled={props.row.disabled}
|
2023-01-08 11:35:30 +01:00
|
|
|
withAsterisk={props.row.required}
|
2023-01-04 13:47:37 +01:00
|
|
|
visibilityToggleIcon={({ reveal, size }) => (
|
2023-11-15 15:28:21 +01:00
|
|
|
<LibIcon
|
2023-01-04 13:47:37 +01:00
|
|
|
icon={reveal ? 'eye-slash' : 'eye'}
|
|
|
|
|
fontSize={size}
|
|
|
|
|
cursor="pointer"
|
|
|
|
|
className={classes.eyeIcon}
|
|
|
|
|
fixedWidth
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2022-05-03 15:08:28 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default InputField;
|