2022-12-16 15:00:01 +01:00
|
|
|
import { TextInput } from '@mantine/core';
|
2022-08-27 15:58:36 +02:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
|
import { useEffect } from 'react';
|
2022-10-27 14:22:15 +02:00
|
|
|
import { IInput } from '../../../../interfaces/dialog';
|
2022-05-03 15:08:28 +02:00
|
|
|
|
|
|
|
|
interface Props {
|
2022-08-09 23:50:14 +02:00
|
|
|
row: IInput;
|
2022-05-03 15:08:28 +02:00
|
|
|
index: number;
|
2022-08-09 23:50:14 +02:00
|
|
|
handleChange: (value: string, index: number) => void;
|
2022-05-03 15:08:28 +02:00
|
|
|
passwordStates: boolean[];
|
|
|
|
|
handlePasswordStates: (index: number) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const InputField: React.FC<Props> = (props) => {
|
2022-08-05 15:10:37 +02:00
|
|
|
useEffect(() => {
|
2022-08-27 15:58:36 +02:00
|
|
|
if (props.row.default) props.handleChange(props.row.default, props.index);
|
2022-08-05 15:10:37 +02:00
|
|
|
}, []);
|
|
|
|
|
|
2022-05-03 15:08:28 +02:00
|
|
|
return (
|
2022-12-16 15:00:01 +01:00
|
|
|
<TextInput
|
|
|
|
|
label={props.row.label}
|
|
|
|
|
description={props.row.description}
|
|
|
|
|
icon={props.row.icon && <FontAwesomeIcon icon={props.row.icon} fixedWidth />}
|
|
|
|
|
placeholder={props.row.placeholder}
|
|
|
|
|
defaultValue={props.row.default}
|
|
|
|
|
disabled={props.row.disabled}
|
|
|
|
|
type={!props.row.password || props.passwordStates[props.index] ? 'text' : 'password'}
|
|
|
|
|
rightSection={
|
|
|
|
|
props.row.password && (
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
onClick={() => props.handlePasswordStates(props.index)}
|
|
|
|
|
cursor="pointer"
|
|
|
|
|
icon={props.passwordStates[props.index] ? 'eye' : 'eye-slash'}
|
|
|
|
|
fixedWidth
|
2022-05-03 15:08:28 +02:00
|
|
|
/>
|
2022-12-16 15:00:01 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
/>
|
2022-05-03 15:08:28 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default InputField;
|