@douyinfe/semi-ui 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cascader/__test__/cascader.test.js +24 -0
- package/cascader/_story/cascader.stories.js +73 -0
- package/cascader/index.tsx +5 -2
- package/datePicker/_story/v2/FixInputRangeFocus.jsx +25 -0
- package/datePicker/_story/v2/index.js +2 -1
- package/datePicker/datePicker.tsx +4 -0
- package/dist/css/semi.css +51 -27
- package/dist/css/semi.min.css +1 -1
- package/dist/umd/semi-ui.js +481 -182
- package/dist/umd/semi-ui.js.map +1 -1
- package/dist/umd/semi-ui.min.js +1 -1
- package/dist/umd/semi-ui.min.js.map +1 -1
- package/form/_story/demo.jsx +1 -0
- package/input/index.tsx +1 -0
- package/input/textarea.tsx +1 -1
- package/lib/cjs/autoComplete/index.d.ts +1 -1
- package/lib/cjs/cascader/index.js +6 -0
- package/lib/cjs/datePicker/datePicker.js +16 -8
- package/lib/cjs/dropdown/index.d.ts +1 -1
- package/lib/cjs/form/baseForm.d.ts +1 -1
- package/lib/cjs/form/field.d.ts +1 -1
- package/lib/cjs/input/index.js +2 -1
- package/lib/cjs/input/textarea.js +1 -1
- package/lib/cjs/select/index.d.ts +3 -3
- package/lib/cjs/select/index.js +32 -28
- package/lib/cjs/select/option.js +2 -2
- package/lib/cjs/select/virtualRow.js +2 -2
- package/lib/cjs/table/Table.d.ts +1 -1
- package/lib/cjs/table/Table.js +8 -2
- package/lib/cjs/table/interface.d.ts +1 -0
- package/lib/cjs/tabs/interface.d.ts +1 -1
- package/lib/cjs/timePicker/TimePicker.js +2 -1
- package/lib/cjs/tooltip/index.d.ts +1 -1
- package/lib/cjs/tooltip/index.js +6 -2
- package/lib/cjs/tree/index.d.ts +2 -0
- package/lib/cjs/tree/index.js +15 -8
- package/lib/cjs/treeSelect/index.d.ts +2 -0
- package/lib/cjs/treeSelect/index.js +64 -27
- package/lib/cjs/upload/fileCard.js +31 -22
- package/lib/cjs/upload/index.d.ts +6 -0
- package/lib/cjs/upload/index.js +15 -8
- package/lib/cjs/upload/interface.d.ts +8 -6
- package/lib/es/autoComplete/index.d.ts +1 -1
- package/lib/es/cascader/index.js +5 -0
- package/lib/es/datePicker/datePicker.js +16 -8
- package/lib/es/dropdown/index.d.ts +1 -1
- package/lib/es/form/baseForm.d.ts +1 -1
- package/lib/es/form/field.d.ts +1 -1
- package/lib/es/input/index.js +2 -1
- package/lib/es/input/textarea.js +1 -1
- package/lib/es/select/index.d.ts +3 -3
- package/lib/es/select/index.js +30 -26
- package/lib/es/select/option.js +2 -2
- package/lib/es/select/virtualRow.js +2 -2
- package/lib/es/table/Table.d.ts +1 -1
- package/lib/es/table/Table.js +10 -2
- package/lib/es/table/interface.d.ts +1 -0
- package/lib/es/tabs/interface.d.ts +1 -1
- package/lib/es/timePicker/TimePicker.js +2 -1
- package/lib/es/tooltip/index.d.ts +1 -1
- package/lib/es/tooltip/index.js +6 -2
- package/lib/es/tree/index.d.ts +2 -0
- package/lib/es/tree/index.js +15 -8
- package/lib/es/treeSelect/index.d.ts +2 -0
- package/lib/es/treeSelect/index.js +64 -27
- package/lib/es/upload/fileCard.js +31 -24
- package/lib/es/upload/index.d.ts +6 -0
- package/lib/es/upload/index.js +14 -8
- package/lib/es/upload/interface.d.ts +8 -6
- package/package.json +9 -8
- package/select/index.tsx +18 -19
- package/select/option.tsx +2 -2
- package/select/virtualRow.tsx +2 -2
- package/table/Table.tsx +7 -2
- package/table/_story/table.stories.js +1 -2
- package/table/_story/v2/FixedHeaderMerge/index.jsx +98 -0
- package/table/_story/v2/FixedResizable/index.jsx +114 -0
- package/table/_story/v2/defaultFilteredValue.tsx +123 -0
- package/table/_story/v2/index.js +5 -0
- package/table/interface.ts +1 -0
- package/tabs/interface.ts +1 -1
- package/timePicker/TimePicker.tsx +1 -0
- package/tooltip/__test__/tooltip.test.js +48 -4
- package/tooltip/_story/tooltip.stories.js +83 -1
- package/tooltip/index.tsx +4 -4
- package/tree/__test__/treeMultiple.test.js +94 -0
- package/tree/_story/tree.stories.js +169 -0
- package/tree/index.tsx +12 -5
- package/treeSelect/__test__/treeMultiple.test.js +94 -0
- package/treeSelect/_story/treeSelect.stories.js +242 -0
- package/treeSelect/index.tsx +72 -40
- package/upload/_story/upload.stories.js +22 -6
- package/upload/fileCard.tsx +23 -23
- package/upload/index.tsx +15 -6
- package/upload/interface.ts +7 -5
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { Table, Avatar, Button, Space } from '@douyinfe/semi-ui';
|
|
3
|
+
import { IconMore } from '@douyinfe/semi-icons';
|
|
4
|
+
|
|
5
|
+
const columns = [
|
|
6
|
+
{
|
|
7
|
+
title: '标题',
|
|
8
|
+
dataIndex: 'name',
|
|
9
|
+
width: 300,
|
|
10
|
+
key: 'name',
|
|
11
|
+
render: (text, record, index) => {
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
14
|
+
<Avatar size="small" shape="square" src={record.nameIconSrc} style={{ marginRight: 12 }}></Avatar>
|
|
15
|
+
{text}
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
title: '大小',
|
|
22
|
+
dataIndex: 'size',
|
|
23
|
+
key: 'size',
|
|
24
|
+
width: 200,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
title: '所有者',
|
|
28
|
+
dataIndex: 'owner',
|
|
29
|
+
key: 'owner',
|
|
30
|
+
width: 200,
|
|
31
|
+
render: (text, record, index) => {
|
|
32
|
+
return (
|
|
33
|
+
<div>
|
|
34
|
+
<Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>
|
|
35
|
+
{typeof text === 'string' && text.slice(0, 1)}
|
|
36
|
+
</Avatar>
|
|
37
|
+
{text}
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
title: '更新日期',
|
|
44
|
+
dataIndex: 'updateTime',
|
|
45
|
+
key: 'updateTime',
|
|
46
|
+
width: 200,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
title: '',
|
|
50
|
+
dataIndex: 'operate',
|
|
51
|
+
key: 'operate',
|
|
52
|
+
render: () => {
|
|
53
|
+
return <IconMore />;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* fix https://github.com/DouyinFE/semi-design/issues/650
|
|
60
|
+
*/
|
|
61
|
+
App.storyName = 'fixed resizable column width bug';
|
|
62
|
+
App.parameters = { chromatic: { disableSnapshot: true } };
|
|
63
|
+
function App() {
|
|
64
|
+
const [cols, setCols] = useState(columns);
|
|
65
|
+
|
|
66
|
+
const onClickHandle = () => {
|
|
67
|
+
const localCols = [...cols].filter((i, index) => index !== 1);
|
|
68
|
+
setCols(localCols);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const data = [
|
|
72
|
+
{
|
|
73
|
+
key: '1',
|
|
74
|
+
name: 'Semi Design 设计稿.fig',
|
|
75
|
+
nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
|
|
76
|
+
size: '2M',
|
|
77
|
+
owner: '姜鹏志',
|
|
78
|
+
updateTime: '2020-02-02 05:13',
|
|
79
|
+
avatarBg: 'grey',
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
key: '2',
|
|
83
|
+
name: 'Semi Design 分享演示文稿',
|
|
84
|
+
nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
|
|
85
|
+
size: '2M',
|
|
86
|
+
owner: '郝宣',
|
|
87
|
+
updateTime: '2020-01-17 05:31',
|
|
88
|
+
avatarBg: 'red',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
key: '3',
|
|
92
|
+
name: '设计文档',
|
|
93
|
+
nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
|
|
94
|
+
size: '34KB',
|
|
95
|
+
owner: 'Zoey Edwards',
|
|
96
|
+
updateTime: '2020-01-26 11:01',
|
|
97
|
+
avatarBg: 'light-blue',
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<>
|
|
103
|
+
<Space>
|
|
104
|
+
<Button onClick={onClickHandle}>减少一列</Button>
|
|
105
|
+
<Button theme="solid" onClick={() => setCols(columns)}>
|
|
106
|
+
reset
|
|
107
|
+
</Button>
|
|
108
|
+
</Space>
|
|
109
|
+
<Table columns={cols} dataSource={data} pagination={false} resizable />
|
|
110
|
+
</>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default App;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import React, { useState, useEffect, useMemo } from 'react';
|
|
2
|
+
import { Table, Avatar, Button } from '@douyinfe/semi-ui';
|
|
3
|
+
import * as dateFns from 'date-fns';
|
|
4
|
+
import { ColumnProps, ChangeInfoFilter } from '@douyinfe/semi-ui/table';
|
|
5
|
+
|
|
6
|
+
const DAY = 24 * 60 * 60 * 1000;
|
|
7
|
+
const figmaIconUrl = 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png';
|
|
8
|
+
|
|
9
|
+
function App() {
|
|
10
|
+
const [dataSource, setData] = useState([]);
|
|
11
|
+
const [filteredValue, setFilteredValue] = useState(['Semi Pro 设计稿']);
|
|
12
|
+
|
|
13
|
+
const scroll = useMemo(() => ({ y: 300 }), []);
|
|
14
|
+
|
|
15
|
+
const columns: ColumnProps[] = [
|
|
16
|
+
{
|
|
17
|
+
title: '标题',
|
|
18
|
+
dataIndex: 'name',
|
|
19
|
+
width: 400,
|
|
20
|
+
render: (text, record, index) => {
|
|
21
|
+
return (
|
|
22
|
+
<div>
|
|
23
|
+
<Avatar size="small" shape="square" src={figmaIconUrl} style={{ marginRight: 12 }}></Avatar>
|
|
24
|
+
{text}
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
},
|
|
28
|
+
filters: [
|
|
29
|
+
{
|
|
30
|
+
text: 'Semi Design 设计稿',
|
|
31
|
+
value: 'Semi Design 设计稿',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
text: 'Semi Pro 设计稿',
|
|
35
|
+
value: 'Semi Pro 设计稿',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
onFilter: (value, record) => record.name.includes(value),
|
|
39
|
+
sorter: (a, b) => a.name.length - b.name.length > 0 ? 1 : -1,
|
|
40
|
+
// filterMultiple: false,
|
|
41
|
+
// filteredValue: filteredValue,
|
|
42
|
+
defaultFilteredValue: filteredValue,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
title: '大小',
|
|
46
|
+
dataIndex: 'size',
|
|
47
|
+
sorter: (a, b) => a.size - b.size > 0 ? 1 : -1,
|
|
48
|
+
render: (text) => `${text} KB`
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
title: '所有者',
|
|
52
|
+
dataIndex: 'owner',
|
|
53
|
+
render: (text, record, index) => {
|
|
54
|
+
return (
|
|
55
|
+
<div>
|
|
56
|
+
<Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>{typeof text === 'string' && text.slice(0, 1)}</Avatar>
|
|
57
|
+
{text}
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
title: '更新日期',
|
|
65
|
+
dataIndex: 'updateTime',
|
|
66
|
+
sorter: (a, b) => a.updateTime - b.updateTime > 0 ? 1 : -1,
|
|
67
|
+
render: (value) => {
|
|
68
|
+
return dateFns.format(new Date(value), 'yyyy-MM-dd');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
const getData = (total) => {
|
|
74
|
+
const data = [];
|
|
75
|
+
for (let i = 0; i < total; i++) {
|
|
76
|
+
const isSemiDesign = i % 2 === 0;
|
|
77
|
+
const randomNumber = (i * 1000) % 199;
|
|
78
|
+
data.push({
|
|
79
|
+
key: '' + i,
|
|
80
|
+
name: isSemiDesign ? `Semi Design 设计稿${i}.fig` : `Semi Pro 设计稿${i}.fig`,
|
|
81
|
+
owner: isSemiDesign ? '姜鹏志' : '郝宣',
|
|
82
|
+
size: randomNumber,
|
|
83
|
+
updateTime: new Date().valueOf() + randomNumber * DAY,
|
|
84
|
+
avatarBg: isSemiDesign ? 'grey' : 'red'
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return data;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const handleFilterChange = (filters: ChangeInfoFilter<any>[]) => {
|
|
91
|
+
console.log('filters', filters);
|
|
92
|
+
if (Array.isArray(filters) && filters.length) {
|
|
93
|
+
const { filteredValue } = filters.find(filter => filter.dataIndex === 'name');
|
|
94
|
+
setFilteredValue(filteredValue);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const handleChange = (options) => {
|
|
99
|
+
const { filters } = options;
|
|
100
|
+
handleFilterChange(filters);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const toggleChangeData = () => {
|
|
104
|
+
const length = dataSource.length;
|
|
105
|
+
const newData = getData(length === 46 ? 25 : 46);
|
|
106
|
+
setData(newData);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
const data = getData(46);
|
|
111
|
+
setData(data);
|
|
112
|
+
}, []);
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<div>
|
|
116
|
+
<Button onClick={toggleChangeData}>toggle change dataSource (46/25)</Button>
|
|
117
|
+
<Table columns={columns} dataSource={dataSource} scroll={scroll} onChange={handleChange} />
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
App.storyName = 'defaultFilteredValue';
|
|
123
|
+
export default App;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as DefaultFilteredValue } from './defaultFilteredValue';
|
|
2
|
+
export { default as FixedColumnsChange } from './FixedColumnsChange';
|
|
3
|
+
export { default as FixedZIndex } from './FixedZIndex';
|
|
4
|
+
export { default as FixedHeaderMerge } from './FixedHeaderMerge';
|
|
5
|
+
export { default as FixedResizable } from './FixedResizable';
|
package/table/interface.ts
CHANGED
|
@@ -79,6 +79,7 @@ export interface ColumnProps<RecordType extends Record<string, any> = any> {
|
|
|
79
79
|
className?: string;
|
|
80
80
|
colSpan?: number;
|
|
81
81
|
dataIndex?: string;
|
|
82
|
+
defaultFilteredValue?: any[];
|
|
82
83
|
defaultSortOrder?: SortOrder;
|
|
83
84
|
filterChildrenRecord?: boolean;
|
|
84
85
|
filterDropdown?: React.ReactNode;
|
package/tabs/interface.ts
CHANGED
|
@@ -72,8 +72,8 @@ describe(`Tooltip`, () => {
|
|
|
72
72
|
expect(elem.state(`visible`)).toBe(true);
|
|
73
73
|
|
|
74
74
|
// click outside
|
|
75
|
-
document.body.click();
|
|
76
|
-
|
|
75
|
+
// document.body.click();
|
|
76
|
+
document.dispatchEvent(new Event('mousedown', { bubbles: true, cancelable: true }));
|
|
77
77
|
// demo.find(`#${triggerId}`)
|
|
78
78
|
// .at(0)
|
|
79
79
|
// .simulate(`mouseDown`);
|
|
@@ -88,7 +88,8 @@ describe(`Tooltip`, () => {
|
|
|
88
88
|
// unmount elem
|
|
89
89
|
demo.unmount();
|
|
90
90
|
await sleep(100);
|
|
91
|
-
document.body.click();
|
|
91
|
+
// document.body.click();
|
|
92
|
+
document.dispatchEvent(new Event('mousedown', { bubbles: true, cancelable: true }));
|
|
92
93
|
expect(document.getElementsByClassName(`${BASE_CLASS_PREFIX}-tooltip-wrapper`).length).toBe(0);
|
|
93
94
|
});
|
|
94
95
|
|
|
@@ -165,7 +166,8 @@ describe(`Tooltip`, () => {
|
|
|
165
166
|
expect(refFn.called).toBeTruthy();
|
|
166
167
|
|
|
167
168
|
// click outside
|
|
168
|
-
document.body.click();
|
|
169
|
+
// document.body.click();
|
|
170
|
+
document.dispatchEvent(new Event('mousedown', { bubbles: true, cancelable: true }));
|
|
169
171
|
await sleep(100);
|
|
170
172
|
expect(
|
|
171
173
|
demo
|
|
@@ -290,6 +292,48 @@ describe(`Tooltip`, () => {
|
|
|
290
292
|
expect(document.querySelector(`.${BASE_CLASS_PREFIX}-tooltip-wrapper`).getAttribute('x-placement')).toBe(position);
|
|
291
293
|
}
|
|
292
294
|
});
|
|
295
|
+
|
|
296
|
+
it(`test click outside handler`, async () => {
|
|
297
|
+
const containerId = `container`;
|
|
298
|
+
|
|
299
|
+
const demo = mount(
|
|
300
|
+
<div style={{ height: 480, width: 320 }}>
|
|
301
|
+
<div id={containerId}>Hello Semi</div>
|
|
302
|
+
<Tooltip
|
|
303
|
+
content='Content'
|
|
304
|
+
trigger='click'
|
|
305
|
+
>
|
|
306
|
+
<Button >Click here</Button>
|
|
307
|
+
</Tooltip>
|
|
308
|
+
</div>
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
const toolTipElem = demo.find(Tooltip);
|
|
312
|
+
const buttonElem = demo.find(Button);
|
|
313
|
+
// click inside
|
|
314
|
+
buttonElem.simulate('click');
|
|
315
|
+
toolTipElem.update();
|
|
316
|
+
await sleep(100);
|
|
317
|
+
expect(toolTipElem.state(`visible`)).toBe(true);
|
|
318
|
+
|
|
319
|
+
// click outside
|
|
320
|
+
// document.body.click();
|
|
321
|
+
document.dispatchEvent(new Event('mousedown', { bubbles: true, cancelable: true }));
|
|
322
|
+
toolTipElem.update();
|
|
323
|
+
await sleep(100);
|
|
324
|
+
expect(toolTipElem.state('visible')).toBe(false);
|
|
325
|
+
|
|
326
|
+
// click button to show tooltip
|
|
327
|
+
buttonElem.simulate('click');
|
|
328
|
+
toolTipElem.update();
|
|
329
|
+
await sleep(100);
|
|
330
|
+
expect(toolTipElem.state('visible')).toBe(true);
|
|
331
|
+
|
|
332
|
+
document.getElementById(containerId).dispatchEvent(new Event('mousedown', { bubbles: true, cancelable: true }));
|
|
333
|
+
toolTipElem.update();
|
|
334
|
+
await sleep(100);
|
|
335
|
+
expect(toolTipElem.state('visible')).toBe(false);
|
|
336
|
+
});
|
|
293
337
|
});
|
|
294
338
|
|
|
295
339
|
it('wrapperClassName', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useState, useMemo } from 'react';
|
|
2
2
|
import Tooltip from '../index';
|
|
3
3
|
import './story.scss';
|
|
4
|
-
import { Tag, Icon, IconButton, Switch, Checkbox, Radio, Button, Select, InputNumber } from '@douyinfe/semi-ui';
|
|
4
|
+
import { Tag, Icon, IconButton, Switch, Checkbox, Radio, Button, Select, InputNumber, Space } from '@douyinfe/semi-ui';
|
|
5
5
|
|
|
6
6
|
import InTableDemo from './InTable';
|
|
7
7
|
import EdgeDemo from './Edge';
|
|
@@ -736,3 +736,85 @@ export const AutoAdjustWithSpacing = () => {
|
|
|
736
736
|
AutoAdjustWithSpacing.story = {
|
|
737
737
|
name: 'AutoAdjustWithSpacing',
|
|
738
738
|
};
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Chromatic UI test
|
|
742
|
+
*/
|
|
743
|
+
export const leftTopOverDemo = () => {
|
|
744
|
+
const [visible, setVisible] = useState(true);
|
|
745
|
+
const content = (
|
|
746
|
+
<div style={{ height: 200, width: 200 }}>
|
|
747
|
+
Semi Design
|
|
748
|
+
</div>
|
|
749
|
+
);
|
|
750
|
+
|
|
751
|
+
const commonProps = {
|
|
752
|
+
content,
|
|
753
|
+
trigger: 'click',
|
|
754
|
+
showArrow: false,
|
|
755
|
+
visible,
|
|
756
|
+
trigger: 'custom',
|
|
757
|
+
motion: false,
|
|
758
|
+
};
|
|
759
|
+
const buttonStyle = {
|
|
760
|
+
width: 200,
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
return (
|
|
764
|
+
<div data-cy='wrapper'>
|
|
765
|
+
<Button onClick={() => setVisible(!visible)}>toggle visible</Button>
|
|
766
|
+
<div style={{ paddingTop: 200 }}>
|
|
767
|
+
<Space spacing={80}>
|
|
768
|
+
<Tooltip {...commonProps} position='leftTopOver' >
|
|
769
|
+
<Button data-cy='leftTopOver' style={buttonStyle}>leftTopOver</Button>
|
|
770
|
+
</Tooltip>
|
|
771
|
+
<Tooltip {...commonProps} position='leftBottomOver'>
|
|
772
|
+
<Button data-cy='leftBottomOver' style={buttonStyle}>leftBottomOver</Button>
|
|
773
|
+
</Tooltip>
|
|
774
|
+
<Tooltip {...commonProps} position='rightTopOver'>
|
|
775
|
+
<Button data-cy='rightTopOver' style={buttonStyle}>rightTopOver</Button>
|
|
776
|
+
</Tooltip>
|
|
777
|
+
<Tooltip {...commonProps} position='rightBottomOver'>
|
|
778
|
+
<Button data-cy='rightBottomOver' style={buttonStyle}>rightBottomOver</Button>
|
|
779
|
+
</Tooltip>
|
|
780
|
+
</Space>
|
|
781
|
+
</div>
|
|
782
|
+
</div>
|
|
783
|
+
)
|
|
784
|
+
};
|
|
785
|
+
leftTopOverDemo.storyName = `leftTopOver visible`;
|
|
786
|
+
leftTopOverDemo.parameters = {
|
|
787
|
+
chromatic: {
|
|
788
|
+
disableSnapshot: false,
|
|
789
|
+
delay: 3000,
|
|
790
|
+
viewports: [1200]
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* Cypress test
|
|
796
|
+
*/
|
|
797
|
+
export const leftTopOverAutoAdjustOverflow = () => {
|
|
798
|
+
const content = (
|
|
799
|
+
<div style={{ height: 200, width: 200 }}>
|
|
800
|
+
Semi Design
|
|
801
|
+
</div>
|
|
802
|
+
);
|
|
803
|
+
|
|
804
|
+
const commonProps = {
|
|
805
|
+
content,
|
|
806
|
+
trigger: 'click',
|
|
807
|
+
showArrow: false,
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
return (
|
|
811
|
+
<div data-cy='wrapper' style={{ width: '200vw', height: '200vw', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
|
812
|
+
<div>
|
|
813
|
+
<Tooltip {...commonProps} position='leftTopOver' >
|
|
814
|
+
<Button data-cy='leftTopOver' style={{ width: 200 }}>leftTopOver</Button>
|
|
815
|
+
</Tooltip>
|
|
816
|
+
</div>
|
|
817
|
+
</div>
|
|
818
|
+
)
|
|
819
|
+
};
|
|
820
|
+
leftTopOverAutoAdjustOverflow.storyName = `leftTopOver autoAdjustOverflow`;
|
package/tooltip/index.tsx
CHANGED
|
@@ -280,7 +280,7 @@ export default class Tooltip extends BaseComponent<TooltipProps, TooltipState> {
|
|
|
280
280
|
getDocumentElementBounding: () => document.documentElement.getBoundingClientRect(),
|
|
281
281
|
setPosition: ({ position, ...style }: { position: Position }) => {
|
|
282
282
|
this.setState(
|
|
283
|
-
{
|
|
283
|
+
{
|
|
284
284
|
containerStyle: { ...this.state.containerStyle, ...style },
|
|
285
285
|
placement: position,
|
|
286
286
|
isPositionUpdated: true
|
|
@@ -326,11 +326,11 @@ export default class Tooltip extends BaseComponent<TooltipProps, TooltipState> {
|
|
|
326
326
|
cb();
|
|
327
327
|
}
|
|
328
328
|
};
|
|
329
|
-
document.addEventListener('
|
|
329
|
+
document.addEventListener('mousedown', this.clickOutsideHandler, { capture: true });
|
|
330
330
|
},
|
|
331
331
|
unregisterClickOutsideHandler: () => {
|
|
332
332
|
if (this.clickOutsideHandler) {
|
|
333
|
-
document.removeEventListener('
|
|
333
|
+
document.removeEventListener('mousedown', this.clickOutsideHandler, { capture: true });
|
|
334
334
|
this.clickOutsideHandler = null;
|
|
335
335
|
}
|
|
336
336
|
},
|
|
@@ -661,4 +661,4 @@ export default class Tooltip extends BaseComponent<TooltipProps, TooltipState> {
|
|
|
661
661
|
}
|
|
662
662
|
}
|
|
663
663
|
|
|
664
|
-
export { Position };
|
|
664
|
+
export { Position };
|
|
@@ -357,6 +357,100 @@ describe('Tree', () => {
|
|
|
357
357
|
).toEqual(true);
|
|
358
358
|
});
|
|
359
359
|
|
|
360
|
+
it('unRelated', () => {
|
|
361
|
+
const spyOnChange = sinon.spy(() => { });
|
|
362
|
+
const tree = getTree({
|
|
363
|
+
defaultExpandAll: true,
|
|
364
|
+
onChange: spyOnChange,
|
|
365
|
+
checkRelation: 'unRelated',
|
|
366
|
+
});
|
|
367
|
+
const nodelevel2 = tree.find(`.${BASE_CLASS_PREFIX}-tree-option.${BASE_CLASS_PREFIX}-tree-option-level-2`);
|
|
368
|
+
const selectedNode = nodelevel2.at(0);
|
|
369
|
+
selectedNode.simulate('click');
|
|
370
|
+
expect(spyOnChange.calledOnce).toBe(true);
|
|
371
|
+
expect(spyOnChange.calledWithMatch(['Zhongguo'])).toEqual(true);
|
|
372
|
+
// Note: selectedNode cannot be used directly here. selectedNode is the original node in the unselected state
|
|
373
|
+
expect(
|
|
374
|
+
tree
|
|
375
|
+
.find(`.${BASE_CLASS_PREFIX}-tree-option.${BASE_CLASS_PREFIX}-tree-option-level-2`)
|
|
376
|
+
.at(0)
|
|
377
|
+
.exists(`.${BASE_CLASS_PREFIX}-checkbox-checked`)
|
|
378
|
+
).toEqual(true);
|
|
379
|
+
const nodelevel3 = tree.find(`.${BASE_CLASS_PREFIX}-tree-option.${BASE_CLASS_PREFIX}-tree-option-level-3`);
|
|
380
|
+
expect(
|
|
381
|
+
nodelevel3
|
|
382
|
+
.exists(`.${BASE_CLASS_PREFIX}-checkbox-unChecked` )
|
|
383
|
+
).toEqual(true);
|
|
384
|
+
expect(
|
|
385
|
+
nodelevel3
|
|
386
|
+
.at(1)
|
|
387
|
+
.exists(`.${BASE_CLASS_PREFIX}-checkbox-unChecked` )
|
|
388
|
+
).toEqual(true);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('unRelated + value', () => {
|
|
392
|
+
const tree = getTree({
|
|
393
|
+
defaultExpandAll: true,
|
|
394
|
+
checkRelation: 'unRelated',
|
|
395
|
+
value: 'Zhongguo'
|
|
396
|
+
});
|
|
397
|
+
expect(
|
|
398
|
+
tree
|
|
399
|
+
.find(`.${BASE_CLASS_PREFIX}-tree-option.${BASE_CLASS_PREFIX}-tree-option-level-2`)
|
|
400
|
+
.at(0)
|
|
401
|
+
.exists(`.${BASE_CLASS_PREFIX}-checkbox-checked`)
|
|
402
|
+
).toEqual(true);
|
|
403
|
+
const nodelevel3 = tree.find(`.${BASE_CLASS_PREFIX}-tree-option.${BASE_CLASS_PREFIX}-tree-option-level-3`);
|
|
404
|
+
expect(
|
|
405
|
+
nodelevel3
|
|
406
|
+
.exists(`.${BASE_CLASS_PREFIX}-checkbox-unChecked` )
|
|
407
|
+
).toEqual(true);
|
|
408
|
+
expect(
|
|
409
|
+
nodelevel3
|
|
410
|
+
.at(1)
|
|
411
|
+
.exists(`.${BASE_CLASS_PREFIX}-checkbox-unChecked` )
|
|
412
|
+
).toEqual(true);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('unRelated + defaultValue', () => {
|
|
416
|
+
const tree = getTree({
|
|
417
|
+
defaultExpandAll: true,
|
|
418
|
+
checkRelation: 'unRelated',
|
|
419
|
+
defaultValue: 'Zhongguo'
|
|
420
|
+
});
|
|
421
|
+
expect(
|
|
422
|
+
tree
|
|
423
|
+
.find(`.${BASE_CLASS_PREFIX}-tree-option.${BASE_CLASS_PREFIX}-tree-option-level-2`)
|
|
424
|
+
.at(0)
|
|
425
|
+
.exists(`.${BASE_CLASS_PREFIX}-checkbox-checked`)
|
|
426
|
+
).toEqual(true);
|
|
427
|
+
const nodelevel3 = tree.find(`.${BASE_CLASS_PREFIX}-tree-option.${BASE_CLASS_PREFIX}-tree-option-level-3`);
|
|
428
|
+
expect(
|
|
429
|
+
nodelevel3
|
|
430
|
+
.exists(`.${BASE_CLASS_PREFIX}-checkbox-unChecked` )
|
|
431
|
+
).toEqual(true);
|
|
432
|
+
expect(
|
|
433
|
+
nodelevel3
|
|
434
|
+
.at(1)
|
|
435
|
+
.exists(`.${BASE_CLASS_PREFIX}-checkbox-unChecked` )
|
|
436
|
+
).toEqual(true);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('unRelated + onSelect', () => {
|
|
440
|
+
const spyOnSelect = sinon.spy(() => { });
|
|
441
|
+
const tree = getTree({
|
|
442
|
+
defaultExpandAll: true,
|
|
443
|
+
onSelect: spyOnSelect,
|
|
444
|
+
checkRelation: 'unRelated',
|
|
445
|
+
});
|
|
446
|
+
const nodelevel2 = tree.find(`.${BASE_CLASS_PREFIX}-tree-option.${BASE_CLASS_PREFIX}-tree-option-level-2`);
|
|
447
|
+
const selectedNode = nodelevel2.at(0);
|
|
448
|
+
selectedNode.simulate('click');
|
|
449
|
+
expect(spyOnSelect.calledOnce).toBe(true);
|
|
450
|
+
// onSelect first args is key, not value
|
|
451
|
+
expect(spyOnSelect.calledWithMatch('zhongguo')).toEqual(true);
|
|
452
|
+
});
|
|
453
|
+
|
|
360
454
|
it('controlled: leaf values show correct', () => {
|
|
361
455
|
let tree = getTree({
|
|
362
456
|
value: 'Beijing'
|