mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
* feat(interface/dialog): readonly, disabled flags * Update TS prop types * refactor(web/input): remove read only property Co-authored-by: davidxd33 <dponce@gmail.com>
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { Box, InputGroup, InputLeftElement, InputRightElement, Text, Input } from '@chakra-ui/react';
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
import { useEffect } from 'react';
|
|
import { IInput } from '../../../interfaces/dialog';
|
|
|
|
interface Props {
|
|
row: IInput;
|
|
index: number;
|
|
handleChange: (value: string, index: number) => void;
|
|
passwordStates: boolean[];
|
|
handlePasswordStates: (index: number) => void;
|
|
}
|
|
|
|
const InputField: React.FC<Props> = (props) => {
|
|
useEffect(() => {
|
|
if (props.row.default) props.handleChange(props.row.default, props.index);
|
|
}, []);
|
|
|
|
return (
|
|
<>
|
|
<Box mb={3} textAlign="left">
|
|
<Text>{props.row.label}</Text>
|
|
<InputGroup>
|
|
{props.row.icon && (
|
|
<InputLeftElement pointerEvents="none" children={<FontAwesomeIcon icon={props.row.icon} fixedWidth />} />
|
|
)}
|
|
<Input
|
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => props.handleChange(e.target.value, props.index)}
|
|
placeholder={props.row.placeholder}
|
|
defaultValue={props.row.default}
|
|
type={!props.row.password || props.passwordStates[props.index] ? 'text' : 'password'}
|
|
isDisabled={props.row.disabled}
|
|
/>
|
|
{props.row.password && (
|
|
<InputRightElement
|
|
cursor="pointer"
|
|
onClick={() => props.handlePasswordStates(props.index)}
|
|
children={
|
|
<FontAwesomeIcon
|
|
fixedWidth
|
|
icon={props.passwordStates[props.index] ? 'eye' : 'eye-slash'}
|
|
fontSize="1em"
|
|
style={{ paddingRight: 8 }}
|
|
/>
|
|
}
|
|
/>
|
|
)}
|
|
</InputGroup>
|
|
</Box>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default InputField;
|