File tree 8 files changed +203
-0
lines changed
packages/components/src/space
8 files changed +203
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * title: 基础用法
3
+ * description: space 基础用法。
4
+ */
5
+
6
+ import React from 'react' ;
7
+ import { Space , Button } from '@tool-pack/react-ui' ;
8
+
9
+ const App : React . FC = ( ) => {
10
+ return (
11
+ < Space >
12
+ < Button type = "primary" > bt1</ Button >
13
+ < Button type = "danger" > bt2</ Button >
14
+ </ Space >
15
+ ) ;
16
+ } ;
17
+
18
+ export default App ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * title: 填充
3
+ * description: 设置子元素填充可使用fill和fillRatio, fillRatio默认100。注意:Space 嵌套的话,如子Space设置fillRatio会影响自身,见第三个Space。
4
+ */
5
+
6
+ import React from 'react' ;
7
+ import { Space } from '@tool-pack/react-ui' ;
8
+
9
+ const App : React . FC = ( ) => {
10
+ const style : React . CSSProperties = { width : '100px' } ;
11
+ const style2 : React . CSSProperties = { height : '100px' } ;
12
+ return (
13
+ < Space vertical fill >
14
+ < Space style = { { height : '200px' } } fill >
15
+ < div style = { { ...style , flex : 1 , background : '#1677ff' } } > </ div >
16
+ < div style = { { ...style , background : '#f56c6c' } } > </ div >
17
+ </ Space >
18
+ < Space style = { { width : '100%' } } vertical fill fillRatio = { 50 } >
19
+ < div
20
+ style = { {
21
+ ...style2 ,
22
+ background : '#1677ff' ,
23
+ } } > </ div >
24
+ < div style = { { ...style2 , background : '#f56c6c' } } > </ div >
25
+ </ Space >
26
+ </ Space >
27
+ ) ;
28
+ } ;
29
+
30
+ export default App ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * title: 自定义间距大小
3
+ * description: space 可以使用 gap 参数自定义间距大小; gap 默认 8px; 传入数字时会使用 px 作为单位。
4
+ */
5
+
6
+ import React from 'react' ;
7
+ import { Space , Button } from '@tool-pack/react-ui' ;
8
+
9
+ const App : React . FC = ( ) => {
10
+ return (
11
+ < Space gap = { 20 } >
12
+ < Button type = "primary" > bt1</ Button >
13
+ < Button type = "danger" > bt2</ Button >
14
+ </ Space >
15
+ ) ;
16
+ } ;
17
+
18
+ export default App ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * title: inline
3
+ * description: 使用 inline 参数使 space 改为行内元素。
4
+ */
5
+
6
+ import React from 'react' ;
7
+ import { Space } from '@tool-pack/react-ui' ;
8
+
9
+ const App : React . FC = ( ) => {
10
+ const style : React . CSSProperties = { width : '200px' , height : '100px' } ;
11
+ return (
12
+ < Space vertical inline style = { { background : '#e6a23c' } } >
13
+ < div style = { { ...style , background : '#1677ff' } } > </ div >
14
+ < div style = { { ...style , background : '#f56c6c' } } > </ div >
15
+ </ Space >
16
+ ) ;
17
+ } ;
18
+
19
+ export default App ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * title: 插入分隔符
3
+ * description: 可以使用 separator 参数指定 space 组件的分隔符,如果为空则不添加间隔,可以使用jsx作为分隔符。
4
+ */
5
+
6
+ import React from 'react' ;
7
+ import { Space , Button } from '@tool-pack/react-ui' ;
8
+
9
+ const App : React . FC = ( ) => {
10
+ return (
11
+ < Space
12
+ vertical
13
+ separator = {
14
+ < div style = { { background : 'gray' , height : '1px' , width : '100%' } } > </ div >
15
+ } >
16
+ < Space tag = "div" separator = "|" gap = { 20 } >
17
+ < Button type = "primary" > bt1</ Button >
18
+ < Button type = "danger" > bt2</ Button >
19
+ </ Space >
20
+ < Space
21
+ tag = "div"
22
+ separator = {
23
+ < div
24
+ style = { {
25
+ background : 'var(--t-primary-bg-color)' ,
26
+ width : '1px' ,
27
+ height : '1em' ,
28
+ } } > </ div >
29
+ } >
30
+ < Button type = "primary" > bt1</ Button >
31
+ < Button type = "danger" > bt2</ Button >
32
+ < Button type = "success" > bt3</ Button >
33
+ </ Space >
34
+ < Space tag = "div" separator = { < button disabled > 使用button分隔</ button > } >
35
+ < Button type = "primary" > bt1</ Button >
36
+ < Button type = "danger" > bt2</ Button >
37
+ < Button type = "success" > bt3</ Button >
38
+ </ Space >
39
+ </ Space >
40
+ ) ;
41
+ } ;
42
+
43
+ export default App ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * title: 指定根html标签
3
+ * description: 可以使用 tag 参数指定 space 组件的根html标签,tag 默认 section。
4
+ */
5
+
6
+ import React from 'react' ;
7
+ import { Space , Button } from '@tool-pack/react-ui' ;
8
+
9
+ const App : React . FC = ( ) => {
10
+ return (
11
+ < Space tag = "div" >
12
+ < Button type = "primary" > bt1</ Button >
13
+ < Button type = "danger" > bt2</ Button >
14
+ </ Space >
15
+ ) ;
16
+ } ;
17
+
18
+ export default App ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * title: 垂直排列
3
+ * description: 使用 vertical 参数使 space 组件垂直排列。
4
+ */
5
+
6
+ import React from 'react' ;
7
+ import { Space } from '@tool-pack/react-ui' ;
8
+
9
+ const App : React . FC = ( ) => {
10
+ const style : React . CSSProperties = { width : '200px' , height : '100px' } ;
11
+ return (
12
+ < Space vertical style = { { background : '#e6a23c' } } >
13
+ < div style = { { ...style , background : '#1677ff' } } > </ div >
14
+ < div style = { { ...style , background : '#f56c6c' } } > </ div >
15
+ </ Space >
16
+ ) ;
17
+ } ;
18
+
19
+ export default App ;
Original file line number Diff line number Diff line change
1
+ ---
2
+ category : Components
3
+ title : Space
4
+ subtitle : 间距
5
+ demo :
6
+ cols : 2
7
+ group :
8
+ title : 布局
9
+ ---
10
+
11
+ Space 间距:用于给多个元素之间添加间距,跟其他组件库不同的是此组件的 children 不使用额外的 item 元素包裹。
12
+
13
+ ## 代码演示
14
+
15
+ <!-- prettier-ignore -->
16
+ <code src =" ./demo/basic.tsx " ></code >
17
+ <code src =" ./demo/tag.tsx " ></code >
18
+ <code src =" ./demo/gap.tsx " ></code >
19
+ <code src =" ./demo/vertical.tsx " ></code >
20
+ <code src =" ./demo/inline.tsx " ></code >
21
+ <code src =" ./demo/fill.tsx " ></code >
22
+ <code src =" ./demo/separator.tsx " ></code >
23
+
24
+ ## API
25
+
26
+ Space 的属性说明如下:
27
+
28
+ | 属性 | 说明 | 类型 | 默认值 | 版本 |
29
+ | --------- | -------------------------------------------- | --------------------------- | --------- | ---- |
30
+ | gap | 间距 | number \| string | ` 8px ` | |
31
+ | tag | 根元素 html 标签 | keyof HTMLElementTagNameMap | ` section ` | |
32
+ | vertical | 垂直排列 | boolean | false | |
33
+ | separator | 分隔符 | React.ReactNode | - | |
34
+ | inline | 是否设为 inline-flex | boolean | false | |
35
+ | fill | 子元素开启 fillRatio 比例填充 | boolean | false | |
36
+ | fillRatio | 子元素 fillRatio(百分比,\[ 1 - 100] )比例填充 | number | 100 | |
37
+
38
+ 支持原生 HTML 的其他所有属性,像一些 wrap、justify、align-items 之类的可以直接写 style。
You can’t perform that action at this time.
0 commit comments