import classNames from 'classnames'; import * as React from 'react'; import { ComponentClassNames } from '../shared/constants'; import { BasePasswordFieldProps, PasswordFieldProps, PasswordFieldType, ForwardRefPrimitive, Primitive, } from '../types'; import { ShowPasswordButton } from './ShowPasswordButton'; import { TextField } from '../TextField'; const PasswordFieldPrimitive: Primitive = ( { autoComplete = 'current-password', label, className, hideShowPassword = false, passwordIsHiddenLabel, passwordIsShownLabel, showPasswordButtonLabel, showPasswordButtonRef, size, hasError, ...rest }, ref ) => { const [type, setType] = React.useState('password'); const showPasswordOnClick = React.useCallback(() => { if (type === 'password') { setType('text'); } else { setType('password'); } }, [setType, type]); return ( ) } size={size} type={type} label={label} className={classNames(ComponentClassNames.PasswordField, className)} ref={ref} hasError={hasError} {...rest} /> ); }; /** * [📖 Docs](https://ui.docs.amplify.aws/react/components/passwordfield) */ export const PasswordField: ForwardRefPrimitive< BasePasswordFieldProps, 'input' > = React.forwardRef(PasswordFieldPrimitive); PasswordField.displayName = 'PasswordField';