@douyinfe/semi-ui 2.17.1 → 2.19.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/anchor/index.tsx +1 -1
  2. package/anchor/link.tsx +3 -4
  3. package/autoComplete/__test__/autoComplete.test.js +6 -6
  4. package/autoComplete/index.tsx +1 -1
  5. package/autoComplete/option.tsx +164 -0
  6. package/calendar/__test__/calendar.test.js +21 -2
  7. package/calendar/_story/calendar.stories.js +31 -0
  8. package/calendar/index.tsx +3 -1
  9. package/calendar/interface.ts +2 -1
  10. package/carousel/index.tsx +5 -5
  11. package/checkbox/checkbox.tsx +10 -2
  12. package/checkbox/checkboxGroup.tsx +2 -0
  13. package/dist/css/semi.css +160 -22
  14. package/dist/css/semi.min.css +1 -1
  15. package/dist/umd/semi-ui.js +15144 -16407
  16. package/dist/umd/semi-ui.js.map +1 -1
  17. package/dist/umd/semi-ui.min.js +1 -1
  18. package/dist/umd/semi-ui.min.js.map +1 -1
  19. package/form/_story/FieldProps/labelOptional.jsx +30 -0
  20. package/form/_story/form.stories.js +7 -0
  21. package/form/hoc/withField.tsx +1 -0
  22. package/form/label.tsx +21 -7
  23. package/gulpfile.js +3 -1
  24. package/lib/cjs/_base/base.css +35 -0
  25. package/lib/cjs/anchor/index.js +2 -1
  26. package/lib/cjs/anchor/link.d.ts +1 -1
  27. package/lib/cjs/anchor/link.js +9 -5
  28. package/lib/cjs/autoComplete/index.d.ts +1 -1
  29. package/lib/cjs/autoComplete/index.js +1 -1
  30. package/lib/cjs/autoComplete/option.d.ts +50 -0
  31. package/lib/cjs/autoComplete/option.js +218 -0
  32. package/lib/cjs/calendar/index.d.ts +2 -0
  33. package/lib/cjs/calendar/index.js +3 -1
  34. package/lib/cjs/calendar/interface.d.ts +2 -1
  35. package/lib/cjs/carousel/index.js +2 -2
  36. package/lib/cjs/checkbox/checkbox.d.ts +4 -0
  37. package/lib/cjs/checkbox/checkbox.js +9 -3
  38. package/lib/cjs/checkbox/checkboxGroup.js +4 -2
  39. package/lib/cjs/form/baseForm.d.ts +1 -1
  40. package/lib/cjs/form/field.d.ts +1 -1
  41. package/lib/cjs/form/hoc/withField.js +2 -1
  42. package/lib/cjs/form/label.d.ts +8 -5
  43. package/lib/cjs/form/label.js +15 -4
  44. package/lib/cjs/locale/interface.d.ts +3 -0
  45. package/lib/cjs/locale/source/ar.js +3 -0
  46. package/lib/cjs/locale/source/de.js +3 -0
  47. package/lib/cjs/locale/source/en_GB.js +3 -0
  48. package/lib/cjs/locale/source/en_US.js +3 -0
  49. package/lib/cjs/locale/source/es.js +3 -0
  50. package/lib/cjs/locale/source/fr.js +3 -0
  51. package/lib/cjs/locale/source/id_ID.js +3 -0
  52. package/lib/cjs/locale/source/it.js +3 -0
  53. package/lib/cjs/locale/source/ja_JP.js +3 -0
  54. package/lib/cjs/locale/source/ko_KR.js +3 -0
  55. package/lib/cjs/locale/source/ms_MY.js +3 -0
  56. package/lib/cjs/locale/source/pt_BR.js +3 -0
  57. package/lib/cjs/locale/source/ru_RU.js +3 -0
  58. package/lib/cjs/locale/source/th_TH.js +3 -0
  59. package/lib/cjs/locale/source/tr_TR.js +3 -0
  60. package/lib/cjs/locale/source/vi_VN.js +3 -0
  61. package/lib/cjs/locale/source/zh_CN.js +3 -0
  62. package/lib/cjs/locale/source/zh_TW.js +3 -0
  63. package/lib/cjs/modal/Modal.js +0 -8
  64. package/lib/cjs/modal/ModalContent.js +4 -1
  65. package/lib/cjs/radio/radio.d.ts +2 -0
  66. package/lib/cjs/radio/radio.js +33 -8
  67. package/lib/cjs/radio/radioGroup.js +4 -2
  68. package/lib/cjs/tag/group.d.ts +3 -0
  69. package/lib/cjs/tag/group.js +24 -6
  70. package/lib/cjs/tag/index.d.ts +2 -1
  71. package/lib/cjs/tag/index.js +7 -5
  72. package/lib/cjs/tag/interface.d.ts +2 -1
  73. package/lib/cjs/tree/index.d.ts +3 -1
  74. package/lib/cjs/tree/index.js +23 -0
  75. package/lib/cjs/tree/interface.d.ts +4 -0
  76. package/lib/cjs/typography/title.d.ts +1 -1
  77. package/lib/es/_base/base.css +35 -0
  78. package/lib/es/anchor/index.js +2 -1
  79. package/lib/es/anchor/link.d.ts +1 -1
  80. package/lib/es/anchor/link.js +9 -5
  81. package/lib/es/autoComplete/index.d.ts +1 -1
  82. package/lib/es/autoComplete/index.js +1 -1
  83. package/lib/es/autoComplete/option.d.ts +50 -0
  84. package/lib/es/autoComplete/option.js +188 -0
  85. package/lib/es/calendar/index.d.ts +2 -0
  86. package/lib/es/calendar/index.js +3 -1
  87. package/lib/es/calendar/interface.d.ts +2 -1
  88. package/lib/es/carousel/index.js +2 -2
  89. package/lib/es/checkbox/checkbox.d.ts +4 -0
  90. package/lib/es/checkbox/checkbox.js +10 -4
  91. package/lib/es/checkbox/checkboxGroup.js +4 -2
  92. package/lib/es/form/baseForm.d.ts +1 -1
  93. package/lib/es/form/field.d.ts +1 -1
  94. package/lib/es/form/hoc/withField.js +2 -1
  95. package/lib/es/form/label.d.ts +8 -5
  96. package/lib/es/form/label.js +13 -4
  97. package/lib/es/locale/interface.d.ts +3 -0
  98. package/lib/es/locale/source/ar.js +3 -0
  99. package/lib/es/locale/source/de.js +3 -0
  100. package/lib/es/locale/source/en_GB.js +3 -0
  101. package/lib/es/locale/source/en_US.js +3 -0
  102. package/lib/es/locale/source/es.js +3 -0
  103. package/lib/es/locale/source/fr.js +3 -0
  104. package/lib/es/locale/source/id_ID.js +3 -0
  105. package/lib/es/locale/source/it.js +3 -0
  106. package/lib/es/locale/source/ja_JP.js +3 -0
  107. package/lib/es/locale/source/ko_KR.js +3 -0
  108. package/lib/es/locale/source/ms_MY.js +3 -0
  109. package/lib/es/locale/source/pt_BR.js +3 -0
  110. package/lib/es/locale/source/ru_RU.js +3 -0
  111. package/lib/es/locale/source/th_TH.js +3 -0
  112. package/lib/es/locale/source/tr_TR.js +3 -0
  113. package/lib/es/locale/source/vi_VN.js +3 -0
  114. package/lib/es/locale/source/zh_CN.js +3 -0
  115. package/lib/es/locale/source/zh_TW.js +3 -0
  116. package/lib/es/modal/Modal.js +0 -8
  117. package/lib/es/modal/ModalContent.js +4 -1
  118. package/lib/es/radio/radio.d.ts +2 -0
  119. package/lib/es/radio/radio.js +31 -8
  120. package/lib/es/radio/radioGroup.js +4 -2
  121. package/lib/es/tag/group.d.ts +3 -0
  122. package/lib/es/tag/group.js +24 -6
  123. package/lib/es/tag/index.d.ts +2 -1
  124. package/lib/es/tag/index.js +7 -5
  125. package/lib/es/tag/interface.d.ts +2 -1
  126. package/lib/es/tree/index.d.ts +3 -1
  127. package/lib/es/tree/index.js +22 -0
  128. package/lib/es/tree/interface.d.ts +4 -0
  129. package/lib/es/typography/title.d.ts +1 -1
  130. package/locale/interface.ts +3 -0
  131. package/locale/source/ar.ts +3 -0
  132. package/locale/source/de.ts +3 -0
  133. package/locale/source/en_GB.ts +3 -0
  134. package/locale/source/en_US.ts +3 -0
  135. package/locale/source/es.ts +3 -0
  136. package/locale/source/fr.ts +3 -0
  137. package/locale/source/id_ID.ts +3 -0
  138. package/locale/source/it.ts +3 -0
  139. package/locale/source/ja_JP.ts +3 -0
  140. package/locale/source/ko_KR.ts +3 -0
  141. package/locale/source/ms_MY.ts +3 -0
  142. package/locale/source/pt_BR.ts +3 -0
  143. package/locale/source/ru_RU.ts +3 -0
  144. package/locale/source/th_TH.ts +3 -0
  145. package/locale/source/tr_TR.ts +4 -1
  146. package/locale/source/vi_VN.ts +3 -0
  147. package/locale/source/zh_CN.ts +3 -0
  148. package/locale/source/zh_TW.ts +3 -0
  149. package/modal/Modal.tsx +0 -6
  150. package/modal/ModalContent.tsx +4 -1
  151. package/modal/__test__/modal.test.js +1 -1
  152. package/modal/_story/__snapshots__/modal.stories.tsx.snap +203 -0
  153. package/package.json +7 -7
  154. package/radio/_story/radio.stories.js +2 -2
  155. package/radio/radio.tsx +27 -5
  156. package/radio/radioGroup.tsx +2 -0
  157. package/rating/__test__/rating.test.js +1 -1
  158. package/select/__test__/select.test.js +11 -17
  159. package/select/_story/select.stories.js +6 -6
  160. package/steps/_story/steps.stories.js +3 -3
  161. package/switch/_story/switch.stories.js +4 -4
  162. package/switch/_story/switch.stories.tsx +4 -4
  163. package/tag/_story/tag.stories.js +57 -1
  164. package/tag/group.tsx +20 -3
  165. package/tag/index.tsx +6 -5
  166. package/tag/interface.ts +2 -1
  167. package/transfer/_story/transfer.stories.js +2 -2
  168. package/tree/_story/tree.stories.js +152 -3
  169. package/tree/index.tsx +16 -1
  170. package/tree/interface.ts +6 -0
  171. package/upload/_story/upload.stories.js +2 -2
  172. package/webpack.config.js +10 -2
