UNPKG

@yamada-ui/password-input

Version:

Yamada UI password input component

83 lines (81 loc) 2.19 kB
"use client" // src/use-password-input.tsx import { layoutStyleProperties } from "@yamada-ui/core"; import { formControlProperties, useFormControlProps } from "@yamada-ui/form-control"; import { useControllableState } from "@yamada-ui/use-controllable-state"; import { handlerAll, pickObject, splitObject } from "@yamada-ui/utils"; import { useCallback } from "react"; var usePasswordInput = (props) => { const { defaultIsVisible, defaultVisible = defaultIsVisible, isVisible, visible: visibleProp = isVisible, onVisibleChange, ...rest } = useFormControlProps(props); const { "aria-readonly": ariaReadonly, ...formControlProps } = pickObject( rest, formControlProperties ); const [containerProps, inputProps] = splitObject(rest, layoutStyleProperties); const { disabled } = formControlProps; const [visible, setVisible] = useControllableState({ defaultValue: defaultVisible, value: visibleProp, onChange: onVisibleChange }); const onPointerDown = useCallback( (ev) => { if (disabled || ev.button !== 0) return; ev.preventDefault(); setVisible((prev) => !prev); }, [disabled, setVisible] ); const getContainerProps = useCallback( (props2 = {}, ref = null) => ({ ref, ...containerProps, ...formControlProps, ...props2 }), [containerProps, formControlProps] ); const getInputProps = useCallback( (props2 = {}, ref = null) => ({ ref, type: visible ? "text" : "password", ...inputProps, "aria-readonly": ariaReadonly, ...formControlProps, ...props2 }), [visible, inputProps, ariaReadonly, formControlProps] ); const getIconProps = useCallback( (props2 = {}, ref = null) => ({ ref, "aria-label": "Toggle password visibility", tabIndex: -1, ...formControlProps, ...props2, onPointerDown: handlerAll(props2.onPointerDown, onPointerDown) }), [formControlProps, onPointerDown] ); return { setVisible, visible, getContainerProps, getIconProps, getInputProps }; }; export { usePasswordInput }; //# sourceMappingURL=chunk-VRAZOS6L.mjs.map