Table
用于结构化数据的行和列。
| Slot | Components | Status |
|---|---|---|
| Header | Command, Button | Override |
| Sidebar | Sidebar, Resizable | Override |
| Footer | Footer | Override |
| EditLink | — | Starlight |
导入
“导入”部分import { Table, TableCaption, TableHeader, TableBody, TableFooter, TableRow, TableHead, TableCell,} from "@pelagornis/page/components";示例
“示例”部分上方预览渲染的就是这个文件。把它复制到 src/components/ 即可开始使用。
import { Badge, Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow,} from "@pelagornis/page/components";
const rows = [ { slot: "Header", component: "Command, Button", status: "Override" }, { slot: "Sidebar", component: "Sidebar, Resizable", status: "Override" }, { slot: "Footer", component: "Footer", status: "Override" }, { slot: "EditLink", component: "—", status: "Starlight" },];
export default function TableDemo() { return ( <Table> <TableCaption>Starlight slots and the RefineUI components behind them</TableCaption> <TableHeader> <TableRow> <TableHead>Slot</TableHead> <TableHead>Components</TableHead> <TableHead>Status</TableHead> </TableRow> </TableHeader> <TableBody> {rows.map((row) => ( <TableRow key={row.slot}> <TableCell>{row.slot}</TableCell> <TableCell>{row.component}</TableCell> <TableCell> <Badge variant={row.status === "Override" ? "success" : "neutral"}>{row.status}</Badge> </TableCell> </TableRow> ))} </TableBody> </Table> );}在 MDX 中使用
“在 MDX 中使用”部分Table 由共享 React 状态的多个部件组成。写在 MDX 中的子元素会各自渲染成独立的岛,部件之间无法互通。请像上面的示例一样在 .tsx 文件中组合,再导入该文件。
---title: Example---
import TableExample from "../../components/TableExample";
<TableExample client:load />client:load 会在页面加载时水合该岛。位于页面靠下位置的内容请使用 client:visible。
在 Markdoc 中使用
“在 Markdoc 中使用”部分Markdoc 标签渲染的是 Astro 组件,而这个组件需要客户端状态。请把示例包进一个负责水合的 .astro 文件,再把该文件注册为标签。
---import TableExample from "../TableExample";---
<TableExample client:load />import { component, defineMarkdocConfig } from "@astrojs/markdoc/config";import starlightMarkdoc from "@astrojs/starlight-markdoc";import pageMarkdoc from "@pelagornis/page/markdoc";
export default defineMarkdocConfig({ extends: [starlightMarkdoc(), pageMarkdoc()], tags: { "table-example": { render: component("./src/components/markdoc/TableExample.astro"), selfClosing: true, }, },});{% table-example /%}结构
“结构”部分组件的组成部分,以及每个部分渲染的 data-refineui 角色。
| 部件 | 角色 |
|---|---|
root | table |
row | table-row |
参考
“参考”部分- 设计指南和令牌细节见 RefineUI · Table。
- 通用规则见在 MDX 中使用和在 Markdoc 中使用。