@navinc/base-react-components
Version:
Nav's Pattern Library
31 lines (28 loc) • 902 B
JavaScript
import React, { useState } from 'react'
import styled from 'styled-components'
import Input from './input.js'
export const PasswordInput = ({
isPasswordShown,
passwordStrengthScore,
requiredPasswordScore,
className,
...props
}) => {
const [isPasswordShownState, setIsPasswordShownState] = useState(isPasswordShown)
const handleToggleShowPassword = () => {
setIsPasswordShownState((isPasswordShownState) => !isPasswordShownState)
}
return (
<Input
className={className}
helperText={`${isPasswordShownState ? 'Hide' : 'Show'} password`}
helperLinkAction={handleToggleShowPassword}
type={isPasswordShownState ? 'text' : 'password'}
passwordStrengthScore={passwordStrengthScore}
requiredPasswordScore={requiredPasswordScore}
{...props}
/>
)
}
const StyledPasswordInput = styled(PasswordInput)``
export default StyledPasswordInput