Просмотр исходного кода

chore: more friendly test demo case and use hooks

DaiQiangReal 4 лет назад
Родитель
Сommit
8399e724a0

+ 50 - 50
packages/semi-ui/_test_/utils/table/index.js

@@ -1,7 +1,7 @@
 import React from 'react';
-import { Tooltip, Tag, Table } from '../../../index';
+import {Table, Tag, Tooltip} from '../../../index';
 
-const { Column } = Table;
+const {Column} = Table;
 
 function getRandomNumber(end = 100, start = 0) {
     const number = Math.ceil(Math.random() * (end - start)) + start;
@@ -26,18 +26,18 @@ function getData(total = 25) {
 
 function getGroupData() {
     const data = [
-        { city: 'Beijing', job: 'FE', department: 'IES' },
-        { city: 'Beijing', job: 'BE', department: 'IES' },
-        { city: 'Shanghai', job: 'Android', department: 'IES' },
-        { city: 'Tokyo', job: 'Android', department: 'IES' },
-        { city: 'Shanghai', job: 'IOS', department: 'EE' },
-        { city: 'LA', job: 'SE', department: 'EE' },
-        { city: 'Beijing', job: 'Android', department: 'EE' },
-        { city: 'Tokyo', job: 'IOS', department: 'EE' },
-        { city: 'Tokyo', job: 'SE', department: 'DATA' },
-        { city: 'Shanghai', job: 'BE', department: 'DATA' },
-        { city: 'LA', job: 'Android', department: 'DATA' },
-        { city: 'LA', job: 'IOS', department: 'DATA' },
+        {city: 'Beijing', job: 'FE', department: 'IES'},
+        {city: 'Beijing', job: 'BE', department: 'IES'},
+        {city: 'Shanghai', job: 'Android', department: 'IES'},
+        {city: 'Tokyo', job: 'Android', department: 'IES'},
+        {city: 'Shanghai', job: 'IOS', department: 'EE'},
+        {city: 'LA', job: 'SE', department: 'EE'},
+        {city: 'Beijing', job: 'Android', department: 'EE'},
+        {city: 'Tokyo', job: 'IOS', department: 'EE'},
+        {city: 'Tokyo', job: 'SE', department: 'DATA'},
+        {city: 'Shanghai', job: 'BE', department: 'DATA'},
+        {city: 'LA', job: 'Android', department: 'DATA'},
+        {city: 'LA', job: 'IOS', department: 'DATA'},
     ];
     return data;
 }
@@ -79,9 +79,9 @@ function getColumns() {
 function getJSXColumns() {
     const jsxColumns = (
         <>
-            <Column title={'Name'} dataIndex={'name'} width={150} />
-            <Column title={'Age'} dataIndex={'age'} width={150} />
-            <Column title={'Address'} dataIndex={'address'} />
+            <Column title={'Name'} dataIndex={'name'} width={150}/>
+            <Column title={'Age'} dataIndex={'age'} width={150}/>
+            <Column title={'Address'} dataIndex={'address'}/>
             <Column
                 render={(text, record) => (
                     <Tooltip content={record.description}>
@@ -97,18 +97,18 @@ function getJSXColumns() {
 
 function getGroupColumns() {
     const columns = [
-        { dataIndex: 'city', title: 'City', width: 400, sorter: (a, b) => (a.city > b.city ? 1 : -1) },
+        {dataIndex: 'city', title: 'City', width: 400, sorter: (a, b) => (a.city > b.city ? 1 : -1)},
         {
             dataIndex: 'job',
             title: 'Job',
             width: 200,
             filters: [
-                { text: 'IOS', value: 'IOS' },
-                { text: 'Android', value: 'Android' },
+                {text: 'IOS', value: 'IOS'},
+                {text: 'Android', value: 'Android'},
             ],
             onFilter: (value, record) => record.job && record.job.indexOf(value) === 0,
         },
-        { dataIndex: 'department', title: 'Department' },
+        {dataIndex: 'department', title: 'Department'},
     ];
     return columns;
 }
@@ -192,53 +192,53 @@ function getTreeData() {
     const childrenData = [
         {
             key: 1,
-            name: 'John Brown sr.',
-            age: 60,
-            address: 'New York No. 1 Lake Park',
+            name: 'ZhangSan',
+            age: 30,
+            address: 'bytedance 1',
             children: [
                 {
                     key: 11,
-                    name: 'John Brown',
-                    age: 42,
-                    address: 'New York No. 2 Lake Park',
+                    name: 'LiSi',
+                    age: 40,
+                    address: 'bytedance 2',
                 },
                 {
                     key: 12,
-                    name: 'John Brown jr.',
+                    name: 'WangWu',
                     age: 30,
-                    address: 'New York No. 3 Lake Park',
+                    address: 'bytedance 2',
                     children: [
                         {
                             key: 121,
-                            name: 'Jimmy Brown',
-                            age: 16,
-                            address: 'New York No. 3 Lake Park',
+                            name: 'XiaoMing',
+                            age: 50,
+                            address: 'bytedance 3',
                         },
                     ],
                 },
                 {
                     key: 13,
-                    name: 'Jim Green sr.',
-                    age: 72,
-                    address: 'London No. 1 Lake Park',
+                    name: 'XiaoZhang',
+                    age: 60,
+                    address: 'bytedance 4',
                     children: [
                         {
                             key: 131,
-                            name: 'Jim Green',
-                            age: 42,
-                            address: 'London No. 2 Lake Park',
+                            name: 'XiaoLi',
+                            age: 50,
+                            address: 'bytedance 5',
                             children: [
                                 {
                                     key: 1311,
-                                    name: 'Jim Green jr.',
-                                    age: 25,
-                                    address: 'London No. 3 Lake Park',
+                                    name: 'XiaoGuo',
+                                    age: 40,
+                                    address: 'bytedance 6',
                                 },
                                 {
                                     key: 1312,
-                                    name: 'Jimmy Green sr.',
-                                    age: 18,
-                                    address: 'London No. 4 Lake Park',
+                                    name: 'XiaoHong',
+                                    age: 30,
+                                    address: 'bytedance 7',
                                 },
                             ],
                         },
@@ -248,9 +248,9 @@ function getTreeData() {
         },
         {
             key: 2,
-            name: 'Joe Black',
-            age: 32,
-            address: 'Sidney No. 1 Lake Park',
+            name: 'XiaoGang',
+            age: 80,
+            address: 'bytedance 8',
         },
     ];
     return childrenData;
@@ -287,10 +287,10 @@ function getJSXNestColumns() {
                 />
             </Column>
             <Column title={'Company Information'} dataIndex={'company'}>
-                <Column title={'Company Name'} dataIndex={'company.name'} />
-                <Column title={'Company Address'} dataIndex={'company.address'} />
+                <Column title={'Company Name'} dataIndex={'company.name'}/>
+                <Column title={'Company Address'} dataIndex={'company.address'}/>
             </Column>
-            <Column title={'Address'} dataIndex={'address'} width={250} fixed="right" />
+            <Column title={'Address'} dataIndex={'address'} width={250} fixed="right"/>
         </>
     );
     return jsxNestColumns;

+ 170 - 171
packages/semi-ui/checkbox/_story/checkbox.stories.js

@@ -1,12 +1,12 @@
-import React, { useState, useCallback, useMemo } from 'react';
-import { storiesOf } from '@storybook/react'; // import { withKnobs, text, boolean } from '@storybook/addon-knobs';
-
+import React, {useCallback, useMemo, useState} from 'react';
+import {storiesOf} from '@storybook/react'; // import { withKnobs, text, boolean } from '@storybook/addon-knobs';
 import Button from '../../button';
 import Popover from '../../popover';
 import Checkbox from '../index';
 import CheckboxGroup from '../checkboxGroup';
-import { Input, Row, Col } from '../../index';
-import { IconClose } from '@douyinfe/semi-icons';
+import {Col, Input, Row} from '../../index';
+import {IconClose} from '@douyinfe/semi-icons';
+
 const stories = storiesOf('Checkbox', module); // stories.addDecorator(withKnobs);;
 
 stories.add('checkbox default', () => {
@@ -15,17 +15,17 @@ stories.add('checkbox default', () => {
             <Checkbox onChange={e => console.log(e)} value={1} onChange={v => console.log(v)}>
                 hello
             </Checkbox>
-            <br />
+            <br/>
             <Checkbox checked>这是一个受控的checked=true的checkbox,没有配onChange</Checkbox>
-            <br />
+            <br/>
             <Checkbox defaultChecked>这是一个不受控的defaultChecked=true的checkbox</Checkbox>
-            <br />
+            <br/>
             <Checkbox disabled>这是一个受控的disabled=true的checkbox</Checkbox>
-            <br />
+            <br/>
             <Checkbox checked disabled>
                 既checked又disabled
             </Checkbox>
-            <br />
+            <br/>
             <Checkbox indeterminate>indeterminate</Checkbox>
         </div>
     );
@@ -33,7 +33,7 @@ stories.add('checkbox default', () => {
 stories.add('checkbox without text', () => {
     return (
         <div>
-            <Checkbox onChange={e => console.log(e)} />
+            <Checkbox onChange={e => console.log(e)}/>
         </div>
     );
 });
@@ -93,7 +93,7 @@ class CheckboxControl extends React.Component {
     }
 }
 
-stories.add('checkbox controlled disabled & checked', () => <CheckboxControl />);
+stories.add('checkbox controlled disabled & checked', () => <CheckboxControl/>);
 
 class GroupDemo extends React.Component {
     constructor() {
@@ -112,7 +112,7 @@ class GroupDemo extends React.Component {
     }
 
     render() {
-        let { value } = this.state;
+        let {value} = this.state;
         return (
             <>
                 水平Group
@@ -122,8 +122,8 @@ class GroupDemo extends React.Component {
                     <Checkbox value="toutiao">今日头条</Checkbox>
                     <Checkbox value="xigua">西瓜视频</Checkbox>
                 </Checkbox.Group>
-                <br />
-                <br />
+                <br/>
+                <br/>
                 垂直Group
                 <Checkbox.Group onChange={v => console.log(v)}>
                     <Checkbox value="dy">抖音</Checkbox>
@@ -131,8 +131,8 @@ class GroupDemo extends React.Component {
                     <Checkbox value="toutiao">今日头条</Checkbox>
                     <Checkbox value="xigua">西瓜视频</Checkbox>
                 </Checkbox.Group>
-                <br />
-                <br />
+                <br/>
+                <br/>
                 默认Group
                 <Checkbox.Group direction="horizontal" defaultValue={['xigua']} onChange={console.log}>
                     <Checkbox value="dy">抖音</Checkbox>
@@ -140,8 +140,8 @@ class GroupDemo extends React.Component {
                     <Checkbox value="toutiao">今日头条</Checkbox>
                     <Checkbox value="xigua">西瓜视频</Checkbox>
                 </Checkbox.Group>
-                <br />
-                <br />
+                <br/>
+                <br/>
                 受控Group
                 <Checkbox.Group direction="horizontal" value={value} onChange={console.log}>
                     <Checkbox value="dy">抖音</Checkbox>
@@ -149,8 +149,8 @@ class GroupDemo extends React.Component {
                     <Checkbox value="toutiao">今日头条</Checkbox>
                     <Checkbox value="xigua">西瓜视频</Checkbox>
                 </Checkbox.Group>
-                <br />
-                <br />
+                <br/>
+                <br/>
                 受控Group+onChange
                 <Checkbox.Group direction="horizontal" value={value} onChange={this.onChange}>
                     <Checkbox value="dy">抖音</Checkbox>
@@ -158,8 +158,8 @@ class GroupDemo extends React.Component {
                     <Checkbox value="toutiao">今日头条</Checkbox>
                     <Checkbox value="xigua">西瓜视频</Checkbox>
                 </Checkbox.Group>
-                <br />
-                <br />
+                <br/>
+                <br/>
                 disabled
                 <Checkbox.Group disabled>
                     <Checkbox value="dy">抖音</Checkbox>
@@ -172,7 +172,7 @@ class GroupDemo extends React.Component {
     }
 }
 
-stories.add('checkbox group', () => <GroupDemo />);
+stories.add('checkbox group', () => <GroupDemo/>);
 stories.add('checkbox group with options ', () => {
     function onChange(checkedValues) {
         console.log('checked = ', checkedValues);
@@ -212,19 +212,19 @@ stories.add('checkbox group with options ', () => {
     return (
         <div>
             default
-            <CheckboxGroup options={plainOptions} defaultValue={['Apple']} onChange={onChange} />
-            <br />
-            <br />
+            <CheckboxGroup options={plainOptions} defaultValue={['Apple']} onChange={onChange}/>
+            <br/>
+            <br/>
             受控
-            <CheckboxGroup options={plainOptions} value={['Apple']} onChange={onChange} />
-            <br />
+            <CheckboxGroup options={plainOptions} value={['Apple']} onChange={onChange}/>
+            <br/>
             最后一个disabled
-            <br />
-            <CheckboxGroup options={options} defaultValue={['Pear']} onChange={onChange} />
-            <br />
+            <br/>
+            <CheckboxGroup options={options} defaultValue={['Pear']} onChange={onChange}/>
+            <br/>
             全体disabled, 优先父级disabled,次选子级disabled
-            <br />
-            <CheckboxGroup options={optionsWithDisabled} disabled defaultValue={['Apple']} onChange={onChange} />
+            <br/>
+            <CheckboxGroup options={optionsWithDisabled} disabled defaultValue={['Apple']} onChange={onChange}/>
         </div>
     );
 });
@@ -282,8 +282,8 @@ stories.add('checkbox 主文本+副文本', () => {
             >
                 我是主文本
             </Checkbox>
-            <br />
-            <br />
+            <br/>
+            <br/>
             checkboxGroup
             <CheckboxGroup>
                 <Checkbox value="Apple" extra="苹果">
@@ -296,8 +296,8 @@ stories.add('checkbox 主文本+副文本', () => {
                     Orange
                 </Checkbox>
             </CheckboxGroup>
-            <br />
-            <br />
+            <br/>
+            <br/>
             checkboxGroup with options
             <CheckboxGroup options={options}></CheckboxGroup>
         </div>
@@ -334,54 +334,53 @@ stories.add('checkbox + grid', () => {
         </Checkbox.Group>
     );
 });
-const plainOptions = ['Apple', 'Pear', 'Orange'];
-const defaultCheckedList = ['Apple', 'Orange'];
 
-class IndeterminateDemo extends React.Component {
-    state = {
-        checkedList: defaultCheckedList,
-        indeterminate: true,
-        checkAll: false,
-    };
-    onChange = checkedList => {
-        this.setState({
-            checkedList,
-            indeterminate: !!checkedList.length && checkedList.length < plainOptions.length,
-            checkAll: checkedList.length === plainOptions.length,
-        });
+
+const IndeterminateDemo = () => {
+    const options = ['yellow', 'green', 'red'];
+    const defaultCheckedColors = ['yellow', 'red'];
+
+    const [checkedList, setCheckList] = useState(defaultCheckedColors);
+    const [indeterminate, setIndeterminate] = useState(true);
+    const [checkAll, setCheckAll] = useState(false);
+
+    const onCheckListChange = checkedList => {
+        setCheckList([...checkedList]);
+        setIndeterminate(!!checkedList.length && checkedList.length < options.length);
+        setCheckAll(checkedList.length === options.length)
     };
-    onCheckAllChange = e => {
-        this.setState({
-            checkedList: e.target.checked ? plainOptions : [],
-            indeterminate: false,
-            checkAll: e.target.checked,
-        });
+
+    const onCheckAllChange = e => {
+        setCheckList([...(e.target.checked ? options : [])]);
+        setIndeterminate(false);
+        setCheckAll(e.target.checked)
     };
 
-    render() {
-        return (
-            <div>
-                <div
-                    style={{
-                        borderBottom: '1px solid #E9E9E9',
-                    }}
+
+    return
+    return (
+        <div>
+            <div
+                style={{
+                    borderBottom: '1px solid #E9E9E9',
+                }}
+            >
+                <Checkbox
+                    indeterminate={indeterminate}
+                    onChange={onCheckAllChange}
+                    checked={state.checkAll}
                 >
-                    <Checkbox
-                        indeterminate={this.state.indeterminate}
-                        onChange={this.onCheckAllChange}
-                        checked={this.state.checkAll}
-                    >
-                        Check all
-                    </Checkbox>
-                </div>
-                <br />
-                <CheckboxGroup options={plainOptions} value={this.state.checkedList} onChange={this.onChange} />
+                    Check all
+                </Checkbox>
             </div>
-        );
-    }
+            <br/>
+            <CheckboxGroup options={options} value={checkedList} onChange={onCheckListChange}/>
+        </div>
+    );
 }
 
-stories.add('checkbox inderterminate联动', () => <IndeterminateDemo />);
+
+stories.add('checkbox inderterminate联动', () => <IndeterminateDemo/>);
 stories.add('checkbox render in div', () => (
     <>
         <div
@@ -420,10 +419,10 @@ const SwitchCheckedFromTrue2Undefined = () => {
     const change = () => {
         if (flag === 0) {
             setFlag(1);
-            setProps({ checked: true });
+            setProps({checked: true});
         } else {
             setFlag(0);
-            setProps({ checked: false });
+            setProps({checked: false});
         }
     };
 
@@ -433,10 +432,10 @@ const SwitchCheckedFromTrue2Undefined = () => {
     </>
 };
 
-stories.add('checkbox switch checked: true => undefined', () => <SwitchCheckedFromTrue2Undefined />);
+stories.add('checkbox switch checked: true => undefined', () => <SwitchCheckedFromTrue2Undefined/>);
 
 const TransformSelect = props => {
-    const { onChange, value, options = [], defaultValue = [], placeholder } = props;
+    const {onChange, value, options = [], defaultValue = [], placeholder} = props;
     const [currentValue, setCurrentValue] = useState([]);
     const [inputValue, setInputValue] = useState(''); // 变化
 
@@ -508,7 +507,7 @@ const TransformSelect = props => {
                                 <div key={option.key ? option.key : idx}>
                                     <span>{option.label}</span>
                                     <span onClick={() => removeValue(idx)}>
-                                        <IconClose size="small" />
+                                        <IconClose size="small"/>
                                     </span>
                                 </div>
                             );
@@ -522,52 +521,52 @@ const TransformSelect = props => {
     );
 };
 
-stories.add(`bugDemo`, () => <TransformSelect />);
+stories.add(`bugDemo`, () => <TransformSelect/>);
 
 stories.add(`checkboxGroup card style`, () => (
     <>
         <div>常见情况</div>
         <CheckboxGroup type='card' direction='horizontal' defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='1' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='2' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='3' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>radio disabled</div>
         <CheckboxGroup type='card' direction='horizontal' defaultValue={['1']}>
-            <Checkbox value='1' disabled extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='1' disabled extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='2' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='3' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>checkboxGroup disabled</div>
         <CheckboxGroup type='card' direction='horizontal' disabled defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='1' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='2' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='3' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>文字很长,并且没有设置宽度,因此换行显示</div>
         <CheckboxGroup type='card' direction='horizontal' defaultValue={['1']}>
             <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统'>
@@ -580,63 +579,63 @@ stories.add(`checkboxGroup card style`, () => (
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>设置了width=180</div>
         <CheckboxGroup type='card' direction='horizontal' defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 180 }}>
+            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 180}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 180 }}>
+            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 180}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 180 }}>
+            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 180}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>没有extra,width=180</div>
         <CheckboxGroup type='card' direction='horizontal' defaultValue={['1']}>
-            <Checkbox value='1' style={{ width: 180 }}>
+            <Checkbox value='1' style={{width: 180}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' style={{ width: 180 }}>
+            <Checkbox value='2' style={{width: 180}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' style={{ width: 180 }}>
+            <Checkbox value='3' style={{width: 180}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>没有标题,width=380</div>
         <CheckboxGroup type='card' direction='horizontal' defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
-        <hr />
+        <br/>
+        <br/>
+        <hr/>
         <div>下面是垂直的情况:</div>
         <div>常见情况</div>
         <CheckboxGroup direction='vertical' type='card' defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='1' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='2' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='3' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>没有设置宽度</div>
         <CheckboxGroup direction='vertical' type='card' defaultValue={['1']}>
             <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统'>
@@ -649,17 +648,17 @@ stories.add(`checkboxGroup card style`, () => (
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>设置了width=380</div>
         <CheckboxGroup direction='vertical' type='card' defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
@@ -670,46 +669,46 @@ stories.add(`checkboxGroup pureCard style`, () => (
     <>
         <div>常见情况</div>
         <CheckboxGroup type='pureCard' defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='1' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='2' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='3' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>radio disabled</div>
         <CheckboxGroup type='pureCard' defaultValue={['1']}>
-            <Checkbox value='1' disabled extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='1' disabled extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='2' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='3' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>checkboxGroup disabled</div>
         <CheckboxGroup type='pureCard' disabled defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='1' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='2' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='3' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>文字很长,并且没有设置宽度,因此换行显示</div>
         <CheckboxGroup type='pureCard' defaultValue={['1']}>
             <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统'>
@@ -722,63 +721,63 @@ stories.add(`checkboxGroup pureCard style`, () => (
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>设置了width=180</div>
         <CheckboxGroup type='pureCard' defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 180 }}>
+            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 180}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 180 }}>
+            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 180}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 180 }}>
+            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 180}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>没有extra,width=180</div>
         <CheckboxGroup type='pureCard' defaultValue={['1']}>
-            <Checkbox value='1' style={{ width: 180 }}>
+            <Checkbox value='1' style={{width: 180}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' style={{ width: 180 }}>
+            <Checkbox value='2' style={{width: 180}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' style={{ width: 180 }}>
+            <Checkbox value='3' style={{width: 180}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>没有标题,width=380</div>
         <CheckboxGroup type='pureCard' defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
-        <hr />
+        <br/>
+        <br/>
+        <hr/>
         <div>下面是垂直的情况:</div>
         <div>常见情况</div>
         <CheckboxGroup direction='vertical' type='pureCard' defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='1' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='2' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design' style={{ width: 280 }}>
+            <Checkbox value='3' extra='Semi Design' style={{width: 280}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>没有设置宽度</div>
         <CheckboxGroup direction='vertical' type='pureCard' defaultValue={['1']}>
             <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统'>
@@ -791,19 +790,19 @@ stories.add(`checkboxGroup pureCard style`, () => (
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
-        <br />
-        <br />
+        <br/>
+        <br/>
         <div>设置了width=380</div>
         <CheckboxGroup direction='vertical' type='pureCard' defaultValue={['1']}>
-            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='1' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='2' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
                 多选框标题
             </Checkbox>
-            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{ width: 380 }}>
+            <Checkbox value='3' extra='Semi Design 是由互娱社区前端团队与 UED 团队共同设计开发并维护的设计系统' style={{width: 380}}>
                 多选框标题
             </Checkbox>
         </CheckboxGroup>
     </>
-));
+));

+ 111 - 104
packages/semi-ui/table/__test__/table.test.js

@@ -1,23 +1,22 @@
 import BaseTable from '../Table';
 import Table from '../index';
 import Column from '../Column';
-import { Tooltip, Tag } from '../../index';
+import {Tag, Tooltip} from '../../index';
 import {
-    mount,
-    sleep,
-    getData,
-    getTreeData,
     getColumns,
+    getData,
+    getGroupColumns,
+    getGroupData,
     getJSXColumns,
-    getRandomNumber,
-    getJSXNestColumns,
     getNestColumns,
     getNestData,
-    getGroupColumns,
-    getGroupData,
+    getRandomNumber,
+    getTreeData,
+    mount,
+    sleep,
 } from '../../_test_/utils';
-import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants';
-import { IconStar } from '@douyinfe/semi-icons';
+import {BASE_CLASS_PREFIX} from '../../../semi-foundation/base/constants';
+import {IconStar} from '@douyinfe/semi-icons';
 
 /**
  * Table 需要测试的使用场景
@@ -45,7 +44,7 @@ const data = getData(dataTotalSize);
 const columns = getColumns();
 
 function testAppearance(demo, params) {
-    const { onRow, myCls, myClsIndex } = params; // check table wrapper
+    const {onRow, myCls, myClsIndex} = params; // check table wrapper
 
     expect(demo.find(`.${BASE_CLASS_PREFIX}-table-wrapper`).length).toBe(1); // check if has header
 
@@ -182,13 +181,13 @@ describe(`Table`, () => {
         const disabledKeys = ['4'];
         let rowSelection = {
             onChange: sinon.spy((selectedRowKeys, selectedRows) => {
-                rowSelection = { ...rowSelection, selectedRowKeys: [...selectedRowKeys] };
+                rowSelection = {...rowSelection, selectedRowKeys: [...selectedRowKeys]};
                 demo.setProps({
                     rowSelection,
                 });
             }),
             onSelectAll: sinon.spy((selected, selectedRows, changedRows) => {
-                rowSelection = { ...rowSelection, selectedRowKeys: selected ? [...selectedRowKeys] : [] };
+                rowSelection = {...rowSelection, selectedRowKeys: selected ? [...selectedRowKeys] : []};
                 demo.setProps({
                     rowSelection,
                 });
@@ -198,11 +197,12 @@ describe(`Table`, () => {
                 // Column configuration not to be checked
                 name: record.name,
             })),
-            onSelect: sinon.spy((record, selected) => {}),
+            onSelect: sinon.spy((record, selected) => {
+            }),
             selectedRowKeys: ['3'],
             defaultSelectedRowKeys: ['0', '1'],
         };
-        const demo = mount(<Table rowKey={rowKey} dataSource={data} columns={columns} rowSelection={rowSelection} />);
+        const demo = mount(<Table rowKey={rowKey} dataSource={data} columns={columns} rowSelection={rowSelection}/>);
         expect(demo.find(`.${BASE_CLASS_PREFIX}-checkbox`).length).toBeGreaterThan(0);
         expect(demo.find(`.${BASE_CLASS_PREFIX}-table-row .${BASE_CLASS_PREFIX}-checkbox-inner-checked`).length).toBe(
             rowSelection.selectedRowKeys.length
@@ -260,7 +260,7 @@ describe(`Table`, () => {
         const disabledKeys = ['4'];
         let rowSelection = {
             onSelectAll: sinon.spy((selected, selectedRows, changedRows) => {
-                rowSelection = { ...rowSelection, selectedRowKeys: selected ? [...selectedRowKeys] : [] };
+                rowSelection = {...rowSelection, selectedRowKeys: selected ? [...selectedRowKeys] : []};
                 demo.setProps({
                     rowSelection,
                 });
@@ -270,9 +270,10 @@ describe(`Table`, () => {
                 // Column configuration not to be checked
                 name: record.name,
             })),
-            onSelect: sinon.spy((record, selected) => {}),
+            onSelect: sinon.spy((record, selected) => {
+            }),
         };
-        const demo = mount(<Table rowKey={rowKey} dataSource={data} columns={columns} rowSelection={rowSelection} />);
+        const demo = mount(<Table rowKey={rowKey} dataSource={data} columns={columns} rowSelection={rowSelection}/>);
         const newData = getData(50);
         demo.setProps({
             dataSource: newData,
@@ -550,7 +551,7 @@ describe(`Table`, () => {
         ];
         let onChangeCalledCount = 0;
         const onChange = sinon.spy();
-        const demo = mount(<Table dataSource={data} columns={columns} onChange={onChange} />);
+        const demo = mount(<Table dataSource={data} columns={columns} onChange={onChange}/>);
         demo.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-filter`).simulate('click');
         expect(demo.find(`.${BASE_CLASS_PREFIX}-dropdown`).length).toBe(1);
         expect(onChange.callCount).toBe(onChangeCalledCount); // click first filter
@@ -620,7 +621,7 @@ describe(`Table`, () => {
                 dataIndex: 'address',
             },
         ];
-        const demo = mount(<Table dataSource={data} columns={columns} pagination={false} />);
+        const demo = mount(<Table dataSource={data} columns={columns} pagination={false}/>);
         demo.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-filter`).simulate('click'); // click first filter
 
         demo.find(`.${BASE_CLASS_PREFIX}-dropdown .${BASE_CLASS_PREFIX}-dropdown-item`)
@@ -692,7 +693,7 @@ describe(`Table`, () => {
                 width: 150,
             },
         ];
-        const onChange = sinon.spy(({ pagination: tablePagination, filters: tableFilters, sorters: tableSorters }) => {
+        const onChange = sinon.spy(({pagination: tablePagination, filters: tableFilters, sorters: tableSorters}) => {
             if (tablePagination && tablePagination.currentPage !== pagination.currentPage) {
                 pagination.currentPage = tablePagination.currentPage;
                 currentData = getPageData();
@@ -705,7 +706,7 @@ describe(`Table`, () => {
             }
         });
         const demo = mount(
-            <Table onChange={onChange} dataSource={currentData} pagination={pagination} columns={columns} />
+            <Table onChange={onChange} dataSource={currentData} pagination={pagination} columns={columns}/>
         );
         const table = demo.find(BaseTable);
         demo.find(`.${BASE_CLASS_PREFIX}-page .${BASE_CLASS_PREFIX}-page-item`)
@@ -770,7 +771,7 @@ describe(`Table`, () => {
         );
 
         const demo = mount(
-            <Table columns={columns} dataSource={data} resizable expandedRowRender={expandedRowRender} />
+            <Table columns={columns} dataSource={data} resizable expandedRowRender={expandedRowRender}/>
         );
         expect(demo.find(`.${BASE_CLASS_PREFIX}-table-thead .react-resizable-handle`).length).toBe(
             columns.reduce((count, col) => (typeof col.width === 'number' ? count + 1 : count), 0)
@@ -820,8 +821,8 @@ describe(`Table`, () => {
             },
         ];
         const targetData = sortData.reduce((a, b) => (a.name.length > b.name.length ? a : b));
-        const { name } = targetData;
-        const sortTable = mount(<Table columns={sortColumns} dataSource={sortData} />);
+        const {name} = targetData;
+        const sortTable = mount(<Table columns={sortColumns} dataSource={sortData}/>);
         const firstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0); // console.log(sortTable.debug({ ignoreProps: true }));
 
         expect(firstCell.text()).toBe(name);
@@ -870,8 +871,8 @@ describe(`Table`, () => {
             },
         ];
         const targetData = sortData.reduce((a, b) => (a.name.length < b.name.length ? a : b));
-        const { name } = targetData;
-        const sortTable = mount(<Table columns={sortColumns} dataSource={sortData} />);
+        const {name} = targetData;
+        const sortTable = mount(<Table columns={sortColumns} dataSource={sortData}/>);
         const firstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
         expect(firstCell.text()).toBe(name);
     });
@@ -919,8 +920,8 @@ describe(`Table`, () => {
             },
         ];
         const targetData = sortData.reduce((a, b) => (a.name.length > b.name.length ? a : b));
-        const { name } = targetData;
-        const sortTable = mount(<Table columns={sortColumns} dataSource={sortData} />);
+        const {name} = targetData;
+        const sortTable = mount(<Table columns={sortColumns} dataSource={sortData}/>);
         const firstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
         expect(firstCell.text()).toBe(name);
         const ascendOrderColumns = [
@@ -945,7 +946,7 @@ describe(`Table`, () => {
         });
         sortTable.update();
         const ascendTargetData = sortData.reduce((a, b) => (a.name.length < b.name.length ? a : b));
-        const { name: ascendTargetName } = ascendTargetData;
+        const {name: ascendTargetName} = ascendTargetData;
         const ascendFirstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
         expect(ascendFirstCell.text()).toBe(ascendTargetName); // test sortOrder: false, expect order as given data
 
@@ -970,7 +971,7 @@ describe(`Table`, () => {
         });
         sortTable.update();
         const defaultTargetData = sortData[0];
-        const { name: defaultTargetName } = defaultTargetData;
+        const {name: defaultTargetName} = defaultTargetData;
         const defaultFirstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
         expect(defaultFirstCell.text()).toBe(defaultTargetName);
     });
@@ -992,14 +993,15 @@ describe(`Table`, () => {
             },
         ];
         const rowSelection = {
-            onSelectAll: sinon.spy(() => {}),
+            onSelectAll: sinon.spy(() => {
+            }),
             getCheckboxProps: sinon.spy(record => ({
                 disabled: true,
                 // disabled all
                 name: record.name,
             })),
         };
-        const demo = mount(<Table columns={columns} dataSource={data} rowSelection={rowSelection} />);
+        const demo = mount(<Table columns={columns} dataSource={data} rowSelection={rowSelection}/>);
         demo.find(
             `.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-selection .${BASE_CLASS_PREFIX}-checkbox`
         ).simulate('click'); // should select 0 rows
@@ -1035,9 +1037,9 @@ describe(`Table`, () => {
         ];
         const demo = mount(
             <Table dataSource={[]}>
-                <Column title="Name" dataIndex="name" key="name" render={(text, record, index) => <a>{text}</a>} />
-                <Column title="Age" dataIndex="age" key="age" />
-                <Column title="Address" dataIndex="address" key="address" />
+                <Column title="Name" dataIndex="name" key="name" render={(text, record, index) => <a>{text}</a>}/>
+                <Column title="Age" dataIndex="age" key="age"/>
+                <Column title="Address" dataIndex="address" key="address"/>
             </Table>
         );
         setTimeout(() => {
@@ -1056,7 +1058,7 @@ describe(`Table`, () => {
             column.align = 'right';
             return column;
         });
-        const demo = mount(<Table dataSource={data} columns={alignRightColumns} />);
+        const demo = mount(<Table dataSource={data} columns={alignRightColumns}/>);
         const titleAlignCells = demo.find(`.${BASE_CLASS_PREFIX}-table-align-right`);
         expect(titleAlignCells.length).toBeGreaterThan(0);
         const bodyAlignCells = document.querySelectorAll(`.${BASE_CLASS_PREFIX}-table-row-cell`);
@@ -1070,7 +1072,7 @@ describe(`Table`, () => {
             column.className = 'test';
             return column;
         });
-        const demo = mount(<Table dataSource={data} columns={alignRightColumns} />);
+        const demo = mount(<Table dataSource={data} columns={alignRightColumns}/>);
         const titleAlignCells = demo.find(`.${BASE_CLASS_PREFIX}-table-row-head`);
         const bodyAlignCells = demo.find(`.${BASE_CLASS_PREFIX}-table-row-cell`);
         titleAlignCells.forEach(cell => {
@@ -1123,7 +1125,7 @@ describe(`Table`, () => {
                 }}
             />
         );
-        const { dataSource } = refObj.current.getCurrentPageData();
+        const {dataSource} = refObj.current.getCurrentPageData();
         expect(dataSource.length).toEqual(pageSize); // jsx column
 
         const jsxColumns = getJSXColumns();
@@ -1141,7 +1143,7 @@ describe(`Table`, () => {
                 {jsxColumns}
             </Table>
         );
-        const { dataSource: jsxData } = jsxRefObj.current.getCurrentPageData();
+        const {dataSource: jsxData} = jsxRefObj.current.getCurrentPageData();
         expect(jsxData.length).toEqual(pageSize);
     });
     it('test render expandIcon', async () => {
@@ -1153,7 +1155,7 @@ describe(`Table`, () => {
                 dataSource={data}
                 columns={columns}
                 expandedRowRender={expandedRowRender}
-                expandIcon={<IconStar size="small" />}
+                expandIcon={<IconStar size="small"/>}
             />
         );
         expect(demo.find('.semi-icon-star').length).toBeGreaterThan(0);
@@ -1163,16 +1165,20 @@ describe(`Table`, () => {
                 columns={columns}
                 expandedRowRender={expandedRowRender}
                 defaultExpandAllRows
-                expandIcon={expanded => <div>{expanded && <IconStar size="small" />}</div>}
+                expandIcon={expanded => <div>{expanded && <IconStar size="small"/>}</div>}
             />
         );
         expect(demo2.find('.semi-icon-star').length).toBeGreaterThan(0);
     });
     it(`test onRow/onCell`, async () => {
-        const onRowClick = sinon.spy(() => {});
-        const onHeaderRowClick = sinon.spy(() => {});
-        const onCellClick = sinon.spy(() => {});
-        const onHeaderCellClick = sinon.spy(() => {});
+        const onRowClick = sinon.spy(() => {
+        });
+        const onHeaderRowClick = sinon.spy(() => {
+        });
+        const onCellClick = sinon.spy(() => {
+        });
+        const onHeaderCellClick = sinon.spy(() => {
+        });
         const onRow = sinon.spy((record, index) => ({
             className: 'test-row',
             onClick: onRowClick,
@@ -1186,9 +1192,9 @@ describe(`Table`, () => {
             const style =
                 index === 0
                     ? {
-                          width: 200,
-                          height: 60,
-                      }
+                        width: 200,
+                        height: 60,
+                    }
                     : {};
 
             column.onCell = () => ({
@@ -1204,7 +1210,7 @@ describe(`Table`, () => {
 
             return column;
         });
-        const demo = mount(<Table dataSource={data} onRow={onRow} onHeaderRow={onHeaderRow} columns={onCellColumns} />);
+        const demo = mount(<Table dataSource={data} onRow={onRow} onHeaderRow={onHeaderRow} columns={onCellColumns}/>);
         const tableCells = demo.find('.semi-table-body .semi-table-row-cell');
         const tableHeaderCells = demo.find('.semi-table-thead .semi-table-row-head'); // cell style
 
@@ -1273,20 +1279,20 @@ describe(`Table`, () => {
                     />
                 </Column>
                 <Column title={'Company Information'} dataIndex={'company'}>
-                    <Column title={'Company Name'} dataIndex={'company.name'} />
-                    <Column title={'Company Address'} dataIndex={'company.address'} />
+                    <Column title={'Company Name'} dataIndex={'company.name'}/>
+                    <Column title={'Company Address'} dataIndex={'company.address'}/>
                 </Column>
-                <Column title={'Address'} dataIndex={'address'} width={250} fixed="right" />
+                <Column title={'Address'} dataIndex={'address'} width={250} fixed="right"/>
             </Table>
         );
         const columns = getNestColumns();
-        const demo = mount(<Table dataSource={nestData} columns={columns} />);
+        const demo = mount(<Table dataSource={nestData} columns={columns}/>);
         testHeaderMerge(jsxDemo);
         testHeaderMerge(demo);
     });
     it('test without columns', async () => {
         const jsxDemo = mount(<Table dataSource={data}></Table>);
-        const demo = mount(<Table dataSource={data} columns={[]} />);
+        const demo = mount(<Table dataSource={data} columns={[]}/>);
         expect(jsxDemo.find('.semi-table-row-head').length).toBe(0);
         expect(jsxDemo.find('.semi-table-row-cell').length).toBe(0);
         expect(demo.find('.semi-table-row-head').length).toBe(0);
@@ -1312,7 +1318,7 @@ describe(`Table`, () => {
                 // 此处将useFullRender设置为true开启完全自定义渲染
                 useFullRender: true,
                 // 此处从render的第四个形参中解构出 展开按钮、选择按钮、文本等内容
-                render: (text, record, index, { expandIcon, selection, indentText }) => {
+                render: (text, record, index, {expandIcon, selection, indentText}) => {
                     return (
                         <span
                             className="custom-render"
@@ -1335,7 +1341,7 @@ describe(`Table`, () => {
                         </span>
                     );
                 },
-                title: ({ sorter, filter, selection }) => (
+                title: ({sorter, filter, selection}) => (
                     <span
                         className="custom-title"
                         style={{
@@ -1457,7 +1463,7 @@ describe(`Table`, () => {
             currentPage: 1,
         };
         const columns = getColumns();
-        const demo = mount(<Table dataSource={getData(total)} columns={columns} pagination={pagination} />);
+        const demo = mount(<Table dataSource={getData(total)} columns={columns} pagination={pagination}/>);
         const paginationProps = demo.find(BaseTable).state('pagination');
         expect(paginationProps.total).toEqual(total);
         expect(paginationProps.pageSize).toEqual(pagination.pageSize);
@@ -1549,7 +1555,7 @@ describe(`Table`, () => {
     it(`test given object columns and children`, async () => {
         const demo = mount(
             <Table dataSource={data} columns={columns}>
-                <Table.Column title="Age" dataIndex="age" key="age" />
+                <Table.Column title="Age" dataIndex="age" key="age"/>
             </Table>
         );
         const test = demo.find(BaseTable); // 同时传columns与children时,columns优先
@@ -1585,46 +1591,46 @@ describe(`Table`, () => {
         const data = [
             {
                 key: '1',
-                name: 'John Brown',
-                age: 32,
-                tel: '0571-22098909',
-                phone: 18889898989,
-                address: 'New York No. 1 Lake Park',
+                name: 'ZhangSan',
+                age: 50,
+                tel: '010-20000000',
+                phone: 10010,
+                address: 'BeiJing No.1 High School',
             },
             {
                 key: '2',
-                name: 'Jim Green',
-                tel: '0571-22098333',
-                phone: 18889898888,
-                age: 42,
-                address: 'London No. 1 Lake Park',
+                name: 'LiSi',
+                tel: '010-30000000',
+                phone: 10086,
+                age: 40,
+                address: 'ShangHai No. 1 High School',
             },
             {
                 key: '3',
-                name: 'Joe Black',
-                age: 32,
-                tel: '0575-22098909',
-                phone: 18900010002,
-                address: 'Sidney No. 1 Lake Park',
+                name: 'WangWu',
+                age: 60,
+                tel: '010-40000000',
+                phone: 10011,
+                address: 'NaiJing No.1 High School',
             },
             {
                 key: '4',
-                name: 'Jim Red',
-                age: 18,
-                tel: '0575-22098909',
-                phone: 18900010002,
-                address: 'London No. 2 Lake Park',
+                name: 'XiaoMing',
+                age: 20,
+                tel: '010-50000000',
+                phone: 12580,
+                address: 'ShiJiaZhuang No.1 High School',
             },
             {
                 key: '5',
-                name: 'Jake White',
-                age: 18,
-                tel: '0575-22098909',
-                phone: 18900010002,
-                address: 'Dublin No. 2 Lake Park',
+                name: 'XiaoHong',
+                age: 40,
+                tel: '010-60000000',
+                phone: 12530,
+                address: 'TaiBei No.2 High School',
             },
         ];
-        const demo = mount(<Table dataSource={data} columns={columns} />);
+        const demo = mount(<Table dataSource={data} columns={columns}/>);
         expect(demo.find('.semi-table-row .semi-table-row-head').length).toBe(columns.length - 1);
     });
 
@@ -1642,12 +1648,12 @@ describe(`Table`, () => {
         />);
 
         const newData = getData(20);
-        demo.setProps({ dataSource: newData });
+        demo.setProps({dataSource: newData});
         demo.update();
         const expandedRows = demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row-expanded`)
         expect(expandedRows.length).toEqual(newData.length);
         // 动态切换 expandAllRows
-        demo.setProps({ expandAllRows: false });
+        demo.setProps({expandAllRows: false});
         demo.update();
         const newExpandedRows = demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row-expanded`)
         expect(newExpandedRows.length).toEqual(0);
@@ -1656,7 +1662,7 @@ describe(`Table`, () => {
     it(`test defaultExpandAllGroupRows`, async () => {
         const data = getGroupData();
         const columns = getGroupColumns();
-        const rowKey = record =>`${record.city && record.city.toLowerCase()}-${record.job && record.job.toLowerCase()}`;
+        const rowKey = record => `${record.city && record.city.toLowerCase()}-${record.job && record.job.toLowerCase()}`;
         const groupSize = new Set(data.map(item => item.city)).size;
 
         const demo = mount(
@@ -1666,7 +1672,7 @@ describe(`Table`, () => {
                 groupBy={'city'}
                 columns={columns}
                 renderGroupSection={groupKey => <strong>Jobs in {groupKey}:</strong>}
-                scroll={{ y: 480 }}
+                scroll={{y: 480}}
                 defaultExpandAllGroupRows
             />
         );
@@ -1678,7 +1684,7 @@ describe(`Table`, () => {
         const data = getGroupData();
         const groupSize = new Set(data.map(item => item.city)).size;
         const columns = getGroupColumns();
-        const rowKey = record =>`${record.city && record.city.toLowerCase()}-${record.job && record.job.toLowerCase()}`;
+        const rowKey = record => `${record.city && record.city.toLowerCase()}-${record.job && record.job.toLowerCase()}`;
 
         const demo = mount(
             <Table
@@ -1687,15 +1693,15 @@ describe(`Table`, () => {
                 groupBy={'city'}
                 columns={columns}
                 renderGroupSection={groupKey => <strong>Jobs in {groupKey}:</strong>}
-                scroll={{ y: 480 }}
+                scroll={{y: 480}}
                 expandAllGroupRows={true}
             />
         );
 
-        demo.setProps({ dataSource: data });
+        demo.setProps({dataSource: data});
         demo.update();
         expect(demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row-section.on`).length).toBe(groupSize);
-        demo.setProps({ expandAllGroupRows: false });
+        demo.setProps({expandAllGroupRows: false});
         demo.update();
         expect(demo.find(`.${BASE_CLASS_PREFIX}-table-tbody .${BASE_CLASS_PREFIX}-table-row-section.on`).length).toBe(0);
     });
@@ -1743,12 +1749,13 @@ describe(`Table`, () => {
                 address: 'London No. 2 Lake Park',
             },
         ];
-        const onChange = sinon.spy(() => {});
+        const onChange = sinon.spy(() => {
+        });
 
         // test default descend
         const targetData = sortData.reduce((a, b) => a.name.length > b.name.length ? a : b);
-        const { name } = targetData;
-        const sortTable = mount(<Table columns={sortColumns} dataSource={sortData} onChange={onChange} />);
+        const {name} = targetData;
+        const sortTable = mount(<Table columns={sortColumns} dataSource={sortData} onChange={onChange}/>);
         const firstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
         expect(firstCell.text()).toBe(name);
 
@@ -1769,10 +1776,10 @@ describe(`Table`, () => {
                 dataIndex: 'address',
             }
         ];
-        sortTable.setProps({ columns: ascendOrderColumns })
+        sortTable.setProps({columns: ascendOrderColumns})
         sortTable.update()
         const ascendTargetData = sortData.reduce((a, b) => a.name.length < b.name.length ? a : b);
-        const { name: ascendTargetName } = ascendTargetData;
+        const {name: ascendTargetName} = ascendTargetData;
         const ascendFirstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
         expect(ascendFirstCell.text()).toBe(ascendTargetName);
 
@@ -1796,15 +1803,15 @@ describe(`Table`, () => {
         sortTable.setProps({columns: defaultOrderColumns})
         sortTable.update()
         const defaultTargetData = sortData[0]
-        const { name: defaultTargetName } = defaultTargetData;
+        const {name: defaultTargetName} = defaultTargetData;
         const defaultFirstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
         expect(defaultFirstCell.text()).toBe(defaultTargetName);
 
         // test click sorter
-        sortTable.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-sorter`).at(0).simulate('click', { nativeEvent: null });
+        sortTable.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-sorter`).at(0).simulate('click', {nativeEvent: null});
         expect(onChange.callCount).toBe(1);
         expect(onChange.getCall(0).args[0].sorter.sortOrder).toBe('ascend');
-        sortTable.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-sorter`).at(0).simulate('click', { nativeEvent: null });
+        sortTable.find(`.${BASE_CLASS_PREFIX}-table-thead .${BASE_CLASS_PREFIX}-table-column-sorter`).at(0).simulate('click', {nativeEvent: null});
         expect(onChange.callCount).toBe(2);
         expect(onChange.getCall(1).args[0].sorter.sortOrder).toBe('descend');
 
@@ -1835,10 +1842,10 @@ describe(`Table`, () => {
                 address: 'London No. 2 Lake Park',
             },
         ];
-        sortTable.setProps({ dataSource: newData });
+        sortTable.setProps({dataSource: newData});
         sortTable.update()
         const newDescendTargetData = newData.reduce((a, b) => a.name.length > b.name.length ? a : b);
-        const { name: newDescendTargetName  } = newDescendTargetData;
+        const {name: newDescendTargetName} = newDescendTargetData;
         const newDataFirstCell = sortTable.find('.semi-table-tbody .semi-table-row .semi-table-row-cell').at(0);
         expect(newDataFirstCell.text()).toBe(newDescendTargetName);
     });

+ 37 - 37
packages/semi-ui/table/_story/ChildrenData/index.js

@@ -1,6 +1,6 @@
-import React, { useState, useMemo } from 'react';
-import { Table, Button } from '@douyinfe/semi-ui/';
-import {IconArrowUp, IconArrowDown} from '@douyinfe/semi-icons';
+import React, {useState} from 'react';
+import {Button, Table} from '@douyinfe/semi-ui/';
+import {IconArrowDown, IconArrowUp} from '@douyinfe/semi-icons';
 
 /**
  * Aligned to Ant Design APIs for migration, see [antd-demo](https://codesandbox.io/s/great-mcclintock-14fl7).
@@ -12,53 +12,53 @@ const Demo = () => {
     const [data, setData] = useState([
         {
             key: 1,
-            name: 'John Brown sr.',
-            age: 60,
-            address: 'New York No. 1 Lake Park',
+            name: 'ZhangSan',
+            age: 30,
+            address: 'bytedance 1',
             children: [
                 {
                     key: 11,
-                    name: 'John Brown',
-                    age: 42,
-                    address: 'New York No. 2 Lake Park',
+                    name: 'LiSi',
+                    age: 40,
+                    address: 'bytedance 2',
                 },
                 {
                     key: 12,
-                    name: 'John Brown jr.',
+                    name: 'WangWu',
                     age: 30,
-                    address: 'New York No. 3 Lake Park',
+                    address: 'bytedance 2',
                     children: [
                         {
                             key: 121,
-                            name: 'Jimmy Brown',
-                            age: 16,
-                            address: 'New York No. 3 Lake Park',
+                            name: 'XiaoMing',
+                            age: 50,
+                            address: 'bytedance 3',
                         },
                     ],
                 },
                 {
                     key: 13,
-                    name: 'Jim Green sr.',
-                    age: 72,
-                    address: 'London No. 1 Lake Park',
+                    name: 'XiaoZhang',
+                    age: 60,
+                    address: 'bytedance 4',
                     children: [
                         {
                             key: 131,
-                            name: 'Jim Green',
-                            age: 42,
-                            address: 'London No. 2 Lake Park',
+                            name: 'XiaoLi',
+                            age: 50,
+                            address: 'bytedance 5',
                             children: [
                                 {
                                     key: 1311,
-                                    name: 'Jim Green jr.',
-                                    age: 25,
-                                    address: 'London No. 3 Lake Park',
+                                    name: 'XiaoGuo',
+                                    age: 40,
+                                    address: 'bytedance 6',
                                 },
                                 {
                                     key: 1312,
-                                    name: 'Jimmy Green sr.',
-                                    age: 18,
-                                    address: 'London No. 4 Lake Park',
+                                    name: 'XiaoHong',
+                                    age: 30,
+                                    address: 'bytedance 7',
                                 },
                             ],
                         },
@@ -68,9 +68,9 @@ const Demo = () => {
         },
         {
             key: 2,
-            name: 'Joe Black',
-            age: 32,
-            address: 'Sidney No. 1 Lake Park',
+            name: 'XiaoGang',
+            age: 80,
+            address: 'bytedance 8',
         },
     ]);
 
@@ -82,8 +82,8 @@ const Demo = () => {
             const item2 = findRecordByKey(key2, newData);
 
             // you have to copy item1 and item2 first
-            const copiedItem1 = { ...item1 };
-            const copiedItem2 = { ...item2 };
+            const copiedItem1 = {...item1};
+            const copiedItem2 = {...item2};
 
             coverRecord(item1, copiedItem2);
             coverRecord(item2, copiedItem1);
@@ -114,7 +114,7 @@ const Demo = () => {
     const coverRecord = (obj, srcObj) => {
         if (obj && typeof obj === 'object' && srcObj && typeof srcObj === 'object') {
             const srcKeys = Object.keys(srcObj);
-            const copied = { ...srcObj };
+            const copied = {...srcObj};
 
             Object.assign(obj, copied);
 
@@ -159,9 +159,9 @@ const Demo = () => {
             width: 150,
             filterChildrenRecord: true,
             filters: [
-                { text: 'age < 30', value: 30 },
-                { text: 'age < 20', value: 20 },
-                { text: 'age < 10', value: 10 },
+                {text: 'age < 30', value: 30},
+                {text: 'age < 20', value: 20},
+                {text: 'age < 10', value: 10},
             ],
             onFilter: (filteredValue, record) => {
                 // console.log(`filteredValue: `, filteredValue, ` record: `, record);
@@ -202,8 +202,8 @@ const Demo = () => {
 
                 return (
                     <>
-                        <Button icon={<IconArrowUp />} {...upProps} />
-                        <Button icon={<IconArrowDown />} {...downProps} />
+                        <Button icon={<IconArrowUp/>} {...upProps} />
+                        <Button icon={<IconArrowDown/>} {...downProps} />
                     </>
                 );
             },

+ 30 - 50
packages/semi-ui/table/_story/ChildrenDataInnerSelected/index.js

@@ -1,5 +1,5 @@
-import { Table, Checkbox } from '@douyinfe/semi-ui';
-import React, { useMemo, useState, useCallback } from 'react';
+import {Checkbox, Table} from '@douyinfe/semi-ui';
+import React, {useCallback, useMemo, useState} from 'react';
 import * as _ from 'lodash-es';
 
 const getKey = (record, rowKey) => (typeof rowKey === 'function' ? rowKey(rowKey) : _.get(record, rowKey));
@@ -45,73 +45,53 @@ function ChildrenDataSelectedDemo(props = {}) {
         () => [
             {
                 key: 1,
-                name: 'John Brown sr.',
-                age: 60,
-                address: 'New York No. 1 Lake Park',
+                name: 'ZhangSan',
+                age: 30,
+                address: 'bytedance 1',
                 children: [
                     {
                         key: 11,
-                        name: 'John Brown',
-                        age: 42,
-                        address: 'New York No. 2 Lake Park',
+                        name: 'LiSi',
+                        age: 40,
+                        address: 'bytedance 2',
                     },
                     {
                         key: 12,
-                        name: 'John Brown jr.',
+                        name: 'WangWu',
                         age: 30,
-                        address: 'New York No. 3 Lake Park',
+                        address: 'bytedance 2',
                         children: [
                             {
                                 key: 121,
-                                name: 'Jimmy Brown',
-                                age: 16,
-                                address: 'New York No. 3 Lake Park',
+                                name: 'XiaoMing',
+                                age: 50,
+                                address: 'bytedance 3',
                             },
                         ],
                     },
                     {
                         key: 13,
-                        name: 'Jim Green sr.',
-                        age: 72,
-                        address: 'London No. 1 Lake Park',
+                        name: 'XiaoZhang',
+                        age: 60,
+                        address: 'bytedance 4',
                         children: [
                             {
                                 key: 131,
-                                name: 'Jim Green',
-                                age: 42,
-                                address: 'London No. 2 Lake Park',
+                                name: 'XiaoLi',
+                                age: 50,
+                                address: 'bytedance 5',
                                 children: [
                                     {
                                         key: 1311,
-                                        name: 'Jim Green jr.',
-                                        age: 25,
-                                        address: 'London No. 3 Lake Park',
+                                        name: 'XiaoGuo',
+                                        age: 40,
+                                        address: 'bytedance 6',
                                     },
                                     {
                                         key: 1312,
-                                        name: 'Jimmy Green sr.',
-                                        age: 18,
-                                        address: 'London No. 4 Lake Park',
-                                    },
-                                ],
-                            },
-                            {
-                                key: 132,
-                                name: 'Jack Green',
-                                age: 48,
-                                address: 'London No. 3 Lake Park',
-                                children: [
-                                    {
-                                        key: 1321,
-                                        name: 'Jack Green jr.',
-                                        age: 35,
-                                        address: 'London No. 31 Lake Park',
-                                    },
-                                    {
-                                        key: 1322,
-                                        name: 'Jack Green sr.',
-                                        age: 28,
-                                        address: 'London No. 41 Lake Park',
+                                        name: 'XiaoHong',
+                                        age: 30,
+                                        address: 'bytedance 7',
                                     },
                                 ],
                             },
@@ -121,9 +101,9 @@ function ChildrenDataSelectedDemo(props = {}) {
             },
             {
                 key: 2,
-                name: 'Joe Black',
-                age: 32,
-                address: 'Sidney No. 1 Lake Park',
+                name: 'XiaoGang',
+                age: 80,
+                address: 'bytedance 8',
             },
         ],
         []
@@ -200,12 +180,12 @@ function ChildrenDataSelectedDemo(props = {}) {
                 key: 'name',
                 width: 300,
                 render: (text, record) => (
-                    <span style={{ display: 'inline-flex', alignItems: 'center' }}>
+                    <span style={{display: 'inline-flex', alignItems: 'center'}}>
                         {_.size(_.get(record, childrenRecordName)) ? (
                             <Checkbox
                                 checked={selectedRowKeys.includes(_.get(record, rowKey))}
                                 onChange={e => doSelect(record, e.target.checked)}
-                                style={{ display: 'inline-flex', marginRight: 5 }}
+                                style={{display: 'inline-flex', marginRight: 5}}
                             />
                         ) : null}
                         {text}

+ 125 - 127
packages/semi-ui/table/_story/table.stories.js

@@ -1,8 +1,7 @@
 import React from 'react';
-import { storiesOf } from '@storybook/react';
+import {storiesOf} from '@storybook/react';
 // import { withKnobs, text, boolean } from '@storybook/addon-knobs';
-
-import { Table, Tooltip, Tag } from '@douyinfe/semi-ui';
+import {Table} from '@douyinfe/semi-ui';
 
 import JSXColumnsSimple from './JSXColumnsSmiple';
 import JSXColumnsComplex from './JSXColumnsComplex';
@@ -52,17 +51,17 @@ import MassiveColumns from './MassiveColumns';
 import ControlledPagination from './ControlledPagination';
 import FulldRenderDemo from './FullRender';
 import VirtualTableOnCell from './VirtualTableOnCell';
-import { 
-        PerfVirtualized,
-        PerfRender,
-        PerfContext,
-        ControlledSelection,
-        PerfComplexRender,
-        PerfResizableSelection,
-        PerfOnRow
-    } from './Perf';
+import {
+    ControlledSelection,
+    PerfComplexRender,
+    PerfContext,
+    PerfOnRow,
+    PerfRender,
+    PerfResizableSelection,
+    PerfVirtualized
+} from './Perf';
 import RenderPagination from './RenderPagination'
-import { RTLAlignScrollBar } from './RTL';
+import {RTLAlignScrollBar} from './RTL';
 import JSXAsyncData from './JSXAsyncData';
 import ScrollBar from './ScrollBar';
 import TableSpan from './TableSpan';
@@ -96,7 +95,7 @@ const emptyColumn = [
 ];
 const emptyData = [];
 
-stories.add('empty table', () => <Table autoWidth columns={emptyColumn} dataSource={emptyData} />);
+stories.add('empty table', () => <Table autoWidth columns={emptyColumn} dataSource={emptyData}/>);
 
 // basic table
 
@@ -176,11 +175,11 @@ const data = [
     },
 ];
 
-stories.add('basic table', () => <Table columns={columns} dataSource={data} />);
+stories.add('basic table', () => <Table columns={columns} dataSource={data}/>);
 
-stories.add('simple jsx', () => <JSXColumnsSimple />);
+stories.add('simple jsx', () => <JSXColumnsSimple/>);
 
-stories.add('complex jsx', () => <JSXColumnsComplex />);
+stories.add('complex jsx', () => <JSXColumnsComplex/>);
 
 // selection table
 
@@ -194,8 +193,8 @@ const rowSelection = {
         name: record.name,
     }),
 };
-stories.add('filter and update dataSource', () => <FilterWithNewDataTable />);
-stories.add('selection table', () => <Table rowSelection={rowSelection} columns={columns} dataSource={data} />);
+stories.add('filter and update dataSource', () => <FilterWithNewDataTable/>);
+stories.add('selection table', () => <Table rowSelection={rowSelection} columns={columns} dataSource={data}/>);
 
 function ControlledSelectionTable() {
     const [selected, setSelected] = React.useState([]);
@@ -252,9 +251,10 @@ function ControlledSelectionTable() {
         }),
         selectedRowKeys: selected
     };
-    return <Table columns={columns} dataSource={data} rowSelection={rowSelection} pagination={false} />;
+    return <Table columns={columns} dataSource={data} rowSelection={rowSelection} pagination={false}/>;
 }
-stories.add('controlled selection table', () => <ControlledSelectionTable />);
+
+stories.add('controlled selection table', () => <ControlledSelectionTable/>);
 // sortable table
 
 const sortColumns = [
@@ -263,30 +263,28 @@ const sortColumns = [
         dataIndex: 'name',
         filters: [
             {
-                text: 'Joe',
-                value: 'Joe',
+                text: 'XiaoMing',
+                value: 'XiaoMing',
             },
             {
-                text: 'Jim',
-                value: 'Jim',
+                text: 'ZhangSan',
+                value: 'ZhangSan',
             },
             {
-                text: 'Submenu',
-                value: 'Submenu',
+                text: 'SubMenu',
+                value: 'SubMenu',
                 children: [
                     {
-                        text: 'Green',
-                        value: 'Green',
+                        text: 'Yellow',
+                        value: 'Yellow',
                     },
                     {
-                        text: 'Black',
-                        value: 'Black',
+                        text: 'Pink',
+                        value: 'Pink',
                     },
                 ],
             },
         ],
-        // specify the condition of filtering result
-        // here is that finding the name started with `value`
         onFilter: (value, record) => record.name.indexOf(value) === 0,
         sorter: (a, b) => a.name.length - b.name.length,
         sortDirections: ['descend'],
@@ -303,12 +301,12 @@ const sortColumns = [
         dataIndex: 'address',
         filters: [
             {
-                text: 'London',
-                value: 'London',
+                text: 'BieJing',
+                value: 'BeiJing',
             },
             {
-                text: 'New York',
-                value: 'New York',
+                text: 'ShangHai',
+                value: 'SHangHai',
             },
         ],
         filterMultiple: false,
@@ -321,116 +319,116 @@ const sortColumns = [
 const sortData = [
     {
         key: '1',
-        name: 'John Brown',
-        age: 32,
-        address: 'New York No. 1 Lake Park',
+        name: 'ZhangSan',
+        age: 50,
+        address: 'BeiJing No.1 High School',
     },
     {
         key: '2',
-        name: 'Jim Green',
-        age: 42,
-        address: 'London No. 1 Lake Park',
+        name: 'LiSi',
+        age: 60,
+        address: 'BeiJing No.2 High School',
     },
     {
         key: '3',
-        name: 'Joe Black',
-        age: 32,
-        address: 'Sidney No. 1 Lake Park',
+        name: 'WangWu',
+        age: 20,
+        address: 'BeiJing No.3 High School',
     },
     {
         key: '4',
-        name: 'Jim Red',
-        age: 32,
-        address: 'London No. 2 Lake Park',
+        name: 'XiaoMing',
+        age: 30,
+        address: 'BeiJing No.5 High School',
     },
 ];
 
-stories.add('sort table', () => <Table columns={sortColumns} dataSource={sortData} />);
-stories.add('controlled sortOrder table', () => <ControlledSortOrder />);
+stories.add('sort table', () => <Table columns={sortColumns} dataSource={sortData}/>);
+stories.add('controlled sortOrder table', () => <ControlledSortOrder/>);
 
-stories.add('middle table', () => <Table columns={columns} dataSource={data} size="middle" />);
+stories.add('middle table', () => <Table columns={columns} dataSource={data} size="middle"/>);
 
-stories.add('small table', () => <Table columns={columns} dataSource={data} size="small" />);
+stories.add('small table', () => <Table columns={columns} dataSource={data} size="small"/>);
 
-stories.add('expand table', () => <ExpandDemo />);
+stories.add('expand table', () => <ExpandDemo/>);
 
-stories.add('resizable columns', () => <ResizableColumns />);
+stories.add('resizable columns', () => <ResizableColumns/>);
 
-stories.add('dragable table', () => <DragableTableDemo />);
-stories.add('fixed table', () => <FixedTable />);
-stories.add('fixed jsx table', () => <JSXFixedTable />);
-stories.add(`fixed expanded rows`, () => <FixedExpandedRows />);
+stories.add('dragable table', () => <DragableTableDemo/>);
+stories.add('fixed table', () => <FixedTable/>);
+stories.add('fixed jsx table', () => <JSXFixedTable/>);
+stories.add(`fixed expanded rows`, () => <FixedExpandedRows/>);
 
-stories.add(`jsx titles`, () => <JSXTitles />);
+stories.add(`jsx titles`, () => <JSXTitles/>);
 
 stories.add('dynamic table', () => (
-    <div style={{ padding: 20 }}>
-        <DynamicTableDemo />
+    <div style={{padding: 20}}>
+        <DynamicTableDemo/>
     </div>
 ));
 
-stories.add('linked scroll', () => <LinkedScroll />);
-
-stories.add('modal table', () => <ModalTable />);
-
-stories.add('tabs table', () => <TabsTable />);
-
-stories.add('event table', () => <EventTable />);
-
-stories.add('fn table', () => <FnTable />);
-
-stories.add('dynamic filters', () => <DynamicFilters />);
-
-stories.add('resizable table', () => <ResizableTable />);
-
-stories.add('with pagination', () => <PaginationDemo />);
-stories.add(`controlled pagination`, () => <ControlledPagination />);
-
-stories.add('selected rows', () => <SelectedRowsDemo />);
-
-stories.add('children data', () => <ChildrenData />);
-
-stories.add('children data selected rows', () => <ChildrenDataSelected />);
-stories.add(`with side sheet`, () => <WithSideSheet />);
-stories.add(`in side sheet`, () => <InSideSheet />);
-stories.add(`grouped rows`, () => <GroupedRows />);
-stories.add(`grouped rows fixed`, () => <GroupedRowsFixed />);
-stories.add(`grouped cols`, () => <GroupedCols />);
-stories.add(`grouped cols fixed`, () => <GroupedColsFixed />);
-stories.add(`grouped cols fixed jsx`, () => <GroupedColsFixedJSX />);
-
-stories.add(`grouped cols fixed virtualized`, () => <GroupedColsFixedVirtualized />);
-stories.add(`grouped cols fixed virtualized groups`, () => <GroupedColsFixedVirtualizedGroups />);
-
-stories.add(`fixed groups`, () => <FixedGroups />);
-stories.add(`custom components`, () => <CustomComponents />);
-stories.add(`custom expand icons`, () => <CustomExpandIcons />);
-stories.add(`custom filter dropdown item`, () => <CustomFilterDropdownItem />);
-stories.add(`virtualized`, () => <VirtualizedDemo />);
-stories.add(`virtualized fixed`, () => <VirtualizedFixedDemo />);
-stories.add(`virtualized not fixed`, () => <VirtualizedNotFixedDemo />);
-stories.add(`virtualized data selected`, () => <VirtualizedDataSelected />);
-stories.add(`virtualized grouped rows`, () => <VirtualizedGroupedRows />);
-stories.add(`virtualized dynamic data`, () => <VirtualizedDynamicData />);
-stories.add(`infinite scroll`, () => <InfiniteScroll />);
-stories.add(`massive columns`, () => <MassiveColumns />);
-stories.add(`full render`, () => <FulldRenderDemo />);
-stories.add(`VirtualTableOnCell`, () => <VirtualTableOnCell />);
-stories.add(`Perf Virtualized`, () => <PerfVirtualized />);
-stories.add(`Perf Render`, () => <PerfRender />);
-stories.add(`Perf Complex Render`, () => <PerfComplexRender />);
-stories.add(`Perf Controlled Selection`, () => <ControlledSelection />);
-stories.add(`Perf Context`, () => <PerfContext />);
-stories.add(`Perf Resizable Selection`, () => <PerfResizableSelection />);
-stories.add(`Perf Render Row Times`, () => <PerfOnRow />);
-stories.add(`renderPagination`, () => <RenderPagination />);
-stories.add(`RTL align scroll bar`, () => <RTLAlignScrollBar />);
-stories.add(`JSX aysnc data`, () => <JSXAsyncData />);
-stories.add(`JSX column and prop clumns`, () => <JSXColumnPropColumn />);
-stories.add(`scroll bar`, () => <ScrollBar />);
-stories.add(`fix table rowSpan/colSpan`, () => <TableSpan />);
-stories.add(`fix column render return props #1373`, () => <FixRenderReturnProps />);
-stories.add('expandAllRows', () => <ExpandAllRows />);
-stories.add('expandAllGroupRows', () => <ExpandAllGroupRows />);
-stories.add('expandRowByClick', () => <ExpandRowByClick />);
-stories.add('rowSelection boolean', () => <Table columns={columns} dataSource={data} rowSelection />);
+stories.add('linked scroll', () => <LinkedScroll/>);
+
+stories.add('modal table', () => <ModalTable/>);
+
+stories.add('tabs table', () => <TabsTable/>);
+
+stories.add('event table', () => <EventTable/>);
+
+stories.add('fn table', () => <FnTable/>);
+
+stories.add('dynamic filters', () => <DynamicFilters/>);
+
+stories.add('resizable table', () => <ResizableTable/>);
+
+stories.add('with pagination', () => <PaginationDemo/>);
+stories.add(`controlled pagination`, () => <ControlledPagination/>);
+
+stories.add('selected rows', () => <SelectedRowsDemo/>);
+
+stories.add('children data', () => <ChildrenData/>);
+
+stories.add('children data selected rows', () => <ChildrenDataSelected/>);
+stories.add(`with side sheet`, () => <WithSideSheet/>);
+stories.add(`in side sheet`, () => <InSideSheet/>);
+stories.add(`grouped rows`, () => <GroupedRows/>);
+stories.add(`grouped rows fixed`, () => <GroupedRowsFixed/>);
+stories.add(`grouped cols`, () => <GroupedCols/>);
+stories.add(`grouped cols fixed`, () => <GroupedColsFixed/>);
+stories.add(`grouped cols fixed jsx`, () => <GroupedColsFixedJSX/>);
+
+stories.add(`grouped cols fixed virtualized`, () => <GroupedColsFixedVirtualized/>);
+stories.add(`grouped cols fixed virtualized groups`, () => <GroupedColsFixedVirtualizedGroups/>);
+
+stories.add(`fixed groups`, () => <FixedGroups/>);
+stories.add(`custom components`, () => <CustomComponents/>);
+stories.add(`custom expand icons`, () => <CustomExpandIcons/>);
+stories.add(`custom filter dropdown item`, () => <CustomFilterDropdownItem/>);
+stories.add(`virtualized`, () => <VirtualizedDemo/>);
+stories.add(`virtualized fixed`, () => <VirtualizedFixedDemo/>);
+stories.add(`virtualized not fixed`, () => <VirtualizedNotFixedDemo/>);
+stories.add(`virtualized data selected`, () => <VirtualizedDataSelected/>);
+stories.add(`virtualized grouped rows`, () => <VirtualizedGroupedRows/>);
+stories.add(`virtualized dynamic data`, () => <VirtualizedDynamicData/>);
+stories.add(`infinite scroll`, () => <InfiniteScroll/>);
+stories.add(`massive columns`, () => <MassiveColumns/>);
+stories.add(`full render`, () => <FulldRenderDemo/>);
+stories.add(`VirtualTableOnCell`, () => <VirtualTableOnCell/>);
+stories.add(`Perf Virtualized`, () => <PerfVirtualized/>);
+stories.add(`Perf Render`, () => <PerfRender/>);
+stories.add(`Perf Complex Render`, () => <PerfComplexRender/>);
+stories.add(`Perf Controlled Selection`, () => <ControlledSelection/>);
+stories.add(`Perf Context`, () => <PerfContext/>);
+stories.add(`Perf Resizable Selection`, () => <PerfResizableSelection/>);
+stories.add(`Perf Render Row Times`, () => <PerfOnRow/>);
+stories.add(`renderPagination`, () => <RenderPagination/>);
+stories.add(`RTL align scroll bar`, () => <RTLAlignScrollBar/>);
+stories.add(`JSX aysnc data`, () => <JSXAsyncData/>);
+stories.add(`JSX column and prop clumns`, () => <JSXColumnPropColumn/>);
+stories.add(`scroll bar`, () => <ScrollBar/>);
+stories.add(`fix table rowSpan/colSpan`, () => <TableSpan/>);
+stories.add(`fix column render return props #1373`, () => <FixRenderReturnProps/>);
+stories.add('expandAllRows', () => <ExpandAllRows/>);
+stories.add('expandAllGroupRows', () => <ExpandAllGroupRows/>);
+stories.add('expandRowByClick', () => <ExpandRowByClick/>);
+stories.add('rowSelection boolean', () => <Table columns={columns} dataSource={data} rowSelection/>);

+ 279 - 272
packages/semi-ui/tree/_story/tree.stories.js

@@ -1,26 +1,12 @@
-import React, { useState, useRef, useEffect } from 'react';
-import { storiesOf } from '@storybook/react';
-// import { withKnobs, text, boolean } from '@storybook/addon-knobs';
-import withPropsCombinations from 'react-storybook-addon-props-combinations';
+import React, {useRef, useState} from 'react';
+import {storiesOf} from '@storybook/react';
 import Tree from '../index';
 import AutoSizer from '../autoSizer';
-import { Icon, Toast, ButtonGroup, Button, Popover, Input } from '../../index';
+import {Button, ButtonGroup, Input, Popover, Toast} from '../../index';
 import BigTree from './BigData';
 import testData from './data';
-import {
-    isEmpty,
-    isPlainObject,
-    cloneDeep,
-    isObject,
-    cloneDeepWith,
-    isArray,
-    isEqual,
-    debounce,
-    omit,
-    update,
-    difference,
-} from 'lodash-es';
-import {IconMapPin, IconMore, IconEdit } from '@douyinfe/semi-icons';
+import {cloneDeep, difference, isEqual,} from 'lodash-es';
+import {IconEdit, IconMapPin, IconMore} from '@douyinfe/semi-icons';
 
 const TreeNode = Tree.TreeNode;
 
@@ -138,19 +124,19 @@ const treeDataWithIcon = [
         label: 'Asia',
         value: 'Asia',
         key: '0',
-        icon: <IconMapPin style={{ color: 'var(--semi-color-text-2)' }} />,
+        icon: <IconMapPin style={{color: 'var(--semi-color-text-2)'}}/>,
         children: [
             {
                 label: 'China',
                 value: 'China',
                 key: '0-0',
-                icon: <IconMapPin style={{ color: 'var(--semi-color-text-2)' }} />,
+                icon: <IconMapPin style={{color: 'var(--semi-color-text-2)'}}/>,
             },
             {
                 label: 'Japan',
                 value: 'Japan',
                 key: '0-1',
-                icon: <IconMapPin style={{ color: 'var(--semi-color-text-2)' }} />,
+                icon: <IconMapPin style={{color: 'var(--semi-color-text-2)'}}/>,
             },
         ],
     },
@@ -165,9 +151,9 @@ const treeDataWithNode = [
     {
         label: (
             <span>
-                <span style={{ marginRight: 30 }}>亚洲</span>
+                <span style={{marginRight: 30}}>亚洲</span>
                 <Button
-                    style={{ zIndex: 2 }}
+                    style={{zIndex: 2}}
                     onClick={e => {
                         Toast.info(opts);
                         e.stopPropagation();
@@ -280,17 +266,17 @@ stories.add('multiple tree', () => (
 ));
 
 stories.add('searchable tree', () => (
-    <Tree treeData={treeData1} filterTreeNode treeNodeFilterProp="value" multiple searchStyle={{ width: '300px' }} />
+    <Tree treeData={treeData1} filterTreeNode treeNodeFilterProp="value" multiple searchStyle={{width: '300px'}}/>
 ));
 
 stories.add('disabled tree', () => (
-    <Tree treeData={treeData1} defaultValue={['dongjing', 'daban']} multiple disabled />
+    <Tree treeData={treeData1} defaultValue={['dongjing', 'daban']} multiple disabled/>
 ));
 
 stories.add('default tree', () => (
     <div>
-        <Tree treeData={treeData1} defaultValue={['zhongguo']} />
-        <br />
+        <Tree treeData={treeData1} defaultValue={['zhongguo']}/>
+        <br/>
         <Tree
             treeData={treeData1}
             multiple
@@ -303,8 +289,8 @@ stories.add('default tree', () => (
 
 stories.add('expandAction', () => (
     <div>
-        <Tree treeData={treeData1} defaultValue={['zhongguo']} />
-        <br />
+        <Tree treeData={treeData1} defaultValue={['zhongguo']}/>
+        <br/>
         <Tree
             treeData={treeData1}
             //multiple
@@ -312,7 +298,7 @@ stories.add('expandAction', () => (
             expandAction="click"
             onDoubleClick={e => console.log(e.detail)}
         />
-        <br />
+        <br/>
         <Tree
             treeData={treeData1}
             multiple
@@ -329,14 +315,16 @@ class Demo extends React.Component {
             value: 'shanghai',
         };
     }
+
     onChange(value) {
-        this.setState({ value });
+        this.setState({value});
     }
+
     render() {
         return (
             <Tree
-                style={{ width: 300 }}
-                dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
+                style={{width: 300}}
+                dropdownStyle={{maxHeight: 400, overflow: 'auto'}}
                 treeData={treeData1}
                 value={this.state.value}
                 placeholder="Please select"
@@ -346,7 +334,7 @@ class Demo extends React.Component {
     }
 }
 
-stories.add('controlled Component single', () => <Demo />);
+stories.add('controlled Component single', () => <Demo/>);
 
 class Demo2 extends React.Component {
     constructor() {
@@ -355,17 +343,19 @@ class Demo2 extends React.Component {
             value: ['shanghai', 'beijing', 'zhongguo'],
         };
     }
+
     onChange(value) {
         console.log(value);
-        this.setState({ value });
+        this.setState({value});
     }
+
     render() {
         console.log(this.state.value);
         return (
             <Tree
-                style={{ width: 300 }}
+                style={{width: 300}}
                 multiple
-                dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
+                dropdownStyle={{maxHeight: 200, overflow: 'auto'}}
                 treeData={treeData1}
                 value={this.state.value}
                 placeholder="Please select"
@@ -375,7 +365,7 @@ class Demo2 extends React.Component {
     }
 }
 
-stories.add('controlled Component multiple', () => <Demo2 />);
+stories.add('controlled Component multiple', () => <Demo2/>);
 
 stories.add('json tree', () => (
     <div>
@@ -384,20 +374,20 @@ stories.add('json tree', () => (
             onChange={e => console.log('change', e)}
             onSelect={e => console.log('select', e)}
         />
-        <br />
-        <Tree treeDataSimpleJson={treeJson} multiple onChange={e => console.log(e)} onSelect={e => console.log(e)} />
+        <br/>
+        <Tree treeDataSimpleJson={treeJson} multiple onChange={e => console.log(e)} onSelect={e => console.log(e)}/>
     </div>
 ));
 
 stories.add('icon tree', () => (
     <div>
-        <Tree treeData={treeDataWithIcon} />
-        <br />
-        <Tree treeData={treeDataWithIcon} multiple blockNode />
+        <Tree treeData={treeDataWithIcon}/>
+        <br/>
+        <Tree treeData={treeDataWithIcon} multiple blockNode/>
     </div>
 ));
 
-stories.add('directory tree', () => <Tree treeData={treeData1} directory multiple blockNode />);
+stories.add('directory tree', () => <Tree treeData={treeData1} directory multiple blockNode/>);
 
 const button = (
     <ButtonGroup size="small" theme="borderless">
@@ -470,7 +460,7 @@ const treeDataWithNode2 = [
 
 stories.add('tree label using node', () => (
     <div>
-        <Tree treeData={treeDataWithNode2} blockNode defaultExpandAll />
+        <Tree treeData={treeDataWithNode2} blockNode defaultExpandAll/>
     </div>
 ));
 
@@ -494,24 +484,27 @@ class TagSideSheet2 extends React.Component {
         this.renderLabel = this.renderLabel.bind(this);
         this.transLabel = this.transLabel.bind(this);
     }
+
     componentDidMount() {
         let tagList = [...treeDataTest];
         this.setState({
             tagList,
         });
     }
+
     onVisible(visibles) {
         this.setState({
             visibles,
         });
     }
+
     renderLabel(item) {
-        const { visibles } = this.state;
+        const {visibles} = this.state;
         console.log('rendering label', visibles);
         return (
             <Popover trigger="custom" position="bottomLeft" visible={visibles} content={'测试popover'}>
                 <Button
-                    icon={<IconEdit />}
+                    icon={<IconEdit/>}
                     onClick={e => {
                         e.stopPropagation();
                         this.onVisible(!visibles);
@@ -522,6 +515,7 @@ class TagSideSheet2 extends React.Component {
             </Popover>
         );
     }
+
     transLabel(list) {
         // list = cloneDeep(list);
         list.forEach(item => {
@@ -530,29 +524,30 @@ class TagSideSheet2 extends React.Component {
         });
         return list;
     }
+
     render() {
-        const { tagList = [] } = this.state;
+        const {tagList = []} = this.state;
         const transformedTags = this.transLabel(cloneDeep(tagList));
         console.log('transformedTags', transformedTags, treeDataTest);
-        return <Tree treeData={transformedTags} />;
+        return <Tree treeData={transformedTags}/>;
     }
 }
 
-stories.add('tree label using popover', () => <TagSideSheet2 />);
+stories.add('tree label using popover', () => <TagSideSheet2/>);
 
 stories.add('defaultExpandKeys tree', () => (
     <>
-        <Tree treeData={treeData1} defaultExpandedKeys={['zhongguo', 'beimeizhou']} blockNode />
-        <Tree treeData={treeData1} defaultExpandAll blockNode />
-        <Tree treeData={treeData1} defaultExpandAll multiple blockNode />
+        <Tree treeData={treeData1} defaultExpandedKeys={['zhongguo', 'beimeizhou']} blockNode/>
+        <Tree treeData={treeData1} defaultExpandAll blockNode/>
+        <Tree treeData={treeData1} defaultExpandAll multiple blockNode/>
     </>
 ));
 
 stories.add('labelInValue tree', () => (
     <>
-        <Tree treeData={treeData1} labelInValue onChange={e => console.log(e)} />
-        <Tree treeData={treeData1} labelInValue onChange={e => console.log(e)} multiple />
-        <Tree treeData={treeDataWithIcon} labelInValue onChange={e => console.log(e)} multiple />
+        <Tree treeData={treeData1} labelInValue onChange={e => console.log(e)}/>
+        <Tree treeData={treeData1} labelInValue onChange={e => console.log(e)} multiple/>
+        <Tree treeData={treeDataWithIcon} labelInValue onChange={e => console.log(e)} multiple/>
     </>
 ));
 
@@ -567,7 +562,7 @@ class Test extends React.Component {
     componentDidMount() {
         setTimeout(() => {
             console.log('set loading');
-            this.setState({ loading: true });
+            this.setState({loading: true});
         }, 5000);
     }
 
@@ -620,11 +615,11 @@ class Test extends React.Component {
                 ],
             },
         ];
-        return <Tree treeData={treeDataWithNode2} />;
+        return <Tree treeData={treeDataWithNode2}/>;
     }
 }
 
-stories.add('setState after 5s', () => <Test />);
+stories.add('setState after 5s', () => <Test/>);
 
 class DemoExpandedKeys extends React.Component {
     constructor() {
@@ -633,15 +628,17 @@ class DemoExpandedKeys extends React.Component {
             expand: ['zhongguo', 'beimeizhou'],
         };
     }
+
     onExpand(expand) {
         console.log(expand);
-        this.setState({ expand });
+        this.setState({expand});
     }
+
     render() {
         return (
             <Tree
-                style={{ width: 300 }}
-                dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
+                style={{width: 300}}
+                dropdownStyle={{maxHeight: 400, overflow: 'auto'}}
                 treeData={treeData1}
                 expandedKeys={this.state.expand}
                 placeholder="Please select"
@@ -658,16 +655,18 @@ class DemoExpandeKeysMulti extends React.Component {
             expand: ['zhongguo'],
         };
     }
+
     onExpand(expand) {
         console.log(expand);
-        this.setState({ expand });
+        this.setState({expand});
     }
+
     render() {
         return (
             <Tree
-                style={{ width: 300 }}
+                style={{width: 300}}
                 multiple
-                dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
+                dropdownStyle={{maxHeight: 400, overflow: 'auto'}}
                 treeData={treeData1}
                 expandedKeys={this.state.expand}
                 placeholder="Please select"
@@ -679,9 +678,9 @@ class DemoExpandeKeysMulti extends React.Component {
 
 stories.add('expandedKeys', () => (
     <>
-        <DemoExpandedKeys />
-        <br />
-        <DemoExpandeKeysMulti />
+        <DemoExpandedKeys/>
+        <br/>
+        <DemoExpandeKeysMulti/>
     </>
 ));
 
@@ -699,6 +698,7 @@ class DmExpandedKeys extends React.Component {
         };
         this.add = this.add.bind(this);
     }
+
     add() {
         let itemLength = Math.floor(Math.random() * 5) + 1;
         let treeData = new Array(itemLength).fill(0).map((v, i) => {
@@ -719,14 +719,15 @@ class DmExpandedKeys extends React.Component {
             };
             return item;
         });
-        this.setState({ treeData });
+        this.setState({treeData});
     }
+
     render() {
-        const { treeData } = this.state;
+        const {treeData} = this.state;
         return (
             <>
-                <Tree treeData={this.state.treeData} expandedKeys={['0', '1']} />
-                <br />
+                <Tree treeData={this.state.treeData} expandedKeys={['0', '1']}/>
+                <br/>
                 <Button onClick={this.add}>动态改变数据</Button>
             </>
         );
@@ -735,7 +736,7 @@ class DmExpandedKeys extends React.Component {
 
 stories.add('dynamic expandKeys', () => (
     <>
-        <DmExpandedKeys />
+        <DmExpandedKeys/>
     </>
 ));
 
@@ -753,6 +754,7 @@ class DmSelectedKeys extends React.Component {
         };
         this.add = this.add.bind(this);
     }
+
     add() {
         let itemLength = Math.floor(Math.random() * 5) + 1;
         let treeData = new Array(itemLength).fill(0).map((v, i) => {
@@ -773,14 +775,15 @@ class DmSelectedKeys extends React.Component {
             };
             return item;
         });
-        this.setState({ treeData });
+        this.setState({treeData});
     }
+
     render() {
-        const { treeData } = this.state;
+        const {treeData} = this.state;
         return (
             <>
-                <Tree treeData={treeData} value={['0-0']} onChange={e => console.log(e)} />
-                <br />
+                <Tree treeData={treeData} value={['0-0']} onChange={e => console.log(e)}/>
+                <br/>
                 <Button onClick={this.add}>动态改变数据</Button>
             </>
         );
@@ -790,13 +793,13 @@ class DmSelectedKeys extends React.Component {
 // the demo will not work anymore as value does not exist when the tree mounts
 stories.add('dynamic selectedKey', () => (
     <>
-        <DmSelectedKeys />
+        <DmSelectedKeys/>
     </>
 ));
 
 stories.add('large amount of data', () => (
     <>
-        <BigTree />
+        <BigTree/>
     </>
 ));
 
@@ -814,10 +817,10 @@ stories.add('autosizer', () => (
             }}
         >
             <AutoSizer
-            // defaultHeight={defaultHeight}
-            // defaultWidth={defaultWidth}
+                // defaultHeight={defaultHeight}
+                // defaultWidth={defaultWidth}
             >
-                {({ height, width }) => (
+                {({height, width}) => (
                     <div
                         style={{
                             width: width,
@@ -872,11 +875,11 @@ const MotionCustomLabelDemo = () => {
                 return;
             }
             list.forEach(item => {
-                const { type, label, key } = item;
+                const {type, label, key} = item;
                 item.label = (
                     <div onMouseEnter={() => setHoverKey(key)}>
                         {label}
-                        {hoverKey === key ? <IconMore /> : null}
+                        {hoverKey === key ? <IconMore/> : null}
                     </div>
                 );
                 recusive(item.children);
@@ -885,10 +888,10 @@ const MotionCustomLabelDemo = () => {
         recusive(list);
         return list;
     };
-    return <Tree treeData={cusLabel(treeData)} defaultExpandAll />;
+    return <Tree treeData={cusLabel(treeData)} defaultExpandAll/>;
 };
 
-stories.add('motion custom label', () => <MotionCustomLabelDemo />);
+stories.add('motion custom label', () => <MotionCustomLabelDemo/>);
 
 const AutoParentDemo = () => {
     const [expandedKeys, setExpandedKeys] = useState(['beimeizhou']);
@@ -934,7 +937,7 @@ const AutoParentDemo = () => {
 
 stories.add('autoExpandParent', () => (
     <>
-        <AutoParentDemo />
+        <AutoParentDemo/>
     </>
 ));
 
@@ -942,7 +945,7 @@ const findDescendantKeys = node => {
     let res = [node.key];
     const findChild = item => {
         if (!item) return;
-        const { children } = item;
+        const {children} = item;
 
         if (children && children.length) {
             children.forEach(child => {
@@ -978,7 +981,7 @@ class DyTreeWithExpandControlled extends React.Component {
             !isEqual(prevState.treeData, this.state.treeData) ||
             !isEqual(prevState.inputValue, this.state.inputValue)
         ) {
-            const { treeData, inputValue, collapsedKeys } = this.state;
+            const {treeData, inputValue, collapsedKeys} = this.state;
             let filteredKeys = [];
 
             const findFilteredKey = arr => {
@@ -1020,14 +1023,14 @@ class DyTreeWithExpandControlled extends React.Component {
             };
             return item;
         });
-        this.setState({ treeData });
+        this.setState({treeData});
     };
 
     search = val => {
-        this.setState({ inputValue: val });
+        this.setState({inputValue: val});
     };
 
-    onExpand = (keys, { expanded, node }) => {
+    onExpand = (keys, {expanded, node}) => {
         let collapsed = this.state.collapsedKeys;
         let desKeys = findDescendantKeys(node);
         if (!expanded) {
@@ -1043,7 +1046,7 @@ class DyTreeWithExpandControlled extends React.Component {
     };
 
     render() {
-        const { treeData, expandedKeys, autoExpandParent } = this.state;
+        const {treeData, expandedKeys, autoExpandParent} = this.state;
         return (
             <div>
                 <Tree
@@ -1054,8 +1057,8 @@ class DyTreeWithExpandControlled extends React.Component {
                     onSearch={this.search}
                     onExpand={this.onExpand}
                 />
-                <br />
-                <Button onClick={this.add} style={{ margin: 20 }}>
+                <br/>
+                <Button onClick={this.add} style={{margin: 20}}>
                     动态改变数据
                 </Button>
             </div>
@@ -1063,7 +1066,7 @@ class DyTreeWithExpandControlled extends React.Component {
     }
 }
 
-stories.add('dynamic treeData with searchValue and controlled expand', () => <DyTreeWithExpandControlled />);
+stories.add('dynamic treeData with searchValue and controlled expand', () => <DyTreeWithExpandControlled/>);
 
 const CusSearchRender = () => {
     const [inputValue, setInputValue] = useState('');
@@ -1080,7 +1083,7 @@ const CusSearchRender = () => {
             treeData={treeData1}
             filterTreeNode
             showFilteredOnly
-            searchRender={({ prefix, placeholder }) => (
+            searchRender={({prefix, placeholder}) => (
                 <Input
                     prefix={prefix}
                     placeholder={placeholder}
@@ -1094,7 +1097,7 @@ const CusSearchRender = () => {
 
 stories.add('CusSearchRender', () => (
     <>
-        <CusSearchRender />
+        <CusSearchRender/>
     </>
 ));
 
@@ -1157,7 +1160,7 @@ const RefSearch = () => {
     ];
     return (
         <div>
-            <Input onChange={v => ref.current.search(v)} />
+            <Input onChange={v => ref.current.search(v)}/>
             <Tree
                 treeData={treeData}
                 defaultValue="Shanghai"
@@ -1172,7 +1175,7 @@ const RefSearch = () => {
 
 stories.add('RefSearch', () => (
     <>
-        <RefSearch />
+        <RefSearch/>
     </>
 ));
 
@@ -1195,10 +1198,10 @@ const initTreeDate = [
 function updateTreeData(list, key, children) {
     return list.map(node => {
         if (node.key === key) {
-            return { ...node, children };
+            return {...node, children};
         }
         if (node.children) {
-            return { ...node, children: updateTreeData(node.children, key, children) };
+            return {...node, children: updateTreeData(node.children, key, children)};
         }
 
         return node;
@@ -1208,7 +1211,7 @@ function updateTreeData(list, key, children) {
 const LoadingTreeDemo = () => {
     const [treeData, setTreeData] = useState(initTreeDate);
 
-    function onLoadData({ key, children }) {
+    function onLoadData({key, children}) {
         return new Promise(resolve => {
             if (children) {
                 resolve();
@@ -1233,19 +1236,19 @@ const LoadingTreeDemo = () => {
         });
     }
 
-    return <Tree loadData={onLoadData} treeData={cloneDeep(treeData)} />;
+    return <Tree loadData={onLoadData} treeData={cloneDeep(treeData)}/>;
 };
 
 stories.add('loading', () => (
     <>
-        <LoadingTreeDemo />
+        <LoadingTreeDemo/>
     </>
 ));
 
 const LoadingWithSearch = () => {
     const [treeData, setTreeData] = useState(initTreeDate);
 
-    function onLoadData({ key, children }) {
+    function onLoadData({key, children}) {
         return new Promise(resolve => {
             if (children) {
                 resolve();
@@ -1270,12 +1273,12 @@ const LoadingWithSearch = () => {
         });
     }
 
-    return <Tree loadData={onLoadData} treeData={cloneDeep(treeData)} filterTreeNode />;
+    return <Tree loadData={onLoadData} treeData={cloneDeep(treeData)} filterTreeNode/>;
 };
 
 stories.add('Loading with search', () => (
     <>
-        <LoadingWithSearch />
+        <LoadingWithSearch/>
     </>
 ));
 
@@ -1329,7 +1332,7 @@ const DisabledStrictly = () => {
                 defaultExpandAll
                 disableStrictly
             />
-            <br />
+            <br/>
             <span> disable shanghai(checked), beijing(checked) </span>
             <Tree
                 treeData={[
@@ -1423,7 +1426,7 @@ const DisabledStrictly = () => {
                 defaultExpandAll
                 disableStrictly
             />
-            <br />
+            <br/>
             <span> disable shanghai </span>
             <Tree
                 treeData={[
@@ -1570,7 +1573,7 @@ const DisabledStrictly = () => {
     )
 }
 
-stories.add('disableStrictly', () => <DisabledStrictly />);
+stories.add('disableStrictly', () => <DisabledStrictly/>);
 
 const ActionTree = () => {
     let initData = [{
@@ -1619,7 +1622,7 @@ const ActionTree = () => {
     );
 };
 
-stories.add('Delete or Add Child Node', () => <ActionTree />);
+stories.add('Delete or Add Child Node', () => <ActionTree/>);
 
 
 const MutipleHLTree = () => {
@@ -1630,7 +1633,7 @@ const MutipleHLTree = () => {
         let res = [node.key];
         const findChild = item => {
             if (!item) return;
-            const { children } = item;
+            const {children} = item;
 
             if (children && children.length) {
                 children.forEach(child => {
@@ -1655,7 +1658,7 @@ const MutipleHLTree = () => {
         onClick,
         expandIcon
     }) => {
-        const { label, icon, key } = data;
+        const {label, icon, key} = data;
         const isLeaf = !(data.children && data.children.length);
         const style = {
             backgroundColor: selected.has(key)
@@ -1692,7 +1695,7 @@ const MutipleHLTree = () => {
     )
 }
 
-stories.add('renderOuterLable', () => <MutipleHLTree />)
+stories.add('renderOuterLable', () => <MutipleHLTree/>)
 
 stories.add('tree without value props', () => (
     <Tree
@@ -1715,7 +1718,7 @@ const generateData = (_level, _preKey, _tns) => {
     const children = [];
     for (let i = 0; i < x; i++) {
         const key = `${preKey}-${i}`;
-        tns.push({ label: key, key });
+        tns.push({label: key, key});
         if (i < y) {
             children.push(key);
         }
@@ -1732,15 +1735,17 @@ const generateData = (_level, _preKey, _tns) => {
 generateData(z);
 const DnDTree = () => {
     function generateData(x = 3, y = 2, z = 1, gData = []) {
-        // x:每一级下的节点总数。y:每级节点里有y个节点、存在子节点。z:树的level层级数(0表示一级)
-        function _loop(_level, _preKey, _tns) {
+        // x:每一级下的节点总数。
+        // y:每级节点里有y个节点、存在子节点。
+        // z:树的level层级数(0表示一级)
+        function dfs(_level, _preKey, _tns) {
             const preKey = _preKey || '0';
             const tns = _tns || gData;
 
             const children = [];
             for (let i = 0; i < x; i++) {
                 const key = `${preKey}-${i}`;
-                tns.push({ label: `${key}`, key: `${key}-key`, value: `${key}-value` });
+                tns.push({label: `${key}`, key: `${key}-key`, value: `${key}-value`});
                 if (i < y) {
                     children.push(key);
                 }
@@ -1751,18 +1756,20 @@ const DnDTree = () => {
             const __level = _level - 1;
             children.forEach((key, index) => {
                 tns[index].children = [];
-                return _loop(__level, key, tns[index].children);
+                return dfs(__level, key, tns[index].children);
             });
 
             return null;
         }
-        _loop(z);
+
+        dfs(z);
         return gData;
     }
 
     const initialData = generateData();
 
     const [treeData, setTreeData] = useState(initialData);
+
     // const [expandedKeys, setExpandedKeys] = useState(['zhongguo']);
 
     function onDragEnter(info) {
@@ -1772,7 +1779,7 @@ const DnDTree = () => {
     }
 
     function onDrop(info) {
-        const { dropToGap, node, dragNode } = info;
+        const {dropToGap, node, dragNode} = info;
         const dropKey = node.key;
         const dragKey = dragNode.key;
         const dropPos = node.pos.split('-');
@@ -1831,14 +1838,14 @@ const DnDTree = () => {
     />;
 };
 
-stories.add('draggable Tree', () => <DnDTree />)
+stories.add('draggable Tree', () => <DnDTree/>)
 
 const TestTree = () => {
     return (
         <Tree
             treeData={testData}
             // motion={false}
-            style={{ height: '100%' }}
+            style={{height: '100%'}}
             filterTreeNode
             expandAction="click"
             showFilteredOnly
@@ -1846,165 +1853,165 @@ const TestTree = () => {
     );
 };
 
-stories.add('draggable', () => <TestTree />);
+stories.add('draggable', () => <TestTree/>);
 
 stories.add('renderFullLabel with draggable', () => {
-    const [selected, setSelected] = useState(new Set());
-    const [selectedThroughParent, setSelectedThroughParent] = useState(new Set());
-    const defaultTreeData = [
-        {
-            label: '黑色固定按钮',
-            key: 'fix-btn-0'
-        },
-        {
-            label: '模块',
-            key: 'module-0',
-            children: [
-                {
-                    label: '可自由摆放的组件',
-                    key: 'free-compo-0',
-                },
-                {
-                    label: '分栏容器',
-                    key: 'split-col-0',
-                    children: [
-                        {
-                            label: '按钮组件',
-                            key: 'btn-0'
-                        },
-                        {
-                            label: '按钮组件',
-                            key: 'btn-1'
-                        }
-                    ]
-                },
-            ],
-        },
-        {
-            label: '模块',
-            key: 'module-1',
-            children: [
-                {
-                    label: '自定义组件',
-                    key: 'cus-0'
-                }
-            ]
-        }
-    ]
-    const [treeData, setTreeData] = useState(defaultTreeData);
-
-    const onDrop = (info) => {
-        const { dropToGap, node, dragNode } = info;
-        const dropKey = node.key;
-        const dragKey = dragNode.key;
-        const dropPos = node.pos.split('-');
-        const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]);
+        const [selected, setSelected] = useState(new Set());
+        const [selectedThroughParent, setSelectedThroughParent] = useState(new Set());
+        const defaultTreeData = [
+            {
+                label: '黑色固定按钮',
+                key: 'fix-btn-0'
+            },
+            {
+                label: '模块',
+                key: 'module-0',
+                children: [
+                    {
+                        label: '可自由摆放的组件',
+                        key: 'free-compo-0',
+                    },
+                    {
+                        label: '分栏容器',
+                        key: 'split-col-0',
+                        children: [
+                            {
+                                label: '按钮组件',
+                                key: 'btn-0'
+                            },
+                            {
+                                label: '按钮组件',
+                                key: 'btn-1'
+                            }
+                        ]
+                    },
+                ],
+            },
+            {
+                label: '模块',
+                key: 'module-1',
+                children: [
+                    {
+                        label: '自定义组件',
+                        key: 'cus-0'
+                    }
+                ]
+            }
+        ]
+        const [treeData, setTreeData] = useState(defaultTreeData);
+
+        const onDrop = (info) => {
+            const {dropToGap, node, dragNode} = info;
+            const dropKey = node.key;
+            const dragKey = dragNode.key;
+            const dropPos = node.pos.split('-');
+            const dropPosition = info.dropPosition - Number(dropPos[dropPos.length - 1]);
+
+            const data = [...treeData];
+            const loop = (data, key, callback) => {
+                data.forEach((item, ind, arr) => {
+                    if (item.key === key) return callback(item, ind, arr);
+                    if (item.children) return loop(item.children, key, callback);
+                })
+            }
 
-        const data = [...treeData];
-        const loop = (data, key, callback) => {
-            data.forEach((item, ind, arr) => {
-                if (item.key === key) return callback(item, ind, arr);
-                if (item.children) return loop(item.children, key, callback);
+            let dragObj;
+            loop(data, dragKey, (item, ind, arr) => {
+                arr.splice(ind, 1);
+                dragObj = item;
             })
-        }
 
-        let dragObj;
-        loop(data, dragKey, (item, ind, arr) => {
-            arr.splice(ind, 1);
-            dragObj = item;
-        })
-
-        if (!dropToGap) {
-            loop(data, dropKey, (item, ind, arr) => {
-                item.children = item.children || [];
-                item.children.push(dragObj)
-            })
-        } else if (dropPosition === 1 && node.children && node.expanded) {
-            loop(data, dropKey, item => {
-                item.children = item.children || [];
-                item.children.unshift(dragObj)
-            })
-        } else {
-            let dropNodeInd;
-            let dropNodePosArr;
-            loop(data, dropKey, (item, ind, arr) => {
-                dropNodePosArr = arr;
-                dropNodeInd = ind;
-            })
-            if (dropPosition === -1) {
-                dropNodePosArr.splice(dropNodeInd, 0, dragObj)
+            if (!dropToGap) {
+                loop(data, dropKey, (item, ind, arr) => {
+                    item.children = item.children || [];
+                    item.children.push(dragObj)
+                })
+            } else if (dropPosition === 1 && node.children && node.expanded) {
+                loop(data, dropKey, item => {
+                    item.children = item.children || [];
+                    item.children.unshift(dragObj)
+                })
             } else {
-                dropNodePosArr.splice(dropNodeInd + 1, 0, dragObj)
+                let dropNodeInd;
+                let dropNodePosArr;
+                loop(data, dropKey, (item, ind, arr) => {
+                    dropNodePosArr = arr;
+                    dropNodeInd = ind;
+                })
+                if (dropPosition === -1) {
+                    dropNodePosArr.splice(dropNodeInd, 0, dragObj)
+                } else {
+                    dropNodePosArr.splice(dropNodeInd + 1, 0, dragObj)
+                }
             }
+            setTreeData(data)
         }
-        setTreeData(data)
-    }
-
-    const findDescendantKeys = (node) => {
-        let res = [node.key];
-        const findChild = item => {
-            if (!item) return;
-            const { children } = item;
 
-            if (children && children.length) {
-                children.forEach(child => {
-                    res.push(child.key);
-                    findChild(child);
-                });
-            }
-        };
-        findChild(node);
-        return res;
-    }
+        const findDescendantKeys = (node) => {
+            let res = [node.key];
+            const findChild = item => {
+                if (!item) return;
+                const {children} = item;
+
+                if (children && children.length) {
+                    children.forEach(child => {
+                        res.push(child.key);
+                        findChild(child);
+                    });
+                }
+            };
+            findChild(node);
+            return res;
+        }
 
-    const handleSelect = (key, bool, node) => {
-        setSelected(new Set([key]));
-        const descendantKeys = findDescendantKeys(node);
-        setSelectedThroughParent(new Set(descendantKeys));
-    }
+        const handleSelect = (key, bool, node) => {
+            setSelected(new Set([key]));
+            const descendantKeys = findDescendantKeys(node);
+            setSelectedThroughParent(new Set(descendantKeys));
+        }
 
-    const renderLabel = ({
-        className,
-        data,
-        onClick,
-        expandIcon
-    }) => {
-        const { label, icon, key } = data;
-        const isLeaf = !(data.children && data.children.length);
-        const style = {
-            backgroundColor: selected.has(key)
-                ? 'rgba(var(--semi-blue-0), 1)'
-                : selectedThroughParent.has(key)
-                    ? 'rgba(var(--semi-blue-0), .5)' : 'transparent'
+        const renderLabel = ({
+            className,
+            data,
+            onClick,
+            expandIcon
+        }) => {
+            const {label, icon, key} = data;
+            const isLeaf = !(data.children && data.children.length);
+            const style = {
+                backgroundColor: selected.has(key)
+                    ? 'rgba(var(--semi-blue-0), 1)'
+                    : selectedThroughParent.has(key)
+                        ? 'rgba(var(--semi-blue-0), .5)' : 'transparent'
+            }
+            return (
+                <li
+                    className={className}
+                    role="treenode"
+                    onClick={onClick}
+                    style={style}
+                >
+                    {isLeaf ? <span style={{width: 24}}></span> : expandIcon}
+                    {icon ? icon : null}
+                    <span>{label}</span>
+                </li>
+            )
         }
-        return (
-            <li
-                className={className}
-                role="treenode"
-                onClick={onClick}
-                style={style}
-            >
-                {isLeaf ? <span style={{ width: 24 }}></span> : expandIcon}
-                {icon ? icon : null}
-                <span>{label}</span>
-            </li>
-        )
-    }
 
-    const treeStyle = {
-        height: 420,
-        border: '1px solid var(--semi-color-border)'
-    }
+        const treeStyle = {
+            height: 420,
+            border: '1px solid var(--semi-color-border)'
+        }
 
 
-    return <Tree
-        treeData={treeData}
-        draggable
-        onDrop={onDrop}
-        renderFullLabel={renderLabel}
-        onSelect={handleSelect}
-        style={treeStyle}
-        defaultExpandAll
-    />;
-}
-);
+        return <Tree
+            treeData={treeData}
+            draggable
+            onDrop={onDrop}
+            renderFullLabel={renderLabel}
+            onSelect={handleSelect}
+            style={treeStyle}
+            defaultExpandAll
+        />;
+    }
+);