For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/v/0.6.0/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/v/0.6.0/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/v/0.6.0/components/grid.md.
  • 简体中文
  • Grid 栅格

    根据屏幕宽度排列内容。

    基本用法

    设计
    开发
    发布
    basic.tsx
    import { Card, Grid } from '@ifhover/leaf-ui';
    
    export function GridBasic() {
      return (
        <Grid columns={{ xs: 1, sm: 2, lg: 3 }} gap={16}>
          {['设计', '开发', '发布'].map((label) => (
            <Card key={label}>{label}</Card>
          ))}
        </Grid>
      );
    }
    

    更多用法

    8 / 24
    16 / 24
    自适应宽度
    窄屏隐藏
    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>自适应宽度</Card>
            </Col>
            <Col xs={0} md={12}>
              <Card>窄屏隐藏</Card>
            </Col>
          </Row>
        </Space>
      );
    }
    

    使用说明

    Grid 使用 columns 设置等宽列;Row / Col 使用 24 栅格跨度与 offset。响应式配置按浏览器宽度生效,较大断点继承较小断点的设置。

    类型

    组装数据、定义回调和使用 ref 时,可以导入这些类型。

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

    ColProps API

    属性类型默认值说明
    spannumber24跨列数,Col 的 0 表示隐藏
    offsetnumber0前方空出的列数
    xsnumber—小屏配置
    smnumber—≥ 576px 配置
    mdnumber—≥ 768px 配置
    lgnumber—≥ 992px 配置
    xlnumber—≥ 1200px 配置

    GridProps API

    属性类型默认值说明
    columnsnumber | Partial<Record<'xs' | 'sm' | 'md' | 'lg' | 'xl', number>>3列数;较大断点继承较小断点
    gapnumber | string | readonly [number | string, number | string]16间距;数组为 [纵向, 横向]
    align'start' | 'center' | 'end' | 'stretch''stretch'对齐方式

    RowProps API

    属性类型默认值说明
    align'start' | 'center' | 'end' | 'stretch''stretch'对齐方式
    gutterGridProps['gap']16栅格间距;数组为 [纵向, 横向]