mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
'use client';
|
|
|
|
import { useState } from 'react';
|
|
|
|
import { Icon } from '@iconify/react';
|
|
import TextInput, { TextInputProps } from '@/components/input/TextInput';
|
|
import Button from '@/components/Button';
|
|
|
|
type PasswordInputProps = Omit<
|
|
TextInputProps,
|
|
'type' | 'startAdornment' | 'endAdornment'
|
|
>;
|
|
|
|
const PasswordInput = (props: PasswordInputProps) => {
|
|
const [type, setType] = useState('password');
|
|
|
|
const showPasswordHandler = () => {
|
|
setType((prevType) => {
|
|
if (prevType === 'password') return 'text';
|
|
|
|
return 'password';
|
|
});
|
|
};
|
|
|
|
return (
|
|
<TextInput
|
|
{...props}
|
|
type={type}
|
|
endAdornment={
|
|
<Button
|
|
tabIndex={-1}
|
|
type='button'
|
|
variant='ghost'
|
|
onClick={showPasswordHandler}
|
|
className='btn btn-ghost w-fit h-fit p-2 rounded-full'
|
|
disabled={props.disabled}
|
|
>
|
|
<Icon
|
|
icon={type === 'password' ? 'mdi:eye' : 'mdi:eye-off'}
|
|
width={16}
|
|
height={16}
|
|
/>
|
|
</Button>
|
|
}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default PasswordInput;
|