Scroll Area
Augments native scroll functionality for custom, styled scrollbars.
Basic Usage
Installation
pnpm add @corew500/uiUsage
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
| Prop | Type | Default | Description |
|---|---|---|---|
| overflowEdgeThreshold | enum | 0 | The 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. |
| style | enum | — | Style applied to the element, or a function that returns a style object based on the component’s state. |
| className | enum | — | CSS class applied to the element, or a function that returns a class based on the component’s state. |
| render | enum | — | Allows 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
| Prop | Type | Default | Description |
|---|---|---|---|
| orientation | enum | vertical | Whether the scrollbar controls vertical or horizontal scroll. |
| keepMounted | enum | false | Whether to keep the HTML element in the DOM when the viewport isn’t scrollable. |
| style | enum | — | Style applied to the element, or a function that returns a style object based on the component’s state. |
| className | enum | — | CSS class applied to the element, or a function that returns a class based on the component’s state. |
| render | enum | — | Allows 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. |