{
  "schemaVersion": 1,
  "target": "react",
  "name": "scroll-area",
  "version": "0.1.0",
  "category": "layout",
  "title": "Scroll Area",
  "description": "A scrolling region built on Base UI Scroll Area with thin scrollbars that appear on hover or scroll and edges that fade where there is more content.",
  "tags": [
    "layout",
    "scroll",
    "overflow",
    "base-ui"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {
    "@base-ui/react": "^1.9.0"
  },
  "registryDependencies": [],
  "docsPath": "/components/scroll-area",
  "props": [
    {
      "name": "orientation",
      "type": "\"vertical\" | \"horizontal\" | \"both\"",
      "default": "\"vertical\"",
      "description": "Which axes scroll and get a scrollbar."
    },
    {
      "name": "fade",
      "type": "boolean",
      "default": "true",
      "description": "Fades content out at edges that have more to scroll. Each fade grows with the scroll distance, so there is none at the very start."
    },
    {
      "name": "fadeSize",
      "type": "number",
      "default": "24",
      "description": "Maximum length of each edge fade, in pixels."
    },
    {
      "name": "aria-label",
      "type": "string",
      "description": "Names the scrolling region (role=\"region\") when no heading labels it."
    },
    {
      "name": "className / viewportClassName / contentClassName",
      "type": "string",
      "description": "Classes for the root (set the height here), the scrolling viewport, and the content wrapper (for padding)."
    },
    {
      "name": "ScrollBar orientation",
      "type": "\"vertical\" | \"horizontal\"",
      "default": "\"vertical\"",
      "description": "The overlay scrollbar, exported for custom layouts."
    }
  ],
  "accessibility": [
    "Scrolling is native: wheel, touch, trackpad, Page Up, Page Down, and Space work as usual.",
    "The viewport is focusable when it overflows, so keyboard users can scroll it with the arrow keys; its focus ring is drawn on the root so the edge fade cannot hide it.",
    "With aria-label the viewport becomes a named region.",
    "Scrollbars are visual helpers hidden at rest; they fade in within 100ms on hover or scroll and out over 300ms. With reduced motion they show and hide without transitions.",
    "Edge fades are a mask tied directly to the scroll position, not an animation."
  ],
  "states": [
    "at-start",
    "scrolling",
    "at-end"
  ],
  "files": [
    {
      "path": "ui/scroll-area.tsx",
      "content": "\"use client\";\n\nimport { ScrollArea as BaseScrollArea } from \"@base-ui/react/scroll-area\";\nimport type { CSSProperties } from \"react\";\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\ntype ClassName<State> = string | ((state: State) => string | undefined) | undefined;\n\n/** Prepends base classes while keeping Base UI's state-function form of className working. */\nfunction withBase<State>(base: string, className: ClassName<State>) {\n  return typeof className === \"function\" ? (state: State) => cx(base, className(state)) : cx(base, className);\n}\n\nexport type ScrollAreaOrientation = \"vertical\" | \"horizontal\" | \"both\";\n\n/**\n * Edge fades drawn with a mask on the viewport. Base UI exposes how far the content is scrolled\n * from each edge; each fade grows with that distance up to `--scroll-fade` (24px by default), so\n * it is absent at the very top and reaches full size after a short scroll. Nothing animates: the\n * fade follows the scroll position directly.\n */\nconst fadeY =\n  \"linear-gradient(to bottom, transparent, #000 min(var(--scroll-area-overflow-y-start, 0px), var(--scroll-fade, 24px)), #000 calc(100% - min(var(--scroll-area-overflow-y-end, 0px), var(--scroll-fade, 24px))), transparent)\";\nconst fadeX =\n  \"linear-gradient(to right, transparent, #000 min(var(--scroll-area-overflow-x-start, 0px), var(--scroll-fade, 24px)), #000 calc(100% - min(var(--scroll-area-overflow-x-end, 0px), var(--scroll-fade, 24px))), transparent)\";\n\nconst masks: Record<ScrollAreaOrientation, CSSProperties> = {\n  vertical: { maskImage: fadeY, WebkitMaskImage: fadeY },\n  horizontal: { maskImage: fadeX, WebkitMaskImage: fadeX },\n  both: {\n    maskImage: `${fadeY}, ${fadeX}`,\n    WebkitMaskImage: `${fadeY}, ${fadeX}`,\n    maskComposite: \"intersect\",\n    WebkitMaskComposite: \"source-in\",\n  },\n};\n\nexport interface ScrollAreaProps extends Omit<BaseScrollArea.Root.Props, \"className\"> {\n  /** Which axes scroll and get a scrollbar. */\n  orientation?: ScrollAreaOrientation;\n  /** Fades the content out at edges that have more to scroll. */\n  fade?: boolean;\n  /** Maximum length of each edge fade, in pixels. */\n  fadeSize?: number;\n  /** Classes for the root. Set the height (or max height) here. */\n  className?: string;\n  /** Classes for the scrolling viewport. */\n  viewportClassName?: string;\n  /** Classes for the content wrapper inside the viewport, for example padding. */\n  contentClassName?: string;\n  /** Accessible name for the scrollable region when its content has no heading to point at. */\n  \"aria-label\"?: string;\n}\n\n/**\n * A scrolling region with thin scrollbars that appear while the pointer is over it or while it\n * scrolls, then fade away. Native scrolling, wheel, touch, and keyboard paging are unchanged;\n * the viewport is focusable so it can be scrolled with the arrow keys.\n */\nexport function ScrollArea({\n  orientation = \"vertical\",\n  fade = true,\n  fadeSize = 24,\n  className,\n  viewportClassName,\n  contentClassName,\n  \"aria-label\": label,\n  children,\n  style,\n  ...props\n}: ScrollAreaProps) {\n  const x = orientation !== \"vertical\";\n  const y = orientation !== \"horizontal\";\n  return (\n    <BaseScrollArea.Root\n      className={cx(\n        \"relative flex min-h-0 min-w-0 overflow-hidden rounded-[inherit]\",\n        // The focus ring belongs on the root; on the viewport the edge fade would mask it.\n        \"has-[[data-slot=scroll-viewport]:focus-visible]:outline-2 has-[[data-slot=scroll-viewport]:focus-visible]:outline-offset-2 has-[[data-slot=scroll-viewport]:focus-visible]:outline-sky-500\",\n        className,\n      )}\n      style={{ ...style, [\"--scroll-fade\" as string]: `${fadeSize}px` }}\n      {...props}\n    >\n      <BaseScrollArea.Viewport\n        data-slot=\"scroll-viewport\"\n        aria-label={label}\n        role={label ? \"region\" : undefined}\n        className={cx(\"h-full w-full flex-1 overscroll-contain rounded-[inherit] outline-none\", viewportClassName)}\n        style={fade ? masks[orientation] : undefined}\n      >\n        <BaseScrollArea.Content className={cx(x && \"min-w-full\", contentClassName)}>{children}</BaseScrollArea.Content>\n      </BaseScrollArea.Viewport>\n      {y ? <ScrollBar orientation=\"vertical\" /> : null}\n      {x ? <ScrollBar orientation=\"horizontal\" /> : null}\n      {x && y ? <BaseScrollArea.Corner /> : null}\n    </BaseScrollArea.Root>\n  );\n}\n\nexport interface ScrollBarProps extends BaseScrollArea.Scrollbar.Props {}\n\n/**\n * A thin overlay scrollbar. Hidden at rest; it fades in within 100ms when the pointer enters the\n * area or scrolling starts, and fades out more slowly once both stop. The thumb darkens while it\n * is hovered or dragged. Rendered automatically by `ScrollArea`; export for custom layouts.\n */\nexport function ScrollBar({ orientation = \"vertical\", className, ...props }: ScrollBarProps) {\n  return (\n    <BaseScrollArea.Scrollbar\n      orientation={orientation}\n      className={withBase(\n        cx(\n          \"group/scrollbar absolute z-10 flex touch-none p-0.5 select-none\",\n          \"data-[orientation=vertical]:top-0 data-[orientation=vertical]:right-0 data-[orientation=vertical]:bottom-(--scroll-area-corner-height) data-[orientation=vertical]:w-2.5\",\n          \"data-[orientation=horizontal]:right-(--scroll-area-corner-width) data-[orientation=horizontal]:bottom-0 data-[orientation=horizontal]:left-0 data-[orientation=horizontal]:h-2.5 data-[orientation=horizontal]:flex-col\",\n          // Fade out over 300ms after a short pause; fade in quickly when needed.\n          \"opacity-0 transition-opacity delay-300 duration-300 ease-out motion-reduce:transition-none\",\n          \"data-[hovering]:opacity-100 data-[hovering]:delay-0 data-[hovering]:duration-100\",\n          \"data-[scrolling]:opacity-100 data-[scrolling]:delay-0 data-[scrolling]:duration-100\",\n        ),\n        className,\n      )}\n      {...props}\n    >\n      <BaseScrollArea.Thumb\n        className={cx(\n          \"rounded-full bg-zinc-950/25 dark:bg-white/25\",\n          \"transition-colors duration-150 ease-out motion-reduce:transition-none\",\n          \"group-hover/scrollbar:bg-zinc-950/45 active:bg-zinc-950/55 dark:group-hover/scrollbar:bg-white/45 dark:active:bg-white/55\",\n          \"data-[orientation=vertical]:w-full data-[orientation=horizontal]:h-full\",\n        )}\n      />\n    </BaseScrollArea.Scrollbar>\n  );\n}\n"
    }
  ],
  "example": {
    "content": "import { ScrollArea } from \"@/components/shaken/ui/scroll-area\";\n\nconst log: [time: string, level: \"info\" | \"warn\" | \"error\", message: string][] = [\n  [\"14:02:11\", \"info\", \"Cloning acme/billing-api at 4f2c91e\"],\n  [\"14:02:13\", \"info\", \"Installing dependencies with pnpm 9.12\"],\n  [\"14:02:41\", \"info\", \"Resolved 1,184 packages in 27.8s\"],\n  [\"14:02:42\", \"info\", \"Running typecheck\"],\n  [\"14:02:58\", \"warn\", \"src/invoices/export.ts: 'legacyFormat' is deprecated\"],\n  [\"14:02:59\", \"info\", \"Typecheck passed with 1 warning\"],\n  [\"14:03:00\", \"info\", \"Running 412 tests across 38 files\"],\n  [\"14:03:19\", \"error\", \"invoices.test.ts > rounds tax per line item: expected 18.40, got 18.39\"],\n  [\"14:03:20\", \"info\", \"Agent is reading src/invoices/tax.ts\"],\n  [\"14:03:24\", \"info\", \"Proposed fix: round each line before summing\"],\n  [\"14:03:25\", \"info\", \"Applying patch to src/invoices/tax.ts (+6 -3)\"],\n  [\"14:03:26\", \"info\", \"Re-running invoices.test.ts\"],\n  [\"14:03:31\", \"info\", \"38 of 38 test files passed\"],\n  [\"14:03:32\", \"info\", \"Building production bundle\"],\n  [\"14:03:58\", \"info\", \"Bundle size 412 kB, 3 kB smaller than main\"],\n  [\"14:03:59\", \"info\", \"Uploading build artifacts\"],\n  [\"14:04:06\", \"info\", \"Preview ready at billing-api-git-fix-tax.acme.dev\"],\n  [\"14:04:07\", \"warn\", \"Waiting for approval to open a pull request\"],\n];\n\nconst levelTone = {\n  info: \"text-zinc-500\",\n  warn: \"text-amber-600 dark:text-amber-400\",\n  error: \"text-red-600 dark:text-red-400\",\n} as const;\n\nconst artifacts = [\n  [\"tax.ts\", \"Patch\", \"+6 −3\"],\n  [\"invoices.test.ts\", \"Test run\", \"38 passed\"],\n  [\"bundle-report.html\", \"Report\", \"412 kB\"],\n  [\"preview.png\", \"Screenshot\", \"1440 × 900\"],\n  [\"coverage.json\", \"Coverage\", \"91.4%\"],\n  [\"changelog.md\", \"Notes\", \"12 lines\"],\n  [\"pr-body.md\", \"Draft\", \"Pull request\"],\n];\n\nexport default function ScrollAreaExample() {\n  return (\n    <div className=\"flex w-full max-w-lg flex-col gap-6\">\n      <section className=\"overflow-hidden rounded-xl border border-zinc-950/10 bg-white shadow-[0_1px_2px_rgb(0_0_0/0.04)] dark:border-white/10 dark:bg-black dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06)]\">\n        <header className=\"flex items-center justify-between border-b border-zinc-950/[0.07] px-4 py-2.5 dark:border-white/[0.08]\">\n          <h3 id=\"run-log\" className=\"m-0 text-sm font-semibold text-zinc-950 dark:text-white\">\n            Run log\n          </h3>\n          <span className=\"font-mono text-xs text-zinc-500 tabular-nums\">{log.length} lines</span>\n        </header>\n        <ScrollArea className=\"h-56\" aria-label=\"Run log output\" contentClassName=\"py-2\">\n          <ol className=\"m-0 list-none p-0 font-mono text-xs leading-6\">\n            {log.map(([time, level, message], index) => (\n              <li key={index} className=\"flex gap-3 px-4\">\n                <span className=\"shrink-0 text-zinc-400 tabular-nums dark:text-zinc-600\">{time}</span>\n                <span className={`w-10 shrink-0 ${levelTone[level]}`}>{level}</span>\n                <span className=\"min-w-0 text-zinc-700 dark:text-zinc-300\">{message}</span>\n              </li>\n            ))}\n          </ol>\n        </ScrollArea>\n      </section>\n\n      <section className=\"flex flex-col gap-2\">\n        <h3 className=\"m-0 text-xs font-medium text-zinc-500\">Artifacts from this run</h3>\n        <ScrollArea orientation=\"horizontal\" aria-label=\"Artifacts from this run\" contentClassName=\"pb-3\">\n          <ul className=\"m-0 flex w-max list-none gap-2 p-0\">\n            {artifacts.map(([name, kind, meta]) => (\n              <li\n                key={name}\n                className=\"flex w-40 flex-col gap-1 rounded-lg border border-zinc-950/10 px-3 py-2.5 dark:border-white/10\"\n              >\n                <span className=\"truncate font-mono text-xs text-zinc-950 dark:text-white\">{name}</span>\n                <span className=\"text-xs text-zinc-500\">\n                  {kind} · <span className=\"tabular-nums\">{meta}</span>\n                </span>\n              </li>\n            ))}\n          </ul>\n        </ScrollArea>\n      </section>\n    </div>\n  );\n}\n"
  }
}
