Veil UI
Components

Grid Item

Places an item across columns and rows of a 12-column grid.

Installation

$ npx veil-ui@latest add grid-item

Usage

import { Grid } from "@/components/ui/grid";
import { GridItem } from "@/components/ui/grid-item";

<Grid cols={12}>
  <GridItem colSpan={8}>Main</GridItem>
  <GridItem colSpan={4}>Aside</GridItem>
</Grid>;

Examples

Basic

Main
Aside

Spans

Full width
Half
Half

Dashboard

Sidebar
Header
Content

API reference

PropTypeDefaultDescription
colSpan1–121Columns to span on a 12-column parent grid.
rowSpan1–61Rows to span on the parent grid.
...propsReact.ComponentProps<"div">—All native div attributes.

Accessibility

  • Presentational wrapper; grid placement is visual only.
  • Keep the reading order of the items matching the visual order.
  • For responsive placement, add your own sm:/lg: span classes through className.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add grid-item --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { computed } from "vue";

import { cn } from "@/lib/utils";

const colSpans = {
  1: "col-span-1",
  2: "col-span-2",
  3: "col-span-3",
  4: "col-span-4",
  5: "col-span-5",
  6: "col-span-6",
  7: "col-span-7",
  8: "col-span-8",
  9: "col-span-9",
  10: "col-span-10",
  11: "col-span-11",
  12: "col-span-12",
} as const;

const rowSpans = {
  1: "row-span-1",
  2: "row-span-2",
  3: "row-span-3",
  4: "row-span-4",
  5: "row-span-5",
  6: "row-span-6",
} as const;

const props = withDefaults(
  defineProps<{
    colSpan?: keyof typeof colSpans;
    rowSpan?: keyof typeof rowSpans;
    class?: string;
  }>(),
  { colSpan: 1, rowSpan: 1 },
);

const classes = computed(() =>
  cn("min-w-0", colSpans[props.colSpan], rowSpans[props.rowSpan], props.class),
);
</script>

<template>
  <div
    data-slot="grid-item"
    :data-col-span="colSpan"
    :data-row-span="rowSpan"
    :class="classes"
  >
    <slot />
  </div>
</template>

On this page