# Scroll area

shadcn scroll area with a dithered track and a beveled thumb.

Source: https://www.ui95.dev/ui/scroll-area

## Examples

```tsx
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"

import type { ShowcaseDemo } from "../types"

const LOG_LINES = Array.from(
  { length: 24 },
  (_, index) => `${String(index + 1).padStart(2, "0")} DRV${index}.SYS`
)

const WIDE_ROW = "0x80100000 2bd49666 ntoskrnl.exe ncrc710.sys scsidisk.sys Floppy.SYS atd.sys"

export const demo: ShowcaseDemo = {
  span: "single",
  variants: [
    {
      label: "vertical",
      render: () => (
        <ScrollArea className="h-40 pixel-border border-border bg-card">
          <ul className="p-2 pr-7 text-lg leading-tight">
            {LOG_LINES.map((line) => (
              <li key={line}>{line}</li>
            ))}
          </ul>
        </ScrollArea>
      ),
    },
    {
      label: "horizontal",
      render: () => (
        <ScrollArea className="pixel-border border-border bg-card">
          <p className="w-max p-2 pb-7 text-lg whitespace-nowrap">{WIDE_ROW}</p>
          <ScrollBar orientation="horizontal" />
        </ScrollArea>
      ),
    },
    {
      label: "both",
      render: () => (
        <ScrollArea className="h-32 pixel-border border-border bg-card">
          <ul className="w-max p-2 pr-7 pb-7 text-lg leading-tight whitespace-nowrap">
            {LOG_LINES.map((line) => (
              <li key={line}>
                {line} {WIDE_ROW}
              </li>
            ))}
          </ul>
          <ScrollBar orientation="horizontal" />
        </ScrollArea>
      ),
    },
  ],
}
```

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/scroll-area.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install cn radix-ui
```

`components/ui/scroll-area.tsx`

```tsx
"use client"

import { cn } from "cn"
import { ScrollArea as ScrollAreaPrimitive } from "radix-ui"
import * as React from "react"

function ScrollArea({
  className,
  children,
  type = "auto",
  ...props
}: React.ComponentProps<typeof ScrollAreaPrimitive.Root>) {
  return (
    <ScrollAreaPrimitive.Root
      data-slot="scroll-area"
      type={type}
      className={cn("relative", className)}
      {...props}
    >
      <ScrollAreaPrimitive.Viewport
        data-slot="scroll-area-viewport"
        className="size-full focus-visible:outline-offset-[calc(var(--pixel)*-2)] [&>div]:block!"
      >
        {children}
      </ScrollAreaPrimitive.Viewport>
      <ScrollBar />
      <ScrollAreaPrimitive.Corner className="bg-secondary" />
    </ScrollAreaPrimitive.Root>
  )
}

function ScrollBar({
  className,
  orientation = "vertical",
  ...props
}: React.ComponentProps<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>) {
  return (
    <ScrollAreaPrimitive.ScrollAreaScrollbar
      data-slot="scroll-area-scrollbar"
      data-orientation={orientation}
      orientation={orientation}
      className={cn(
        "flex touch-none border-border bg-card select-none data-horizontal:h-5 data-horizontal:flex-col data-horizontal:border-t-(length:--pixel) data-vertical:h-full data-vertical:w-5 data-vertical:border-l-(length:--pixel)",
        className
      )}
      {...props}
    >
      <span
        aria-hidden="true"
        className="pointer-events-none absolute inset-0 bg-foreground dither-25"
      />
      <ScrollAreaPrimitive.ScrollAreaThumb
        data-slot="scroll-area-thumb"
        className="relative flex-1 pixel-border border-border bg-secondary bevel-raised offset-shadow-none"
      />
    </ScrollAreaPrimitive.ScrollAreaScrollbar>
  )
}

export { ScrollArea, ScrollBar }
```

## API reference

### ScrollArea

No props of its own. It forwards the props of the element or primitive it wraps.

### ScrollBar

No props of its own. It forwards the props of the element or primitive it wraps.

## Used by

- [window](https://www.ui95.dev/ui/window)
