@douyinfe/semi-ui 2.9.0-beta.1 → 2.10.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/anchor/__test__/anchor.test.js +1 -0
  2. package/anchor/_story/anchor.stories.js +23 -1
  3. package/badge/_story/badge.stories.js +34 -2
  4. package/banner/_story/banner.stories.js +62 -1
  5. package/banner/index.tsx +5 -5
  6. package/carousel/CarouselArrow.tsx +62 -0
  7. package/carousel/CarouselIndicator.tsx +84 -0
  8. package/carousel/__test__/carousel.test.js +159 -0
  9. package/carousel/_story/carousel.stories.js +486 -0
  10. package/carousel/index.tsx +294 -0
  11. package/carousel/interface.ts +64 -0
  12. package/cascader/_story/cascader.stories.js +17 -2
  13. package/cascader/index.tsx +2 -3
  14. package/checkbox/_story/checkbox.stories.js +1 -1
  15. package/collapse/item.tsx +2 -0
  16. package/datePicker/_story/datePicker.stories.js +37 -0
  17. package/dist/css/semi.css +344 -2
  18. package/dist/css/semi.min.css +1 -1
  19. package/dist/umd/semi-ui.js +1068 -330
  20. package/dist/umd/semi-ui.js.map +1 -1
  21. package/dist/umd/semi-ui.min.js +1 -1
  22. package/dist/umd/semi-ui.min.js.map +1 -1
  23. package/form/hoc/withField.tsx +8 -5
  24. package/index.ts +2 -0
  25. package/input/__test__/input.test.js +12 -3
  26. package/input/__test__/textArea.test.js +53 -0
  27. package/lib/cjs/banner/index.js +11 -5
  28. package/lib/cjs/carousel/CarouselArrow.d.ts +8 -0
  29. package/lib/cjs/carousel/CarouselArrow.js +91 -0
  30. package/lib/cjs/carousel/CarouselIndicator.d.ts +23 -0
  31. package/lib/cjs/carousel/CarouselIndicator.js +145 -0
  32. package/lib/cjs/carousel/index.d.ts +58 -0
  33. package/lib/cjs/carousel/index.js +345 -0
  34. package/lib/cjs/carousel/interface.d.ts +62 -0
  35. package/lib/cjs/carousel/interface.js +7 -0
  36. package/lib/cjs/cascader/index.js +2 -2
  37. package/lib/cjs/collapse/item.js +4 -2
  38. package/lib/cjs/form/hoc/withField.js +6 -4
  39. package/lib/cjs/index.d.ts +1 -0
  40. package/lib/cjs/index.js +9 -0
  41. package/lib/cjs/modal/Modal.js +3 -0
  42. package/lib/cjs/scrollList/scrollItem.js +5 -1
  43. package/lib/cjs/switch/index.d.ts +3 -0
  44. package/lib/cjs/switch/index.js +26 -6
  45. package/lib/cjs/tabs/TabPane.js +4 -0
  46. package/lib/cjs/tabs/index.js +2 -0
  47. package/lib/cjs/toast/toast.d.ts +1 -1
  48. package/lib/cjs/tooltip/index.js +1 -1
  49. package/lib/cjs/transfer/index.d.ts +1 -0
  50. package/lib/cjs/transfer/index.js +3 -1
  51. package/lib/es/banner/index.js +11 -5
  52. package/lib/es/carousel/CarouselArrow.d.ts +8 -0
  53. package/lib/es/carousel/CarouselArrow.js +72 -0
  54. package/lib/es/carousel/CarouselIndicator.d.ts +23 -0
  55. package/lib/es/carousel/CarouselIndicator.js +125 -0
  56. package/lib/es/carousel/index.d.ts +58 -0
  57. package/lib/es/carousel/index.js +311 -0
  58. package/lib/es/carousel/interface.d.ts +62 -0
  59. package/lib/es/carousel/interface.js +1 -0
  60. package/lib/es/cascader/index.js +2 -2
  61. package/lib/es/collapse/item.js +4 -2
  62. package/lib/es/form/hoc/withField.js +6 -4
  63. package/lib/es/index.d.ts +1 -0
  64. package/lib/es/index.js +1 -0
  65. package/lib/es/modal/Modal.js +3 -0
  66. package/lib/es/scrollList/scrollItem.js +5 -1
  67. package/lib/es/switch/index.d.ts +3 -0
  68. package/lib/es/switch/index.js +26 -6
  69. package/lib/es/tabs/TabPane.js +4 -0
  70. package/lib/es/tabs/index.js +2 -0
  71. package/lib/es/toast/toast.d.ts +1 -1
  72. package/lib/es/tooltip/index.js +1 -1
  73. package/lib/es/transfer/index.d.ts +1 -0
  74. package/lib/es/transfer/index.js +3 -1
  75. package/modal/Modal.tsx +2 -0
  76. package/modal/confirm.tsx +1 -1
  77. package/overflowList/_story/overflowList.stories.js +44 -0
  78. package/package.json +9 -9
  79. package/scrollList/_story/SingleWheelList/index.js +72 -0
  80. package/scrollList/_story/scrolllist.stories.js +7 -0
  81. package/scrollList/scrollItem.tsx +4 -1
  82. package/switch/index.tsx +20 -3
  83. package/table/__test__/table.test.js +1 -0
  84. package/tabs/TabPane.tsx +2 -0
  85. package/tabs/_story/tabs.stories.js +72 -0
  86. package/tabs/index.tsx +1 -0
  87. package/tagInput/__test__/tagInput.test.js +11 -11
  88. package/tagInput/_story/tagInput.stories.js +14 -1
  89. package/timePicker/TimePicker.tsx +1 -1
  90. package/timePicker/_story/timepicker.stories.js +20 -1
  91. package/tooltip/_story/tooltip.stories.js +127 -15
  92. package/tooltip/index.tsx +1 -1
  93. package/transfer/index.tsx +4 -1
  94. package/typography/__test__/typography.test.js +1 -0
  95. package/upload/__test__/upload.test.js +2 -0
  96. package/upload/_story/upload.stories.js +2 -2
