Primitives
Stack
Stack children in a line with a consistent gap — vertical by default. Replaces ad-hoc space-y / mt utilities.
Motionnone — layout primitive
Install
Install Kineto and follow the theme setup once in your app.
bash
npm install kinetotsx
import { Stack, stackVariants } from "kineto/stack";Preview
First
Second
Third
tsx
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/cn";
import { gapClass, type Gap } from "@/lib/gap";
const stackVariants = cva("flex min-w-0", {
variants: {
direction: {
vertical: "flex-col",
horizontal: "flex-row",
},
align: {
start: "items-start",
center: "items-center",
end: "items-end",
stretch: "items-stretch",
baseline: "items-baseline",
},
justify: {
start: "justify-start",
center: "justify-center",
end: "justify-end",
between: "justify-between",
around: "justify-around",
evenly: "justify-evenly",
},
wrap: {
true: "flex-wrap",
false: "flex-nowrap",
},
},
defaultVariants: {
direction: "vertical",
align: "stretch",
justify: "start",
wrap: false,
},
});
export interface StackProps
extends React.HTMLAttributes<HTMLDivElement>,
Omit<VariantProps<typeof stackVariants>, "wrap"> {
/** Space between children, from the shared gap scale. */
gap?: Gap;
/** Allow children to wrap onto multiple lines. */
wrap?: boolean;
/** Render as the child element instead of a `<div>`. */
asChild?: boolean;
}
/**
* Stack things in a line with a consistent gap. Vertical by default (the common case); flip to
* `direction="horizontal"` for a row. This is the primitive that replaces a hundred ad-hoc
* `space-y-*` / `mt-*` choices — pick a `gap` from the scale and move on.
*/
const Stack = React.forwardRef<HTMLDivElement, StackProps>(
({ className, direction, align, justify, wrap, gap = "md", asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "div";
return (
<Comp
ref={ref}
className={cn(stackVariants({ direction, align, justify, wrap }), gapClass[gap], className)}
{...props}
/>
);
}
);
Stack.displayName = "Stack";
export { Stack, stackVariants };src/components/ui/stack.tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| direction | "vertical" | "horizontal" | "vertical" | Lay children out in a column or a row. |
| gap | "none" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "md" | Space between children, from the shared gap scale. |
| align | "start" | "center" | "end" | "stretch" | "baseline" | "stretch" | Cross-axis alignment (align-items). |
| justify | "start" | "center" | "end" | "between" | "around" | "evenly" | "start" | Main-axis distribution (justify-content). |
| wrap | boolean | false | Allow children to wrap onto multiple lines. |
| asChild | boolean | false | Render as the child element instead of a <div>. |