{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reading-settings",
  "type": "registry:ui",
  "title": "Reading Settings",
  "description": "A text size control and a More contrast toggle: two small controls for the reader, not the theme author. They write the `data-text-size` and `data-contrast` attributes on `<html>` through `useReadingPrefs`, remember the choice, and `THEME_SCRIPT` puts it…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "foundation",
    "primitive"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/toggle.json",
    "https://ds.interlace.tools/r/use-reading-prefs.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/reading-settings.tsx",
      "target": "components/ui/reading-settings.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/reading-settings v1.0.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/reading-settings\n// What changed since: https://ds.interlace.tools/c/reading-settings#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — ReadingSettings\n *\n * A text size control and a More contrast toggle: two small controls for the reader, not the theme author. They write the\n * `data-text-size` and `data-contrast` attributes on `<html>` through\n * `useReadingPrefs`, remember the choice, and `THEME_SCRIPT` puts it back\n * before first paint on the next visit.\n *\n * ─── TextSizeControl ─────────────────────────────────────────────\n *\n * Three buttons in a labelled group: smaller, the current size (which resets\n * to 100%), larger. The middle button shows the size as a number, because\n * \"A\" alone tells a reader nothing about where they are on the scale.\n *\n * At the ends the outer buttons are `aria-disabled`, not `disabled`. A\n * keyboard user pressing \"Larger\" until it stops would otherwise have focus\n * thrown to `<body>` on the last press, and land at the top of the page.\n *\n * ─── ContrastToggle ──────────────────────────────────────────────\n *\n * A pressed/unpressed button for More contrast. Pressed shows what is on\n * screen, from either the reader's choice or `prefers-contrast: more`.\n * Pressing it stores an explicit choice, so turning it off while the OS asks\n * for more contrast stores `'normal'`: the reader said no, and the page\n * should stop overriding them.\n *\n * Both take their words as props (`label`, `labels`), so a consumer can\n * translate them. Neither carries a colour of its own.\n */\n\nimport { ContrastIcon } from 'lucide-react';\n\nimport { cn } from '@/lib/utils';\nimport { useReadingPrefs } from '@/hooks/use-reading-prefs';\nimport { Toggle } from '@/components/ui/toggle';\n\nconst STEP = cn(\n  'inline-flex h-control-sm min-w-control-sm items-center justify-center rounded-md px-2 text-ui-sm font-medium',\n  'text-foreground transition-colors hover:bg-accent hover:text-accent-foreground',\n  'focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background focus-visible:outline-hidden',\n  'aria-disabled:pointer-events-none aria-disabled:opacity-40',\n);\n\ninterface TextSizeLabels {\n  /** Name of the step-down button. Default: `'Smaller text'`. */\n  smaller?: string;\n  /** Name of the reset button, before the current size. Default: `'Reset text size'`. */\n  reset?: string;\n  /** Name of the step-up button. Default: `'Larger text'`. */\n  larger?: string;\n}\n\ninterface TextSizeControlProps extends Omit<React.ComponentProps<'div'>, 'children'> {\n  /** The group's accessible name. Default: `'Text size'`. */\n  label?: string;\n  /** The three buttons' names, for translation. */\n  labels?: TextSizeLabels;\n}\n\nfunction TextSizeControl({\n  className,\n  label = 'Text size',\n  labels,\n  ...props\n}: TextSizeControlProps) {\n  const { textSize, textSizes, setTextSize, stepTextSize, mounted } = useReadingPrefs();\n  const index = textSizes.findIndex((size) => size.value === textSize);\n  const current = textSizes[index] ?? textSizes[0];\n  const atMin = index <= 0;\n  const atMax = index >= textSizes.length - 1;\n  const names = {\n    smaller: labels?.smaller ?? 'Smaller text',\n    reset: labels?.reset ?? 'Reset text size',\n    larger: labels?.larger ?? 'Larger text',\n  };\n\n  return (\n    <div\n      role=\"group\"\n      aria-label={label}\n      data-slot=\"text-size-control\"\n      data-text-size-value={textSize}\n      className={cn(\n        'inline-flex w-fit items-center gap-0.5 rounded-lg border border-input bg-background p-0.5',\n        className,\n      )}\n      {...props}\n    >\n      <button\n        type=\"button\"\n        data-slot=\"text-size-smaller\"\n        aria-label={names.smaller}\n        aria-disabled={atMin || undefined}\n        onClick={() => !atMin && stepTextSize(-1)}\n        className={STEP}\n      >\n        <span aria-hidden=\"true\" className=\"text-[0.75em]\">\n          A\n        </span>\n        <span aria-hidden=\"true\">−</span>\n      </button>\n      <button\n        type=\"button\"\n        data-slot=\"text-size-reset\"\n        // The visible number is inside the name (WCAG 2.5.3, label in name).\n        aria-label={`${names.reset}, ${current.label}`}\n        onClick={() => setTextSize('default')}\n        className={cn(STEP, 'min-w-14 tabular-nums')}\n      >\n        {/* Before the storage read the hook reports the default; showing\n            \"100%\" for a reader at 125% would be wrong, so hold the width. */}\n        <span className={cn(!mounted && 'invisible')}>{current.label}</span>\n      </button>\n      <button\n        type=\"button\"\n        data-slot=\"text-size-larger\"\n        aria-label={names.larger}\n        aria-disabled={atMax || undefined}\n        onClick={() => !atMax && stepTextSize(1)}\n        className={STEP}\n      >\n        <span aria-hidden=\"true\" className=\"text-[1.15em]\">\n          A\n        </span>\n        <span aria-hidden=\"true\">+</span>\n      </button>\n    </div>\n  );\n}\n\ninterface ContrastToggleProps\n  extends Omit<\n    React.ComponentProps<typeof Toggle>,\n    'pressed' | 'defaultPressed' | 'onPressedChange' | 'value' | 'children'\n  > {\n  /** Accessible name and visible text. Default: `'More contrast'`. */\n  label?: string;\n  /** Show the label beside the icon. Default: `true`. */\n  showLabel?: boolean;\n}\n\nfunction ContrastToggle({\n  className,\n  label = 'More contrast',\n  showLabel = true,\n  ...props\n}: ContrastToggleProps) {\n  const { moreContrast, setContrast, mounted } = useReadingPrefs();\n\n  return (\n    <Toggle\n      data-slot=\"contrast-toggle\"\n      variant=\"outline\"\n      size=\"sm\"\n      aria-label={showLabel ? undefined : label}\n      pressed={moreContrast}\n      onPressedChange={(pressed: boolean) => setContrast(pressed ? 'more' : 'normal')}\n      // Until storage is read the hook reports \"off\", so a reader who chose\n      // More contrast would see the toggle flip on. Keep it transparent (in\n      // place, and still in the accessibility tree) for that first frame.\n      className={cn(!mounted && 'opacity-0', className)}\n      {...props}\n    >\n      <ContrastIcon aria-hidden=\"true\" className=\"size-4\" />\n      {showLabel ? <span>{label}</span> : null}\n    </Toggle>\n  );\n}\n\nexport { ContrastToggle, TextSizeControl };\nexport type { ContrastToggleProps, TextSizeControlProps, TextSizeLabels };\n"
    }
  ],
  "meta": {
    "tier": "primitive",
    "client": true,
    "minViewport": null,
    "loading": false,
    "version": "1.0.1",
    "since": "2.0.0"
  },
  "docs": "## @interlace/reading-settings\n\nInstalled to `components/ui/reading-settings.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/reading-settings';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/reading-settings\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
