{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "password-input",
  "type": "registry:ui",
  "title": "Password Input",
  "description": "A password field with a button that shows and hides what was typed, a note when Caps Lock is on, and an optional list of the project's rules, each marked met or not met in words as the person types.",
  "categories": [
    "ui"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/cn",
    "@rivier-ui/input",
    "@rivier-ui/use-controllable-state"
  ],
  "files": [
    {
      "path": "registry/ui/password-input.tsx",
      "type": "registry:ui",
      "target": "components/ui/password-input.tsx",
      "content": "\"use client\";\n/**\n * @name password-input\n * @category ui\n * @description A password field with a button that shows and hides what was typed, a note when Caps Lock is on, and an optional list of the project's rules, each marked met or not met in words as the person types.\n * @when Signing in (current-password) or choosing a password (new-password, with `rules`). For a one-time code use otp-input; for other secrets that must never be shown, a plain input of type password.\n * @example\n * <PasswordInput\n *   aria-label=\"New password\"\n *   autoComplete=\"new-password\"\n *   rules={[\n *     { label: \"At least 12 characters\", test: (v) => v.length >= 12 },\n *     { label: \"A number\", test: (v) => /\\d/.test(v) },\n *   ]}\n * />\n */\nimport { Check, Eye, EyeOff, X } from \"lucide-react\";\nimport { useId, useState, type ComponentProps } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { useControllableState } from \"@/lib/use-controllable-state\";\nimport { inputVariants } from \"@/components/ui/input\";\n\nexport type PasswordRule = { label: string; test: (value: string) => boolean };\n\nexport type PasswordInputLabels = { show: string; hide: string; capsLock: string; met: string; notMet: string };\n\nconst LABELS: PasswordInputLabels = { show: \"Show password\", hide: \"Hide password\", capsLock: \"Caps Lock is on\", met: \"done\", notMet: \"not yet\" };\n\nexport type PasswordInputProps = Omit<ComponentProps<\"input\">, \"type\" | \"value\" | \"defaultValue\" | \"size\"> & {\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  /** Rules shown under the field, each marked as it is met. */\n  rules?: readonly PasswordRule[];\n  /** Shown: controlled. */\n  visible?: boolean;\n  defaultVisible?: boolean;\n  onVisibleChange?: (visible: boolean) => void;\n  labels?: Partial<PasswordInputLabels>;\n  invalid?: boolean;\n};\n\nexport function PasswordInput({\n  value,\n  defaultValue = \"\",\n  onValueChange,\n  rules,\n  visible: visibleProp,\n  defaultVisible = false,\n  onVisibleChange,\n  labels: given,\n  invalid,\n  className,\n  onChange,\n  onKeyDown,\n  onKeyUp,\n  disabled,\n  \"aria-describedby\": describedBy,\n  ...props\n}: PasswordInputProps) {\n  const labels = { ...LABELS, ...given };\n  const [text, setText] = useControllableState<string>({ value, defaultValue, onChange: onValueChange });\n  const [visible, setVisible] = useControllableState<boolean>({ value: visibleProp, defaultValue: defaultVisible, onChange: onVisibleChange });\n  const [caps, setCaps] = useState(false);\n  const rulesId = useId();\n  const capsId = useId();\n  const described = [describedBy, rules && rules.length > 0 ? rulesId : undefined, caps ? capsId : undefined].filter(Boolean).join(\" \") || undefined;\n  return (\n    <div data-slot=\"password-input\" className={cn(\"flex w-full min-w-0 flex-col gap-2\", className)}>\n      <div className=\"relative\">\n        <input\n          type={visible ? \"text\" : \"password\"}\n          value={text}\n          disabled={disabled}\n          aria-invalid={invalid || undefined}\n          aria-describedby={described}\n          spellCheck={false}\n          autoCapitalize=\"none\"\n          onChange={(event) => {\n            setText(event.target.value);\n            onChange?.(event);\n          }}\n          onKeyDown={(event) => {\n            setCaps(event.getModifierState(\"CapsLock\"));\n            onKeyDown?.(event);\n          }}\n          onKeyUp={(event) => {\n            setCaps(event.getModifierState(\"CapsLock\"));\n            onKeyUp?.(event);\n          }}\n          className={cn(inputVariants(), \"pe-12\")}\n          {...props}\n        />\n        <button\n          type=\"button\"\n          aria-pressed={visible}\n          aria-label={visible ? labels.hide : labels.show}\n          disabled={disabled}\n          onClick={() => setVisible(!visible)}\n          className=\"absolute inset-y-0 end-0 flex w-11 items-center justify-center rounded-e-control text-muted-foreground hover:text-foreground disabled:opacity-50\"\n        >\n          {visible ? <EyeOff aria-hidden=\"true\" className=\"size-4\" /> : <Eye aria-hidden=\"true\" className=\"size-4\" />}\n        </button>\n      </div>\n      {caps ? (\n        <p id={capsId} data-slot=\"password-input-caps\" className=\"text-sm\">\n          <span className=\"rounded-control bg-warning px-1.5 py-0.5 text-warning-foreground\">{labels.capsLock}</span>\n        </p>\n      ) : null}\n      {rules && rules.length > 0 ? (\n        <ul id={rulesId} data-slot=\"password-input-rules\" className=\"flex flex-col gap-1 text-sm\">\n          {rules.map((rule) => {\n            const met = rule.test(text);\n            return (\n              <li key={rule.label} data-met={met ? \"\" : undefined} className={cn(\"flex items-center gap-2\", met ? \"text-foreground\" : \"text-muted-foreground\")}>\n                {met ? <Check aria-hidden=\"true\" className=\"size-4 text-success\" /> : <X aria-hidden=\"true\" className=\"size-4\" />}\n                <span>\n                  {rule.label}\n                  <span className=\"sr-only\">: {met ? labels.met : labels.notMet}</span>\n                </span>\n              </li>\n            );\n          })}\n        </ul>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "ui",
    "when": "Signing in (current-password) or choosing a password (new-password, with `rules`). For a one-time code use otp-input; for other secrets that must never be shown, a plain input of type password.",
    "example": "<PasswordInput\n  aria-label=\"New password\"\n  autoComplete=\"new-password\"\n  rules={[\n    { label: \"At least 12 characters\", test: (v) => v.length >= 12 },\n    { label: \"A number\", test: (v) => /\\d/.test(v) },\n  ]}\n/>",
    "client": true
  }
}
