{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reading-layout",
  "type": "registry:ui",
  "title": "Reading Layout",
  "description": "A long read with its table of contents: the text column, and beside it a `Toc` rail that stays in view as the reader scrolls. When the layout is too narrow for a rail, the contents fold into a slim bar (`TocBar`) that sticks to the top of the column, names…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "blog",
    "pattern"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/toc.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/patterns/reading-layout.tsx",
      "target": "components/ui/patterns/reading-layout.tsx",
      "type": "registry:ui",
      "content": "import * as React from 'react';\n\n// @interlace/reading-layout v1.3.0 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/reading-layout\n// What changed since: https://ds.interlace.tools/c/reading-layout#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — ReadingLayout\n *\n * A long read with its table of contents: the text column, and beside it a\n * `Toc` rail that stays in view as the reader scrolls. When the layout is\n * too narrow for a rail, the contents fold into a slim bar (`TocBar`) that\n * sticks to the top of the column, names the section being read, shows the\n * page's progress along its foot, and opens the list in a bottom sheet.\n *\n * ## Container, not viewport\n *\n * The switch is a container query on the layout's own width, not a media\n * query on the window. The same layout shows its rail in a wide main column\n * and folds it in a narrow one (next to a sidebar, in a split view, inside\n * a card) with no prop. The rail appears at `@4xl` (56rem) of layout width.\n *\n * ## Sticky offset\n *\n * A page with its own sticky header sets `--reading-offset` to that header's\n * height. The rail and the bar stick below it, and headings with an `id`\n * get a scroll margin, so a jump from the contents never lands under the\n * header or the bar. Defaults to 0.\n *\n * ## Anatomy\n *\n *   ReadingLayout                   (div — data-slot=\"reading-layout\", @container/reading)\n *     └─ div grid                   (one column, or text + rail at @4xl)\n *         ├─ bar                    (div — data-slot=\"reading-layout-bar\", sticky; hidden at @4xl)\n *         │   └─ TocBar\n *         ├─ content                (div — data-slot=\"reading-layout-content\", min-w-0)\n *         └─ rail                   (div — data-slot=\"reading-layout-rail\", shown at @4xl)\n *             └─ div sticky         (data-toc-scroller; scrolls on its own when taller than the screen)\n *                 └─ Toc\n *\n * With no `toc` items, it renders the content alone: no bar, no rail.\n *\n * ## MIN_VIEWPORT — 320\n *\n * Below `@4xl` it is one column and the bar holds one button, so it reads on\n * the narrowest phone.\n *\n * | Rule | Concept                 | Where in this file                                       |\n * | ---- | ----------------------- | -------------------------------------------------------- |\n * | R4   | Extends native el       | `React.ComponentProps<'div'>`                            |\n * | R6   | data-slot per part      | reading-layout / -bar / -content / -rail                 |\n * | R7   | cn + ...rest            | `cn(…, className)` + `{...props}`                        |\n * | R14  | Declares min viewport   | `data-min-viewport` on the root + exported const         |\n * | R18  | Tailwind only           | Container query variants; the offset is a CSS variable   |\n * | R19  | Tokens only             | `bg-background`, `border-border`                         |\n * | R26  | A11y                    | Toc's named `<nav>` is the one landmark; the rail is a div |\n */\n\nimport { cn } from '@/lib/utils';\nimport { Toc, TocBar, type TocItem } from '@/components/ui/toc';\n\nexport const MIN_VIEWPORT = 320 as const;\n\ntype ReadingLayoutProps = React.ComponentProps<'div'> & {\n  /** The headings to list, in order. Empty or absent: no rail and no bar. */\n  toc?: TocItem[];\n  /** The contents' accessible name. @default 'Table of contents' */\n  tocLabel?: string;\n  /** The rail's title, the bar's label and the sheet's title. @default 'On this page' */\n  triggerLabel?: React.ReactNode;\n};\n\nfunction ReadingLayout({\n  toc = [],\n  tocLabel,\n  triggerLabel,\n  className,\n  children,\n  ...props\n}: ReadingLayoutProps) {\n  const hasToc = toc.length > 0;\n  return (\n    <div\n      data-slot=\"reading-layout\"\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn(\n        '@container/reading',\n        // A jump from the contents lands below the page's header and the bar.\n        hasToc &&\n          '[&_:is(h2,h3,h4)[id]]:scroll-mt-[calc(var(--reading-offset,0px)+4rem)] @4xl/reading:[&_:is(h2,h3,h4)[id]]:scroll-mt-[calc(var(--reading-offset,0px)+1.5rem)]',\n        className,\n      )}\n      {...props}\n    >\n      <div className=\"grid grid-cols-1 gap-6 @4xl/reading:grid-cols-[minmax(0,1fr)_15rem] @4xl/reading:gap-12\">\n        {hasToc ? (\n          <div\n            data-slot=\"reading-layout-bar\"\n            className=\"border-border bg-background sticky top-[var(--reading-offset,0px)] z-sticky -mt-2 border-b @4xl/reading:hidden\"\n          >\n            <TocBar items={toc} label={tocLabel} triggerLabel={triggerLabel} />\n          </div>\n        ) : null}\n        <div data-slot=\"reading-layout-content\" className=\"min-w-0\">\n          {children}\n        </div>\n        {hasToc ? (\n          // A div, not an aside: the Toc's named <nav> is already the\n          // landmark, and an unnamed complementary one around it is noise.\n          <div data-slot=\"reading-layout-rail\" className=\"hidden @4xl/reading:block\">\n            <div\n              data-toc-scroller=\"\"\n              className=\"sticky top-[calc(var(--reading-offset,0px)+1.5rem)] max-h-[calc(100dvh-var(--reading-offset,0px)-3rem)] -m-1 overflow-y-auto overscroll-contain p-1\"\n            >\n              <Toc items={toc} label={tocLabel} title={triggerLabel ?? 'On this page'} />\n            </div>\n          </div>\n        ) : null}\n      </div>\n    </div>\n  );\n}\n\nexport { ReadingLayout };\nexport type { ReadingLayoutProps };\n"
    }
  ],
  "meta": {
    "tier": "pattern",
    "client": false,
    "minViewport": 320,
    "loading": false,
    "version": "1.3.0",
    "since": "2.0.0"
  },
  "docs": "## @interlace/reading-layout\n\nInstalled to `components/ui/patterns/reading-layout.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/patterns/reading-layout';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/reading-layout\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
