UNPKG

@yamada-ui/password-input

Version:

Yamada UI password input component

103 lines (102 loc) 3.42 kB
"use client" "use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/use-password-input.tsx var use_password_input_exports = {}; __export(use_password_input_exports, { usePasswordInput: () => usePasswordInput }); module.exports = __toCommonJS(use_password_input_exports); var import_core = require("@yamada-ui/core"); var import_form_control = require("@yamada-ui/form-control"); var import_use_controllable_state = require("@yamada-ui/use-controllable-state"); var import_utils = require("@yamada-ui/utils"); var import_react = require("react"); var usePasswordInput = (props) => { const { defaultIsVisible, defaultVisible = defaultIsVisible, isVisible, visible: visibleProp = isVisible, onVisibleChange, ...rest } = (0, import_form_control.useFormControlProps)(props); const { "aria-readonly": ariaReadonly, ...formControlProps } = (0, import_utils.pickObject)( rest, import_form_control.formControlProperties ); const [containerProps, inputProps] = (0, import_utils.splitObject)(rest, import_core.layoutStyleProperties); const { disabled } = formControlProps; const [visible, setVisible] = (0, import_use_controllable_state.useControllableState)({ defaultValue: defaultVisible, value: visibleProp, onChange: onVisibleChange }); const onPointerDown = (0, import_react.useCallback)( (ev) => { if (disabled || ev.button !== 0) return; ev.preventDefault(); setVisible((prev) => !prev); }, [disabled, setVisible] ); const getContainerProps = (0, import_react.useCallback)( (props2 = {}, ref = null) => ({ ref, ...containerProps, ...formControlProps, ...props2 }), [containerProps, formControlProps] ); const getInputProps = (0, import_react.useCallback)( (props2 = {}, ref = null) => ({ ref, type: visible ? "text" : "password", ...inputProps, "aria-readonly": ariaReadonly, ...formControlProps, ...props2 }), [visible, inputProps, ariaReadonly, formControlProps] ); const getIconProps = (0, import_react.useCallback)( (props2 = {}, ref = null) => ({ ref, "aria-label": "Toggle password visibility", tabIndex: -1, ...formControlProps, ...props2, onPointerDown: (0, import_utils.handlerAll)(props2.onPointerDown, onPointerDown) }), [formControlProps, onPointerDown] ); return { setVisible, visible, getContainerProps, getIconProps, getInputProps }; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { usePasswordInput }); //# sourceMappingURL=use-password-input.js.map