Primitives
Grid
CSS grid wrapper with a column count and a gap from the shared scale. Layer responsive cols via className.
Motionnone — layout primitive
Install
Install Kineto and follow the theme setup once in your app.
bash
npm install kinetotsx
import { Grid, gridVariants } from "kineto/grid";Preview
01
02
03
04
05
06
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 gridVariants = cva("grid min-w-0", {
variants: {
cols: {
1: "grid-cols-1",
2: "grid-cols-2",
3: "grid-cols-3",
4: "grid-cols-4",
5: "grid-cols-5",
6: "grid-cols-6",
12: "grid-cols-12",
},
align: {
start: "items-start",
center: "items-center",
end: "items-end",
stretch: "items-stretch",
},
justify: {
start: "justify-items-start",
center: "justify-items-center",
end: "justify-items-end",
stretch: "justify-items-stretch",
},
flow: {
row: "grid-flow-row",
col: "grid-flow-col",
dense: "grid-flow-row-dense",
},
},
defaultVariants: {
cols: 1,
},
});
export interface GridProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof gridVariants> {
/** Space between cells, from the shared gap scale. */
gap?: Gap;
/** Render as the child element instead of a `<div>`. */
asChild?: boolean;
}
/**
* A CSS grid wrapper with a fixed column count and a `gap` from the shared scale. For responsive
* layouts, set a base `cols` and layer breakpoint utilities via `className`
* (e.g. `<Grid cols={1} className="md:grid-cols-3">`) — tailwind-merge keeps the override.
*/
const Grid = React.forwardRef<HTMLDivElement, GridProps>(
({ className, cols, align, justify, flow, gap = "md", asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "div";
return (
<Comp
ref={ref}
className={cn(gridVariants({ cols, align, justify, flow }), gapClass[gap], className)}
{...props}
/>
);
}
);
Grid.displayName = "Grid";
export { Grid, gridVariants };src/components/ui/grid.tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| cols | 1 | 2 | 3 | 4 | 5 | 6 | 12 | 1 | Column count. For responsive layouts add breakpoint utilities via className. |
| gap | "none" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "md" | Space between cells, from the shared gap scale. |
| align | "start" | "center" | "end" | "stretch" | — | Cell block-axis alignment (align-items). |
| justify | "start" | "center" | "end" | "stretch" | — | Cell inline-axis alignment (justify-items). |
| flow | "row" | "col" | "dense" | — | Grid auto-flow. |
| asChild | boolean | false | Render as the child element instead of a <div>. |