@douyinfe/semi-ui 2.9.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 (47) hide show
  1. package/banner/_story/banner.stories.js +62 -1
  2. package/banner/index.tsx +5 -5
  3. package/carousel/CarouselArrow.tsx +62 -0
  4. package/carousel/CarouselIndicator.tsx +84 -0
  5. package/carousel/__test__/carousel.test.js +159 -0
  6. package/carousel/_story/carousel.stories.js +486 -0
  7. package/carousel/index.tsx +294 -0
  8. package/carousel/interface.ts +64 -0
  9. package/cascader/index.tsx +1 -2
  10. package/dist/css/semi.css +342 -0
  11. package/dist/css/semi.min.css +1 -1
  12. package/dist/umd/semi-ui.js +884 -66
  13. package/dist/umd/semi-ui.js.map +1 -1
  14. package/dist/umd/semi-ui.min.js +1 -1
  15. package/dist/umd/semi-ui.min.js.map +1 -1
  16. package/index.ts +2 -0
  17. package/lib/cjs/banner/index.js +11 -5
  18. package/lib/cjs/carousel/CarouselArrow.d.ts +8 -0
  19. package/lib/cjs/carousel/CarouselArrow.js +91 -0
  20. package/lib/cjs/carousel/CarouselIndicator.d.ts +23 -0
  21. package/lib/cjs/carousel/CarouselIndicator.js +145 -0
  22. package/lib/cjs/carousel/index.d.ts +58 -0
  23. package/lib/cjs/carousel/index.js +345 -0
  24. package/lib/cjs/carousel/interface.d.ts +62 -0
  25. package/lib/cjs/carousel/interface.js +7 -0
  26. package/lib/cjs/cascader/index.js +1 -1
  27. package/lib/cjs/index.d.ts +1 -0
  28. package/lib/cjs/index.js +9 -0
  29. package/lib/cjs/switch/index.d.ts +3 -0
  30. package/lib/cjs/switch/index.js +26 -6
  31. package/lib/es/banner/index.js +11 -5
  32. package/lib/es/carousel/CarouselArrow.d.ts +8 -0
  33. package/lib/es/carousel/CarouselArrow.js +72 -0
  34. package/lib/es/carousel/CarouselIndicator.d.ts +23 -0
  35. package/lib/es/carousel/CarouselIndicator.js +125 -0
  36. package/lib/es/carousel/index.d.ts +58 -0
  37. package/lib/es/carousel/index.js +311 -0
  38. package/lib/es/carousel/interface.d.ts +62 -0
  39. package/lib/es/carousel/interface.js +1 -0
  40. package/lib/es/cascader/index.js +1 -1
  41. package/lib/es/index.d.ts +1 -0
  42. package/lib/es/index.js +1 -0
  43. package/lib/es/switch/index.d.ts +3 -0
  44. package/lib/es/switch/index.js +26 -6
  45. package/package.json +9 -9
  46. package/switch/index.tsx +20 -3
  47. package/tagInput/__test__/tagInput.test.js +11 -11
@@ -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
+ }
@@ -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
  }