@douyinfe/semi-ui 2.4.1 → 2.5.1

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.
Files changed (103) hide show
  1. package/button/index.tsx +1 -1
  2. package/cascader/__test__/cascader.test.js +24 -0
  3. package/cascader/_story/cascader.stories.js +73 -0
  4. package/cascader/index.tsx +5 -2
  5. package/datePicker/_story/v2/FixInputRangeFocus.jsx +25 -0
  6. package/datePicker/_story/v2/index.js +2 -1
  7. package/datePicker/datePicker.tsx +3 -0
  8. package/dist/css/semi.css +56 -29
  9. package/dist/css/semi.min.css +1 -1
  10. package/dist/umd/semi-ui.js +523 -227
  11. package/dist/umd/semi-ui.js.map +1 -1
  12. package/dist/umd/semi-ui.min.js +1 -1
  13. package/dist/umd/semi-ui.min.js.map +1 -1
  14. package/form/__test__/formApi.test.js +182 -0
  15. package/form/_story/FormApi/arrayDemo.jsx +4 -7
  16. package/form/_story/Layout/slotDemo.jsx +2 -2
  17. package/form/_story/demo.jsx +18 -1
  18. package/form/_story/form.stories.js +6 -6
  19. package/form/baseForm.tsx +2 -2
  20. package/lib/cjs/autoComplete/index.d.ts +1 -1
  21. package/lib/cjs/button/Button.d.ts +4 -4
  22. package/lib/cjs/button/buttonGroup.d.ts +2 -2
  23. package/lib/cjs/button/index.d.ts +5 -6
  24. package/lib/cjs/cascader/index.js +6 -0
  25. package/lib/cjs/datePicker/datePicker.js +4 -0
  26. package/lib/cjs/dropdown/index.d.ts +1 -1
  27. package/lib/cjs/form/baseForm.d.ts +1 -1
  28. package/lib/cjs/form/baseForm.js +2 -2
  29. package/lib/cjs/form/field.d.ts +1 -1
  30. package/lib/cjs/iconButton/index.d.ts +2 -2
  31. package/lib/cjs/select/index.d.ts +3 -3
  32. package/lib/cjs/select/index.js +32 -28
  33. package/lib/cjs/select/option.js +2 -2
  34. package/lib/cjs/select/virtualRow.js +2 -2
  35. package/lib/cjs/table/Table.d.ts +1 -1
  36. package/lib/cjs/table/Table.js +8 -2
  37. package/lib/cjs/table/interface.d.ts +1 -0
  38. package/lib/cjs/tabs/interface.d.ts +1 -1
  39. package/lib/cjs/tooltip/index.d.ts +1 -1
  40. package/lib/cjs/tooltip/index.js +12 -4
  41. package/lib/cjs/tree/index.d.ts +2 -0
  42. package/lib/cjs/tree/index.js +15 -8
  43. package/lib/cjs/treeSelect/index.d.ts +2 -0
  44. package/lib/cjs/treeSelect/index.js +64 -27
  45. package/lib/cjs/upload/fileCard.js +31 -22
  46. package/lib/cjs/upload/index.d.ts +6 -0
  47. package/lib/cjs/upload/index.js +15 -8
  48. package/lib/cjs/upload/interface.d.ts +8 -6
  49. package/lib/es/autoComplete/index.d.ts +1 -1
  50. package/lib/es/button/Button.d.ts +4 -4
  51. package/lib/es/button/buttonGroup.d.ts +2 -2
  52. package/lib/es/button/index.d.ts +5 -6
  53. package/lib/es/cascader/index.js +5 -0
  54. package/lib/es/datePicker/datePicker.js +4 -0
  55. package/lib/es/dropdown/index.d.ts +1 -1
  56. package/lib/es/form/baseForm.d.ts +1 -1
  57. package/lib/es/form/baseForm.js +2 -2
  58. package/lib/es/form/field.d.ts +1 -1
  59. package/lib/es/iconButton/index.d.ts +2 -2
  60. package/lib/es/select/index.d.ts +3 -3
  61. package/lib/es/select/index.js +30 -26
  62. package/lib/es/select/option.js +2 -2
  63. package/lib/es/select/virtualRow.js +2 -2
  64. package/lib/es/table/Table.d.ts +1 -1
  65. package/lib/es/table/Table.js +10 -2
  66. package/lib/es/table/interface.d.ts +1 -0
  67. package/lib/es/tabs/interface.d.ts +1 -1
  68. package/lib/es/tooltip/index.d.ts +1 -1
  69. package/lib/es/tooltip/index.js +12 -4
  70. package/lib/es/tree/index.d.ts +2 -0
  71. package/lib/es/tree/index.js +15 -8
  72. package/lib/es/treeSelect/index.d.ts +2 -0
  73. package/lib/es/treeSelect/index.js +64 -27
  74. package/lib/es/upload/fileCard.js +31 -24
  75. package/lib/es/upload/index.d.ts +6 -0
  76. package/lib/es/upload/index.js +14 -8
  77. package/lib/es/upload/interface.d.ts +8 -6
  78. package/package.json +9 -9
  79. package/select/index.tsx +18 -19
  80. package/select/option.tsx +2 -2
  81. package/select/virtualRow.tsx +2 -2
  82. package/table/Table.tsx +7 -2
  83. package/table/_story/Perf/Virtualized/index.jsx +6 -0
  84. package/table/_story/table.stories.js +1 -2
  85. package/table/_story/v2/FixedHeaderMerge/index.jsx +98 -0
  86. package/table/_story/v2/FixedResizable/index.jsx +114 -0
  87. package/table/_story/v2/defaultFilteredValue.tsx +114 -0
  88. package/table/_story/v2/index.js +5 -0
  89. package/table/interface.ts +1 -0
  90. package/tabs/interface.ts +1 -1
  91. package/tooltip/__test__/tooltip.test.js +48 -4
  92. package/tooltip/_story/tooltip.stories.js +718 -559
  93. package/tooltip/index.tsx +6 -6
  94. package/tree/__test__/treeMultiple.test.js +94 -0
  95. package/tree/_story/tree.stories.js +169 -0
  96. package/tree/index.tsx +12 -5
  97. package/treeSelect/__test__/treeMultiple.test.js +94 -0
  98. package/treeSelect/_story/treeSelect.stories.js +242 -0
  99. package/treeSelect/index.tsx +72 -40
  100. package/upload/_story/upload.stories.js +22 -6
  101. package/upload/fileCard.tsx +23 -23
  102. package/upload/index.tsx +15 -6
  103. package/upload/interface.ts +7 -5
