import { composeEventHandlers } from "@radix-ui/primitive" import { Primitive } from "@radix-ui/react-primitive" import { useControllableState } from "@radix-ui/react-use-controllable-state" import type { ComponentProps, ReactNode } from "react" import { createContext, useContext, useMemo } from "react" export type PasswordInputContextProps = Required< Pick > const PasswordInputContext = createContext({ visible: false, onVisibleChange: () => {}, }) export const usePasswordInputContext = () => useContext(PasswordInputContext) export interface PasswordInputProps { visible?: boolean defaultVisible?: boolean onVisibleChange?: (visible: boolean) => void children?: ReactNode } const PasswordInput = ({ visible: visibleProp, defaultVisible, onVisibleChange, children, }: PasswordInputProps) => { const [visible = false, setVisible] = useControllableState({ prop: visibleProp, defaultProp: defaultVisible ?? false, onChange: onVisibleChange, }) const contextValue = useMemo( () => ({ visible, onVisibleChange: setVisible, }), [visible, setVisible], ) return ( {children} ) } PasswordInput.displayName = "PasswordInput" const PasswordInputInput = ({ ref, ...props }: ComponentProps) => { const { visible } = usePasswordInputContext() return } PasswordInputInput.displayName = "PasswordInputInput" const PasswordInputToggle = ({ onClick, ...props }: ComponentProps) => { const { visible, onVisibleChange } = usePasswordInputContext() return ( onVisibleChange(!visible))} {...props} /> ) } PasswordInputToggle.displayName = "PasswordInputToggle" const PasswordInputIndicator = ({ ...props }: ComponentProps) => { const { visible } = usePasswordInputContext() return (