Open History to see the last commit
1import { ScrollArea as ScrollAreaPrimitive } from '@ark-ui/solid'
2import { splitProps } from 'solid-js'
3import { cn } from '@/utils'
4β
5// Ported from the original shadcn/ui + Radix UI + React component.
6// This wraps the Ark UI + SolidJS primitive and preserves shadcn's Tailwind-based
7// design-system API, variants, and styling.
8// https://ui.shadcn.com/
9β
10/**
11 * A styled scroll container with a viewport, corner, and default vertical
12 * scrollbar.
13 *
14 * @example
15 * ```tsx
16 * <ScrollArea class="h-40" horizontalScrollbar>
17 * <div class="p-4">Scrollable content</div>
18 * </ScrollArea>
19 * ```
20 */
21interface ScrollAreaProps extends ScrollAreaPrimitive.RootProps {
22 horizontalScrollbar?: boolean
23}
24β
25function ScrollArea(props: ScrollAreaProps) {
26 const [local, others] = splitProps(props, [
27 'class',
28 'children',
29 'horizontalScrollbar',
30 ])
31β
32 return (
33 <ScrollAreaPrimitive.Root
34 data-slot="scroll-area"
35 class={cn('relative', local.class)}
36 {...others}
37 >
38 <ScrollAreaPrimitive.Viewport
39 data-slot="scroll-area-viewport"
40 class="size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1"
41 >
42 <ScrollAreaPrimitive.Content
43 data-slot="scroll-area-content"
44 class="min-h-full"
45 >
46 {local.children}
47 </ScrollAreaPrimitive.Content>
48 </ScrollAreaPrimitive.Viewport>
49 <ScrollBar />
50 {local.horizontalScrollbar && <ScrollBar orientation="horizontal" />}
51 <ScrollAreaPrimitive.Corner data-slot="scroll-area-corner" />
52 </ScrollAreaPrimitive.Root>
53 )
54}
55β
56/**
57 * The styled scrollbar part used by ScrollArea.
58 */
59function ScrollBar(props: ScrollAreaPrimitive.ScrollbarProps) {
60 const [local, others] = splitProps(props, ['class', 'orientation'])
61β
62 const orientation = () => local.orientation ?? 'vertical'
63β
64 return (
65 <ScrollAreaPrimitive.Scrollbar
66 data-slot="scroll-area-scrollbar"
67 data-orientation={orientation()}
68 orientation={orientation()}
69 class={cn(
70 'flex touch-none p-px transition-colors select-none data-horizontal:h-2.5 data-horizontal:flex-col data-horizontal:border-t data-horizontal:border-t-transparent data-vertical:h-full data-vertical:w-2.5 data-vertical:border-l data-vertical:border-l-transparent',
71 local.class,
72 )}
73 {...others}
74 >
75 <ScrollAreaPrimitive.Thumb
76 data-slot="scroll-area-thumb"
77 class="relative flex-1 rounded-full bg-border"
78 />
79 </ScrollAreaPrimitive.Scrollbar>
80 )
81}
82β
83export { ScrollArea, ScrollBar }