@@ -1,4 +1,4 @@
1
- import { ReactNode, CSSProperties, MouseEvent } from 'react';
1
+ import { ReactNode, CSSProperties } from 'react';
2
2
  import { BaseFileItem } from '@douyinfe/semi-foundation/lib/es/upload/foundation';
3
3
  import { strings } from '@douyinfe/semi-foundation/lib/es/upload/constants';
4
4
  import { ArrayElement } from '../_base/base';
@@ -45,14 +45,16 @@ export interface RenderFileItemProps extends FileItem {
45
45
  index?: number;
46
46
  previewFile?: (fileItem: RenderFileItemProps) => ReactNode;
47
47
  listType: UploadListType;
48
- onRemove: (props: RenderFileItemProps, e: MouseEvent) => void;
49
- onRetry: (props: RenderFileItemProps, e: MouseEvent) => void;
50
- onReplace: (props: RenderFileItemProps, e: MouseEvent) => void;
48
+ onRemove: () => void;
49
+ onRetry: () => void;
50
+ onReplace: () => void;
51
51
  key: string;
52
52
  showPicInfo?: boolean;
53
53
  renderPicInfo?: (renderFileItemProps: RenderFileItemProps) => ReactNode;
54
- showRetry: boolean;
55
- showReplace: boolean;
54
+ renderPicPreviewIcon?: (renderFileItemProps: RenderFileItemProps) => ReactNode;
55
+ renderFileOperation?: (fileItem: RenderFileItemProps) => ReactNode;
56
+ showRetry?: boolean;
57
+ showReplace?: boolean;
56
58
  style?: CSSProperties;
57
59
  disabled: boolean;
58
60
  onPreviewClick: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-ui",
3
- "version": "2.4.1",
3
+ "version": "2.5.1",
4
4
  "description": "",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es/index.js",
@@ -14,12 +14,12 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@babel/runtime-corejs3": "^7.15.4",
17
- "@douyinfe/semi-animation": "2.4.1",
18
- "@douyinfe/semi-animation-react": "2.4.1",
19
- "@douyinfe/semi-foundation": "2.4.1",
20
- "@douyinfe/semi-icons": "2.4.1",
21
- "@douyinfe/semi-illustrations": "2.4.1",
22
- "@douyinfe/semi-theme-default": "2.4.1",
17
+ "@douyinfe/semi-animation": "2.5.1",
18
+ "@douyinfe/semi-animation-react": "2.5.1",
19
+ "@douyinfe/semi-foundation": "2.5.1",
20
+ "@douyinfe/semi-icons": "2.5.1",
21
+ "@douyinfe/semi-illustrations": "2.5.1",
22
+ "@douyinfe/semi-theme-default": "2.5.1",
23
23
  "@types/react-window": "^1.8.2",
24
24
  "async-validator": "^3.5.0",
25
25
  "classnames": "^2.2.6",
@@ -69,13 +69,13 @@
69
69
  ],
