{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ink/password-input",
  "title": "Password Input",
  "description": "Password input with masked characters and reveal toggle",
  "dependencies": [
    "ink"
  ],
  "registryDependencies": [
    "https://termcn.dev/r/ink/interaction.json",
    "https://termcn.dev/r/ink/terminal-style.json",
    "https://termcn.dev/r/ink/terminal-symbols.json",
    "https://termcn.dev/r/ink/terminal-text.json",
    "https://termcn.dev/r/ink/types.json",
    "https://termcn.dev/r/ink/use-theme.json",
    "https://termcn.dev/r/ink/use-unicode.json"
  ],
  "files": [
    {
      "path": "registry/ui/password-input.tsx",
      "content": "import { useCursor, Box, Text } from \"ink\";\nimport React, { useEffect, useState } from \"react\";\n\nimport { useInteraction } from \"@/hooks/use-interaction\";\nimport { useTheme } from \"@/hooks/use-theme\";\nimport { useUnicode } from \"@/hooks/use-unicode\";\nimport { resolveBorderStyle } from \"@/lib/terminal-style\";\nimport { resolveTerminalSymbol } from \"@/lib/terminal-symbols\";\nimport {\n  cursorCellOffset,\n  graphemeLength,\n  removeGraphemeBefore,\n} from \"@/lib/terminal-text\";\nimport type { BorderStyle } from \"@/components/ui/types\";\n\nexport interface PasswordInputProps {\n  value?: string;\n  defaultValue?: string;\n  onValueChange?: (value: string) => void;\n  onChange?: (value: string) => void;\n  onSubmit?: (value: string) => void;\n  placeholder?: string;\n  mask?: string;\n  showToggle?: boolean;\n  label?: string;\n  id?: string;\n  autoFocus?: boolean;\n  isActive?: boolean;\n  disabled?: boolean;\n  readOnly?: boolean;\n  required?: boolean;\n  \"aria-label\"?: string;\n  cursorOrigin?: { x: number; y: number };\n  borderStyle?: BorderStyle;\n  paddingX?: number;\n  width?: number;\n  cursor?: string;\n}\n\nexport const PasswordInput = ({\n  value: controlledValue,\n  defaultValue = \"\",\n  onValueChange,\n  onChange,\n  onSubmit,\n  placeholder = \"\",\n  mask,\n  showToggle = false,\n  label,\n  id,\n  autoFocus = false,\n  isActive = true,\n  disabled = false,\n  readOnly = false,\n  required = false,\n  \"aria-label\": ariaLabel,\n  cursorOrigin,\n  borderStyle = \"round\",\n  paddingX = 1,\n  width,\n  cursor,\n}: PasswordInputProps) => {\n  const unicode = useUnicode();\n  const resolvedMask = mask ?? resolveTerminalSymbol(unicode, \"●\", \"*\");\n  const resolvedCursor = cursor ?? resolveTerminalSymbol(unicode, \"█\", \"|\");\n  const [internalValue, setInternalValue] = useState(defaultValue);\n  const [isVisible, setIsVisible] = useState(false);\n  const theme = useTheme();\n  const { setCursorPosition } = useCursor();\n\n  const value = controlledValue ?? internalValue;\n\n  const setValue = (newVal: string) => {\n    const changeHandler = onValueChange ?? onChange;\n    if (changeHandler) {\n      changeHandler(newVal);\n    } else {\n      setInternalValue(newVal);\n    }\n  };\n\n  const { isFocused } = useInteraction(\n    (input, key) => {\n      if (showToggle && key.ctrl && input === \"h\") {\n        setIsVisible((v) => !v);\n        return;\n      }\n\n      if (key.return) {\n        onSubmit?.(value);\n        return;\n      }\n\n      if (readOnly) {\n        return;\n      }\n\n      if (key.backspace) {\n        setValue(removeGraphemeBefore(value, graphemeLength(value)).value);\n        return;\n      }\n\n      if (key.escape || key.upArrow || key.downArrow || key.tab) {\n        return;\n      }\n\n      if (input && input.length > 0) {\n        setValue(value + input);\n      }\n    },\n    { autoFocus, disabled, id, isActive }\n  );\n\n  const valueLength = graphemeLength(value);\n  const displayValue = isVisible ? value : resolvedMask.repeat(valueLength);\n  const borderColor = isFocused ? theme.colors.focusRing : theme.colors.border;\n  const useNativeCursor = Boolean(cursorOrigin && isFocused);\n  useEffect(() => {\n    setCursorPosition(\n      useNativeCursor && cursorOrigin\n        ? {\n            x: cursorOrigin.x + cursorCellOffset(displayValue, valueLength),\n            y: cursorOrigin.y,\n          }\n        : undefined\n    );\n    return () => setCursorPosition(undefined);\n  }, [\n    cursorOrigin,\n    displayValue,\n    setCursorPosition,\n    useNativeCursor,\n    valueLength,\n  ]);\n\n  return (\n    <Box flexDirection=\"column\">\n      {label && <Text bold>{label}</Text>}\n      <Box flexDirection=\"row\" alignItems=\"center\" gap={1}>\n        <Text aria-hidden>{isFocused ? \">\" : \" \"}</Text>\n        <Box\n          aria-label={\n            ariaLabel ?? `${label ?? \"Password\"}: ${valueLength} characters`\n          }\n          aria-role=\"textbox\"\n          aria-state={{ disabled, readonly: readOnly, required }}\n          borderStyle={resolveBorderStyle(borderStyle, unicode)}\n          borderColor={borderColor}\n          paddingX={paddingX}\n          width={width}\n        >\n          <Text\n            color={\n              value ? theme.colors.foreground : theme.colors.mutedForeground\n            }\n          >\n            {displayValue || placeholder}\n          </Text>\n          {isFocused && !useNativeCursor && (\n            <Text aria-hidden color={theme.colors.focusRing}>\n              {resolvedCursor}\n            </Text>\n          )}\n        </Box>\n        {showToggle && isFocused && (\n          <Text color={theme.colors.mutedForeground}>\n            {isVisible ? \"Ctrl+H hide\" : \"Ctrl+H show\"}\n          </Text>\n        )}\n      </Box>\n    </Box>\n  );\n};\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "input"
  ],
  "type": "registry:ui"
}