A box that scrolls with a thin themed scrollbar and edges that fade where there's more.
- 1.0 kB JS 2.9 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
60 members
This example also uses Avatar. Install it too:
npx shadcn@latest add checkfu/uicontext/avatarimport type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Avatar } from "./ui/uicontext/components/Avatar.ts"import { ScrollArea } from "./ui/uicontext/components/ScrollArea.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, corner, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"import { workspace } from "./people.ts"const styles = stylex.create({ box: { inlineSize: "min(100%, 18rem)", borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel }, head: { paddingBlock: space.md, paddingInline: space.lg, fontSize: font.sm, fontWeight: 600, color: color.fg, borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line }, scroll: { maxBlockSize: 280 }, list: { margin: 0, padding: space.xs, listStyle: "none" }, row: { display: "flex", alignItems: "center", gap: space.md, minBlockSize: 36, paddingInline: space.sm, fontSize: font.base, color: color.fg }, name: { minInlineSize: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },})const members = workspace.slice(0, 60)// a channel's members: sixty people in a box the height of a fewexport const ChannelMembers = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.box)).children( h.div.attrs(sx(styles.head)).children(`${members.length} members`), ScrollArea(h, { label: "Members", style: styles.scroll, children: [ h.ul.attrs(sx(styles.list)).children( members.map((m) => h.li.key(m.id).attrs(sx(styles.row)).children(Avatar(h, { ...m, size: "xs", decorative: true }), h.span.attrs(sx(styles.name)).children(m.name))), ), ], }), )When to use
A box that scrolls with a thin themed scrollbar and edges that fade where there's more. Use Resizable Panels instead when people should choose how much room the content gets.
Usage
import { ScrollArea } from "./ui/uicontext/components/ScrollArea.ts"const styles = stylex.create({ box: { maxBlockSize: 240 } })export const Channels = <M>(h: Html.H<M>, names: ReadonlyArray<string>) => ScrollArea(h, { label: "Channels", style: styles.box, children: [h.ul.children(names.map((n) => h.li.key(n).children(n)))] })Examples
Sideways
orientation: "horizontal" scrolls a wide table inside a narrow card; the edge fades where there's more.
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { ScrollArea } from "./ui/uicontext/components/ScrollArea.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, corner, font, space, stroke } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ box: { inlineSize: "min(100%, 30rem)" }, table: { borderCollapse: "collapse", fontSize: font.sm, fontVariantNumeric: "tabular-nums", whiteSpace: "nowrap" }, cell: { paddingBlock: space.sm, paddingInline: space.lg, textAlign: "end", borderBlockEndWidth: stroke.hairline, borderBlockEndStyle: "solid", borderBlockEndColor: color.line, color: color.fg }, head: { color: color.muted, fontWeight: 500 }, first: { textAlign: "start", position: "sticky", insetInlineStart: 0, backgroundColor: color.panel }, frame: { borderWidth: stroke.hairline, borderStyle: "solid", borderColor: color.line, borderRadius: corner.card, backgroundColor: color.panel },})const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]const rows: ReadonlyArray<readonly [string, ReadonlyArray<number>]> = [ ["New customers", [212, 198, 240, 266, 251, 280, 302, 295, 318, 331, 347, 362]], ["Churned", [31, 28, 35, 30, 26, 33, 29, 27, 31, 25, 24, 22]], ["Net revenue ($k)", [84, 86, 91, 97, 99, 104, 111, 113, 119, 124, 131, 138]],]// a year of numbers in a narrow card: it scrolls sideways, the first column stays putexport const MonthlyNumbers = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.box, styles.frame)).children( ScrollArea(h, { label: "Monthly numbers, 2026", orientation: "horizontal", children: [ h.table.attrs(sx(styles.table)).children( h.thead.children(h.tr.children(h.th.attrs({ scope: "col", ...sx(styles.cell, styles.head, styles.first) }).children("2026"), months.map((m) => h.th.key(m).attrs({ scope: "col", ...sx(styles.cell, styles.head) }).children(m)))), h.tbody.children( rows.map(([label, values]) => h.tr.key(label).children( h.th.attrs({ scope: "row", ...sx(styles.cell, styles.head, styles.first) }).children(label), values.map((v, i) => h.td.key(String(i)).attrs(sx(styles.cell)).children(v.toLocaleString("en-US"))), )), ), ), ], }), )API reference
Options
| Name | Type | Default | Description |
|---|---|---|---|
key | string | — | Names the area among others in the same view; needed for more than one. |
label | string | — | What the area holds, for screen readers when it takes focus: "Members". |
orientation | "vertical" | "horizontal" | "both" | vertical | Which way it scrolls; vertical by default. |
fade | boolean | on | Fade the edges where there's more to scroll to; on by default. |
childrenrequired | View.Children | — | — |
style | Style | — | StyleX styles for the box: its height or max height, a border, a radius. |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/scroll-area