Since 1.0.0BETA

Grid

Structured layout and alignment

This page was migrated by AI, please review carefully

Migration is complete, but please validate against source code and manual review.

Grid

Grid provides a modern CSS Grid layout system with responsive and flexible configuration.

Basic Usage

Grid

Demo loads on client.

Simple grid layout:

EXAMPLE.VUE
<template>
  <TxGrid :cols="3" gap="16">
    <TxGridItem>Item 1</TxGridItem>
    <TxGridItem>Item 2</TxGridItem>
    <TxGridItem>Item 3</TxGridItem>
    <TxGridItem>Item 4</TxGridItem>
    <TxGridItem>Item 5</TxGridItem>
    <TxGridItem>Item 6</TxGridItem>
  </TxGrid>
</template>

Responsive Grid

Responsive columns

EXAMPLE.VUE
<template>
  <TxGrid :cols="{ xs: 1, sm: 2, md: 3, lg: 4, xl: 5 }" gap="20">
    <TxGridItem v-for="i in 10" :key="i">
      <TxCard>Item {{ i }}</TxCard>
    </TxGridItem>
  </TxGrid>
</template>

Auto-fit grid

EXAMPLE.VUE
<template>
  <TxGrid min-item-width="250px" gap="24">
    <TxGridItem v-for="item in items" :key="item.id">
      <TxCard>
        <h3>{{ item.title }}</h3>
        <p>{{ item.description }}</p>
      </TxCard>
    </TxGridItem>
  </TxGrid>
</template>

Grid Gaps

Uniform gap

EXAMPLE.VUE
<template>
  <TxGrid :cols="3" gap="32">
    <TxGridItem v-for="i in 6" :key="i">
      Item {{ i }}
    </TxGridItem>
  </TxGrid>
</template>

Row / column gaps

EXAMPLE.VUE
<template>
  <TxGrid :cols="3" :gap="{ row: 24, col: 16 }">
    <TxGridItem v-for="i in 6" :key="i">
      Item {{ i }}
    </TxGridItem>
  </TxGrid>
</template>

Responsive gaps

EXAMPLE.VUE
<template>
  <TxGrid
    :cols="{ xs: 1, md: 2, lg: 3 }"
    :gap="{ xs: 16, md: 24, lg: 32 }"
  >
    <TxGridItem v-for="i in 6" :key="i">
      Item {{ i }}
    </TxGridItem>
  </TxGrid>
</template>

Grid Items

Column span

EXAMPLE.VUE
<template>
  <TxGrid :cols="4" gap="16">
    <TxGridItem>Item</TxGridItem>
    <TxGridItem :col-span="2">Span 2</TxGridItem>
    <TxGridItem>Item</TxGridItem>
    <TxGridItem :col-span="3">Span 3</TxGridItem>
    <TxGridItem>Item</TxGridItem>
  </TxGrid>
</template>

Row span

EXAMPLE.VUE
<template>
  <TxGrid :cols="3" gap="16">
    <TxGridItem>Item 1</TxGridItem>
    <TxGridItem :row-span="2">Span 2 rows</TxGridItem>
    <TxGridItem>Item 3</TxGridItem>
    <TxGridItem>Item 4</TxGridItem>
    <TxGridItem>Item 5</TxGridItem>
  </TxGrid>
</template>

Alignment

Grid alignment

EXAMPLE.VUE
<template>
  <TxGrid
    :cols="3"
    gap="16"
    justify="center"
    align="center"
    style="height: 400px;"
  >
    <TxGridItem v-for="i in 3" :key="i">
      Item {{ i }}
    </TxGridItem>
  </TxGrid>
</template>

Item alignment

EXAMPLE.VUE
<template>
  <TxGrid :cols="3" gap="16">
    <TxGridItem justify-self="start">Start</TxGridItem>
    <TxGridItem justify-self="center">Center</TxGridItem>
    <TxGridItem justify-self="end">End</TxGridItem>
  </TxGrid>
</template>

API Reference

Grid Props

NameTypeDefaultDescription
colsnumber | ResponsiveValue1Columns
rowsnumber | ResponsiveValueautoRows
gapnumber | string | ResponsiveValue | GapValue0Grid gap
minItemWidthstring-Min item width (auto-fit)
justify'start' | 'end' | 'center' | 'stretch''stretch'Horizontal alignment
align'start' | 'end' | 'center' | 'stretch''stretch'Vertical alignment
autoRowsstring'auto'Auto row height
densebooleanfalseDense layout

GridItem Props

NameTypeDefaultDescription
colSpannumber | ResponsiveValue1Column span
rowSpannumber | ResponsiveValue1Row span
colStartnumber-Column start
colEndnumber-Column end
rowStartnumber-Row start
rowEndnumber-Row end
justifySelf'start' | 'end' | 'center' | 'stretch'-Item horizontal alignment
alignSelf'start' | 'end' | 'center' | 'stretch'-Item vertical alignment

Types

EXAMPLE.TS
interface ResponsiveValue {
  xs?: number
  sm?: number
  md?: number
  lg?: number
  xl?: number
  xxl?: number
}

interface GapValue {
  row?: number | string
  col?: number | string
}
Was this helpful?