@douyinfe/semi-ui 2.6.0-beta.0 → 2.6.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-ui",
3
- "version": "2.6.0-beta.0",
3
+ "version": "2.6.0",
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.6.0-beta.0",
18
- "@douyinfe/semi-animation-react": "2.6.0-beta.0",
19
- "@douyinfe/semi-foundation": "2.6.0-beta.0",
20
- "@douyinfe/semi-icons": "2.6.0-beta.0",
21
- "@douyinfe/semi-illustrations": "2.6.0-beta.0",
22
- "@douyinfe/semi-theme-default": "2.6.0-beta.0",
17
+ "@douyinfe/semi-animation": "2.6.0",
18
+ "@douyinfe/semi-animation-react": "2.6.0",
19
+ "@douyinfe/semi-foundation": "2.6.0",
20
+ "@douyinfe/semi-icons": "2.6.0",
21
+ "@douyinfe/semi-illustrations": "2.6.0",
22
+ "@douyinfe/semi-theme-default": "2.6.0",
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": "49d107f759f3610a471c34bb9568ad9408aa2cb0",
72
+ "gitHead": "d3a844137fb02b81a93320eb5c183636b05a4a68",
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.6.0-beta.0",
78
+ "@douyinfe/semi-scss-compile": "2.6.0",
79
79
  "@storybook/addon-knobs": "^6.3.1",
80
80
  "@types/lodash": "^4.14.176",
81
81
  "babel-loader": "^8.2.2",
@@ -89,6 +89,8 @@ export interface BodyState {
89
89
 
90
90
  export interface BodyContext {
91
91
  getVirtualizedListRef: GetVirtualizedListRef;
92
+ flattenedColumns: ColumnProps[];
93
+ getCellWidths: (flattenedColumns: ColumnProps[]) => number[];
92
94
  }
93
95
 
94
96
  class Body extends BaseComponent<BodyProps, BodyState> {
@@ -128,6 +130,8 @@ class Body extends BaseComponent<BodyProps, BodyState> {
128
130
  listRef: React.MutableRefObject<any>;
129
131
  observer: ResizeObserver;
130
132
  foundation: BodyFoundation;
133
+ cellWidths: number[];
134
+ flattenedColumns: ColumnProps[];
131
135
  constructor(props: BodyProps, context: BodyContext) {
132
136
  super(props);
133
137
  this.ref = React.createRef();
@@ -142,7 +146,7 @@ class Body extends BaseComponent<BodyProps, BodyState> {
142
146
  };
143
147
 
144
148
  this.listRef = React.createRef();
145
- const { getVirtualizedListRef } = context;
149
+ const { getVirtualizedListRef, flattenedColumns, getCellWidths } = context;
146
150
  if (getVirtualizedListRef) {
147
151
  if (props.virtualized) {
148
152
  getVirtualizedListRef(this.listRef);
@@ -152,6 +156,8 @@ class Body extends BaseComponent<BodyProps, BodyState> {
152
156
  }
153
157
  }
154
158
  this.foundation = new BodyFoundation(this.adapter);
159
+ this.flattenedColumns = flattenedColumns;
160
+ this.cellWidths = getCellWidths(flattenedColumns);
155
161
  this.observer = null;
156
162
  }
157
163
 
@@ -199,7 +205,7 @@ class Body extends BaseComponent<BodyProps, BodyState> {
199
205
  this.observer.unobserve(bodyWrapDOM);
200
206
  this.observer = null;
201
207
  }
202
- }
208
+ },
203
209
  };
204
210
  }
205
211
 
@@ -494,7 +500,12 @@ class Body extends BaseComponent<BodyProps, BodyState> {
494
500
  }
495
501
 
496
502
  const { flattenedColumns, getCellWidths } = this.context;
497
- const cellWidths = getCellWidths(flattenedColumns);
503
+
504
+ // we use memoized cellWidths to avoid re-render expanded row (fix #686)
505
+ if (flattenedColumns !== this.flattenedColumns) {
506
+ this.flattenedColumns = flattenedColumns;
507
+ this.cellWidths = getCellWidths(flattenedColumns);
508
+ }
498
509
 
499
510
  return (
500
511
  <ExpandedRow
@@ -508,7 +519,7 @@ class Body extends BaseComponent<BodyProps, BodyState> {
508
519
  index={index}
509
520
  virtualized={virtualized}
510
521
  key={genExpandedRowKey(key)}
511
- cellWidths={cellWidths}
522
+ cellWidths={this.cellWidths}
512
523
  />
513
524
  );
514
525
  };
