For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/en/components/grid.md.

Grid

Arrange content for different screen widths.

Basic usage

Design
Develop
Release
basic.tsx
import { Card, Grid } from '@ifhover/leaf-ui';

export function GridBasic() {
  return (
    <Grid columns={{ xs: 1, sm: 2, lg: 3 }} gap={16}>
      {['Design', 'Develop', 'Release'].map((label) => (
        <Card key={label}>{label}</Card>
      ))}
    </Grid>
  );
}

More examples

8 / 24
16 / 24
Responsive width
Hidden on narrow screens
advanced.tsx
import { Card, Col, Row, Space } from '@ifhover/leaf-ui';

export function GridColumns() {
  return (
    <Space direction="vertical" align="stretch">
      <Row gutter={12}>
        <Col span={8}>
          <Card>8 / 24</Card>
        </Col>
        <Col span={16}>
          <Card>16 / 24</Card>
        </Col>
      </Row>
      <Row gutter={12}>
        <Col xs={24} md={12}>
          <Card>Responsive width</Card>
        </Col>
        <Col xs={0} md={12}>
          <Card>Hidden on narrow screens</Card>
        </Col>
      </Row>
    </Space>
  );
}

Usage

Grid uses columns for equal-width columns. Row / Col use a 24-column span and offset. Responsive values follow viewport width and inherit values from smaller breakpoints.

Types

Import these types for data, callbacks and refs.

import type { ColProps, GridProps, RowProps } from '@ifhover/leaf-ui';

ColProps API

PropertyTypeDefaultDescription
spannumber24Column span; Col span 0 hides a column
offsetnumber0Preceding empty columns
xsnumber—Base breakpoint
smnumber—At 576px and above
mdnumber—At 768px and above
lgnumber—At 992px and above
xlnumber—At 1200px and above

GridProps API

PropertyTypeDefaultDescription
columnsnumber | Partial<Record<'xs' | 'sm' | 'md' | 'lg' | 'xl', number>>3Columns; unspecified breakpoints inherit smaller ones
gapnumber | string | readonly [number | string, number | string]16Gap; tuples use [vertical, horizontal]
align'start' | 'center' | 'end' | 'stretch''stretch'Alignment

RowProps API

PropertyTypeDefaultDescription
align'start' | 'center' | 'end' | 'stretch''stretch'Alignment
gutterGridProps['gap']16Grid gap; tuples use [vertical, horizontal]