@@ -1,9 +1,9 @@
1
- import React, { useRef, useState } from 'react';
1
+ import React, { useRef, useState, useCallback } from 'react';
2
2
  import { cloneDeep, difference, isEqual } from 'lodash';
3
3
  import { IconEdit, IconMapPin, IconMore } from '@douyinfe/semi-icons';
4
4
  import Tree from '../index';
5
5
  import AutoSizer from '../autoSizer';
6
- import { Button, ButtonGroup, Input, Popover, Toast, Space } from '../../index';
6
+ import { Button, ButtonGroup, Input, Popover, Toast, Space, Select, Switch } from '../../index';
7
7
  import BigTree from './BigData';
8
8
  import testData from './data';
9
9
  const TreeNode = Tree.TreeNode;
@@ -2398,4 +2398,153 @@ export const ValueImpactExpansionWithDynamicTreeData = () => {
2398
2398
  </Space>
2399
2399
  </>
2400
2400
  )
2401
- }
2401
+ }
2402
+
2403
+ class DemoV extends React.Component {
2404
+ constructor() {
2405
+ super();
2406
+ this.state = {
2407
+ gData: [],
2408
+ total: 0,
2409
+ align: 'center',
2410
+ scrollKey: '',
2411
+ expandAll: false,
2412
+ };
2413
+ this.onGen = this.onGen.bind(this);
2414
+ this.onScroll = this.onScroll.bind(this);
2415
+ this.onInputChange = this.onInputChange.bind(this);
2416
+ this.onInputBlur = this.onInputBlur.bind(this);
2417
+ this.onSelectChange = this.onSelectChange.bind(this);
2418
+ this.treeRef = React.createRef();
2419
+ }
2420
+
2421
+ generateData(x = 5, y = 4, z = 3, gData = []) {
2422
+ // x:每一级下的节点总数。y:每级节点里有y个节点、存在子节点。z:树的level层级数(0表示一级)
2423
+ function _loop(_level, _preKey, _tns) {
2424
+ const preKey = _preKey || '0';
2425
+ const tns = _tns || gData;
2426
+
2427
+ const children = [];
2428
+ for (let i = 0; i < x; i++) {
2429
+ const key = `${preKey}-${i}`;
2430
+ tns.push({ label: `${key}-标签`, key: `${key}-key`, value: `${key}-value` });
2431
+ if (i < y) {
2432
+ children.push(key);
2433
+ }
2434
+ }
2435
+ if (_level < 0) {
2436
+ return tns;
2437
+ }
2438
+ const __level = _level - 1;
2439
+ children.forEach((key, index) => {
2440
+ tns[index].children = [];
2441
+ return _loop(__level, key, tns[index].children);
2442
+ });
2443
+
2444
+ return null;
2445
+ }
2446
+ _loop(z);
2447
+
2448
+ function calcTotal(x, y, z) {
2449
+ const rec = n => (n >= 0 ? x * y ** n-- + rec(n) : 0);
2450
+ return rec(z + 1);
2451
+ }
2452
+ return { gData, total: calcTotal(x, y, z) };
2453
+ }
2454
+
2455
+ onGen() {
2456
+ const { gData, total } = this.generateData();
2457
+ this.setState({
2458
+ gData,
2459
+ total
2460
+ });
2461
+ };
2462
+
2463
+ onScroll(scrollKey, align) {
2464
+ this.treeRef?.current.scrollTo({ key: scrollKey, align});
2465
+ }
2466
+
2467
+ onInputChange(value) {
2468
+ this.setState({
2469
+ scrollKey: value,
2470
+ })
2471
+ }
2472
+
2473
+ onInputBlur(e) {
2474
+ const { value } = e.target;
2475
+ this.onScroll(value, this.state.align);
2476
+ }
2477
+
2478
+ onSelectChange(align){
2479
+ this.setState({
2480
+ align: align,
2481
+ })
2482
+ this.onScroll(this.state.scrollKey, align);
2483
+ }
2484
+
2485
+ render() {
2486
+ const style = {
2487
+ width: 260,
2488
+ border: '1px solid var(--semi-color-border)'
2489
+ };
2490
+ return (
2491
+ <div style={{ padding: '0 20px' }}>
2492
+ <Button onClick={this.onGen}>生成数据: </Button>
2493
+ <span>共 {this.state.total} 个节点</span>
2494
+ <br/>
2495
+ <br/>
2496
+ <div style={{ display: 'flex', alignItems: 'center', }}>
2497
+ <span>defaultExpandAll</span>
2498
+ <Switch onChange={(value) => {
2499
+ this.setState({
2500
+ expandAll: value,
2501
+ })
2502
+ }}/>
2503
+ </div>
2504
+ <br/>
2505
+ <span>跳转的key:</span>
2506
+ <Input
2507
+ placeholder={'格式:x-x-key'}
2508
+ style={{ width: 180, marginRight: 20 }}
2509
+ onChange={this.onInputChange}
2510
+ onBlur={this.onInputBlur}
2511
+ ></Input>
2512
+ <span>scroll align:</span>
2513
+ <Select
2514
+ defaultValue='center'
2515
+ style={{ width: 180 }}
2516
+ optionList={['center', 'start', 'end', 'smart', 'auto'].map(item => ({
2517
+ value: item,
2518
+ label: item,
2519
+ }))}
2520
+ onChange={this.onSelectChange}
2521
+ >
2522
+ </Select>
2523
+ <br />
2524
+ <br />
2525
+ {this.state.gData.length ? (
2526
+ <Tree
2527
+ key={`key-${this.state.expandAll}`}
2528
+ ref={this.treeRef}
2529
+ defaultExpandAll={this.state.expandAll}
2530
+ treeData={this.state.gData}
2531
+ filterTreeNode
2532
+ showFilteredOnly
2533
+ style={style}
2534
+ virtualize={{
2535
+ // if set height for tree, it will fill 100%
2536
+ height: 300,
2537
+ itemSize: 28,
2538
+ }}
2539
+ />
2540
+ ) : null}
2541
+ </div>
2542
+ );
2543
+ }
2544
+ }
2545
+
2546
+ export const virtualizeTree = () => <DemoV />;
2547
+
2548
+ virtualizeTree.story = {
2549
+ name: 'virtualize tree',
2550
+ };
package/tree/index.tsx CHANGED
@@ -39,7 +39,8 @@ import {
39
39
  TreeNodeData,
40
40
  FlattenNode,
41
41
  KeyEntity,
42
- OptionProps
42
+ OptionProps,
43
+ ScrollData,
43
44
  } from './interface';
