{
"type": "composition",
"npmDependencies": [
"react-icons"
],
"fileDependencies": [],
"id": "password-input",
"file": {
"name": "password-input.tsx",
"content": "\"use client\"\n\nimport type {\n ButtonProps,\n GroupProps,\n InputProps,\n StackProps,\n} from \"@chakra-ui/react\"\nimport {\n Box,\n HStack,\n IconButton,\n Input,\n InputGroup,\n Stack,\n mergeRefs,\n useControllableState,\n} from \"@chakra-ui/react\"\nimport * as React from \"react\"\nimport { LuEye, LuEyeOff } from \"react-icons/lu\"\n\nexport interface PasswordVisibilityProps {\n defaultVisible?: boolean\n visible?: boolean\n onVisibleChange?: (visible: boolean) => void\n visibilityIcon?: { on: React.ReactNode; off: React.ReactNode }\n}\n\nexport interface PasswordInputProps\n extends InputProps,\n PasswordVisibilityProps {\n rootProps?: GroupProps\n}\n\nexport const PasswordInput = React.forwardRef<\n HTMLInputElement,\n PasswordInputProps\n>(function PasswordInput(props, ref) {\n const {\n rootProps,\n defaultVisible,\n visible: visibleProp,\n onVisibleChange,\n visibilityIcon = { on: , off: },\n ...rest\n } = props\n\n const [visible, setVisible] = useControllableState({\n value: visibleProp,\n defaultValue: defaultVisible || false,\n onChange: onVisibleChange,\n })\n\n const inputRef = React.useRef(null)\n\n return (\n {\n if (rest.disabled) return\n if (e.button !== 0) return\n e.preventDefault()\n setVisible(!visible)\n }}\n >\n {visible ? visibilityIcon.off : visibilityIcon.on}\n \n }\n {...rootProps}\n >\n \n \n )\n})\n\nconst VisibilityTrigger = React.forwardRef(\n function VisibilityTrigger(props, ref) {\n return (\n \n )\n },\n)\n\ninterface PasswordStrengthMeterProps extends StackProps {\n max?: number\n value: number\n}\n\nexport const PasswordStrengthMeter = React.forwardRef<\n HTMLDivElement,\n PasswordStrengthMeterProps\n>(function PasswordStrengthMeter(props, ref) {\n const { max = 4, value, ...rest } = props\n\n const percent = (value / max) * 100\n const { label, colorPalette } = getColorPalette(percent)\n\n return (\n \n \n {Array.from({ length: max }).map((_, index) => (\n \n ))}\n \n {label && {label}}\n \n )\n})\n\nfunction getColorPalette(percent: number) {\n switch (true) {\n case percent < 33:\n return { label: \"Low\", colorPalette: \"red\" }\n case percent < 66:\n return { label: \"Medium\", colorPalette: \"orange\" }\n default:\n return { label: \"High\", colorPalette: \"green\" }\n }\n}\n"
},
"component": "PasswordInput"
}