feat: add password input with show and hide

This commit is contained in:
rajun 2026-10-27 16:28:56 +05:30
parent c560a86f97
commit 7e3f875f35

View 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>}
</>
);
}