mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 15:06:02 +01:00
refactor(web/input): use mantine password field component
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { TextInput } from '@mantine/core';
|
||||
import { createStyles, PasswordInput, TextInput } from '@mantine/core';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import React, { useEffect } from 'react';
|
||||
import { IInput } from '../../../../interfaces/dialog';
|
||||
@@ -8,32 +8,50 @@ interface Props {
|
||||
register: UseFormRegisterReturn;
|
||||
row: IInput;
|
||||
index: number;
|
||||
passwordStates: boolean[];
|
||||
handlePasswordStates: (index: number) => void;
|
||||
}
|
||||
|
||||
const useStyles = createStyles((theme) => ({
|
||||
eyeIcon: {
|
||||
color: theme.colors.dark[2],
|
||||
},
|
||||
}));
|
||||
|
||||
const InputField: React.FC<Props> = (props) => {
|
||||
const { classes } = useStyles();
|
||||
|
||||
return (
|
||||
<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}
|
||||
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
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<>
|
||||
{!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
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user