Descriptions
以结构化、易读的格式显示键值对。
import { Descriptions } from 'asterui'基础描述列表
简单的键值对显示。
| Name | John Doe | john@example.com | Phone | +1 234 567 890 | |
|---|---|---|---|---|---|
| Location | San Francisco, CA | Status | Active |
import { Descriptions } from 'asterui'
function App() {
const items = [
{ key: 'name', label: 'Name', children: 'John Doe' },
{ key: 'email', label: 'Email', children: 'john@example.com' },
{ key: 'phone', label: 'Phone', children: '+1 234 567 890' },
{ key: 'location', label: 'Location', children: 'San Francisco, CA' },
{ key: 'status', label: 'Status', children: 'Active' },
]
return (
<Descriptions items={items} />
)
}
export default App 带边框
带边框的描述列表。
Order Details
| Product | AsterUI Pro | Price | $99.00 | Quantity | 2 |
|---|---|---|---|---|---|
| Total | $198.00 |
import { Descriptions } from 'asterui'
function App() {
const items = [
{ key: 'product', label: 'Product', children: 'AsterUI Pro' },
{ key: 'price', label: 'Price', children: '$99.00' },
{ key: 'quantity', label: 'Quantity', children: '2' },
{ key: 'total', label: 'Total', children: '$198.00' },
]
return (
<Descriptions items={items} bordered title="Order Details" />
)
}
export default App 尺寸
不同的尺寸变体。
Small
| Name | Jane Smith | Role | Engineer | Team | Frontend |
|---|
Medium
| Name | Jane Smith | Role | Engineer | Team | Frontend |
|---|
Large
| Name | Jane Smith | Role | Engineer | Team | Frontend |
|---|
import { Descriptions, Space } from 'asterui'
function App() {
const items = [
{ key: 'name', label: 'Name', children: 'Jane Smith' },
{ key: 'role', label: 'Role', children: 'Engineer' },
{ key: 'team', label: 'Team', children: 'Frontend' },
]
return (
<Space direction="vertical" size="lg" className="w-full">
<Descriptions items={items} size="sm" bordered title="Small" />
<Descriptions items={items} size="md" bordered title="Medium" />
<Descriptions items={items} size="lg" bordered title="Large" />
</Space>
)
}
export default App 带标题和额外内容
在头部显示标题和额外内容。
User Profile
| Name | John Doe | john@example.com | Status | Active |
|---|
import { Descriptions, Button, Badge } from 'asterui'
function App() {
const items = [
{ key: 'name', label: 'Name', children: 'John Doe' },
{ key: 'email', label: 'Email', children: 'john@example.com' },
{ key: 'status', label: 'Status', children: <Badge color="success">Active</Badge> },
]
return (
<Descriptions
items={items}
bordered
title="User Profile"
extra={<Button size="sm">Edit</Button>}
/>
)
}
export default App 垂直布局
标签和内容垂直布局。
| Created | Updated | Author |
|---|---|---|
| 2024-01-15 10:30:00 | 2024-01-20 14:45:00 | Jane Smith |
import { Descriptions } from 'asterui'
function App() {
const items = [
{ key: 'created', label: 'Created', children: '2024-01-15 10:30:00' },
{ key: 'updated', label: 'Updated', children: '2024-01-20 14:45:00' },
{ key: 'author', label: 'Author', children: 'Jane Smith' },
]
return (
<Descriptions items={items} layout="vertical" bordered />
)
}
export default App 自定义列数
控制列的数量。
| Name | Alice Johnson | Age | 28 |
|---|---|---|---|
| Gender | Female | Occupation | Software Engineer |
| Department | Engineering | Start Date | 2022-03-15 |
import { Descriptions } from 'asterui'
function App() {
const items = [
{ key: 'name', label: 'Name', children: 'Alice Johnson' },
{ key: 'age', label: 'Age', children: '28' },
{ key: 'gender', label: 'Gender', children: 'Female' },
{ key: 'occupation', label: 'Occupation', children: 'Software Engineer' },
{ key: 'department', label: 'Department', children: 'Engineering' },
{ key: 'start-date', label: 'Start Date', children: '2022-03-15' },
]
return (
<Descriptions items={items} column={2} bordered />
)
}
export default App 响应式列数
列数根据视口宽度调整。
Resize window to see columns change
| Field 1 | Value 1 | Field 2 | Value 2 | Field 3 | Value 3 |
|---|---|---|---|---|---|
| Field 4 | Value 4 | Field 5 | Value 5 | Field 6 | Value 6 |
import { Descriptions } from 'asterui'
function App() {
const items = [
{ key: 'field1', label: 'Field 1', children: 'Value 1' },
{ key: 'field2', label: 'Field 2', children: 'Value 2' },
{ key: 'field3', label: 'Field 3', children: 'Value 3' },
{ key: 'field4', label: 'Field 4', children: 'Value 4' },
{ key: 'field5', label: 'Field 5', children: 'Value 5' },
{ key: 'field6', label: 'Field 6', children: 'Value 6' },
]
return (
<Descriptions
items={items}
bordered
column={{ xs: 1, sm: 2, md: 3, lg: 4 }}
title="Resize window to see columns change"
/>
)
}
export default App 列跨度
跨越多列的项目。
| Name | Product X | SKU | PRD-12345 | Category | Electronics |
|---|---|---|---|---|---|
| Description | A detailed product description that spans multiple columns for better readability. | ||||
import { Descriptions } from 'asterui'
function App() {
const items = [
{ key: 'name', label: 'Name', children: 'Product X' },
{ key: 'sku', label: 'SKU', children: 'PRD-12345' },
{ key: 'category', label: 'Category', children: 'Electronics' },
{ key: 'description', label: 'Description', children: 'A detailed product description that spans multiple columns for better readability.', span: 3 },
]
return (
<Descriptions items={items} bordered />
)
}
export default App 填充跨度
填充剩余行空间的项目。
| Name | John Doe | Notes | This field fills the remaining space in the row. | ||
|---|---|---|---|---|---|
| john@example.com | Phone | +1 234 567 890 | Address | 123 Main St, San Francisco, CA 94102 | |
import { Descriptions } from 'asterui'
function App() {
const items = [
{ key: 'name', label: 'Name', children: 'John Doe' },
{ key: 'notes', label: 'Notes', children: 'This field fills the remaining space in the row.', span: 'filled' as const },
{ key: 'email', label: 'Email', children: 'john@example.com' },
{ key: 'phone', label: 'Phone', children: '+1 234 567 890' },
{ key: 'address', label: 'Address', children: '123 Main St, San Francisco, CA 94102', span: 'filled' as const },
]
return (
<Descriptions items={items} bordered />
)
}
export default App 无冒号
隐藏标签后的冒号。
| Field One | Value One | Field Two | Value Two | Field Three | Value Three |
|---|
import { Descriptions } from 'asterui'
function App() {
const items = [
{ key: 'field1', label: 'Field One', children: 'Value One' },
{ key: 'field2', label: 'Field Two', children: 'Value Two' },
{ key: 'field3', label: 'Field Three', children: 'Value Three' },
]
return (
<Descriptions items={items} colon={false} bordered />
)
}
export default App 自定义样式
为语义部分应用自定义样式和类名。
Custom Styled
| Name | Jane Doe | Highlighted | This item has custom styles | Status | Active |
|---|
import { Descriptions } from 'asterui'
function App() {
const items = [
{ key: 'name', label: 'Name', children: 'Jane Doe' },
{ key: 'highlight', label: 'Highlighted', children: 'This item has custom styles', labelClassName: 'text-primary', contentClassName: 'text-accent font-bold' },
{ key: 'status', label: 'Status', children: 'Active' },
]
return (
<Descriptions
items={items}
bordered
styles={{
label: { backgroundColor: 'oklch(var(--b2))' },
content: { backgroundColor: 'oklch(var(--b1))' },
}}
classNames={{
title: 'text-primary',
}}
title="Custom Styled"
/>
)
}
export default App 组合模式
使用 Descriptions.Item 子元素代替 items 属性。
Using Compound Pattern
| Name | John Doe | john@example.com | Phone | +1 234 567 890 | |
|---|---|---|---|---|---|
| Address | 123 Main Street, San Francisco, CA 94102 | ||||
import { Descriptions } from 'asterui'
function App() {
const { Item } = Descriptions
return (
<Descriptions bordered title="Using Compound Pattern">
<Item key="name" label="Name">John Doe</Item>
<Item key="email" label="Email">john@example.com</Item>
<Item key="phone" label="Phone">+1 234 567 890</Item>
<Item key="address" label="Address" span={3}>
123 Main Street, San Francisco, CA 94102
</Item>
</Descriptions>
)
}
export default App Descriptions
Section titled “Descriptions”| 属性 | 描述 | 类型 | 默认值 |
|---|---|---|---|
items | 描述项目(children 的替代方案) | DescriptionsItemConfig[] | - |
title | 描述列表的标题 | React.ReactNode | - |
extra | 右上角的额外内容 | React.ReactNode | - |
column | 列数(或响应式配置) | number | { xs?, sm?, md?, lg?, xl?, 2xl? } | 3 |
bordered | 在单元格周围显示边框 | boolean | false |
layout | 布局方向 | 'horizontal' | 'vertical' | 'horizontal' |
size | 尺寸变体 | 'sm' | 'md' | 'lg' | 'md' |
colon | 在标签后显示冒号 | boolean | true |
styles | 组件部分的语义样式 | Partial<Record<SemanticDOM, CSSProperties>> | - |
classNames | 组件部分的语义类名 | Partial<Record<SemanticDOM, string>> | - |
labelStyle | 默认标签样式(已弃用,使用 styles.label) | React.CSSProperties | - |
contentStyle | 默认内容样式(已弃用,使用 styles.content) | React.CSSProperties | - |
className | 额外的 CSS 类名 | string | - |
style | 根元素的内联样式 | React.CSSProperties | - |
data-testid | 组件的测试 ID | string | 'descriptions' |
DescriptionsItemConfig
Section titled “DescriptionsItemConfig”| 属性 | 描述 | 类型 | 默认值 |
|---|---|---|---|
key | 项目的唯一键(用于测试 ID 和 React 键) | string | - |
label | 项目的标签 | React.ReactNode | - |
children | 项目的内容 | React.ReactNode | - |
span | 跨越的列数,或 ‘filled’ 填充剩余空间 | number | 'filled' | 1 |
labelStyle | 自定义标签样式 | React.CSSProperties | - |
contentStyle | 自定义内容样式 | React.CSSProperties | - |
labelClassName | 自定义标签类名 | string | - |
contentClassName | 自定义内容类名 | string | - |
Descriptions.Item (组合模式)
Section titled “Descriptions.Item (组合模式)”| 属性 | 描述 | 类型 | 默认值 |
|---|---|---|---|
key | React 键,由父组件提取 | string | - |
itemKey | 显式键(React key 的替代方案) | string | - |
label | 项目的标签 | React.ReactNode | - |
children | 项目的内容 | React.ReactNode | - |
span | 跨越的列数,或 ‘filled’ | number | 'filled' | 1 |
labelStyle | 自定义标签样式 | React.CSSProperties | - |
contentStyle | 自定义内容样式 | React.CSSProperties | - |
labelClassName | 自定义标签类名 | string | - |
contentClassName | 自定义内容类名 | string | - |
SemanticDOM 键
Section titled “SemanticDOM 键”| 属性 | 描述 | 类型 |
|---|---|---|
root | 根容器元素 | - |
header | 包含标题和额外内容的头部 | - |
title | 标题元素 | - |
extra | 额外内容元素 | - |
table | 表格元素 | - |
label | 标签单元格(th 元素) | - |
content | 内容单元格(td 元素) | - |
- 使用语义化的
<table>标记确保正确的结构 - 头部单元格使用
scope属性,方便屏幕阅读器使用 - 当提供标题时,表格有
<caption>元素(视觉上隐藏) - 内容单元格通过
aria-labelledby链接到其标签 - 标签后的冒号用
aria-hidden标记,以避免重复朗读