2020-03-22 11:38:02 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
2022-11-09 12:28:04 +08:00
|
|
|
|
group: 布局
|
2020-03-22 11:38:02 +08:00
|
|
|
|
title: Space
|
2024-03-22 14:22:42 +08:00
|
|
|
|
subtitle: 间距
|
|
|
|
|
description: 设置组件之间的间距。
|
2022-11-30 20:14:41 +08:00
|
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*ZiJ3SbOH9SUAAAAAAAAAAAAADrJ8AQ/original
|
2023-02-09 22:17:31 +08:00
|
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*37T2R6O9oi0AAAAAAAAAAAAADrJ8AQ/original
|
2020-03-22 11:38:02 +08:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## 何时使用
|
|
|
|
|
|
|
|
|
|
避免组件紧贴在一起,拉开统一的空间。
|
|
|
|
|
|
2020-08-03 13:56:58 +08:00
|
|
|
|
- 适合行内元素的水平间距。
|
|
|
|
|
- 可以设置各种水平对齐方式。
|
2022-11-27 01:58:55 +08:00
|
|
|
|
- 需要表单组件之间紧凑连接且合并边框时,使用 Space.Compact(自 `antd@4.24.0` 版本开始提供该组件)。
|
2020-08-03 13:56:58 +08:00
|
|
|
|
|
2023-10-11 14:45:09 +08:00
|
|
|
|
### 与 Flex 组件的区别
|
|
|
|
|
|
|
|
|
|
- Space 为内联元素提供间距,其本身会为每一个子元素添加包裹元素用于内联对齐。适用于行、列中多个子元素的等距排列。
|
|
|
|
|
- Flex 为块级元素提供间距,其本身不会添加包裹元素。适用于垂直或水平方向上的子元素布局,并提供了更多的灵活性和控制能力。
|
|
|
|
|
|
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/base.tsx">基本用法</code>
|
|
|
|
|
<code src="./demo/vertical.tsx">垂直间距</code>
|
|
|
|
|
<code src="./demo/size.tsx">间距大小</code>
|
|
|
|
|
<code src="./demo/align.tsx">对齐</code>
|
|
|
|
|
<code src="./demo/wrap.tsx">自动换行</code>
|
|
|
|
|
<code src="./demo/split.tsx">分隔符</code>
|
|
|
|
|
<code src="./demo/compact.tsx">紧凑布局组合</code>
|
|
|
|
|
<code src="./demo/compact-buttons.tsx">Button 紧凑布局</code>
|
|
|
|
|
<code src="./demo/compact-button-vertical.tsx">垂直方向紧凑布局</code>
|
|
|
|
|
<code src="./demo/compact-debug.tsx" debug>调试 Input 前置/后置标签</code>
|
|
|
|
|
<code src="./demo/compact-nested.tsx" debug>紧凑布局嵌套</code>
|
|
|
|
|
<code src="./demo/debug.tsx" debug>多样的 Child</code>
|
|
|
|
|
<code src="./demo/gap-in-line.tsx" debug>Flex gap 样式</code>
|
|
|
|
|
|
2020-03-22 11:38:02 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2023-08-08 18:27:48 +08:00
|
|
|
|
通用属性参考:[通用属性](/docs/react/common-props)
|
|
|
|
|
|
2022-10-18 16:23:10 +08:00
|
|
|
|
### Space
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| align | 对齐方式 | `start` \| `end` \|`center` \|`baseline` | - | 4.2.0 |
|
2024-02-05 11:45:42 +08:00
|
|
|
|
| classNames | 语义化 className | [Record<SemanticDOM, string>](#semantic-dom) | - | |
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| direction | 间距方向 | `vertical` \| `horizontal` | `horizontal` | 4.1.0 |
|
2022-12-22 14:12:26 +08:00
|
|
|
|
| size | 间距大小 | [Size](#size) \| [Size\[\]](#size) | `small` | 4.1.0 \| Array: 4.9.0 |
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| split | 设置拆分 | ReactNode | - | 4.7.0 |
|
2024-02-05 11:45:42 +08:00
|
|
|
|
| styles | 语义化 style | [Record<SemanticDOM, CSSProperties>](#semantic-dom) | - | |
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| wrap | 是否自动换行,仅在 `horizontal` 时有效 | boolean | false | 4.9.0 |
|
2020-11-27 13:40:40 +08:00
|
|
|
|
|
|
|
|
|
### Size
|
|
|
|
|
|
|
|
|
|
`'small' | 'middle' | 'large' | number`
|
2022-10-18 16:23:10 +08:00
|
|
|
|
|
|
|
|
|
### Space.Compact
|
|
|
|
|
|
|
|
|
|
> 自 antd@4.24.0 版本开始提供该组件。
|
|
|
|
|
|
|
|
|
|
需要表单组件之间紧凑连接且合并边框时,使用 Space.Compact。支持的组件有:
|
|
|
|
|
|
|
|
|
|
- Button
|
|
|
|
|
- AutoComplete
|
|
|
|
|
- Cascader
|
|
|
|
|
- DatePicker
|
|
|
|
|
- Input/Input.Search
|
2023-10-11 10:31:36 +08:00
|
|
|
|
- InputNumber
|
2022-10-18 16:23:10 +08:00
|
|
|
|
- Select
|
|
|
|
|
- TimePicker
|
|
|
|
|
- TreeSelect
|
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
|
| block | 将宽度调整为父元素宽度的选项 | boolean | false | 4.24.0 |
|
|
|
|
|
| direction | 指定排列方向 | `vertical` \| `horizontal` | `horizontal` | 4.24.0 |
|
|
|
|
|
| size | 子组件大小 | `large` \| `middle` \| `small` | `middle` | 4.24.0 |
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
2024-02-05 11:45:42 +08:00
|
|
|
|
## Semantic DOM
|
2023-05-31 13:43:38 +08:00
|
|
|
|
|
2024-02-05 11:45:42 +08:00
|
|
|
|
<code src="./demo/_semantic.tsx" simplify="true"></code>
|
2023-05-31 13:43:38 +08:00
|
|
|
|
|
2023-08-30 23:02:35 +08:00
|
|
|
|
## 主题变量(Design Token)
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Space"></ComponentTokenTable>
|