mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 19:33:46 +00:00
e1e8410ba4
migrate pin page migrate copy tag migrate pin input migrate dropdown menus migrate radio buttons migrate switch migrate select migrate textarea migrate colour picker migrate select migrate context menu migrate viewparams remove chakra
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { PropsWithChildren, useState } from 'react';
|
|
import { UseFormRegister } from 'react-hook-form';
|
|
import { IoEyeOutline } from 'react-icons/io5';
|
|
import { Settings } from 'ontime-types';
|
|
|
|
import IconButton from '../../../../../common/components/buttons/IconButton';
|
|
import Input from '../../../../../common/components/input/input/Input';
|
|
import { isAlphanumeric } from '../../../../../common/utils/regex';
|
|
|
|
import style from './GeneralPinInput.module.scss';
|
|
|
|
interface GeneralPinInputProps {
|
|
register: UseFormRegister<Settings>;
|
|
formName: keyof Settings;
|
|
disabled?: boolean;
|
|
}
|
|
|
|
export default function GeneralPinInput({ register, formName, disabled }: PropsWithChildren<GeneralPinInputProps>) {
|
|
const [isVisible, setVisible] = useState(false);
|
|
|
|
return (
|
|
<div className={style.container}>
|
|
<Input
|
|
type={isVisible ? 'text' : 'password'}
|
|
maxLength={4}
|
|
{...register(formName, {
|
|
pattern: {
|
|
value: isAlphanumeric,
|
|
message: 'Only alphanumeric characters are allowed',
|
|
},
|
|
})}
|
|
placeholder='-'
|
|
disabled={disabled}
|
|
/>
|
|
<IconButton
|
|
onMouseDown={() => setVisible(true)}
|
|
onMouseUp={() => setVisible(false)}
|
|
variant='ghosted'
|
|
aria-label='Show pin code'
|
|
>
|
|
<IoEyeOutline />
|
|
</IconButton>
|
|
</div>
|
|
);
|
|
}
|