@@ -1930,4 +1930,22 @@ describe(`Table`, () => {
1930
1930
  expect(newExpandedRows.length).toEqual(1);
1931
1931
  expect(table.state(`expandedRowKeys`)).toEqual(['1']);
1932
1932
  });
1933
+
1934
+ it(`test expanded row re-render`, () => {
1935
+ const expandedRowRender = sinon.spy(() => <div>Semi Design</div>);
1936
+ const demo = mount(
1937
+ <Table
1938
+ columns={columns}
1939
+ dataSource={data}
1940
+ expandedRowRender={expandedRowRender}
1941
+ />
1942
+ );
1943
+
1944
+ const table = demo.find(BaseTable);
1945
+
1946
+ const expandIcons = demo.find(`.semi-table-tbody .semi-table-row .semi-table-expand-icon`);
1947
+ expandIcons.at(0).simulate('click');
1948
+ expandIcons.at(1).simulate('click');
1949
+ expect(expandedRowRender.calledTwice).toBeTruthy();
1950
+ });
1933
1951
  });
@@ -0,0 +1,95 @@
1
+ import React from 'react';
2
+ import { Table, Avatar } from '@douyinfe/semi-ui';
3
+ import { IconMore } from '@douyinfe/semi-icons';
4
+
5
+ const columns = [
6
+ {
7
+ title: '标题',
8
+ width: 500,
9
+ dataIndex: 'name',
10
+ render: (text, record, index) => {
11
+ return (
12
+ <span>
13
+ <Avatar size="small" shape="square" src={record.nameIconSrc} style={{ marginRight: 12 }}></Avatar>
14
+ {text}
15
+ </span>
16
+ );
17
+ },
18
+ },
19
+ {
20
+ title: '大小',
21
+ dataIndex: 'size',
22
+ },
23
+ {
24
+ title: '所有者',
25
+ dataIndex: 'owner',
26
+ render: (text, record, index) => {
27
+ return (
28
+ <div>
29
+ <Avatar size="small" color={record.avatarBg} style={{ marginRight: 4 }}>
30
+ {typeof text === 'string' && text.slice(0, 1)}
31
+ </Avatar>
32
+ {text}
33
+ </div>
34
+ );
35
+ },
36
+ },
37
+ {
38
+ title: '更新日期',
39
+ dataIndex: 'updateTime',
40
+ },
41
+ {
42
+ title: '',
43
+ dataIndex: 'operate',
44
+ render: () => {
45
+ return <IconMore />;
46
+ },
47
+ },
48
+ ];
49
+
50
+ const data = [
51
+ {
52
+ key: '1',
53
+ name: 'Semi Design 设计稿.fig',
54
+ nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
55
+ size: '2M',
56
+ owner: '姜鹏志',
57
+ updateTime: '2020-02-02 05:13',
58
+ avatarBg: 'grey',
59
+ },
60
+ {
61
+ key: '2',
62
+ name: 'Semi Design 分享演示文稿',
63
+ nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
64
+ size: '2M',
65
+ owner: '郝宣',
66
+ updateTime: '2020-01-17 05:31',
67
+ avatarBg: 'red',
68
+ },
69
+ {
70
+ key: '3',
71
+ name: '设计文档',
72
+ nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
73
+ size: '34KB',
74
+ owner: 'Zoey Edwards',
75
+ updateTime: '2020-01-26 11:01',
76
+ avatarBg: 'light-blue',
77
+ },
78
+ ];
79
+
80
+ export default function App() {
81
+ const expandRowRender = (record, index) => {
82
+ console.log('render', index);
83
+ return <div>semi design</div>;
84
+ };
85
+
86
+ return (
87
+ <Table
88
+ rowKey="name"
89
+ columns={columns}
90
+ dataSource={data}
91
+ expandedRowRender={expandRowRender}
92
+ pagination={false}
93
+ />
94
+ );
95
+ }
@@ -2,4 +2,5 @@ export { default as DefaultFilteredValue } from './defaultFilteredValue';
2
2
  export { default as FixedColumnsChange } from './FixedColumnsChange';
3
3
  export { default as FixedZIndex } from './FixedZIndex';
4
4
  export { default as FixedHeaderMerge } from './FixedHeaderMerge';
5
- export { default as FixedResizable } from './FixedResizable';
5
+ export { default as FixedResizable } from './FixedResizable';
6
+ export { default as FixedExpandedRow } from './FixedExpandedRow';