Stack
LayoutVertical or horizontal stack with consistent spacing.
Preview
Vertical 1
Vertical 2
Vertical 3
Horizontal 1
Horizontal 2
Horizontal 3
Usage
example.jsx
import { Stack } from "@/components/ui/stack";
export default function Example() {
return <Stack />;
}Source Code
Copy this file into components/ui/stack.jsx in your project.
stack.jsx
import { forwardRef } from "react";
import { cn } from "@/lib/utils";
const Stack = forwardRef(({ className, gap = 4, direction = "vertical", align, justify, ...props }, ref) => (
<div
ref={ref}
className={cn(
"flex",
direction === "vertical" && "flex-col",
direction === "horizontal" && "flex-row",
gap === 1 && "gap-1",
gap === 2 && "gap-2",
gap === 3 && "gap-3",
gap === 4 && "gap-4",
gap === 6 && "gap-6",
gap === 8 && "gap-8",
align === "start" && "items-start",
align === "center" && "items-center",
align === "end" && "items-end",
align === "stretch" && "items-stretch",
justify === "start" && "justify-start",
justify === "center" && "justify-center",
justify === "end" && "justify-end",
justify === "between" && "justify-between",
className
)}
{...props}
/>
));
Stack.displayName = "Stack";
export { Stack };
Quick Install
Make sure you have the cn() utility set up. It requires clsx and tailwind-merge.
npm install clsx tailwind-merge