GitHub

Scroll Area

Augments native scroll functionality for custom, styled scrollbars.

Basic Usage

Loading...
Scroll AreaCustom scrollable containers

Installation

pnpm add @corew500/ui

Usage

import { ScrollArea } from "@mordecai-design-system/ui"
<ScrollArea className="h-[200px]">
  <div className="p-4">
    {/* Long content here */}
  </div>
</ScrollArea>

Examples

Vertical Scroll

<ScrollArea className="h-72 w-48 rounded-md border">
  <div className="p-4">
    {tags.map((tag) => (
      <div key={tag} className="text-sm">{tag}</div>
    ))}
  </div>
</ScrollArea>

Horizontal Scroll

<ScrollArea className="w-96 whitespace-nowrap rounded-md border">
  <div className="flex w-max space-x-4 p-4">
    {works.map((artwork) => (
      <figure key={artwork.artist} className="shrink-0">
        <img src={artwork.src} alt={artwork.title} />
      </figure>
    ))}
  </div>
  <ScrollBar orientation="horizontal" />
</ScrollArea>

With ScrollBar

import { ScrollArea, ScrollBar } from "@mordecai-design-system/ui"

<ScrollArea className="h-[200px] w-[350px]">
  <div className="p-4">
    {/* Content */}
  </div>
  <ScrollBar orientation="vertical" />
</ScrollArea>

Both Directions

<ScrollArea className="h-[300px] w-[400px]">
  <div className="w-[600px] p-4">
    {/* Wide and tall content */}
  </div>
  <ScrollBar orientation="vertical" />
  <ScrollBar orientation="horizontal" />
</ScrollArea>

Props

ScrollArea

PropTypeDefaultDescription
overflowEdgeThresholdenum0The threshold in pixels that must be passed before the overflow edge attributes are applied. Accepts a single number for all edges or an object to configure them individually.
styleenumStyle applied to the element, or a function that returns a style object based on the component’s state.
classNameenumCSS class applied to the element, or a function that returns a class based on the component’s state.
renderenumAllows you to replace the component’s HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.

ScrollBar

PropTypeDefaultDescription
orientationenumverticalWhether the scrollbar controls vertical or horizontal scroll.
keepMountedenumfalseWhether to keep the HTML element in the DOM when the viewport isn’t scrollable.
styleenumStyle applied to the element, or a function that returns a style object based on the component’s state.
classNameenumCSS class applied to the element, or a function that returns a class based on the component’s state.
renderenumAllows you to replace the component’s HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.