44
45
  import CheckboxGroup from '../checkbox/checkboxGroup';
45
46
 
@@ -146,6 +147,7 @@ class Tree extends BaseComponent<TreeProps, TreeState> {
146
147
  onNodeClick: any;
147
148
  onMotionEnd: any;
148
149
  context: ContextValue;
150
+ virtualizedListRef: React.RefObject<any>;
149
151
 
150
152
  constructor(props: TreeProps) {
151
153
  super(props);
@@ -179,6 +181,7 @@ class Tree extends BaseComponent<TreeProps, TreeState> {
179
181
  this.optionsRef = React.createRef();
180
182
  this.foundation = new TreeFoundation(this.adapter);
181
183
  this.dragNode = null;
184
+ this.virtualizedListRef = React.createRef();
182
185
  }
183
186
 
184
187
  /**
@@ -493,6 +496,17 @@ class Tree extends BaseComponent<TreeProps, TreeState> {
493
496
  this.foundation.handleInputChange(value);
494
497
  };
495
498
 
499
+ scrollTo = (scrollData: ScrollData) => {
500
+ const { key, align = 'center' } = scrollData;
501
+ const { flattenNodes } = this.state;
502
+ if (key) {
503
+ const index = flattenNodes?.findIndex((node) => {
504
+ return node.key === key;
505
+ });
506
+ index >= 0 && (this.virtualizedListRef.current as any)?.scrollToItem(index, align);
507
+ }
508
+ }
509
+
496
510
  renderInput() {
497
511
  const {
498
512
  searchClassName,
@@ -664,6 +678,7 @@ class Tree extends BaseComponent<TreeProps, TreeState> {
664
678
  <AutoSizer defaultHeight={virtualize.height} defaultWidth={virtualize.width}>
665
679
  {({ height, width }: { width: string | number; height: string | number }) => (
666
680
  <VirtualList
681
+ ref={this.virtualizedListRef}
667
682
  itemCount={flattenNodes.length}
668
683
  itemSize={virtualize.itemSize}
669
684
  height={height}
package/tree/interface.ts CHANGED
@@ -140,3 +140,9 @@ export interface NodeListState {
140
140
  cachedMotionKeys?: Set<string>;
141
141
  cachedData?: FlattenNode[];
142
142
  }
143
+
144
+ export interface ScrollData {
145
+ key: string;
146
+ // The align parameter is consistent with react-window
147
+ align?: 'center' | 'start' | 'end' | 'smart' | 'auto';
148
+ }
@@ -311,7 +311,7 @@ DefaultFileList.story = {
311
311
  name: 'defaultFileList',
312
312
  };
313
313
 
314
- class ControledUpload extends React.Component {
314
+ class ControlledUpload extends React.Component {
315
315
  constructor(props) {
316
316
  super(props);
317
317
  this.state = {
@@ -344,7 +344,7 @@ class ControledUpload extends React.Component {
344
344
  }
345
345
  }
346
346
 
347
- export const ControlledFileList = () => <ControledUpload></ControledUpload>;
347
+ export const ControlledFileList = () => <ControlledUpload></ControlledUpload>;
348
348
 
349
349
  ControlledFileList.story = {
350
350
  name: 'controlled fileList',
package/webpack.config.js CHANGED
@@ -22,6 +22,7 @@ module.exports = function ({ minimize }) {
22
22
  library: 'SemiUI',
23
23
  libraryTarget: 'umd'
24
24
  },
25
+
25
26
  module: {
26
27
  rules: [
27
28
  {
@@ -45,7 +46,7 @@ module.exports = function ({ minimize }) {
45
46
  }
46
47
  ]
47
48
  },
48
- {
49
+ {
49
50
  test: /semi-icons\/.+\.css$/,
50
51
  loaders: 'null-loader'
51
52
  },
@@ -66,7 +67,14 @@ module.exports = function ({ minimize }) {
66
67
  new HashedModuleIdsPlugin()
67
68
  ],
68
69
  resolve: {
69
- extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
70
+ extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
71
+ alias: {
72
+ "@douyinfe/semi-foundation": path.resolve(__dirname, "../semi-foundation"),
73
+ "@douyinfe/semi-icons": path.resolve(__dirname, "../semi-icons"),
74
+ "@douyinfe/semi-illustrations":path.resolve(__dirname, "../semi-illustrations"),
75
+ "@douyinfe/semi-animation":path.resolve(__dirname, "../semi-animation"),
76
+ "@douyinfe/semi-animation-react":path.resolve(__dirname, "../semi-animation-react")
77
+ },
70
78
  },
71
79
  externals: {
72
80
  react: {