Components
Text that swaps in and out vertically as its scrollable container is navigated, with the current line sliding up while a clone rises into place.
Loading preview...
"use client";
import * as React from "react";
import { ScrollSwapText } from "@/components/ui/scroll-swap-text";
const features = [
"Zero-config setup",
"Spring physics built-in",
"Accessible by default",
"TypeScript first",
"Tree-shakeable exports",
"Server component ready",
];
export default function ScrollSwapTextFeatureList() {
const containerRef = React.useRef<HTMLDivElement>(null);
return (
<div className="flex min-h-[320px] w-full items-center justify-center bg-background px-6 py-10">
<div
className="h-48 w-full max-w-sm overflow-y-scroll rounded-lg border border-border bg-card"
ref={containerRef}
>
{features.map((feature) => (
<ScrollSwapText
as="div"
className="border-border border-b px-5 py-4 font-medium text-base text-foreground last:border-0"
containerRef={containerRef}
key={feature}
>
{feature}
</ScrollSwapText>
))}
</div>
</div>
);
}