mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
refactor: password input component
This commit is contained in:
@ -1,9 +1,6 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import { Eye, EyeOff } from 'lucide-react';
|
|
||||||
|
|
||||||
import { cn } from '../lib/utils';
|
import { cn } from '../lib/utils';
|
||||||
import { Button } from './button';
|
|
||||||
|
|
||||||
export type InputProps = React.InputHTMLAttributes<HTMLInputElement>;
|
export type InputProps = React.InputHTMLAttributes<HTMLInputElement>;
|
||||||
|
|
||||||
@ -28,38 +25,4 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|||||||
|
|
||||||
Input.displayName = 'Input';
|
Input.displayName = 'Input';
|
||||||
|
|
||||||
const PasswordInput = React.forwardRef<HTMLInputElement, InputProps>(
|
export { Input };
|
||||||
({ className, ...props }, ref) => {
|
|
||||||
const [showPassword, setShowPassword] = React.useState(false);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="relative">
|
|
||||||
<Input
|
|
||||||
id="password"
|
|
||||||
type={showPassword ? 'text' : 'password'}
|
|
||||||
className={cn('pr-10', className)}
|
|
||||||
ref={ref}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
variant="link"
|
|
||||||
type="button"
|
|
||||||
className="absolute right-0 top-0 flex h-full items-center justify-center pr-3"
|
|
||||||
aria-label={showPassword ? 'Mask password' : 'Reveal password'}
|
|
||||||
onClick={() => setShowPassword((show) => !show)}
|
|
||||||
>
|
|
||||||
{showPassword ? (
|
|
||||||
<EyeOff aria-hidden className="text-muted-foreground h-5 w-5" />
|
|
||||||
) : (
|
|
||||||
<Eye aria-hidden className="text-muted-foreground h-5 w-5" />
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
PasswordInput.displayName = 'Input';
|
|
||||||
|
|
||||||
export { Input, PasswordInput };
|
|
||||||
|
|||||||
Reference in New Issue
Block a user