Primitives
Scroll Area
Custom-styled scrollbars plus fade-edge masks that appear only on edges with more content. A quiet upgrade for any overflowing region.
Motionnone — fade mask follows scroll position
Install
Install Kineto and follow the theme setup once in your app.
bash
npm install kinetotsx
import { ScrollArea, ScrollBar } from "kineto/scroll-area";Preview
tsx
"use client";
import * as React from "react";
import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
import { cn } from "@/lib/cn";
const ScrollBar = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
>(({ className, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.ScrollAreaScrollbar
ref={ref}
orientation={orientation}
className={cn(
"flex touch-none select-none transition-colors",
orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent p-px",
orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent p-px",
className
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border transition-colors hover:bg-muted-foreground/40" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
));
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
/** Build a `mask-image` that fades whichever edges still have content past them. */
function fadeMask(axis: "y" | "x", before: boolean, after: boolean, size: string): string | undefined {
if (!before && !after) return undefined;
const dir = axis === "y" ? "to bottom" : "to right";
const start = before ? "transparent" : "black";
const end = after ? "transparent" : "black";
return `linear-gradient(${dir}, ${start} 0, black ${size}, black calc(100% - ${size}), ${end} 100%)`;
}
export interface ScrollAreaProps
extends React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root> {
orientation?: "vertical" | "horizontal" | "both";
/** Fade content out at the edges it can still scroll toward. */
fade?: boolean;
/** Length of the fade region (any CSS length). */
fadeSize?: string;
viewportClassName?: string;
}
/**
* Custom-styled scrollbars (Radix) plus optional fade-edge masks that appear only on the edges with
* more content past them — a quiet upgrade for any overflowing region. The mask updates on scroll
* and resize, so it always reflects the real overflow state.
*/
const ScrollArea = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
ScrollAreaProps
>(
(
{ className, children, orientation = "vertical", fade = true, fadeSize = "2rem", viewportClassName, ...props },
ref
) => {
const viewportRef = React.useRef<HTMLDivElement>(null);
const [edges, setEdges] = React.useState({ top: false, bottom: false, left: false, right: false });
React.useEffect(() => {
const el = viewportRef.current;
if (!el) return;
const update = () => {
setEdges({
top: el.scrollTop > 1,
bottom: el.scrollTop + el.clientHeight < el.scrollHeight - 1,
left: el.scrollLeft > 1,
right: el.scrollLeft + el.clientWidth < el.scrollWidth - 1,
});
};
update();
el.addEventListener("scroll", update, { passive: true });
const observer = new ResizeObserver(update);
observer.observe(el);
if (el.firstElementChild) observer.observe(el.firstElementChild);
return () => {
el.removeEventListener("scroll", update);
observer.disconnect();
};
}, [children]);
const mask = fade
? orientation === "horizontal"
? fadeMask("x", edges.left, edges.right, fadeSize)
: fadeMask("y", edges.top, edges.bottom, fadeSize)
: undefined;
return (
<ScrollAreaPrimitive.Root
ref={ref}
className={cn("relative overflow-hidden", className)}
{...props}
>
<ScrollAreaPrimitive.Viewport
ref={viewportRef}
className={cn("h-full w-full rounded-[inherit]", viewportClassName)}
style={mask ? { WebkitMaskImage: mask, maskImage: mask } : undefined}
>
{children}
</ScrollAreaPrimitive.Viewport>
{(orientation === "vertical" || orientation === "both") && <ScrollBar orientation="vertical" />}
{(orientation === "horizontal" || orientation === "both") && <ScrollBar orientation="horizontal" />}
<ScrollAreaPrimitive.Corner />
</ScrollAreaPrimitive.Root>
);
}
);
ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
export { ScrollArea, ScrollBar };src/components/ui/scroll-area.tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| orientation | "vertical" | "horizontal" | "both" | "vertical" | Which scrollbar(s) to show. |
| fade | boolean | true | Fade content out at the edges it can still scroll toward. |
| fadeSize | string | "2rem" | Length of the fade region (any CSS length). |