|
| 1 | +/** |
| 2 | + * Copied from shadc/ui on 03/05/2025 |
| 3 | + * @see {@link https://ui.shadcn.com/docs/components/scroll-area} |
| 4 | + */ |
| 5 | +import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"; |
| 6 | +import * as React from "react"; |
| 7 | +import { cn } from "utils/cn"; |
| 8 | + |
| 9 | +export const ScrollArea = React.forwardRef< |
| 10 | + React.ElementRef<typeof ScrollAreaPrimitive.Root>, |
| 11 | + React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root> |
| 12 | +>(({ className, children, ...props }, ref) => ( |
| 13 | + <ScrollAreaPrimitive.Root |
| 14 | + ref={ref} |
| 15 | + className={cn("relative overflow-hidden", className)} |
| 16 | + {...props} |
| 17 | + > |
| 18 | + <ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]"> |
| 19 | + {children} |
| 20 | + </ScrollAreaPrimitive.Viewport> |
| 21 | + <ScrollBar /> |
| 22 | + <ScrollAreaPrimitive.Corner /> |
| 23 | + </ScrollAreaPrimitive.Root> |
| 24 | +)); |
| 25 | +ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName; |
| 26 | + |
| 27 | +export const ScrollBar = React.forwardRef< |
| 28 | + React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>, |
| 29 | + React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar> |
| 30 | +>(({ className, orientation = "vertical", ...props }, ref) => ( |
| 31 | + <ScrollAreaPrimitive.ScrollAreaScrollbar |
| 32 | + ref={ref} |
| 33 | + orientation={orientation} |
| 34 | + className={cn( |
| 35 | + "border-0 border-solid border-border flex touch-none select-none transition-colors", |
| 36 | + orientation === "vertical" && |
| 37 | + "h-full w-2.5 border-l border-l-transparent p-[1px]", |
| 38 | + orientation === "horizontal" && |
| 39 | + "h-2.5 flex-col border-t border-t-transparent p-[1px]", |
| 40 | + className, |
| 41 | + )} |
| 42 | + {...props} |
| 43 | + > |
| 44 | + <ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" /> |
| 45 | + </ScrollAreaPrimitive.ScrollAreaScrollbar> |
| 46 | +)); |
0 commit comments