{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-password-strength",
  "type": "registry:component",
  "title": "Password Strength Input",
  "description": "A password field with a show and hide button, a four segment strength bar and a checklist of rules that tick as they are met.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "password",
    "input",
    "strength",
    "validation",
    "show hide",
    "form"
  ],
  "docs": "https://hyperblur.dev/effects/input-password-strength",
  "files": [
    {
      "path": "registry/hyperblur/input-password-strength.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/input-password-strength.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PasswordRule {\n  label: string;\n  test: (value: string) => boolean;\n}\n\nexport interface InputPasswordStrengthProps\n  extends Omit<React.InputHTMLAttributes<HTMLInputElement>, \"type\" | \"size\" | \"value\" | \"defaultValue\" | \"onChange\"> {\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string, level: number) => void;\n  label?: string;\n  rules?: PasswordRule[];\n  showRules?: boolean;\n  accent?: string;\n}\n\nconst defaultRules: PasswordRule[] = [\n  { label: \"8+ characters\", test: (v) => v.length >= 8 },\n  { label: \"Upper & lower case\", test: (v) => /[a-z]/.test(v) && /[A-Z]/.test(v) },\n  { label: \"A number\", test: (v) => /\\d/.test(v) },\n  { label: \"A symbol\", test: (v) => /[^A-Za-z0-9]/.test(v) },\n];\n\nconst levelLabels = [\"\", \"Weak\", \"Fair\", \"Good\", \"Strong\"];\nconst levelColors = [\"#3a3a3a\", \"#ff5d6c\", \"#ffa23a\", \"#ffd23a\", \"#34d27b\"];\n\nconst css = `\n.hb-qn6 {\n  box-sizing: border-box;\n  width: 100%;\n  font: inherit;\n  color: #ededed;\n}\n.hb-qn6 *, .hb-qn6 *::before, .hb-qn6 *::after { box-sizing: border-box; }\n.hb-qn6-lab { display: block; margin: 0 0 6px 2px; font-size: 13px; font-weight: 500; color: #a1a1a1; }\n.hb-qn6-field {\n  display: flex;\n  align-items: center;\n  height: 46px;\n  border: 1px solid #262626;\n  border-radius: 12px;\n  background: #111;\n  transition: border-color 0.2s ease, box-shadow 0.2s ease;\n}\n.hb-qn6-field:hover { border-color: #3a3a3a; }\n.hb-qn6-field:focus-within {\n  border-color: var(--hb-qn6-a);\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-qn6-a) 18%, transparent);\n}\n.hb-qn6-in {\n  flex: 1;\n  min-width: 0;\n  height: 100%;\n  margin: 0;\n  padding: 0 4px 0 14px;\n  border: 0;\n  outline: 0;\n  background: transparent;\n  color: #ededed;\n  font: inherit;\n  font-size: 15px;\n}\n.hb-qn6-in::placeholder { color: #5f5f5f; }\n.hb-qn6-in:disabled { cursor: not-allowed; opacity: 0.5; }\n.hb-qn6-eye {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 34px;\n  height: 34px;\n  margin: 0 5px 0 0;\n  padding: 0;\n  border: 0;\n  border-radius: 9px;\n  background: transparent;\n  color: #8f8f8f;\n  cursor: pointer;\n  transition: background 0.2s ease, color 0.2s ease;\n}\n.hb-qn6-eye:hover { background: #1c1c1c; color: #ededed; }\n.hb-qn6-eye:focus-visible { outline: 2px solid var(--hb-qn6-a); outline-offset: 1px; }\n.hb-qn6-eye svg { width: 18px; height: 18px; display: block; overflow: visible; }\n.hb-qn6-eye path, .hb-qn6-eye circle { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }\n.hb-qn6-slash {\n  stroke-dasharray: 1 1.1;\n  stroke-dashoffset: 1.05;\n  transition: stroke-dashoffset 0.3s cubic-bezier(0.6, 0, 0.3, 1);\n}\n.hb-qn6-eye[aria-pressed=\"true\"] .hb-qn6-slash { stroke-dashoffset: 0; }\n.hb-qn6-meter { display: flex; align-items: center; gap: 10px; margin-top: 10px; }\n.hb-qn6-bars { display: grid; flex: 1; grid-template-columns: repeat(4, 1fr); gap: 5px; }\n.hb-qn6-seg { position: relative; height: 4px; overflow: hidden; border-radius: 4px; background: #232323; }\n.hb-qn6-seg::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  border-radius: inherit;\n  background: var(--hb-qn6-lc);\n  transform: scaleX(0);\n  transform-origin: left center;\n  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.3s ease;\n}\n.hb-qn6-seg[data-on=\"true\"]::after { transform: scaleX(1); }\n.hb-qn6-seg:nth-child(2)::after { transition-delay: 0.04s; }\n.hb-qn6-seg:nth-child(3)::after { transition-delay: 0.08s; }\n.hb-qn6-seg:nth-child(4)::after { transition-delay: 0.12s; }\n.hb-qn6-lvl { min-width: 44px; font-size: 12px; font-weight: 600; text-align: right; color: var(--hb-qn6-lc); transition: color 0.3s ease; }\n.hb-qn6-rules { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 6px 12px; margin: 10px 0 0; padding: 0; list-style: none; }\n.hb-qn6-rule { display: flex; align-items: center; gap: 7px; min-width: 0; font-size: 12.5px; color: #8f8f8f; transition: color 0.25s ease; }\n.hb-qn6-rule[data-ok=\"true\"] { color: #ededed; }\n.hb-qn6-tick {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 16px;\n  height: 16px;\n  border: 1.5px solid #3a3a3a;\n  border-radius: 50%;\n  transition: border-color 0.25s ease, background 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.7, 0.64, 1);\n}\n.hb-qn6-rule[data-ok=\"true\"] .hb-qn6-tick { border-color: #34d27b; background: #34d27b; transform: scale(1.05); }\n.hb-qn6-tick svg { width: 10px; height: 10px; display: block; overflow: visible; }\n.hb-qn6-tick path {\n  fill: none;\n  stroke: #06130c;\n  stroke-width: 3;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n  stroke-dasharray: 1 1.1;\n  stroke-dashoffset: 1.05;\n  transition: stroke-dashoffset 0.25s cubic-bezier(0.6, 0, 0.3, 1);\n}\n.hb-qn6-rule[data-ok=\"true\"] .hb-qn6-tick path { stroke-dashoffset: 0; transition-delay: 0.08s; }\n.hb-qn6-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }\n@media (prefers-reduced-motion: reduce) {\n  .hb-qn6-field, .hb-qn6-eye, .hb-qn6-slash, .hb-qn6-seg::after, .hb-qn6-lvl, .hb-qn6-rule, .hb-qn6-tick, .hb-qn6-tick path { transition: none; }\n}\n`;\n\nexport function InputPasswordStrength({\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  label = \"Password\",\n  rules = defaultRules,\n  showRules = true,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  id,\n  autoComplete = \"new-password\",\n  ...rest\n}: InputPasswordStrengthProps) {\n  const autoId = React.useId();\n  const inputId = id ?? autoId;\n  const rulesId = `${inputId}-rules`;\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState(defaultValue);\n  const [visible, setVisible] = React.useState(false);\n  const current = controlled ? value : inner;\n\n  const passed = rules.map((rule) => rule.test(current));\n  const count = passed.filter(Boolean).length;\n  const level = current.length === 0 ? 0 : rules.length === 0 ? 4 : Math.max(1, Math.round((count / rules.length) * 4));\n\n  const vars = {\n    \"--hb-qn6-a\": accent,\n    \"--hb-qn6-lc\": levelColors[level],\n    ...style,\n  } as React.CSSProperties;\n\n  function handleChange(e: React.ChangeEvent<HTMLInputElement>) {\n    const next = e.target.value;\n    if (!controlled) setInner(next);\n    const nextCount = rules.filter((rule) => rule.test(next)).length;\n    const nextLevel = next.length === 0 ? 0 : rules.length === 0 ? 4 : Math.max(1, Math.round((nextCount / rules.length) * 4));\n    onValueChange?.(next, nextLevel);\n  }\n\n  return (\n    <>\n      <style href=\"hb-input-password-strength\" precedence=\"default\">{css}</style>\n      <div className={`hb-qn6 ${className}`} style={vars}>\n        <label className=\"hb-qn6-lab\" htmlFor={inputId}>\n          {label}\n        </label>\n        <div className=\"hb-qn6-field\">\n          <input\n            id={inputId}\n            className=\"hb-qn6-in\"\n            type={visible ? \"text\" : \"password\"}\n            value={current}\n            onChange={handleChange}\n            autoComplete={autoComplete}\n            autoCapitalize=\"none\"\n            spellCheck={false}\n            aria-describedby={showRules ? rulesId : undefined}\n            {...rest}\n          />\n          <button\n            type=\"button\"\n            className=\"hb-qn6-eye\"\n            aria-pressed={visible}\n            aria-label={visible ? \"Hide password\" : \"Show password\"}\n            onClick={() => setVisible((v) => !v)}\n          >\n            <svg viewBox=\"0 0 24 24\" focusable=\"false\" aria-hidden=\"true\">\n              <path d=\"M2.5 12s3.6-6.5 9.5-6.5S21.5 12 21.5 12s-3.6 6.5-9.5 6.5S2.5 12 2.5 12z\" />\n              <circle cx=\"12\" cy=\"12\" r=\"2.8\" />\n              <path className=\"hb-qn6-slash\" d=\"M4 4l16 16\" pathLength=\"1\" />\n            </svg>\n          </button>\n        </div>\n        <div className=\"hb-qn6-meter\">\n          <div className=\"hb-qn6-bars\" aria-hidden=\"true\">\n            {[1, 2, 3, 4].map((n) => (\n              <span key={n} className=\"hb-qn6-seg\" data-on={level >= n} />\n            ))}\n          </div>\n          <span className=\"hb-qn6-lvl\" aria-hidden=\"true\">\n            {levelLabels[level]}\n          </span>\n          <span className=\"hb-qn6-sr\" role=\"status\" aria-live=\"polite\">\n            {level > 0 ? `Password strength: ${levelLabels[level]}` : \"\"}\n          </span>\n        </div>\n        {showRules ? (\n          <ul id={rulesId} className=\"hb-qn6-rules\">\n            {rules.map((rule, i) => (\n              <li key={rule.label} className=\"hb-qn6-rule\" data-ok={passed[i]}>\n                <span className=\"hb-qn6-tick\" aria-hidden=\"true\">\n                  <svg viewBox=\"0 0 12 12\" focusable=\"false\">\n                    <path d=\"M2.4 6.3l2.4 2.4 4.8-5.4\" pathLength=\"1\" />\n                  </svg>\n                </span>\n                <span>\n                  {rule.label}\n                  <span className=\"hb-qn6-sr\">{passed[i] ? \" (met)\" : \" (not met)\"}</span>\n                </span>\n              </li>\n            ))}\n          </ul>\n        ) : null}\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}