UNPKG

@yamada-ui/password-input

Version:

Yamada UI password input component

96 lines (95 loc) 3.62 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/password-input-strength-meter.tsx var password_input_strength_meter_exports = {}; __export(password_input_strength_meter_exports, { PasswordInputStrengthMeter: () => PasswordInputStrengthMeter }); module.exports = __toCommonJS(password_input_strength_meter_exports); var import_core = require("@yamada-ui/core"); var import_utils = require("@yamada-ui/utils"); var import_jsx_runtime = require("react/jsx-runtime"); var getDefaultStrengthMeterIndicatorProps = (percent) => { switch (true) { case percent < 33: return { label: "Low", _selected: { bg: "red.500" } }; case percent < 66: return { label: "Medium", _selected: { bg: "orange.500" } }; default: return { label: "High", _selected: { bg: "green.500" } }; } }; var PasswordInputStrengthMeter = (0, import_core.forwardRef)((props, ref) => { const [ styles, { className, max = 4, value, withLabel = true, getStrengthMeterIndicatorProps = getDefaultStrengthMeterIndicatorProps, ...rest } ] = (0, import_core.useComponentMultiStyle)("PasswordInput", props); const percent = value / max * 100; const { label, ...indicatorProps } = getStrengthMeterIndicatorProps(percent); return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( import_core.ui.div, { ref, className: (0, import_utils.cx)("ui-password-input__strength-meter", className), "aria-label": "Password strength meter", "aria-valuemax": max, "aria-valuemin": 0, "aria-valuenow": value, role: "meter", __css: { ...styles.strengthMeter }, ...rest, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_core.ui.div, { ref, className: "ui-password-input__strength-meter-indicators", __css: { ...styles.strengthMeterIndicators }, ...rest, children: Array.from({ length: max }).map((_, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_core.ui.div, { "data-selected": (0, import_utils.dataAttr)(index < value), __css: { ...styles.strengthMeterIndicator }, ...indicatorProps }, index )) } ), withLabel && label ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ui.span, { __css: { ...styles.strengthMeterLabel }, children: label }) : null ] } ); }); PasswordInputStrengthMeter.displayName = "PasswordInputStrengthMeter"; PasswordInputStrengthMeter.__ui__ = "PasswordInputStrengthMeter"; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { PasswordInputStrengthMeter }); //# sourceMappingURL=password-input-strength-meter.js.map