2022-04-11 11:13:16 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
|
|
|
|
subtitle: 分段控制器
|
2022-11-09 12:28:04 +08:00
|
|
|
|
group: 数据展示
|
2022-04-11 11:13:16 +08:00
|
|
|
|
title: Segmented
|
2024-01-29 14:50:36 +08:00
|
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*XJR2TbS1aaQAAAAAAAAAAAAADrJ8AQ/original
|
|
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*-9tSSoO_MkIAAAAAAAAAAAAADrJ8AQ/original
|
2022-11-09 12:28:04 +08:00
|
|
|
|
demo:
|
|
|
|
|
cols: 2
|
2022-04-11 11:13:16 +08:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
分段控制器。自 `antd@4.20.0` 版本开始提供该组件。
|
|
|
|
|
|
|
|
|
|
## 何时使用
|
|
|
|
|
|
|
|
|
|
- 用于展示多个选项并允许用户选择其中单个选项;
|
|
|
|
|
- 当切换选中选项时,关联区域的内容会发生变化。
|
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
|
## 代码演示
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
<!-- prettier-ignore -->
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/basic.tsx">基本</code>
|
|
|
|
|
<code src="./demo/block.tsx">Block 分段选择器</code>
|
|
|
|
|
<code src="./demo/disabled.tsx">不可用</code>
|
|
|
|
|
<code src="./demo/controlled.tsx">受控模式</code>
|
|
|
|
|
<code src="./demo/custom.tsx">自定义渲染</code>
|
|
|
|
|
<code src="./demo/dynamic.tsx">动态数据</code>
|
|
|
|
|
<code src="./demo/size.tsx">三种大小</code>
|
|
|
|
|
<code src="./demo/with-icon.tsx">设置图标</code>
|
|
|
|
|
<code src="./demo/icon-only.tsx">只设置图标</code>
|
|
|
|
|
<code src="./demo/controlled-two.tsx" debug>受控同步模式</code>
|
|
|
|
|
<code src="./demo/size-consistent.tsx" debug>统一高度</code>
|
2023-05-18 22:21:53 +08:00
|
|
|
|
<code src="./demo/componentToken.tsx" debug>自定义组件 Token</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
2022-04-11 11:13:16 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2023-08-08 18:27:48 +08:00
|
|
|
|
通用属性参考:[通用属性](/docs/react/common-props)
|
|
|
|
|
|
2022-04-11 11:13:16 +08:00
|
|
|
|
> 自 `antd@4.20.0` 版本开始提供该组件。
|
|
|
|
|
|
|
|
|
|
### Segmented
|
|
|
|
|
|
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| block | 将宽度调整为父元素宽度的选项 | boolean | false | |
|
|
|
|
|
| defaultValue | 默认选中的值 | string \| number | | |
|
|
|
|
|
| disabled | 是否禁用 | boolean | false | |
|
2022-04-23 21:00:05 +08:00
|
|
|
|
| onChange | 选项变化时的回调函数 | function(value: string \| number) | | |
|
2022-06-09 21:39:35 +08:00
|
|
|
|
| options | 数据化配置选项内容 | string\[] \| number\[] \| Array<{ label: ReactNode value: string icon? ReactNode disabled?: boolean className?: string }> | [] | |
|
2023-02-01 10:11:53 +08:00
|
|
|
|
| size | 控件尺寸 | `large` \| `middle` \| `small` | `middle` | |
|
2022-04-11 11:13:16 +08:00
|
|
|
|
| value | 当前选中的值 | string \| number | | |
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
2023-08-30 23:02:35 +08:00
|
|
|
|
## 主题变量(Design Token)
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Segmented"></ComponentTokenTable>
|