36 lines
949 B
TypeScript
36 lines
949 B
TypeScript
import { Eye, EyeOff } from 'lucide-react';
|
|
import { useState } from 'react';
|
|
import { Box } from './Box';
|
|
import { IconButton } from './IconButton';
|
|
import { Input, InputProps } from './Input';
|
|
|
|
export interface PasswordFieldProps extends InputProps {}
|
|
|
|
export const PasswordField = (props: PasswordFieldProps) => {
|
|
const [showPassword, setShowPassword] = useState(false);
|
|
|
|
return (
|
|
<Box position="relative">
|
|
<Input
|
|
{...props}
|
|
type={showPassword ? 'text' : 'password'}
|
|
/>
|
|
<Box
|
|
position="absolute"
|
|
right="0.5rem"
|
|
top="50%"
|
|
style={{ transform: 'translateY(-50%)' }}
|
|
zIndex={10}
|
|
>
|
|
<IconButton
|
|
icon={showPassword ? EyeOff : Eye}
|
|
onClick={() => setShowPassword(!showPassword)}
|
|
variant="ghost"
|
|
size="sm"
|
|
title={showPassword ? 'Hide password' : 'Show password'}
|
|
/>
|
|
</Box>
|
|
</Box>
|
|
);
|
|
};
|