70
70
  "author": "",
71
71
  "license": "MIT",
72
- "gitHead": "c69c466ecd14aeeda847473e97dad2ec313f09fa",
72
+ "gitHead": "3f83639f8a4fff7f912a237bf2842cb0944d993c",
73
73
  "devDependencies": {
74
74
  "@babel/plugin-proposal-decorators": "^7.15.8",
75
75
  "@babel/plugin-transform-runtime": "^7.15.8",
76
76
  "@babel/preset-env": "^7.15.8",
77
77
  "@babel/preset-react": "^7.14.5",
78
- "@douyinfe/semi-scss-compile": "2.4.1",
78
+ "@douyinfe/semi-scss-compile": "2.5.1",
79
79
  "@storybook/addon-knobs": "^6.3.1",
80
80
  "@types/lodash": "^4.14.176",
81
81
  "babel-loader": "^8.2.2",
package/select/index.tsx CHANGED
@@ -530,9 +530,13 @@ class Select extends BaseComponent<SelectProps, SelectState> {
530
530
 
531
531
  }
532
532
  },
533
- updateScrollTop: () => {
533
+ updateScrollTop: (index?: number) => {
534
534
  // eslint-disable-next-line max-len
535
- let destNode = document.querySelector(`#${prefixcls}-${this.selectOptionListID} .${prefixcls}-option-selected`) as HTMLDivElement;
535
+ let optionClassName = `.${prefixcls}-option-selected`;
536
+ if (index !== undefined) {
537
+ optionClassName = `.${prefixcls}-option:nth-child(${index})`;
538
+ }
539
+ let destNode = document.querySelector(`#${prefixcls}-${this.selectOptionListID} ${optionClassName}`) as HTMLDivElement;
536
540
  if (Array.isArray(destNode)) {
537
541
  // eslint-disable-next-line prefer-destructuring
538
542
  destNode = destNode[0];
@@ -754,31 +758,26 @@ class Select extends BaseComponent<SelectProps, SelectState> {
754
758
  this.foundation.handleOptionMouseEnter(optionIndex);
755
759
  }
756
760
 
757
- renderWithGroup(visibileOptions: OptionProps[]) {
761
+ renderWithGroup(visibleOptions: OptionProps[]) {
758
762
  const content: JSX.Element[] = [];
759
763
  const groupStatus = new Map();
760
764
 
761
- visibileOptions.forEach((option, optionIndex) => {
765
+ visibleOptions.forEach((option, optionIndex) => {
762
766
  const parentGroup = option._parentGroup;
763
767
  const optionContent = this.renderOption(option, optionIndex);
764
- if (parentGroup && groupStatus.has(parentGroup.label)) {
765
- // group content already insert
766
- content.push(optionContent);
767
- } else if (parentGroup) {
768
+ if (parentGroup && !groupStatus.has(parentGroup.label)) {
769
+ // when use with OptionGroup and group content not already insert
768
770
  const groupContent = <OptionGroup {...parentGroup} key={parentGroup.label} />;
769
771
  groupStatus.set(parentGroup.label, true);
770
772
  content.push(groupContent);
771
- content.push(optionContent);
772
- } else {
773
- // when not use with OptionGroup
774
- content.push(optionContent);
775
- }
773
+ }
774
+ content.push(optionContent);
776
775
  });
777
776
 
778
777
  return content;
779
778
  }
780
779
 
781
- renderVirtualizeList(visibileOptions: OptionProps[]) {
780
+ renderVirtualizeList(visibleOptions: OptionProps[]) {
782
781
  const { virtualize } = this.props;
783
782
  const { direction } = this.context;
784
783
  const { height, width, itemSize } = virtualize;
@@ -787,9 +786,9 @@ class Select extends BaseComponent<SelectProps, SelectState> {
787
786
  <List
788
787
  ref={this.virtualizeListRef}
789
788
  height={height || numbers.LIST_HEIGHT}
790
- itemCount={visibileOptions.length}
789
+ itemCount={visibleOptions.length}
791
790
  itemSize={itemSize}
792
- itemData={{ visibileOptions, renderOption: this.renderOption }}
791
+ itemData={{ visibleOptions, renderOption: this.renderOption }}
793
792
  width={width || '100%'}
794
793
  style={{ direction }}
795
794
  >
@@ -814,11 +813,11 @@ class Select extends BaseComponent<SelectProps, SelectState> {
814
813
  } = this.props;
815
814
 
816
815
  // Do a filter first, instead of directly judging in forEach, so that the focusIndex can correspond to
817
- const visibileOptions = options.filter(item => item._show);
816
+ const visibleOptions = options.filter(item => item._show);
818
817
 
819
- let listContent: JSX.Element | JSX.Element[] = this.renderWithGroup(visibileOptions);
818
+ let listContent: JSX.Element | JSX.Element[] = this.renderWithGroup(visibleOptions);
820
819
  if (virtualize) {
821
- listContent = this.renderVirtualizeList(visibileOptions);
820
+ listContent = this.renderVirtualizeList(visibleOptions);
822
821
  }
823
822
 
824
823
  const style = { minWidth: dropdownMinWidth, ...dropdownStyle };
package/select/option.tsx CHANGED
@@ -57,8 +57,8 @@ class Option extends PureComponent<OptionProps> {
57
57
 
58
58
  onClick({ value, label, children, ...rest }: Partial<OptionProps>, event: React.MouseEvent) {
59
59
  const { props } = this;
60
- const isDisbled = props.disabled;
61
- if (!isDisbled) {
60
+ const isDisabled = props.disabled;
61
+ if (!isDisabled) {
62
62
  props.onSelect({ ...rest, value, label: label || children }, event);
63
63
  }
64
64
  }
@@ -5,8 +5,8 @@ export interface VirtualRowProps{
5
5
  style?: React.CSSProperties;
6
6
  }
7
7
  const VirtualRow = ({ index, data, style }: VirtualRowProps) => {
8
- const { visibileOptions } = data;
9
- const option = visibileOptions[index];
8
+ const { visibleOptions } = data;
9
+ const option = visibleOptions[index];
10
10
  return data.renderOption(option, index, style);
11
11
  };
12
12
 
package/table/Table.tsx CHANGED
@@ -424,11 +424,12 @@ class Table<RecordType extends Record<string, any>> extends BaseComponent<Normal
424
424
  willUpdateStates.cachedColumns = props.columns;
425
425
  willUpdateStates.cachedChildren = null;
426
426
  } else if (props.children && props.children !== state.cachedChildren) {
427
- const newFlattenColumns = flattenColumns(getColumns(props.children));
427
+ const newNestedColumns = getColumns(props.children);
428
+ const newFlattenColumns = flattenColumns(newNestedColumns);
428
429
  const columns = mergeColumns(state.queries, newFlattenColumns, null, false);
429
430
  willUpdateStates.flattenColumns = newFlattenColumns;
430
431
  willUpdateStates.queries = [...columns];
431
- willUpdateStates.cachedColumns = [...columns];
432
+ willUpdateStates.cachedColumns = [...newNestedColumns];
432
433
  willUpdateStates.cachedChildren = props.children;
433
434
  }
434
435
 
@@ -943,11 +944,15 @@ class Table<RecordType extends Record<string, any>> extends BaseComponent<Normal
943
944
  titleArr.push(sorter);
944
945
  }
945
946
 
947
+ const stateFilteredValue = get(curQuery, 'filteredValue');
948
+ const defaultFilteredValue = get(curQuery, 'defaultFilteredValue');
949
+ const filteredValue = stateFilteredValue ? stateFilteredValue : defaultFilteredValue;
946
950
  if ((Array.isArray(column.filters) && column.filters.length) || isValidElement(column.filterDropdown)) {
947
951
  const filter = (
948
952
  <ColumnFilter
949
953
  key={strings.DEFAULT_KEY_COLUMN_FILTER}
950
954
  {...curQuery}
955
+ filteredValue={filteredValue}
951
956
  onFilterDropdownVisibleChange={(visible: boolean) => this.foundation.toggleShowFilter(dataIndex, visible)}
952
957
  onSelect={(data: OnSelectData) => this.foundation.handleFilterSelect(dataIndex, data)}
953
958
  />
@@ -9,29 +9,35 @@ class PerfVirtualized extends React.Component {
9
9
  {
10
10
  title: 'A',
11
11
  dataIndex: 'key',
12
+ key: 'a',
12
13
  width: 150,
13
14
  },
14
15
  {
15
16
  title: 'B',
16
17
  dataIndex: 'key',
18
+ key: 'b',
17
19
  },
18
20
  {
19
21
  title: 'C',
20
22
  dataIndex: 'key',
23
+ key: 'c',
21
24
  },
22
25
  {
23
26
  title: 'D',
24
27
  dataIndex: 'key',
28
+ key: 'd',
25
29
  },
26
30
  {
27
31
  title: 'E',
28
32
  dataIndex: 'key',
29
33
  width: 200,
34
+ key: 'e',
30
35
  },
31
36
  {
32
37
  title: 'F',
33
38
  dataIndex: 'key',
34
39
  width: 100,
40
+ key: 'f'
35
41
  },
36
42
  ];
37
43
 
@@ -76,8 +76,7 @@ export { default as ScrollBar } from './ScrollBar';
76
76
  export { default as TableSpan } from './TableSpan';
77
77
  export { default as FixRenderReturnProps } from './FixRenderReturnProps';
78
78
  export { default as WarnColumnWithoutDataIndex } from './WarnColumnWithoutDataIndex';
79
- export { default as FixedColumnsChange } from './v2/FixedColumnsChange';
80
- export { default as FixedZIndex } from './v2/FixedZIndex';
79
+ export * from './v2';
81
80
 
82
81
  // empty table
83
82
 
@@ -0,0 +1,98 @@
1
+ import React, { useMemo } from 'react';
2
+ import { Table, Button } from '@douyinfe/semi-ui';
3
+
4
+ Demo.storyName = "fixed jsx column nested bug";
5
+
6
+
7
+ /**
8
+ * fixed https://github.com/DouyinFE/semi-design/issues/619
9
+ *
10
+ * Test with Cypress
11
+ */
12
+ export default function Demo() {
13
+ const columns = [
14
+ {
15
+ title: 'Base Information',
16
+ fixed: 'left',
17
+ children: [
18
+ {
19
+ title: 'Name',
20
+ dataIndex: 'name',
21
+ width: 200,
22
+ },
23
+ {
24
+ title: 'Age',
25
+ dataIndex: 'age',
26
+ width: 100,
27
+ },
28
+ ],
29
+ },
30
+ {
31
+ title: 'Company Information',
32
+ children: [
33
+ {
34
+ title: 'Company Name',
35
+ dataIndex: 'company.name',
36
+ },
37
+ {
38
+ title: 'Company Address',
39
+ dataIndex: 'company.address',
40
+ },
41
+ ],
42
+ }
43
+ ];
44
+
45
+ const data = useMemo(() => {
46
+ const data = [];
47
+ for (let i = 0; i < 100; i++) {
48
+ let age = (i * 1000) % 149;
49
+ let name = `Edward King ${i}`;
50
+ data.push({
51
+ key: '' + i,
52
+ company: {
53
+ name: 'ByteDance',
54
+ address: 'No. 48, Zhichun Road',
55
+ },
56
+ name,
57
+ age,
58
+ address: `No ${i + 1}, Zhongguancun Street`,
59
+ description: `My name is ${name}, I am ${age} years old, living in No ${i + 1}, Zhongguancun Street`,
60
+ });
61
+ }
62
+ return data;
63
+ }, []);
64
+
65
+ const [flag, setFlag] = React.useState(true);
66
+
67
+ return (
68
+ <>
69
+ <Button data-cy="button" onClick={()=> setFlag(!flag)}>reRender</Button>
70
+ <Table dataSource={data} pagination={true} size="small">
71
+ {columns.map((item, titleIndex) =>
72
+ (
73
+ <Table.Column
74
+ key={titleIndex}
75
+ title={item.title}
76
+ >
77
+ {item.children.map(
78
+ (childItem, columnIndex) =>
79
+ (
80
+ <Table.Column
81
+ title={childItem.title}
82
+ dataIndex={childItem.dataIndex}
83
+ key={titleIndex.toString() + columnIndex.toString()}
84
+ />
85
+ )
86
+ )}
87
+ </Table.Column>
88
+ )
89
+ )}
90
+ <Table.Column
91
+ title=""
92
+ key="lastColumn"
93
+ render={() => 123}
94
+ />
95
+ </Table>
96
+ </>
97
+ );
98
+ }
@@ -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,114 @@
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
+
65
+ const getData = (total) => {
66
+ const data = [];
67
+ for (let i = 0; i < total; i++) {
68
+ const isSemiDesign = i % 2 === 0;
69
+ const randomNumber = (i * 1000) % 199;
70
+ data.push({
71
+ key: '' + i,
72
+ name: isSemiDesign ? `Semi Design 设计稿${i}.fig` : `Semi Pro 设计稿${i}.fig`,
73
+ owner: isSemiDesign ? '姜鹏志' : '郝宣',
74
+ size: randomNumber,
75
+ avatarBg: isSemiDesign ? 'grey' : 'red'
76
+ });
77
+ }
78
+ return data;
79
+ };
80
+
81
+ const handleFilterChange = (filters: ChangeInfoFilter<any>[]) => {
82
+ console.log('filters', filters);
83
+ if (Array.isArray(filters) && filters.length) {
84
+ const { filteredValue } = filters.find(filter => filter.dataIndex === 'name');
85
+ setFilteredValue(filteredValue);
86
+ }
87
+ };
88
+
89
+ const handleChange = (options) => {
90
+ const { filters } = options;
91
+ handleFilterChange(filters);
92
+ };
93
+
94
+ const toggleChangeData = () => {
95
+ const length = dataSource.length;
96
+ const newData = getData(length === 46 ? 25 : 46);
97
+ setData(newData);
98
+ };
99
+
100
+ useEffect(() => {
101
+ const data = getData(46);
102
+ setData(data);
103
+ }, []);
104
+
105
+ return (
106
+ <div>
107
+ <Button onClick={toggleChangeData}>toggle change dataSource (46/25)</Button>
108
+ <Table columns={columns} dataSource={dataSource} scroll={scroll} onChange={handleChange} />
109
+ </div>
110
+ );
111
+ }
112
+
113
+ App.storyName = 'defaultFilteredValue';
114
+ 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';
@@ -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
@@ -58,7 +58,7 @@ export interface TabBarProps {
58
58
  export interface TabPaneProps {
59
59
  className?: string;
60
60
  disabled?: boolean;
61
- icon?: string;
61
+ icon?: ReactNode;
62
62
  itemKey?: string;
63
63
  style?: CSSProperties;
64
64
  tab?: ReactNode;