Table
组合原生 table、caption、thead、tbody、tfoot、tr、th 和 td 元素。外层 container 提供 overflow-x-auto 与拟物 raised 表面。
@neumorphism-ui/table预览
| 代码 | 价格 | 涨跌 | 状态 |
|---|---|---|---|
| NVDA | $181.92 | +2.41% | 交易中 |
| 005930 | ₩72,400 | +1.08% | 已选择 |
| TSLA | $318.27 | −0.64% | 关注 |
安装
安装: table
npx shadcn@latest add @neumorphism-ui/tableCLI 会依次处理 npm 依赖、base token、utils 和组件源码。
首次使用此 Registry?请先完成 namespace 配置 。
用法
Import
Table import 代码
import {
Table,
TableBody,
TableCaption,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"Example
Table 用法代码
<Table>
<TableCaption>最近安装的组件</TableCaption>
<TableHeader>
<TableRow>
<TableHead scope="col">组件</TableHead>
<TableHead scope="col">分类</TableHead>
<TableHead scope="col">状态</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow>
<TableCell>Dialog</TableCell>
<TableCell>浮层</TableCell>
<TableCell>就绪</TableCell>
</TableRow>
</TableBody>
</Table>API 参考
| 组件 | 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|---|
Table | children必填 | React.ReactNode | — | 排列 caption 和各个 table section。 |
TableCaption | children | React.ReactNode | — | 说明表格用途和数据范围。 |
TableHead | scope | "col" | "row" | "colgroup" | "rowgroup" | — | 明确 header 所描述的 cell 方向。 |
TableRow | data-state | "selected" | string | — | 启用选中行的 inset 状态。 |
TableCell | colSpan / rowSpan | number | — | 设置原生 table cell 的合并范围。 |
无障碍
- 01
使用 TableCaption 说明表格用途;需要视觉隐藏时可应用 sr-only class。
- 02
列 header 和行 header 应设置符合语义的 scope。
- 03
不要使用 Table 仅为对齐布局,应改用 CSS grid 或 flex。