@@ -0,0 +1,294 @@
1
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
2
+ import React, { ReactNode, Children, ReactChild, ReactFragment, ReactPortal } from 'react';
3
+ import cls from 'classnames';
4
+ import PropTypes from 'prop-types';
5
+ import BaseComponent from "../_base/baseComponent";
6
+ import { CarouselProps } from './interface';
7
+ import { cssClasses, numbers, strings } from '@douyinfe/semi-foundation/carousel/constants';
8
+ import CarouselFoundation, { CarouselAdapter } from '@douyinfe/semi-foundation/carousel/foundation';
9
+ import CarouselIndicator from './CarouselIndicator';
10
+ import CarouselArrow from './CarouselArrow';
11
+ import '@douyinfe/semi-foundation/carousel/carousel.scss';
12
+ import { debounce } from 'lodash';
13
+ import isNullOrUndefined from '@douyinfe/semi-foundation/utils/isNullOrUndefined';
14
+
15
+ export interface CarouselState {
16
+ activeIndex: number;
17
+ children: (ReactChild | ReactFragment | ReactPortal)[];
18
+ preIndex: number;
19
+ isReverse: boolean;
20
+ isInit: boolean;
21
+ }
22
+
23
+ class Carousel extends BaseComponent<CarouselProps, CarouselState> {
24
+ static propTypes = {
25
+ activeIndex: PropTypes.number,
26
+ animation:PropTypes.oneOf(strings.ANIMATION_MAP),
27
+ arrowProps: PropTypes.object,
28
+ autoPlay: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
29
+ className: PropTypes.string,
30
+ defaultActiveIndex: PropTypes.number,
31
+ indicatorPosition: PropTypes.oneOf(strings.POSITION_MAP),
32
+ indicatorSize: PropTypes.oneOf(strings.SIZE),
33
+ indicatorType: PropTypes.oneOf(strings.TYPE_MAP),
34
+ theme: PropTypes.oneOf(strings.THEME_MAP),
35
+ onChange: PropTypes.func,
36
+ arrowType: PropTypes.oneOf(strings.ARROW_MAP),
37
+ showArrow: PropTypes.bool,
38
+ showIndicator: PropTypes.bool,
39
+ slideDirection: PropTypes.oneOf(strings.DIRECTION),
40
+ speed: PropTypes.number,
41
+ style: PropTypes.object,
42
+ trigger: PropTypes.oneOf(strings.TRIGGER)
43
+ };
44
+
45
+ static defaultProps: CarouselProps = {
46
+ children: [],
47
+ animation: 'slide',
48
+ autoPlay: true,
49
+ arrowType: 'always',
50
+ defaultActiveIndex: numbers.DEFAULT_ACTIVE_INDEX,
51
+ indicatorPosition: 'center',
52
+ indicatorSize: 'small',
53
+ indicatorType: 'dot',
54
+ theme: 'light',
55
+ onChange: () => undefined,
56
+ showArrow: true,
57
+ showIndicator: true,
58
+ slideDirection: 'left',
59
+ speed: numbers.DEFAULT_SPEED,
60
+ trigger: 'click'
61
+ };
62
+
63
+ foundation: CarouselFoundation;
64
+
65
+ constructor(props: CarouselProps) {
66
+ super(props);
67
+
68
+ this.foundation = new CarouselFoundation(this.adapter);
69
+ const defaultActiveIndex = this.foundation.getDefaultActiveIndex();
70
+
71
+ this.state = {
72
+ activeIndex: defaultActiveIndex,
73
+ children: this.getChildren(),
74
+ preIndex: defaultActiveIndex,
75
+ isReverse: false,
76
+ isInit: true
77
+ };
78
+ }
79
+
80
+ get adapter(): CarouselAdapter<CarouselProps, CarouselState> {
81
+ return {
82
+ ...super.adapter,
83
+ notifyChange: (activeIndex: number, preIndex: number): void => {
84
+ this.props.onChange(activeIndex, preIndex);
85
+ },
86
+ setNewActiveIndex: (activeIndex: number): void => {
87
+ this.setState({ activeIndex });
88
+ },
89
+ setPreActiveIndex: (preIndex: number): void => {
90
+ this.setState({ preIndex });
91
+ },
92
+ setIsReverse: (isReverse: boolean): void => {
93
+ this.setState({ isReverse });
94
+ },
95
+ setIsInit: (isInit: boolean): void => {
96
+ this.setState({ isInit });
97
+ }
98
+ };
99
+ }
100
+
101
+ static getDerivedStateFromProps(props: CarouselProps, state: CarouselState): Partial<CarouselState> {
102
+ const states: Partial<CarouselState> = {};
103
+ if (!isNullOrUndefined(props.activeIndex) && props.activeIndex !== state.activeIndex) {
104
+ states.activeIndex = props.activeIndex;
105
+ }
106
+ return states;
107
+ }
108
+
109
+ componentDidMount(): void {
110
+ this.handleAutoPlay();
111
+ }
112
+
113
+ componentWillUnmount(): void {
114
+ this.foundation.destroy();
115
+ }
116
+
117
+ play = (): void => {
118
+ return this.foundation.handleAutoPlay();
119
+ }
120
+
121
+ stop = (): void => {
122
+ return this.foundation.stop();
123
+ };
124
+
125
+ goTo = ( targetIndex: number): void => {
126
+ return this.foundation.goTo(targetIndex);
127
+ };
128
+
129
+ prev = (): void => {
130
+ return this.foundation.prev();
131
+ };
132
+
133
+ next = (): void => {
134
+ return this.foundation.next();
135
+ };
136
+
137
+ handleAutoPlay = (): void => {
138
+ if (!this.foundation.getIsControledComponent()){
139
+ this.foundation.handleAutoPlay();
140
+ }
141
+ }
142
+
143
+ handleMouseEnter = (): void => {
144
+ const { autoPlay } = this.props;
145
+ if (typeof autoPlay !== 'object' || autoPlay.hoverToPause){
146
+ this.foundation.stop();
147
+ }
148
+ }
149
+
150
+ handleMouseLeave = (): void => {
151
+ const { autoPlay } = this.props;
152
+ if ((typeof autoPlay !== 'object' || autoPlay.hoverToPause) && !this.foundation.getIsControledComponent()){
153
+ this.foundation.handleAutoPlay();
154
+ }
155
+ }
156
+
157
+ onIndicatorChange = (activeIndex: number): void => {
158
+ return this.foundation.throttleChange(activeIndex);
159
+ };
160
+
161
+ getChildren = (): (ReactChild | ReactFragment | ReactPortal)[] => {
162
+ const { children: originChildren } = this.props;
163
+ return Children.toArray(originChildren).filter(child=>{
164
+ return React.isValidElement(child);
165
+ });
166
+ }
167
+
168
+ getValidIndex = (activeIndex: number): number => {
169
+ return this.foundation.getValidIndex(activeIndex);
170
+ };
171
+
172
+
173
+ renderChildren = () => {
174
+ const { speed, animation } = this.props;
175
+ const { activeIndex, children, preIndex, isInit } = this.state;
176
+
177
+ return (
178
+ <>
179
+ {children.map((child: any, index: number) => {
180
+ const isCurrent = index === activeIndex;
181
+ const isPrev = index === this.getValidIndex(activeIndex - 1);
182
+ const isNext = index === this.getValidIndex(activeIndex + 1);
183
+
184
+ const animateStyle = {
185
+ transitionTimingFunction: 'ease',
186
+ transitionDuration: `${speed}ms`,
187
+ animationTimingFunction: 'ease',
188
+ animationDuration: `${speed}ms`,
189
+ };
190
+
191
+ return React.cloneElement(child, {
192
+ style: {
193
+ ...child.props.style,
194
+ ...animateStyle,
195
+ },
196
+ className: cls(child.props.className, {
197
+ [`${cssClasses.CAROUSEL_CONTENT}-item-prev`]: isPrev,
198
+ [`${cssClasses.CAROUSEL_CONTENT}-item-next`]: isNext,
199
+ [`${cssClasses.CAROUSEL_CONTENT}-item-current`]: isCurrent,
200
+ [`${cssClasses.CAROUSEL_CONTENT}-item`]: true,
201
+ [`${cssClasses.CAROUSEL_CONTENT}-item-active`]: isCurrent,
202
+ [`${cssClasses.CAROUSEL_CONTENT}-item-slide-in`]:animation === 'slide' && !isInit && isCurrent,
203
+ [`${cssClasses.CAROUSEL_CONTENT}-item-slide-out`]:animation === 'slide' && !isInit && index === preIndex,
204
+ })
205
+ });
206
+ })}
207
+ </>
208
+ );
209
+ }
210
+
211
+ renderIndicator = () => {
212
+ const { children, activeIndex } = this.state;
213
+ const { showIndicator, indicatorType, theme, indicatorPosition, indicatorSize, trigger } = this.props;
214
+
215
+ const carouselIndicatorCls = cls({
216
+ [cssClasses.CAROUSEL_INDICATOR]: true
217
+ });
218
+
219
+ if (showIndicator && children.length > 1){
220
+ return (
221
+ <div className={carouselIndicatorCls}>
222
+ <CarouselIndicator
223
+ type={indicatorType}
224
+ total={children.length}
225
+ activeIndex={activeIndex}
226
+ position={indicatorPosition}
227
+ trigger={trigger}
228
+ size={indicatorSize}
229
+ theme={theme}
230
+ onIndicatorChange={this.onIndicatorChange}
231
+ />
232
+ </div>
233
+ );
234
+ }
235
+ return null;
236
+ }
237
+
238
+ renderArrow = () => {
239
+ const { children } = this.state;
240
+ const { showArrow, arrowType, theme, arrowProps } = this.props;
241
+ const timing = this.foundation.getSwitchingTime();
242
+
243
+ if (showArrow && children.length > 1){
244
+ return (
245
+ <CarouselArrow
246
+ type={arrowType}
247
+ theme={theme}
248
+ prev={this.prev}
249
+ next={this.next}
250
+ timing={timing}
251
+ arrowProps={arrowProps}
252
+ />
253
+ );
254
+ }
255
+ return null;
256
+ };
257
+
258
+
259
+ render(): ReactNode {
260
+ const { animation, className, style, slideDirection } = this.props;
261
+ const { isReverse } = this.state;
262
+
263
+ const carouselWrapperCls = cls(className, {
264
+ [cssClasses.CAROUSEL]: true
265
+ });
266
+
267
+ return (
268
+ <div
269
+ // role='listbox'
270
+ // tabIndex={0}
271
+ className={carouselWrapperCls}
272
+ style={style}
273
+ onMouseEnter={debounce(this.handleMouseEnter, 400)}
274
+ onMouseLeave={debounce(this.handleMouseLeave, 400)}
275
+ // onMouseEnter={this.handleMouseEnter}
276
+ // onMouseLeave={this.handleMouseLeave}
277
+ // onKeyDown={e => this.foundation.handleKeyDown(e)}
278
+ >
279
+ <div
280
+ className={cls([`${cssClasses.CAROUSEL_CONTENT}-${animation}`], {
281
+ [`${cssClasses.CAROUSEL_CONTENT}`]: true,
282
+ [`${cssClasses.CAROUSEL_CONTENT}-reverse`]: slideDirection === 'left' ? isReverse : !isReverse,
283
+ })}
284
+ >
285
+ {this.renderChildren()}
286
+ </div>
287
+ {this.renderIndicator()}
288
+ {this.renderArrow()}
289
+ </div>
290
+ );
291
+ }
292
+ }
293
+
294
+ export default Carousel;
@@ -0,0 +1,64 @@
1
+ import React, { ReactNode } from "react";
2
+ import { strings } from '@douyinfe/semi-foundation/carousel/constants';
3
+
4
+ export interface CarouselMethod {
5
+ next?: () => void;
6
+ prev?: () => void;
7
+ goTo?: () => void;
8
+ play?: () => void;
9
+ stop?: () => void;
10
+ }
11
+
12
+ export interface CarouselProps {
13
+ activeIndex?: number;
14
+ animation?: typeof strings.ANIMATION_MAP[number];
15
+ arrowProps?: ArrowProps;
16
+ autoPlay?: boolean | {interval?: number, hoverToPause?: boolean};
17
+ arrowType?: typeof strings.ARROW_MAP[number];
18
+ children?: ReactNode | Array<ReactNode>;
19
+ className?: string;
20
+ defaultActiveIndex?: number;
21
+ indicatorPosition?: typeof strings.POSITION_MAP[number];
22
+ indicatorSize?: typeof strings.SIZE[number];
23
+ theme?: typeof strings.THEME_MAP[number];
24
+ indicatorType?: typeof strings.TYPE_MAP[number];
25
+ onChange?: (index: number, preIndex: number) => void;
26
+ showArrow?: boolean;
27
+ showIndicator?: boolean;
28
+ slideDirection?: typeof strings.DIRECTION[number];
29
+ speed?: number;
30
+ style?: React.CSSProperties;
31
+ trigger?: typeof strings.TRIGGER[number];
32
+ }
33
+
34
+ export interface CarouselIndicatorProps {
35
+ activeIndex?: number;
36
+ className?: string;
37
+ defaultActiveIndex?: number;
38
+ position?: typeof strings.POSITION_MAP[number];
39
+ size?: typeof strings.SIZE[number];
40
+ total?:number;
41
+ theme?: typeof strings.THEME_MAP[number];
42
+ type?: typeof strings.TYPE_MAP[number];
43
+ onIndicatorChange?: (activeIndex: number) => void;
44
+ style?: React.CSSProperties;
45
+ trigger?: typeof strings.TRIGGER[number];
46
+ }
47
+
48
+ export interface CarouselArrowProps {
49
+ type?: typeof strings.ARROW_MAP[number];
50
+ theme?: typeof strings.THEME_MAP[number];
51
+ prev?: () => void;
52
+ next?: () => void;
53
+ arrowProps?: ArrowProps;
54
+ timing: number;
55
+ }
56
+
57
+ export interface ArrowButton {
58
+ props?: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
59
+ children?: React.ReactNode;
60
+ }
61
+ export interface ArrowProps {
62
+ leftArrow?: ArrowButton;
63
+ rightArrow?: ArrowButton;
64
+ }
@@ -697,7 +697,8 @@ export const ShowClear = () => {
697
697
  <Cascader
698
698
  style={{ marginLeft: 700, width: 300 }}
699
699
  treeData={treeData1}
700
- placeholder="Please select"
700
+ placeholder="Please select when multiple"
701
+ multiple
701
702
  showClear
702
703
  />
703
704
  <br />
@@ -1434,4 +1435,18 @@ export const DynamicTreeData = () => {
1434
1435
  <br />
1435
1436
  </div>
1436
1437
  );
1437
- }
1438
+ }
1439
+
1440
+
1441
+ export const SuperLongList = () => {
1442
+ let treeData = new Array(100).fill().map(() => ({ label: '浙江省', value: 'zhejiang' }));
1443
+ treeData.push({ label: '到底啦', value: 'bottom' })
1444
+ return (
1445
+ <Cascader
1446
+ style={{ width: 300 }}
1447
+ treeData={treeData}
1448
+ placeholder="请选择所在地区"
1449
+ onListScroll={()=>{console.log(123)}}
1450
+ />
1451
+ );
1452
+ };
@@ -508,8 +508,7 @@ class Cascader extends BaseComponent<CascaderProps, CascaderState> {
508
508
  this.handleTagRemove(e, keyEntities[nodeKey].valuePath);
509
509
  }}
