@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.
- package/anchor/__test__/anchor.test.js +1 -0
- package/anchor/_story/anchor.stories.js +23 -1
- package/badge/_story/badge.stories.js +34 -2
- package/banner/_story/banner.stories.js +62 -1
- package/banner/index.tsx +5 -5
- package/carousel/CarouselArrow.tsx +62 -0
- package/carousel/CarouselIndicator.tsx +84 -0
- package/carousel/__test__/carousel.test.js +159 -0
- package/carousel/_story/carousel.stories.js +486 -0
- package/carousel/index.tsx +294 -0
- package/carousel/interface.ts +64 -0
- package/cascader/_story/cascader.stories.js +17 -2
- package/cascader/index.tsx +2 -3
- package/checkbox/_story/checkbox.stories.js +1 -1
- package/collapse/item.tsx +2 -0
- package/datePicker/_story/datePicker.stories.js +37 -0
- package/dist/css/semi.css +344 -2
- package/dist/css/semi.min.css +1 -1
- package/dist/umd/semi-ui.js +1068 -330
- package/dist/umd/semi-ui.js.map +1 -1
- package/dist/umd/semi-ui.min.js +1 -1
- package/dist/umd/semi-ui.min.js.map +1 -1
- package/form/hoc/withField.tsx +8 -5
- package/index.ts +2 -0
- package/input/__test__/input.test.js +12 -3
- package/input/__test__/textArea.test.js +53 -0
- package/lib/cjs/banner/index.js +11 -5
- package/lib/cjs/carousel/CarouselArrow.d.ts +8 -0
- package/lib/cjs/carousel/CarouselArrow.js +91 -0
- package/lib/cjs/carousel/CarouselIndicator.d.ts +23 -0
- package/lib/cjs/carousel/CarouselIndicator.js +145 -0
- package/lib/cjs/carousel/index.d.ts +58 -0
- package/lib/cjs/carousel/index.js +345 -0
- package/lib/cjs/carousel/interface.d.ts +62 -0
- package/lib/cjs/carousel/interface.js +7 -0
- package/lib/cjs/cascader/index.js +2 -2
- package/lib/cjs/collapse/item.js +4 -2
- package/lib/cjs/form/hoc/withField.js +6 -4
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +9 -0
- package/lib/cjs/modal/Modal.js +3 -0
- package/lib/cjs/scrollList/scrollItem.js +5 -1
- package/lib/cjs/switch/index.d.ts +3 -0
- package/lib/cjs/switch/index.js +26 -6
- package/lib/cjs/tabs/TabPane.js +4 -0
- package/lib/cjs/tabs/index.js +2 -0
- package/lib/cjs/toast/toast.d.ts +1 -1
- package/lib/cjs/tooltip/index.js +1 -1
- package/lib/cjs/transfer/index.d.ts +1 -0
- package/lib/cjs/transfer/index.js +3 -1
- package/lib/es/banner/index.js +11 -5
- package/lib/es/carousel/CarouselArrow.d.ts +8 -0
- package/lib/es/carousel/CarouselArrow.js +72 -0
- package/lib/es/carousel/CarouselIndicator.d.ts +23 -0
- package/lib/es/carousel/CarouselIndicator.js +125 -0
- package/lib/es/carousel/index.d.ts +58 -0
- package/lib/es/carousel/index.js +311 -0
- package/lib/es/carousel/interface.d.ts +62 -0
- package/lib/es/carousel/interface.js +1 -0
- package/lib/es/cascader/index.js +2 -2
- package/lib/es/collapse/item.js +4 -2
- package/lib/es/form/hoc/withField.js +6 -4
- package/lib/es/index.d.ts +1 -0
- package/lib/es/index.js +1 -0
- package/lib/es/modal/Modal.js +3 -0
- package/lib/es/scrollList/scrollItem.js +5 -1
- package/lib/es/switch/index.d.ts +3 -0
- package/lib/es/switch/index.js +26 -6
- package/lib/es/tabs/TabPane.js +4 -0
- package/lib/es/tabs/index.js +2 -0
- package/lib/es/toast/toast.d.ts +1 -1
- package/lib/es/tooltip/index.js +1 -1
- package/lib/es/transfer/index.d.ts +1 -0
- package/lib/es/transfer/index.js +3 -1
- package/modal/Modal.tsx +2 -0
- package/modal/confirm.tsx +1 -1
- package/overflowList/_story/overflowList.stories.js +44 -0
- package/package.json +9 -9
- package/scrollList/_story/SingleWheelList/index.js +72 -0
- package/scrollList/_story/scrolllist.stories.js +7 -0
- package/scrollList/scrollItem.tsx +4 -1
- package/switch/index.tsx +20 -3
- package/table/__test__/table.test.js +1 -0
- package/tabs/TabPane.tsx +2 -0
- package/tabs/_story/tabs.stories.js +72 -0
- package/tabs/index.tsx +1 -0
- package/tagInput/__test__/tagInput.test.js +11 -11
- package/tagInput/_story/tagInput.stories.js +14 -1
- package/timePicker/TimePicker.tsx +1 -1
- package/timePicker/_story/timepicker.stories.js +20 -1
- package/tooltip/_story/tooltip.stories.js +127 -15
- package/tooltip/index.tsx +1 -1
- package/transfer/index.tsx +4 -1
- package/typography/__test__/typography.test.js +1 -0
- package/upload/__test__/upload.test.js +2 -0
- package/upload/_story/upload.stories.js +2 -2
package/lib/cjs/toast/toast.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ declare class Toast extends BaseComponent<ToastReactProps, ToastState> {
|
|
|
41
41
|
close(e: React.MouseEvent): void;
|
|
42
42
|
clearCloseTimer: () => void;
|
|
43
43
|
startCloseTimer: () => void;
|
|
44
|
-
renderIcon(): true | React.
|
|
44
|
+
renderIcon(): string | number | true | React.ReactElement<any, string | React.JSXElementConstructor<any>> | React.ReactFragment;
|
|
45
45
|
render(): JSX.Element;
|
|
46
46
|
}
|
|
47
47
|
export default Toast;
|
package/lib/cjs/tooltip/index.js
CHANGED
|
@@ -258,7 +258,7 @@ class Tooltip extends _baseComponent.default {
|
|
|
258
258
|
}, portalEventSet, {
|
|
259
259
|
"x-placement": placement,
|
|
260
260
|
style: (0, _assign.default)({
|
|
261
|
-
visibility: motion ?
|
|
261
|
+
visibility: motion ? 'hidden' : 'visible'
|
|
262
262
|
}, style)
|
|
263
263
|
}), contentNode, icon);
|
|
264
264
|
return /*#__PURE__*/_react.default.createElement(_index.default, {
|
|
@@ -296,7 +296,8 @@ class Transfer extends _baseComponent.default {
|
|
|
296
296
|
loading,
|
|
297
297
|
type,
|
|
298
298
|
emptyContent,
|
|
299
|
-
renderSourcePanel
|
|
299
|
+
renderSourcePanel,
|
|
300
|
+
dataSource
|
|
300
301
|
} = this.props;
|
|
301
302
|
const totalToken = locale.total;
|
|
302
303
|
const inSearchMode = inputValue !== '';
|
|
@@ -356,6 +357,7 @@ class Transfer extends _baseComponent.default {
|
|
|
356
357
|
noMatch,
|
|
357
358
|
filterData,
|
|
358
359
|
sourceData: data,
|
|
360
|
+
propsDataSource: dataSource,
|
|
359
361
|
allChecked: !leftContainesNotInSelected,
|
|
360
362
|
showNumber,
|
|
361
363
|
inputValue,
|
package/lib/es/banner/index.js
CHANGED
|
@@ -67,7 +67,9 @@ export default class Banner extends BaseComponent {
|
|
|
67
67
|
const closer = /*#__PURE__*/React.createElement(Button, {
|
|
68
68
|
className: "".concat(prefixCls, "-close"),
|
|
69
69
|
onClick: this.remove,
|
|
70
|
-
icon: closeIcon || /*#__PURE__*/React.createElement(IconClose,
|
|
70
|
+
icon: closeIcon || /*#__PURE__*/React.createElement(IconClose, {
|
|
71
|
+
"aria-hidden": true
|
|
72
|
+
}),
|
|
71
73
|
theme: "borderless",
|
|
72
74
|
size: "small",
|
|
73
75
|
type: "tertiary",
|
|
@@ -83,16 +85,20 @@ export default class Banner extends BaseComponent {
|
|
|
83
85
|
} = this.props;
|
|
84
86
|
const iconMap = {
|
|
85
87
|
warning: /*#__PURE__*/React.createElement(IconAlertTriangle, {
|
|
86
|
-
size: "large"
|
|
88
|
+
size: "large",
|
|
89
|
+
"aria-label": 'warning'
|
|
87
90
|
}),
|
|
88
91
|
success: /*#__PURE__*/React.createElement(IconTickCircle, {
|
|
89
|
-
size: "large"
|
|
92
|
+
size: "large",
|
|
93
|
+
"aria-label": 'success'
|
|
90
94
|
}),
|
|
91
95
|
info: /*#__PURE__*/React.createElement(IconInfoCircle, {
|
|
92
|
-
size: "large"
|
|
96
|
+
size: "large",
|
|
97
|
+
"aria-label": 'info'
|
|
93
98
|
}),
|
|
94
99
|
danger: /*#__PURE__*/React.createElement(IconAlertCircle, {
|
|
95
|
-
size: "large"
|
|
100
|
+
size: "large",
|
|
101
|
+
"aria-label": 'danger'
|
|
96
102
|
})
|
|
97
103
|
};
|
|
98
104
|
let iconType = iconMap[type];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import { CarouselArrowProps } from "./interface";
|
|
3
|
+
declare class CarouselArrow extends React.PureComponent<CarouselArrowProps> {
|
|
4
|
+
renderLeftIcon: () => any;
|
|
5
|
+
renderRightIcon: () => any;
|
|
6
|
+
render(): ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export default CarouselArrow;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import _throttle from "lodash/throttle";
|
|
2
|
+
import _get from "lodash/get";
|
|
3
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
4
|
+
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
5
|
+
|
|
6
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
7
|
+
|
|
8
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
9
|
+
import React from "react";
|
|
10
|
+
import cls from 'classnames';
|
|
11
|
+
import { cssClasses } from '@douyinfe/semi-foundation/lib/es/carousel/constants';
|
|
12
|
+
import { IconChevronLeft, IconChevronRight } from "@douyinfe/semi-icons";
|
|
13
|
+
|
|
14
|
+
class CarouselArrow extends React.PureComponent {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
|
|
18
|
+
this.renderLeftIcon = () => {
|
|
19
|
+
return _get(this.props, 'arrowProps.leftArrow.children', /*#__PURE__*/React.createElement(IconChevronLeft, {
|
|
20
|
+
"aria-label": "Previous index",
|
|
21
|
+
size: "inherit"
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
this.renderRightIcon = () => {
|
|
26
|
+
return _get(this.props, 'arrowProps.rightArrow.children', /*#__PURE__*/React.createElement(IconChevronRight, {
|
|
27
|
+
"aria-label": "Next index",
|
|
28
|
+
size: "inherit"
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
render() {
|
|
34
|
+
var _context, _context2, _context3;
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
type,
|
|
38
|
+
theme,
|
|
39
|
+
prev,
|
|
40
|
+
next,
|
|
41
|
+
timing
|
|
42
|
+
} = this.props;
|
|
43
|
+
const classNames = cls({
|
|
44
|
+
[cssClasses.CAROUSEL_ARROW]: true,
|
|
45
|
+
[_concatInstanceProperty(_context = "".concat(cssClasses.CAROUSEL_ARROW, "-")).call(_context, theme)]: theme,
|
|
46
|
+
["".concat(cssClasses.CAROUSEL_ARROW, "-hover")]: type === 'hover'
|
|
47
|
+
});
|
|
48
|
+
const leftClassNames = cls({
|
|
49
|
+
["".concat(cssClasses.CAROUSEL_ARROW, "-prev")]: true,
|
|
50
|
+
[_concatInstanceProperty(_context2 = "".concat(cssClasses.CAROUSEL_ARROW, "-")).call(_context2, theme)]: theme
|
|
51
|
+
});
|
|
52
|
+
const rightClassNames = cls({
|
|
53
|
+
["".concat(cssClasses.CAROUSEL_ARROW, "-next")]: true,
|
|
54
|
+
[_concatInstanceProperty(_context3 = "".concat(cssClasses.CAROUSEL_ARROW, "-")).call(_context3, theme)]: theme
|
|
55
|
+
});
|
|
56
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
57
|
+
className: classNames
|
|
58
|
+
}, /*#__PURE__*/React.createElement("div", _Object$assign({
|
|
59
|
+
// role='button'
|
|
60
|
+
className: leftClassNames,
|
|
61
|
+
onClick: _throttle(prev, timing)
|
|
62
|
+
}, _get(this.props, 'arrowProps.leftArrow.props')), this.renderLeftIcon()), /*#__PURE__*/React.createElement("div", _Object$assign({
|
|
63
|
+
// role='button'
|
|
64
|
+
// tabIndex={0}
|
|
65
|
+
className: rightClassNames,
|
|
66
|
+
onClick: _throttle(next, timing)
|
|
67
|
+
}, _get(this.props, 'arrowProps.rightArrow.props')), this.renderRightIcon()));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default CarouselArrow;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { CarouselIndicatorProps } from "./interface";
|
|
4
|
+
declare class CarouselIndicator extends React.PureComponent<CarouselIndicatorProps> {
|
|
5
|
+
static propTypes: {
|
|
6
|
+
activeKey: PropTypes.Requireable<number>;
|
|
7
|
+
className: PropTypes.Requireable<string>;
|
|
8
|
+
position: PropTypes.Requireable<"left" | "right" | "center">;
|
|
9
|
+
size: PropTypes.Requireable<"small" | "medium">;
|
|
10
|
+
style: PropTypes.Requireable<object>;
|
|
11
|
+
theme: PropTypes.Requireable<"primary" | "dark" | "light">;
|
|
12
|
+
total: PropTypes.Requireable<number>;
|
|
13
|
+
onIndicatorChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
14
|
+
type: PropTypes.Requireable<"line" | "dot" | "columnar">;
|
|
15
|
+
trigger: PropTypes.Requireable<"hover" | "click">;
|
|
16
|
+
};
|
|
17
|
+
onIndicatorChange: (activeIndex: number) => void;
|
|
18
|
+
handleIndicatorClick: (activeIndex: number) => void;
|
|
19
|
+
handleIndicatorHover: (activeIndex: number) => void;
|
|
20
|
+
renderIndicatorContent(): ReactNode;
|
|
21
|
+
render(): ReactNode;
|
|
22
|
+
}
|
|
23
|
+
export default CarouselIndicator;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import _indexOfInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/index-of";
|
|
2
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
4
|
+
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
5
|
+
|
|
6
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
7
|
+
var t = {};
|
|
8
|
+
|
|
9
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && _indexOfInstanceProperty(e).call(e, p) < 0) t[p] = s[p];
|
|
10
|
+
|
|
11
|
+
if (s != null && typeof _Object$getOwnPropertySymbols === "function") for (var i = 0, p = _Object$getOwnPropertySymbols(s); i < p.length; i++) {
|
|
12
|
+
if (_indexOfInstanceProperty(e).call(e, p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
13
|
+
}
|
|
14
|
+
return t;
|
|
15
|
+
};
|
|
16
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
17
|
+
|
|
18
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
import React from "react";
|
|
22
|
+
import cls from 'classnames';
|
|
23
|
+
import PropTypes from 'prop-types';
|
|
24
|
+
import { cssClasses, strings } from '@douyinfe/semi-foundation/lib/es/carousel/constants';
|
|
25
|
+
import getDataAttr from '@douyinfe/semi-foundation/lib/es/utils/getDataAttr';
|
|
26
|
+
|
|
27
|
+
class CarouselIndicator extends React.PureComponent {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
|
|
31
|
+
this.onIndicatorChange = activeIndex => {
|
|
32
|
+
this.props.onIndicatorChange(activeIndex);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
this.handleIndicatorClick = activeIndex => {
|
|
36
|
+
const {
|
|
37
|
+
trigger
|
|
38
|
+
} = this.props;
|
|
39
|
+
|
|
40
|
+
if (trigger === 'click') {
|
|
41
|
+
this.onIndicatorChange(activeIndex);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
this.handleIndicatorHover = activeIndex => {
|
|
46
|
+
const {
|
|
47
|
+
trigger
|
|
48
|
+
} = this.props;
|
|
49
|
+
|
|
50
|
+
if (trigger === 'hover') {
|
|
51
|
+
this.onIndicatorChange(activeIndex);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
renderIndicatorContent() {
|
|
57
|
+
const {
|
|
58
|
+
total,
|
|
59
|
+
theme,
|
|
60
|
+
size,
|
|
61
|
+
activeIndex
|
|
62
|
+
} = this.props;
|
|
63
|
+
const indicatorContent = [];
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < total; i++) {
|
|
66
|
+
var _context, _context2;
|
|
67
|
+
|
|
68
|
+
indicatorContent.push( /*#__PURE__*/React.createElement("span", {
|
|
69
|
+
// role='none'
|
|
70
|
+
key: i,
|
|
71
|
+
"data-index": i,
|
|
72
|
+
className: cls(["".concat(cssClasses.CAROUSEL_INDICATOR, "-item")], {
|
|
73
|
+
["".concat(cssClasses.CAROUSEL_INDICATOR, "-item-active")]: i === activeIndex,
|
|
74
|
+
[_concatInstanceProperty(_context = "".concat(cssClasses.CAROUSEL_INDICATOR, "-item-")).call(_context, theme)]: theme,
|
|
75
|
+
[_concatInstanceProperty(_context2 = "".concat(cssClasses.CAROUSEL_INDICATOR, "-item-")).call(_context2, size)]: size
|
|
76
|
+
}),
|
|
77
|
+
onClick: () => this.handleIndicatorClick(i),
|
|
78
|
+
onMouseEnter: () => this.handleIndicatorHover(i)
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return indicatorContent;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
render() {
|
|
86
|
+
var _context3, _context4;
|
|
87
|
+
|
|
88
|
+
const _a = this.props,
|
|
89
|
+
{
|
|
90
|
+
type,
|
|
91
|
+
size,
|
|
92
|
+
theme,
|
|
93
|
+
style,
|
|
94
|
+
className,
|
|
95
|
+
position
|
|
96
|
+
} = _a,
|
|
97
|
+
restProps = __rest(_a, ["type", "size", "theme", "style", "className", "position"]);
|
|
98
|
+
|
|
99
|
+
const classNames = cls(className, {
|
|
100
|
+
[cssClasses.CAROUSEL_INDICATOR]: true,
|
|
101
|
+
[_concatInstanceProperty(_context3 = "".concat(cssClasses.CAROUSEL_INDICATOR, "-")).call(_context3, type)]: type,
|
|
102
|
+
[_concatInstanceProperty(_context4 = "".concat(cssClasses.CAROUSEL_INDICATOR, "-")).call(_context4, position)]: position
|
|
103
|
+
});
|
|
104
|
+
const indicatorContent = this.renderIndicatorContent();
|
|
105
|
+
return /*#__PURE__*/React.createElement("div", _Object$assign({
|
|
106
|
+
className: classNames,
|
|
107
|
+
style: style
|
|
108
|
+
}, getDataAttr(restProps)), indicatorContent);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
CarouselIndicator.propTypes = {
|
|
114
|
+
activeKey: PropTypes.number,
|
|
115
|
+
className: PropTypes.string,
|
|
116
|
+
position: PropTypes.oneOf(strings.POSITION_MAP),
|
|
117
|
+
size: PropTypes.oneOf(strings.SIZE),
|
|
118
|
+
style: PropTypes.object,
|
|
119
|
+
theme: PropTypes.oneOf(strings.THEME_MAP),
|
|
120
|
+
total: PropTypes.number,
|
|
121
|
+
onIndicatorChange: PropTypes.func,
|
|
122
|
+
type: PropTypes.oneOf(strings.TYPE_MAP),
|
|
123
|
+
trigger: PropTypes.oneOf(strings.TRIGGER)
|
|
124
|
+
};
|
|
125
|
+
export default CarouselIndicator;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ReactNode, ReactChild, ReactFragment, ReactPortal } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import BaseComponent from "../_base/baseComponent";
|
|
4
|
+
import { CarouselProps } from './interface';
|
|
5
|
+
import CarouselFoundation, { CarouselAdapter } from '@douyinfe/semi-foundation/lib/es/carousel/foundation';
|
|
6
|
+
import '@douyinfe/semi-foundation/lib/es/carousel/carousel.css';
|
|
7
|
+
export interface CarouselState {
|
|
8
|
+
activeIndex: number;
|
|
9
|
+
children: (ReactChild | ReactFragment | ReactPortal)[];
|
|
10
|
+
preIndex: number;
|
|
11
|
+
isReverse: boolean;
|
|
12
|
+
isInit: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare class Carousel extends BaseComponent<CarouselProps, CarouselState> {
|
|
15
|
+
static propTypes: {
|
|
16
|
+
activeIndex: PropTypes.Requireable<number>;
|
|
17
|
+
animation: PropTypes.Requireable<"slide" | "fade">;
|
|
18
|
+
arrowProps: PropTypes.Requireable<object>;
|
|
19
|
+
autoPlay: PropTypes.Requireable<boolean | object>;
|
|
20
|
+
className: PropTypes.Requireable<string>;
|
|
21
|
+
defaultActiveIndex: PropTypes.Requireable<number>;
|
|
22
|
+
indicatorPosition: PropTypes.Requireable<"left" | "right" | "center">;
|
|
23
|
+
indicatorSize: PropTypes.Requireable<"small" | "medium">;
|
|
24
|
+
indicatorType: PropTypes.Requireable<"line" | "dot" | "columnar">;
|
|
25
|
+
theme: PropTypes.Requireable<"primary" | "dark" | "light">;
|
|
26
|
+
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
27
|
+
arrowType: PropTypes.Requireable<"hover" | "always">;
|
|
28
|
+
showArrow: PropTypes.Requireable<boolean>;
|
|
29
|
+
showIndicator: PropTypes.Requireable<boolean>;
|
|
30
|
+
slideDirection: PropTypes.Requireable<"left" | "right">;
|
|
31
|
+
speed: PropTypes.Requireable<number>;
|
|
32
|
+
style: PropTypes.Requireable<object>;
|
|
33
|
+
trigger: PropTypes.Requireable<"hover" | "click">;
|
|
34
|
+
};
|
|
35
|
+
static defaultProps: CarouselProps;
|
|
36
|
+
foundation: CarouselFoundation;
|
|
37
|
+
constructor(props: CarouselProps);
|
|
38
|
+
get adapter(): CarouselAdapter<CarouselProps, CarouselState>;
|
|
39
|
+
static getDerivedStateFromProps(props: CarouselProps, state: CarouselState): Partial<CarouselState>;
|
|
40
|
+
componentDidMount(): void;
|
|
41
|
+
componentWillUnmount(): void;
|
|
42
|
+
play: () => void;
|
|
43
|
+
stop: () => void;
|
|
44
|
+
goTo: (targetIndex: number) => void;
|
|
45
|
+
prev: () => void;
|
|
46
|
+
next: () => void;
|
|
47
|
+
handleAutoPlay: () => void;
|
|
48
|
+
handleMouseEnter: () => void;
|
|
49
|
+
handleMouseLeave: () => void;
|
|
50
|
+
onIndicatorChange: (activeIndex: number) => void;
|
|
51
|
+
getChildren: () => (ReactChild | ReactFragment | ReactPortal)[];
|
|
52
|
+
getValidIndex: (activeIndex: number) => number;
|
|
53
|
+
renderChildren: () => JSX.Element;
|
|
54
|
+
renderIndicator: () => JSX.Element;
|
|
55
|
+
renderArrow: () => JSX.Element;
|
|
56
|
+
render(): ReactNode;
|
|
57
|
+
}
|
|
58
|
+
export default Carousel;
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import _debounce from "lodash/debounce";
|
|
2
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
3
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
4
|
+
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
5
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
6
|
+
|
|
7
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
8
|
+
import React, { Children } from 'react';
|
|
9
|
+
import cls from 'classnames';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
import BaseComponent from "../_base/baseComponent";
|
|
12
|
+
import { cssClasses, numbers, strings } from '@douyinfe/semi-foundation/lib/es/carousel/constants';
|
|
13
|
+
import CarouselFoundation from '@douyinfe/semi-foundation/lib/es/carousel/foundation';
|
|
14
|
+
import CarouselIndicator from './CarouselIndicator';
|
|
15
|
+
import CarouselArrow from './CarouselArrow';
|
|
16
|
+
import '@douyinfe/semi-foundation/lib/es/carousel/carousel.css';
|
|
17
|
+
import isNullOrUndefined from '@douyinfe/semi-foundation/lib/es/utils/isNullOrUndefined';
|
|
18
|
+
|
|
19
|
+
class Carousel extends BaseComponent {
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(props);
|
|
22
|
+
|
|
23
|
+
this.play = () => {
|
|
24
|
+
return this.foundation.handleAutoPlay();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
this.stop = () => {
|
|
28
|
+
return this.foundation.stop();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
this.goTo = targetIndex => {
|
|
32
|
+
return this.foundation.goTo(targetIndex);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
this.prev = () => {
|
|
36
|
+
return this.foundation.prev();
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
this.next = () => {
|
|
40
|
+
return this.foundation.next();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
this.handleAutoPlay = () => {
|
|
44
|
+
if (!this.foundation.getIsControledComponent()) {
|
|
45
|
+
this.foundation.handleAutoPlay();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
this.handleMouseEnter = () => {
|
|
50
|
+
const {
|
|
51
|
+
autoPlay
|
|
52
|
+
} = this.props;
|
|
53
|
+
|
|
54
|
+
if (typeof autoPlay !== 'object' || autoPlay.hoverToPause) {
|
|
55
|
+
this.foundation.stop();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
this.handleMouseLeave = () => {
|
|
60
|
+
const {
|
|
61
|
+
autoPlay
|
|
62
|
+
} = this.props;
|
|
63
|
+
|
|
64
|
+
if ((typeof autoPlay !== 'object' || autoPlay.hoverToPause) && !this.foundation.getIsControledComponent()) {
|
|
65
|
+
this.foundation.handleAutoPlay();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
this.onIndicatorChange = activeIndex => {
|
|
70
|
+
return this.foundation.throttleChange(activeIndex);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
this.getChildren = () => {
|
|
74
|
+
var _context;
|
|
75
|
+
|
|
76
|
+
const {
|
|
77
|
+
children: originChildren
|
|
78
|
+
} = this.props;
|
|
79
|
+
return _filterInstanceProperty(_context = Children.toArray(originChildren)).call(_context, child => {
|
|
80
|
+
return /*#__PURE__*/React.isValidElement(child);
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
this.getValidIndex = activeIndex => {
|
|
85
|
+
return this.foundation.getValidIndex(activeIndex);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
this.renderChildren = () => {
|
|
89
|
+
const {
|
|
90
|
+
speed,
|
|
91
|
+
animation
|
|
92
|
+
} = this.props;
|
|
93
|
+
const {
|
|
94
|
+
activeIndex,
|
|
95
|
+
children,
|
|
96
|
+
preIndex,
|
|
97
|
+
isInit
|
|
98
|
+
} = this.state;
|
|
99
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, _mapInstanceProperty(children).call(children, (child, index) => {
|
|
100
|
+
const isCurrent = index === activeIndex;
|
|
101
|
+
const isPrev = index === this.getValidIndex(activeIndex - 1);
|
|
102
|
+
const isNext = index === this.getValidIndex(activeIndex + 1);
|
|
103
|
+
const animateStyle = {
|
|
104
|
+
transitionTimingFunction: 'ease',
|
|
105
|
+
transitionDuration: "".concat(speed, "ms"),
|
|
106
|
+
animationTimingFunction: 'ease',
|
|
107
|
+
animationDuration: "".concat(speed, "ms")
|
|
108
|
+
};
|
|
109
|
+
return /*#__PURE__*/React.cloneElement(child, {
|
|
110
|
+
style: _Object$assign(_Object$assign({}, child.props.style), animateStyle),
|
|
111
|
+
className: cls(child.props.className, {
|
|
112
|
+
["".concat(cssClasses.CAROUSEL_CONTENT, "-item-prev")]: isPrev,
|
|
113
|
+
["".concat(cssClasses.CAROUSEL_CONTENT, "-item-next")]: isNext,
|
|
114
|
+
["".concat(cssClasses.CAROUSEL_CONTENT, "-item-current")]: isCurrent,
|
|
115
|
+
["".concat(cssClasses.CAROUSEL_CONTENT, "-item")]: true,
|
|
116
|
+
["".concat(cssClasses.CAROUSEL_CONTENT, "-item-active")]: isCurrent,
|
|
117
|
+
["".concat(cssClasses.CAROUSEL_CONTENT, "-item-slide-in")]: animation === 'slide' && !isInit && isCurrent,
|
|
118
|
+
["".concat(cssClasses.CAROUSEL_CONTENT, "-item-slide-out")]: animation === 'slide' && !isInit && index === preIndex
|
|
119
|
+
})
|
|
120
|
+
});
|
|
121
|
+
}));
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
this.renderIndicator = () => {
|
|
125
|
+
const {
|
|
126
|
+
children,
|
|
127
|
+
activeIndex
|
|
128
|
+
} = this.state;
|
|
129
|
+
const {
|
|
130
|
+
showIndicator,
|
|
131
|
+
indicatorType,
|
|
132
|
+
theme,
|
|
133
|
+
indicatorPosition,
|
|
134
|
+
indicatorSize,
|
|
135
|
+
trigger
|
|
136
|
+
} = this.props;
|
|
137
|
+
const carouselIndicatorCls = cls({
|
|
138
|
+
[cssClasses.CAROUSEL_INDICATOR]: true
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
if (showIndicator && children.length > 1) {
|
|
142
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
143
|
+
className: carouselIndicatorCls
|
|
144
|
+
}, /*#__PURE__*/React.createElement(CarouselIndicator, {
|
|
145
|
+
type: indicatorType,
|
|
146
|
+
total: children.length,
|
|
147
|
+
activeIndex: activeIndex,
|
|
148
|
+
position: indicatorPosition,
|
|
149
|
+
trigger: trigger,
|
|
150
|
+
size: indicatorSize,
|
|
151
|
+
theme: theme,
|
|
152
|
+
onIndicatorChange: this.onIndicatorChange
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return null;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
this.renderArrow = () => {
|
|
160
|
+
const {
|
|
161
|
+
children
|
|
162
|
+
} = this.state;
|
|
163
|
+
const {
|
|
164
|
+
showArrow,
|
|
165
|
+
arrowType,
|
|
166
|
+
theme,
|
|
167
|
+
arrowProps
|
|
168
|
+
} = this.props;
|
|
169
|
+
const timing = this.foundation.getSwitchingTime();
|
|
170
|
+
|
|
171
|
+
if (showArrow && children.length > 1) {
|
|
172
|
+
return /*#__PURE__*/React.createElement(CarouselArrow, {
|
|
173
|
+
type: arrowType,
|
|
174
|
+
theme: theme,
|
|
175
|
+
prev: this.prev,
|
|
176
|
+
next: this.next,
|
|
177
|
+
timing: timing,
|
|
178
|
+
arrowProps: arrowProps
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return null;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
this.foundation = new CarouselFoundation(this.adapter);
|
|
186
|
+
const defaultActiveIndex = this.foundation.getDefaultActiveIndex();
|
|
187
|
+
this.state = {
|
|
188
|
+
activeIndex: defaultActiveIndex,
|
|
189
|
+
children: this.getChildren(),
|
|
190
|
+
preIndex: defaultActiveIndex,
|
|
191
|
+
isReverse: false,
|
|
192
|
+
isInit: true
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
get adapter() {
|
|
197
|
+
return _Object$assign(_Object$assign({}, super.adapter), {
|
|
198
|
+
notifyChange: (activeIndex, preIndex) => {
|
|
199
|
+
this.props.onChange(activeIndex, preIndex);
|
|
200
|
+
},
|
|
201
|
+
setNewActiveIndex: activeIndex => {
|
|
202
|
+
this.setState({
|
|
203
|
+
activeIndex
|
|
204
|
+
});
|
|
205
|
+
},
|
|
206
|
+
setPreActiveIndex: preIndex => {
|
|
207
|
+
this.setState({
|
|
208
|
+
preIndex
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
setIsReverse: isReverse => {
|
|
212
|
+
this.setState({
|
|
213
|
+
isReverse
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
setIsInit: isInit => {
|
|
217
|
+
this.setState({
|
|
218
|
+
isInit
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static getDerivedStateFromProps(props, state) {
|
|
225
|
+
const states = {};
|
|
226
|
+
|
|
227
|
+
if (!isNullOrUndefined(props.activeIndex) && props.activeIndex !== state.activeIndex) {
|
|
228
|
+
states.activeIndex = props.activeIndex;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return states;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
componentDidMount() {
|
|
235
|
+
this.handleAutoPlay();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
componentWillUnmount() {
|
|
239
|
+
this.foundation.destroy();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
render() {
|
|
243
|
+
var _context2;
|
|
244
|
+
|
|
245
|
+
const {
|
|
246
|
+
animation,
|
|
247
|
+
className,
|
|
248
|
+
style,
|
|
249
|
+
slideDirection
|
|
250
|
+
} = this.props;
|
|
251
|
+
const {
|
|
252
|
+
isReverse
|
|
253
|
+
} = this.state;
|
|
254
|
+
const carouselWrapperCls = cls(className, {
|
|
255
|
+
[cssClasses.CAROUSEL]: true
|
|
256
|
+
});
|
|
257
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
258
|
+
// role='listbox'
|
|
259
|
+
// tabIndex={0}
|
|
260
|
+
className: carouselWrapperCls,
|
|
261
|
+
style: style,
|
|
262
|
+
onMouseEnter: _debounce(this.handleMouseEnter, 400),
|
|
263
|
+
onMouseLeave: _debounce(this.handleMouseLeave, 400)
|
|
264
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
265
|
+
className: cls([_concatInstanceProperty(_context2 = "".concat(cssClasses.CAROUSEL_CONTENT, "-")).call(_context2, animation)], {
|
|
266
|
+
["".concat(cssClasses.CAROUSEL_CONTENT)]: true,
|
|
267
|
+
["".concat(cssClasses.CAROUSEL_CONTENT, "-reverse")]: slideDirection === 'left' ? isReverse : !isReverse
|
|
268
|
+
})
|
|
269
|
+
}, this.renderChildren()), this.renderIndicator(), this.renderArrow());
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
Carousel.propTypes = {
|
|
275
|
+
activeIndex: PropTypes.number,
|
|
276
|
+
animation: PropTypes.oneOf(strings.ANIMATION_MAP),
|
|
277
|
+
arrowProps: PropTypes.object,
|
|
278
|
+
autoPlay: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
|
|
279
|
+
className: PropTypes.string,
|
|
280
|
+
defaultActiveIndex: PropTypes.number,
|
|
281
|
+
indicatorPosition: PropTypes.oneOf(strings.POSITION_MAP),
|
|
282
|
+
indicatorSize: PropTypes.oneOf(strings.SIZE),
|
|
283
|
+
indicatorType: PropTypes.oneOf(strings.TYPE_MAP),
|
|
284
|
+
theme: PropTypes.oneOf(strings.THEME_MAP),
|
|
285
|
+
onChange: PropTypes.func,
|
|
286
|
+
arrowType: PropTypes.oneOf(strings.ARROW_MAP),
|
|
287
|
+
showArrow: PropTypes.bool,
|
|
288
|
+
showIndicator: PropTypes.bool,
|
|
289
|
+
slideDirection: PropTypes.oneOf(strings.DIRECTION),
|
|
290
|
+
speed: PropTypes.number,
|
|
291
|
+
style: PropTypes.object,
|
|
292
|
+
trigger: PropTypes.oneOf(strings.TRIGGER)
|
|
293
|
+
};
|
|
294
|
+
Carousel.defaultProps = {
|
|
295
|
+
children: [],
|
|
296
|
+
animation: 'slide',
|
|
297
|
+
autoPlay: true,
|
|
298
|
+
arrowType: 'always',
|
|
299
|
+
defaultActiveIndex: numbers.DEFAULT_ACTIVE_INDEX,
|
|
300
|
+
indicatorPosition: 'center',
|
|
301
|
+
indicatorSize: 'small',
|
|
302
|
+
indicatorType: 'dot',
|
|
303
|
+
theme: 'light',
|
|
304
|
+
onChange: () => undefined,
|
|
305
|
+
showArrow: true,
|
|
306
|
+
showIndicator: true,
|
|
307
|
+
slideDirection: 'left',
|
|
308
|
+
speed: numbers.DEFAULT_SPEED,
|
|
309
|
+
trigger: 'click'
|
|
310
|
+
};
|
|
311
|
+
export default Carousel;
|