{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroll-area",
  "title": "ScrollArea",
  "description": "A scrolling region with a thin scrollbar in the theme's color, inside a height you set.",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-dev",
    "@ouro/lib-env",
    "@ouro/lib-scroll-fade",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/scroll-area/scroll-area.tsx",
      "content": "\"use client\";\n\nimport { type HTMLAttributes, type JSX, type ReactNode, type Ref, useEffect, useRef } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { devWarn } from \"@/registry/ouro/lib/ouro/dev\";\nimport { scrollFadeClass, useScrollFade } from \"@/registry/ouro/lib/ouro/scroll-fade\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\n\n/** Which way a ScrollArea scrolls. */\nexport type ScrollAreaOrientation = \"vertical\" | \"horizontal\" | \"both\";\n\n/** The props ScrollArea adds to the div attributes it passes through. */\nexport interface ScrollAreaOwnProps {\n  /** The content that scrolls. */\n  children: ReactNode;\n  /**\n   * Which way the content scrolls. `horizontal` keeps a row of tags or cards on one line.\n   * @default \"vertical\"\n   */\n  orientation?: ScrollAreaOrientation | (string & { 'Use \"vertical\", \"horizontal\" or \"both\"': never }) | undefined;\n  /**\n   * Names the scrolling region for screen readers (\"Method\", \"Order history\"). A keyboard\n   * user can focus the region to scroll it, so give it a name when nothing else inside can\n   * take focus.\n   */\n  label?: string | undefined;\n  /**\n   * Keeps a scroll that reaches the area's end from scrolling the page behind it, for a\n   * chat thread or a list inside a dialog. Off by default, so a finger that runs out of a\n   * recipe's method keeps scrolling the page.\n   * @default false\n   */\n  contain?: boolean | undefined;\n  /**\n   * Layout: the area's height or maximum height, which it scrolls inside (`h-72`,\n   * `max-h-80`), and its width and margins. Appearance classes warn in development.\n   */\n  className?: string | undefined;\n  ref?: Ref<HTMLDivElement> | undefined;\n\n  /**\n   * Not a prop. The scrollbar is the browser's own, thin and in the theme's color, with a mouse or a finger.\n   */\n  type?: { \"Use <ScrollArea>; the scrollbar is the browser's own\": never };\n  /** Not a prop. Set the height with a class: `<ScrollArea className=\"max-h-80\">`. */\n  maxHeight?: { 'Use <ScrollArea className=\"max-h-80\">': never };\n  /** Not a prop. Set the height with a class: `<ScrollArea className=\"h-72\">`. */\n  height?: { 'Use <ScrollArea className=\"h-72\">': never };\n}\n\n/** Props for {@link ScrollArea}: its own props and the div attributes it passes through to the root. */\nexport type ScrollAreaProps = Omit<HTMLAttributes<HTMLDivElement>, keyof ScrollAreaOwnProps> & ScrollAreaOwnProps;\n\nconst orientations = [\"vertical\", \"horizontal\", \"both\"] as const;\n\n/**\n * The browser's own scrollbar, thin and in the theme's muted color, so nothing measures the page to draw one:\n * a custom scrollbar needs a layout read at mount. A mouse drags it, a finger pans past it and the keyboard scrolls the viewport.\n */\nconst scrollbar =\n  \"[scrollbar-width:thin] [scrollbar-color:color-mix(in_oklab,var(--muted-foreground)_40%,transparent)_transparent] \" +\n  // Stryker disable next-line StringLiteral: a pointer-hover-only colour, which no test pointer state reaches\n  \"pointer-fine:hover:[scrollbar-color:color-mix(in_oklab,var(--muted-foreground)_60%,transparent)_transparent]\";\nconst viewports = {\n  vertical: \"overflow-x-hidden overflow-y-auto\",\n  horizontal: \"overflow-x-auto overflow-y-hidden\",\n  both: \"overflow-auto\",\n} as const;\n\n/** The mask for the top and bottom fade, set only while the viewport scrolls. */\nconst verticalFade =\n  \"data-ouro-scroll-fade-y:[mask-image:linear-gradient(to_bottom,transparent,#000_min(var(--scroll-area-overflow-y-start),2rem),#000_calc(100%-min(var(--scroll-area-overflow-y-end),2rem)),transparent)]\"; // fade-ok: fades a scrolling list of rows, not a picture\n\nconst focusable = \"a[href],button,input,select,textarea,summary,[tabindex]:not([tabindex='-1']),[contenteditable='true']\";\n\n/**\n * Makes the viewport a tab stop while its content overflows, so a keyboard user can scroll it, and\n * says how far it hides content above and below: `data-overflow-y-start` and `data-overflow-y-end`\n * while that side hides more, with `--scroll-area-overflow-y-start` and `--scroll-area-overflow-y-end`\n * in pixels. Reads sizes when the browser reports a resize or a scroll, after layout, not while React commits.\n */\nfunction useScrollTabStop(viewportRef: { current: HTMLDivElement | null }): void {\n  useEffect(() => {\n    const viewport = viewportRef.current!;\n    const update = () => {\n      viewport.tabIndex = viewport.scrollHeight > viewport.clientHeight || viewport.scrollWidth > viewport.clientWidth ? 0 : -1;\n      const hidden = viewport.scrollHeight - viewport.clientHeight;\n      const start = Math.max(0, viewport.scrollTop);\n      const end = Math.max(0, hidden - start);\n      // Stryker disable next-line EqualityOperator: a one pixel threshold only absorbs rounding; no test can make content exactly one pixel taller\n      const scrolls = hidden > 1 && getComputedStyle(viewport).overflowY !== \"hidden\";\n      viewport.toggleAttribute(\"data-ouro-scroll-fade-y\", scrolls);\n      // Stryker disable next-line EqualityOperator: a one pixel threshold only absorbs rounding; no test can place a scroll offset at exactly one pixel\n      viewport.toggleAttribute(\"data-overflow-y-start\", scrolls && start > 1);\n      // Stryker disable next-line EqualityOperator: a one pixel threshold only absorbs rounding; no test can place a scroll offset at exactly one pixel\n      viewport.toggleAttribute(\"data-overflow-y-end\", scrolls && end > 1);\n      viewport.style.setProperty(\"--scroll-area-overflow-y-start\", `${scrolls ? start : 0}px`);\n      viewport.style.setProperty(\"--scroll-area-overflow-y-end\", `${scrolls ? end : 0}px`);\n    };\n    const observer = new ResizeObserver(update);\n    // Stryker disable next-line CallExpression: the observer fires for the first child's resize too, so a height change reaches update either way\n    observer.observe(viewport);\n    observer.observe(viewport.firstElementChild!);\n    viewport.addEventListener(\"scroll\", update);\n    // Stryker disable next-line BlockStatement,CallExpression,StringLiteral: cleanup only releases listeners on an element that is going away, which nothing can observe\n    return () => {\n      // Stryker disable next-line CallExpression: cleanup only releases an observer on an element that is going away, which nothing can observe\n      observer.disconnect();\n      // Stryker disable next-line CallExpression,StringLiteral: cleanup only releases a listener on an element that is going away, which nothing can observe\n      viewport.removeEventListener(\"scroll\", update);\n    };\n  },\n  // Stryker disable next-line ArrayDeclaration: the ref object never changes, so the effect runs once either way\n  [viewportRef]);\n}\n\n/**\n * Warns when the viewport takes keyboard focus to scroll (it is a tab stop once\n * the content overflows) but has no name and nothing inside that could take focus instead.\n * Development only.\n * @claim \"Warns when the viewport takes keyboard\" registry/ouro/components/ouro/scroll-area/scroll-area.test.tsx verify:testExists(registry/ouro/components/ouro/scroll-area/scroll-area.test.tsx::ScrollArea development messages > warns when the area takes keyboard focus to scroll but has no name)\n */\nfunction useUnnamedRegionCheck(viewportRef: { current: HTMLDivElement | null }, label: string | undefined): void {\n  const key = useRef({});\n  useEffect(() => {\n    /* istanbul ignore else @preserve -- the else path exists only in production bundles; scripts/dev-strip.test.mjs covers it */\n    if (process.env.NODE_ENV !== \"production\") {\n      const viewport = viewportRef.current;\n      if (!viewport || label) return;\n      const check = () => {\n        if (viewport.tabIndex === 0 && !viewport.querySelector(focusable)) {\n          devWarn(\"ScrollArea\", \"the area takes keyboard focus to scroll, and has no name\", '<ScrollArea label=\"Method\">', key.current);\n        }\n      };\n      check();\n      const observer = new MutationObserver(check);\n      observer.observe(viewport, { attributes: true, attributeFilter: [\"tabindex\"] });\n      return () => observer.disconnect();\n    }\n  }, [viewportRef, label]);\n}\n\n/**\n * A scrolling region with a thin scrollbar in the theme's color, inside a height you set.\n * It keeps the browser's own scrolling, so touch, the mouse wheel, the keyboard and\n * momentum all work; Content\n * wider than the area fades out at the side where it goes on, and a vertical area fades at the\n * top and bottom edge that hides more, so at rest it reads as more to scroll to, not as cut off.\n * A vertical area also marks the viewport with `data-overflow-y-start` and `data-overflow-y-end`\n * while that edge hides content, and sets `--scroll-area-overflow-y-start` and `--scroll-area-overflow-y-end`\n * (pixels hidden), so a parent can draw a hairline once it is scrolled from the start. Its focus ring\n * is drawn over the content, so a header that sticks to the top never hides an edge of it.\n *\n * Use plain page scrolling instead for a page's main content, and `Dialog` or `Sheet`,\n * which scroll their own bodies, for long content in an overlay.\n *\n * @group Layout\n * @see https://ui.ouroboros.bot/docs/scroll-area\n *\n * @example\n * <ScrollArea className=\"h-72\" label=\"Method\">\n *   {steps.map((step) => <Text key={step.id}>{step.text}</Text>)}\n * </ScrollArea>\n * <ScrollArea orientation=\"horizontal\" label=\"Tags\">\n *   <Row gap=\"sm\">{tags.map((tag) => <Badge key={tag}>{tag}</Badge>)}</Row>\n * </ScrollArea>\n * @claim \"Content wider than the area fades out\" registry/ouro/components/ouro/scroll-area/scroll-area.test.tsx verify:testExists(registry/ouro/components/ouro/scroll-area/scroll-area.test.tsx::ScrollArea > fades out at the side that hides more, drawing its focus ring over the fade, and keeps keyboard scrolling)\n * @claim \"Its focus ring is drawn over the content\" registry/ouro/components/ouro/scroll-area/scroll-area.test.tsx verify:testExists(registry/ouro/components/ouro/scroll-area/scroll-area.test.tsx::ScrollArea > draws its focus ring whole over content that sticks to an edge, and leaves the pointer to the content)\n * @claim \"It keeps the browser's own scrolling\" registry/ouro/components/ouro/scroll-area/scroll-area.touch.test.tsx verify:testExists(registry/ouro/components/ouro/scroll-area/scroll-area.touch.test.tsx::leaves touch scrolling to the browser: the viewport is a native scroll container)\n * @claim \"It keeps the browser's own scrolling\" registry/ouro/components/ouro/scroll-area/scroll-area.test.tsx verify:testExists(registry/ouro/components/ouro/scroll-area/scroll-area.test.tsx::ScrollArea > draws a thin native scrollbar in the theme's muted color, and scrolls only the way it is asked to)\n */\nexport function ScrollArea(props: ScrollAreaProps): JSX.Element {\n  const { children, orientation: orientationProp = \"vertical\", label, contain, className, type, maxHeight, height, ...rest } = props;\n  const viewportRef = useRef<HTMLDivElement>(null);\n  useUnnamedRegionCheck(viewportRef, label);\n  useScrollFade(viewportRef);\n  useScrollTabStop(viewportRef);\n  const orientation = (orientations as readonly string[]).includes(orientationProp) ? (orientationProp as ScrollAreaOrientation) : \"vertical\";\n  useAppearanceClassNameCheck(\n    \"ScrollArea\",\n    className,\n    process.env.NODE_ENV !== \"production\" ? \"put the ScrollArea inside a <Card> for a frame\" : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"ScrollArea\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          orientation !== orientationProp && [\n            `orientation=\"${String(orientationProp)}\" is not an orientation; use \"vertical\", \"horizontal\", \"both\"`,\n            `<ScrollArea orientation=\"${String(orientationProp).toLowerCase().startsWith(\"x\") ? \"horizontal\" : \"vertical\"}\">`,\n          ],\n          type !== undefined && [\"type is not a prop; the scrollbar is the browser's own\", \"<ScrollArea>\"],\n          maxHeight !== undefined && [\"maxHeight is not a prop\", '<ScrollArea className=\"max-h-80\">'],\n          height !== undefined && [\"height is not a prop\", '<ScrollArea className=\"h-72\">'],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  // Stryker disable next-line ConditionalExpression: the mask needs the data attribute, which only a vertical area gets\n  const fadeY = orientation === \"vertical\" && verticalFade;\n  return (\n    <div\n      {...rest}\n      data-ouro=\"scroll-area\"\n      className={cn(\n        \"group/scroll-area relative flex min-h-0 min-w-0 flex-col overflow-hidden\",\n        className,\n      )}\n    >\n      <div\n        ref={viewportRef}\n        data-scroll-viewport=\"\"\n        // Stryker disable next-line UnaryOperator: the observer sets the real value as soon as it starts, before any read\n        tabIndex={-1}\n        data-ouro-control=\"scroll-area\"\n        data-ouro-part=\"viewport\"\n        role={label ? \"region\" : undefined}\n        aria-label={label}\n        // While focused, isolate keeps the content's own stacking (a sticky header's z-index) inside the viewport, under the\n        // focus ring. Only then: at rest the content stacks with the page, as it always has.\n        className={cn(\"peer min-h-0 focus-visible:isolate flex-1 rounded-[inherit] outline-none\", viewports[orientation], scrollbar, scrollFadeClass, fadeY, contain && \"overscroll-contain\")}\n      >\n        <div className={orientation === \"vertical\" ? \"min-w-0\" : \"min-w-fit\"}>{children}</div>\n      </div>\n      {/* The viewport's focus ring, drawn over it, so neither the edge fade nor content that sticks to an edge covers it. It is\n          there only while the viewport has focus: at rest nothing lies over the content, so a contrast check sees the text's own background. */}\n      <span\n        aria-hidden=\"true\"\n        data-scroll-focus-ring=\"\"\n        className=\"pointer-events-none absolute inset-0 hidden rounded-[inherit] outline-ring -outline-offset-2 peer-focus-visible:block peer-focus-visible:outline-2 peer-focus-visible:outline-solid\"\n      />\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/scroll-area/scroll-area.tsx"
    }
  ],
  "docs": "A scrolling region with a thin scrollbar in the theme's color, inside a height you set. Import: import { ScrollArea } from \"@/components/ouro/scroll-area/scroll-area\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/scroll-area.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}