符号列表
中弹 列表将列出一个具有自定义标记(标注或数字)和灵活渲染的项目.
安装
npm install @cleartrip/ct-design-bulleted-list
# or
pnpm add @cleartrip/ct-design-bulleted-list
同伴依赖关系
# Required for all targets
npm install react
# Web only
npm install react-dom
# React Native only
npm install react-native
使用量
基本命令列表
import { BulletedList } from '@cleartrip/ct-design-bulleted-list';
const items = [
{ id: '1', title: 'First Item', content: 'Description here' },
{ id: '2', title: 'Second Item', content: 'Another description' },
{ id: '3', title: 'Third Item', content: 'More content' },
];
function Example() {
return (
<BulletedList
list={items}
listType="ol"
renderItem={(item, index) => (
<div>
<strong>{item.title}</strong>
<p>{item.content}</p>
</div>
)}
/>
);
}
项目列表( 未排序)
<BulletedList
list={items}
listType="ul"
renderItem={(item) => <span>{item.title}</span>}
/>
样式覆盖
<BulletedList
list={items}
listType="ol"
renderItem={(item) => <span>{item.title}</span>}
styleConfig={{
itemWrapper: [{ padding: 12, borderBottom: '1px solid #eee' }],
marker: [{ color: '#007bff', fontWeight: 'bold' }],
}}
/>
道具
| Prop | 类型 | 默认 | 需求 | 说明 |
|---|---|---|---|---|
list | T[] | —— 说 | 对 | 清单中需要提出的项目 |
renderItem | (item: T, index: number) => ReactNode | —— 说 | 对 | 将每个列表项调回 |
listType | 'ol' | 'ul' | 'ol' | 没有 | 要显示的标记类型 |
styleConfig | IBulletedListStyleConfig | —— 说 | 没有 | 样式配置覆盖 |
列表类型
'ol'- 编号名单(1.2.3.)'ul'- 子弹清单(-)
样式
这个 styleConfig 界面允许精细的样式定制 :
interface IBulletedListStyleConfig {
itemWrapper?: Styles[];
placeHolder?: Styles[];
itemContent?: Styles[];
marker?: Styles[];
}
槽数
| 槽 | 说明 |
|---|---|
itemWrapper | 每个列表项外行容器的样式 |
placeHolder | 标记容器的样式(弹夹/数字占位符区域) |
itemContent | 显示项目输出的内容容器样式 |
marker | 标记行的样式( 命令列表中的数字+点) |
项目密钥
- 有下列项目:
id属性将它作为反应密钥 - 无项目
id使用数组索引作为密钥 - 为了取得最佳业绩,提供独特的
id每个项目的值
无障碍
- 顺序列表使用语义
<ol>要素 - 无序列表使用语义
<ul>要素 - 每件东西都被包裹在
<li>用于正确屏幕阅读器支持的元素 - 考虑为复杂的列表项目添加 ARIA 标签
移徙
如果从上一版本迁移:
- import { BulletedList } from 'old-package';
+ import { BulletedList } from '@cleartrip/ct-design-bulleted-list';