feat: add password input with show and hide
This commit is contained in:
parent
c560a86f97
commit
7e3f875f35
39
app/components/auth/form/password-input.tsx
Normal file
39
app/components/auth/form/password-input.tsx
Normal file
@ -0,0 +1,39 @@
|
||||
import { useState } from 'react';
|
||||
import { Lock } from 'lucide-react';
|
||||
import { Button } from '~/components/ui/button';
|
||||
import { IconInput } from '~/components/ui/icon-input';
|
||||
import { InlineMessage } from '~/components/ui/inline-message';
|
||||
import type { InputProps } from '~/components/ui/input';
|
||||
|
||||
export function PasswordInput(props: Omit<InputProps, 'type'>) {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [capsLock, setCapsLock] = useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
<IconInput
|
||||
icon={Lock}
|
||||
type={visible ? 'text' : 'password'}
|
||||
onKeyUp={(e) => setCapsLock(e.getModifierState('CapsLock'))}
|
||||
trailing={
|
||||
<Button
|
||||
type='button'
|
||||
variant='ghost'
|
||||
size='sm'
|
||||
aria-label={visible ? 'Hide password' : 'Show password'}
|
||||
aria-pressed={visible}
|
||||
onClick={() => setVisible((v) => !v)}
|
||||
>
|
||||
{visible ? 'Hide' : 'Show'}
|
||||
</Button>
|
||||
}
|
||||
{...props}
|
||||
onBlur={(e) => {
|
||||
setCapsLock(false);
|
||||
props.onBlur?.(e);
|
||||
}}
|
||||
/>
|
||||
{capsLock && <InlineMessage tone='warning'>Caps Lock is on</InlineMessage>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user