510
510
  >
511
- {displayProp === 'label' && keyEntities[nodeKey].data.label}
512
- {displayProp === 'value' && keyEntities[nodeKey].data.value}
511
+ {keyEntities[nodeKey].data[displayProp]}
513
512
  </Tag>
514
513
  );
515
514
  }
@@ -828,7 +827,7 @@ class Cascader extends BaseComponent<CascaderProps, CascaderState> {
828
827
  */
829
828
  handleClearEnterPress = (e: KeyboardEvent) => {
830
829
  e && e.stopPropagation();
831
- this.foundation.handleClearEnterPress();
830
+ this.foundation.handleClearEnterPress(e);
832
831
  };
833
832
 
834
833
  showClearBtn = () => {
@@ -754,7 +754,7 @@ export const CheckboxGroupCardStyle = () => (
754
754
  >
755
755
  多选框标题
756
756
  </Checkbox>
757
- </CheckboxGroup> */}
757
+ </CheckboxGroup>
758
758
  </>
759
759
  );
760
760
 
package/collapse/item.tsx CHANGED
@@ -89,6 +89,8 @@ export default class CollapsePanel extends PureComponent<CollapsePanelProps> {
89
89
  children,
90
90
  itemKey,
91
91
  reCalcKey,
92
+ header,
93
+ extra,
92
94
  ...restProps
93
95
  } = this.props;
94
96
  const {
@@ -814,3 +814,40 @@ export const FixTriggerRenderClosePanel = () => {
814
814
  };
815
815
  FixTriggerRenderClosePanel.storyName = "fix triggerRender close bug"
816
816
 
817
+ export const A11yKeyboardDemo = () => {
818
+ const [value, setValue] = useState(new Date('2022-08-08 00:00'));
819
+ const [rangeValue, setRangeValue] = useState([new Date('2022-08-08 00:00'), new Date('2022-08-09 12:00')]);
820
+
821
+ const handleChange = v => {
822
+ console.log('change', v);
823
+ setValue(v);
824
+ };
825
+
826
+ const handleRangeChange = v => {
827
+ console.log('change', v);
828
+ setRangeValue(v);
829
+ };
830
+
831
+ return (
832
+ <Space vertical align='start' data-cy="space">
833
+ <div data-cy="dateRange">
834
+ <DatePicker
835
+ value={rangeValue}
836
+ type="dateRange"
837
+ onChange={handleRangeChange}
838
+ showClear
839
+ />
840
+ </div>
841
+ <div data-cy="date">
842
+ <DatePicker
843
+ onChange={handleChange}
844
+ showClear
845
+ multiple
846
+ />
847
+ </div>
848
+ </Space>
849
+ );
850
+ };
851
+
852
+ A11yKeyboardDemo.storyName = "a11y keyboard demo"
853
+