{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "kit-auth",
  "type": "registry:lib",
  "title": "Kit auth",
  "description": "Helpers shared by the auth blocks.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/input.json",
    "https://ui.klarhimmel.com/r/kit-app.json",
    "https://ui.klarhimmel.com/r/text-link.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/blocks/_shared/auth-kit.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/_shared/auth-kit.tsx",
      "content": "// Pieces shared by the authentication blocks (sign in, sign up, reset, code). No fetching: the form never submits unless\n// the host gives it an action and method (form-kit), and a state prop says what the host wants shown.\nimport { useState, type ReactNode } from 'react';\nimport { Text, type PropPath } from '../../editing';\nimport { cn } from '../../lib/utils';\nimport { nameEmptied, safeHref } from '../../ui/button';\nimport { Input } from '../../ui/input';\nimport { TextLink } from '../../ui/text-link';\nimport { Swap } from './app-kit';\nimport { useEditing } from './kit';\n\n/** A labelled field row: the label above, the control, then hint and message with ids the control points at. */\n/** `error` stays in the DOM while `showError` is false (so editors reach its copy) but is hidden and not described. */\nexport function FieldRow({ id, label, hint, error, showError = true, children }: { id: string; label: ReactNode; hint?: ReactNode; error?: ReactNode; showError?: boolean; children: ReactNode }) {\n  const editing = useEditing();\n  if (!editing && nameEmptied(label)) return null; // an emptied label: the field is not drawn (a control with no name is worse than none)\n  return (\n    <div className=\"flex flex-col gap-1.5\">\n      <label htmlFor={id} className=\"text-kh-small font-medium\">\n        {label}\n      </label>\n      {children}\n      {hint && (\n        <p id={`${id}-h`} className=\"text-kh-small text-kh-muted\">\n          {hint}\n        </p>\n      )}\n      {error && (\n        <p id={`${id}-e`} hidden={!showError && !editing} className=\"text-kh-small text-kh-ink\">\n          {error}\n        </p>\n      )}\n    </div>\n  );\n}\n\n/** The ids a control describes itself by, in the order they appear. */\nexport const describedBy = (id: string, hint: boolean, error: boolean) => [hint && `${id}-h`, error && `${id}-e`].filter(Boolean).join(' ') || undefined;\n\n/** A password input with a button that shows or hides what is typed. The button's name is its current action. */\nexport function PasswordInput({ id, name, autoComplete, showLabel, hideLabel, showPath, hidePath, invalid, describedby, required, minLength }: {\n  id: string; name: string; autoComplete: 'current-password' | 'new-password'; showLabel: string; hideLabel: string; showPath: PropPath; hidePath: PropPath;\n  invalid?: boolean; describedby?: string; required?: boolean; minLength?: number;\n}) {\n  const [visible, setVisible] = useState(false);\n  return (\n    <div className=\"relative\">\n      <Input id={id} name={name} type={visible ? 'text' : 'password'} autoComplete={autoComplete} autoCapitalize=\"none\" spellCheck={false} required={required} minLength={minLength} aria-invalid={invalid || undefined} aria-describedby={describedby} className=\"pr-24\" />\n      <button\n        type=\"button\"\n        aria-controls={id}\n        onClick={() => setVisible((v) => !v)}\n        className={cn('absolute inset-y-0 right-0 inline-flex min-h-11 items-center rounded-r-kh px-3 text-kh-small font-medium text-kh-ink-2 hover:text-kh-ink', 'focus-visible:outline-2 focus-visible:outline-offset-0 focus-visible:outline-(--kh-focus)')}\n      >\n        <Swap show={!visible}>\n          <Text path={showPath} value={showLabel} as=\"span\" />\n        </Swap>\n        <Swap show={visible}>\n          <Text path={hidePath} value={hideLabel} as=\"span\" />\n        </Swap>\n      </button>\n    </div>\n  );\n}\n\n/** A link whose label is a prop: with no label there is no link (never a nameless <a>), except while editing, so it can be filled in. */\nexport function LabelLink({ path, link }: { path: PropPath; link: { label: string; href: string } }) {\n  const editing = useEditing();\n  if (!link.label && !editing) return null;\n  return (\n    <TextLink className=\"inline-block py-1\" href={safeHref(link.href)}>\n      <Text path={[...path, 'label']} value={link.label} as=\"span\" placeholder=\"Label\" />\n    </TextLink>\n  );\n}\n"
    }
  ]
}
