All components alwayshoverxssmmdlg
Scroll Area
Custom scroll containers with a palette-tinted scrollbar in four thicknesses.
Deploy preview ready
Ana joined the team
Billing plan upgraded
New API key created
Domain verified
Webhook delivered
Backup completed
Invite sent to Sam
123456789101112131415161718import { ScrollArea } from "#components/ui/ui-sdk/scroll-area.tsx";
export function Example() { return ( // variant/size resolve once on Root; overflow detection, thumb sizing, // drag scrolling and scrollbar visibility come from UI SDK — the hover // variant reveals the scrollbar while hovering or scrolling (data-visible) <ScrollArea.Root variant="always" size="md"> <ScrollArea.Viewport> <ScrollArea.Content>{/* long content */}</ScrollArea.Content> </ScrollArea.Viewport> <ScrollArea.Scrollbar orientation="vertical"> <ScrollArea.Thumb /> </ScrollArea.Scrollbar> <ScrollArea.Corner /> </ScrollArea.Root> );}Variants
Deploy preview ready
Ana joined the team
Billing plan upgraded
New API key created
Domain verified
Webhook delivered
Backup completed
Invite sent to Sam
Deploy preview ready
Ana joined the team
Billing plan upgraded
New API key created
Domain verified
Webhook delivered
Backup completed
Invite sent to Sam
Sizes
Deploy preview ready
Ana joined the team
Billing plan upgraded
New API key created
Domain verified
Webhook delivered
Backup completed
Invite sent to Sam
Deploy preview ready
Ana joined the team
Billing plan upgraded
New API key created
Domain verified
Webhook delivered
Backup completed
Invite sent to Sam
Deploy preview ready
Ana joined the team
Billing plan upgraded
New API key created
Domain verified
Webhook delivered
Backup completed
Invite sent to Sam
Deploy preview ready
Ana joined the team
Billing plan upgraded
New API key created
Domain verified
Webhook delivered
Backup completed
Invite sent to Sam
Install
1npx stylexblocks add scroll-areaSource
components/ui/ui-sdk/scroll-area.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234import * as stylex from "@stylexjs/stylex";import { useContext } from "react";import { ScrollArea as UiSdkScrollArea, ScrollAreaContent as UiSdkScrollAreaContent, ScrollAreaCorner as UiSdkScrollAreaCorner, ScrollAreaScrollbar as UiSdkScrollAreaScrollbar, ScrollAreaThumb as UiSdkScrollAreaThumb, ScrollAreaViewport as UiSdkScrollAreaViewport,} from "@ui-sdk/react/scroll-area";import { createSlotRecipeContext } from "#lib/ui-sdk/create-slot-recipe-context.tsx";import { defineSlotRecipe, resolveSlotStyles } from "#lib/recipe-props.ts";import { colorPalette } from '@stylexblocks/ui/color-palette.stylex.ts'import { radii } from '@stylexblocks/ui/tokens/radii.stylex.ts'import { semanticColors } from '@stylexblocks/ui/semantic-tokens/colors.stylex.ts'import { sizes } from '@stylexblocks/ui/tokens/sizes.stylex.ts'
const scrollAreaRoot = stylex.create({ base: { display: 'flex', flexDirection: 'column', width: '100%', height: '100%', position: 'relative', overflow: 'hidden', '--scrollbar-margin': '2px', '--scrollbar-click-area': 'calc(var(--scrollbar-size) + calc(var(--scrollbar-margin) * 2))', },})
const scrollAreaRootSizes = stylex.create({ xs: { '--scrollbar-size': sizes._1, }, sm: { '--scrollbar-size': sizes._1_5, }, md: { '--scrollbar-size': sizes._2, }, lg: { '--scrollbar-size': sizes._3, },})
const scrollAreaViewport = stylex.create({ base: { display: 'flex', flexDirection: 'column', height: '100%', width: '100%', borderRadius: 'inherit', scrollbarWidth: 'none', },})
const scrollAreaContent = stylex.create({ base: { minWidth: '100%', },})
const scrollAreaScrollbar = stylex.create({ base: { display: 'flex', userSelect: 'none', touchAction: 'none', borderRadius: radii.full, transition: 'opacity 150ms 300ms', position: 'relative', margin: 'var(--scrollbar-margin)', backgroundColor: `color-mix(in oklch, ${colorPalette.solid} 10%, transparent)`, '--thumb-bg': `color-mix(in oklch, ${colorPalette.solid} 25%, transparent)`, '::before': { content: '""', position: 'absolute', }, },})
const scrollAreaScrollbarVariants = stylex.create({ hover: { opacity: 0, }, always: { opacity: 1, },})
const scrollAreaThumb = stylex.create({ base: { borderRadius: 'inherit', backgroundColor: 'var(--thumb-bg)', transition: 'backgrounds', },})
const scrollAreaCorner = stylex.create({ base: { backgroundColor: semanticColors.bgMuted, margin: 'var(--scrollbar-margin)', opacity: 0, transition: 'opacity 150ms 300ms', },})
export type ScrollAreaVariant = keyof typeof scrollAreaScrollbarVariants
export type ScrollAreaSize = keyof typeof scrollAreaRootSizes
// The generated recipe colors the scrollbar; its geometry (rail placement// per orientation, thumb fill from UI SDK's sizing vars) lives with the// component. UI SDK stamps `data-orientation` on scrollbar and thumb, and// decides visibility itself: each scrollbar gets `data-visible` per the// root's `type`, which the `hover` variant reveals on.const chrome = stylex.create({ scrollbar: { position: "absolute", flexDirection: { default: null, ':is([data-orientation="vertical"])': "column", }, width: { default: null, ':is([data-orientation="vertical"])': "var(--scrollbar-size)", }, height: { default: null, ':is([data-orientation="horizontal"])': "var(--scrollbar-size)", }, top: { default: null, ':is([data-orientation="vertical"])': "var(--scrollbar-margin)", }, bottom: { default: null, ':is([data-orientation="vertical"])': "var(--scrollbar-margin)", ':is([data-orientation="horizontal"])': 0, }, insetInlineEnd: { default: null, ':is([data-orientation="vertical"])': 0, ':is([data-orientation="horizontal"])': "var(--scrollbar-margin)", }, insetInlineStart: { default: null, ':is([data-orientation="horizontal"])': "var(--scrollbar-margin)", }, }, // Restates the hover variant's hidden state: StyleX merges per property, // so a `default: null` here would drop the variant's `opacity: 0`. scrollbarReveal: { opacity: { default: 0, ":is([data-visible])": 1, }, }, thumb: { width: { default: "100%", ':is([data-orientation="horizontal"])': "var(--scroll-area-thumb-width)", }, height: { default: "var(--scroll-area-thumb-height)", ':is([data-orientation="horizontal"])': "100%", }, }, viewport: { overflow: "auto" },});
// defineSlotRecipe validates the shape at compile time: default values must// exist in the axis maps, and slot keys must be `styles` or a declared axisconst scrollAreaSlotRecipe = defineSlotRecipe({ slots: { root: { styles: scrollAreaRoot, sizes: scrollAreaRootSizes }, viewport: { styles: scrollAreaViewport }, content: { styles: scrollAreaContent }, scrollbar: { styles: scrollAreaScrollbar, variants: scrollAreaScrollbarVariants, }, thumb: { styles: scrollAreaThumb }, corner: { styles: scrollAreaCorner }, }, defaultVariants: { size: "md", variant: "hover" },});
const { withProvider, withContext, VariantContext } = createSlotRecipeContext(scrollAreaSlotRecipe);
// The variant picks UI SDK's visibility mode unless `type` is passed:// `hover` shows the scrollbars while hovering or scrolling, `always` keeps// them up whenever their axis overflows.function RootNode(props: React.ComponentProps<typeof UiSdkScrollArea>) { const v = useContext(VariantContext); return ( <UiSdkScrollArea type={v.variant === "always" ? "auto" : "hover"} {...props} /> );}
/** * ScrollArea — UI SDK's scroll area wearing the generated recipe. * `<ScrollArea.Root variant size>` resolves the recipe once and every part * inherits it through context; overflow detection, thumb sizing, drag * scrolling and scrollbar visibility are UI SDK's. The `hover` variant * reveals the scrollbar while hovering or scrolling. Composition per part * via `render`. */export const ScrollArea = { Root: withProvider(RootNode, "root", "ScrollAreaRoot"), Viewport: withContext( UiSdkScrollAreaViewport, () => [scrollAreaViewport.base, chrome.viewport], "ScrollAreaViewport", ), Content: withContext(UiSdkScrollAreaContent, "content", "ScrollAreaContent"), Scrollbar: withContext( UiSdkScrollAreaScrollbar, (v) => [ ...resolveSlotStyles(scrollAreaSlotRecipe.slots.scrollbar, v), chrome.scrollbar, v.variant === "hover" && chrome.scrollbarReveal, ], "ScrollAreaScrollbar", ), Thumb: withContext( UiSdkScrollAreaThumb, () => [scrollAreaThumb.base, chrome.thumb], "ScrollAreaThumb", ), Corner: withContext(UiSdkScrollAreaCorner, "corner", "ScrollAreaCorner"),};