@douyinfe/semi-ui 2.9.1 → 2.10.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/banner/_story/banner.stories.js +62 -1
- package/banner/index.tsx +5 -5
- package/button/buttonGroup.tsx +2 -2
- package/carousel/CarouselArrow.tsx +62 -0
- package/carousel/CarouselIndicator.tsx +83 -0
- package/carousel/__test__/carousel.test.js +159 -0
- package/carousel/_story/carousel.stories.js +486 -0
- package/carousel/index.tsx +292 -0
- package/carousel/interface.ts +63 -0
- package/cascader/index.tsx +1 -2
- package/datePicker/monthsGrid.tsx +8 -8
- package/dist/css/semi.css +342 -0
- package/dist/css/semi.min.css +1 -1
- package/dist/umd/semi-ui.js +1238 -266
- 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/baseForm.tsx +10 -1
- package/form/hoc/withField.tsx +17 -5
- package/index.ts +2 -0
- package/inputNumber/__test__/inputNumber.test.js +40 -3
- package/inputNumber/_story/inputNumber.stories.js +56 -1
- package/inputNumber/index.tsx +22 -14
- package/lib/cjs/banner/index.js +11 -5
- package/lib/cjs/button/buttonGroup.d.ts +1 -1
- package/lib/cjs/carousel/CarouselArrow.d.ts +8 -0
- package/lib/cjs/carousel/CarouselArrow.js +88 -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 +343 -0
- package/lib/cjs/carousel/interface.d.ts +61 -0
- package/lib/cjs/carousel/interface.js +7 -0
- package/lib/cjs/cascader/index.js +1 -1
- package/lib/cjs/datePicker/monthsGrid.js +6 -6
- package/lib/cjs/form/baseForm.d.ts +1 -0
- package/lib/cjs/form/baseForm.js +10 -1
- package/lib/cjs/form/hoc/withField.js +8 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +9 -0
- package/lib/cjs/inputNumber/index.d.ts +2 -6
- package/lib/cjs/inputNumber/index.js +27 -11
- package/lib/cjs/switch/index.d.ts +3 -0
- package/lib/cjs/switch/index.js +26 -6
- package/lib/cjs/transfer/index.js +5 -5
- package/lib/cjs/treeSelect/index.js +1 -1
- package/lib/es/banner/index.js +11 -5
- package/lib/es/button/buttonGroup.d.ts +1 -1
- package/lib/es/carousel/CarouselArrow.d.ts +8 -0
- package/lib/es/carousel/CarouselArrow.js +70 -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 +309 -0
- package/lib/es/carousel/interface.d.ts +61 -0
- package/lib/es/carousel/interface.js +1 -0
- package/lib/es/cascader/index.js +1 -1
- package/lib/es/datePicker/monthsGrid.js +7 -7
- package/lib/es/form/baseForm.d.ts +1 -0
- package/lib/es/form/baseForm.js +10 -1
- package/lib/es/form/hoc/withField.js +8 -1
- package/lib/es/index.d.ts +1 -0
- package/lib/es/index.js +1 -0
- package/lib/es/inputNumber/index.d.ts +2 -6
- package/lib/es/inputNumber/index.js +26 -11
- package/lib/es/switch/index.d.ts +3 -0
- package/lib/es/switch/index.js +26 -6
- package/lib/es/transfer/index.js +1 -1
- package/lib/es/treeSelect/index.js +1 -1
- package/package.json +9 -9
- package/switch/index.tsx +20 -3
- package/tagInput/__test__/tagInput.test.js +11 -11
- package/transfer/index.tsx +1 -1
- package/treeSelect/index.tsx +1 -1
|
@@ -26,6 +26,7 @@ export interface SwitchProps {
|
|
|
26
26
|
export interface SwitchState {
|
|
27
27
|
nativeControlChecked: boolean;
|
|
28
28
|
nativeControlDisabled: boolean;
|
|
29
|
+
focusVisible: boolean;
|
|
29
30
|
}
|
|
30
31
|
declare class Switch extends BaseComponent<SwitchProps, SwitchState> {
|
|
31
32
|
static propTypes: {
|
|
@@ -55,6 +56,8 @@ declare class Switch extends BaseComponent<SwitchProps, SwitchState> {
|
|
|
55
56
|
componentDidUpdate(prevProps: SwitchProps): void;
|
|
56
57
|
componentWillUnmount(): void;
|
|
57
58
|
get adapter(): SwitchAdapter<SwitchProps, SwitchState>;
|
|
59
|
+
handleFocusVisible: (event: React.FocusEvent) => void;
|
|
60
|
+
handleBlur: (event: React.FocusEvent) => void;
|
|
58
61
|
render(): JSX.Element;
|
|
59
62
|
}
|
|
60
63
|
export default Switch;
|
package/lib/cjs/switch/index.js
CHANGED
|
@@ -30,13 +30,23 @@ require("@douyinfe/semi-foundation/lib/cjs/switch/switch.css");
|
|
|
30
30
|
|
|
31
31
|
var _spin = _interopRequireDefault(require("../spin"));
|
|
32
32
|
|
|
33
|
-
/* eslint-disable max-len
|
|
33
|
+
/* eslint-disable max-len */
|
|
34
34
|
class Switch extends _baseComponent.default {
|
|
35
35
|
constructor(props) {
|
|
36
36
|
super(props);
|
|
37
|
+
|
|
38
|
+
this.handleFocusVisible = event => {
|
|
39
|
+
this.foundation.handleFocusVisible(event);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
this.handleBlur = event => {
|
|
43
|
+
this.foundation.handleBlur();
|
|
44
|
+
};
|
|
45
|
+
|
|
37
46
|
this.state = {
|
|
38
47
|
nativeControlChecked: false,
|
|
39
|
-
nativeControlDisabled: false
|
|
48
|
+
nativeControlDisabled: false,
|
|
49
|
+
focusVisible: false
|
|
40
50
|
};
|
|
41
51
|
this.switchRef = /*#__PURE__*/_react.default.createRef();
|
|
42
52
|
this.foundation = new _foundation.default(this.adapter);
|
|
@@ -72,6 +82,11 @@ class Switch extends _baseComponent.default {
|
|
|
72
82
|
nativeControlDisabled
|
|
73
83
|
});
|
|
74
84
|
},
|
|
85
|
+
setFocusVisible: focusVisible => {
|
|
86
|
+
this.setState({
|
|
87
|
+
focusVisible
|
|
88
|
+
});
|
|
89
|
+
},
|
|
75
90
|
notifyChange: (checked, e) => {
|
|
76
91
|
this.props.onChange(checked, e);
|
|
77
92
|
}
|
|
@@ -81,7 +96,8 @@ class Switch extends _baseComponent.default {
|
|
|
81
96
|
render() {
|
|
82
97
|
const {
|
|
83
98
|
nativeControlChecked,
|
|
84
|
-
nativeControlDisabled
|
|
99
|
+
nativeControlDisabled,
|
|
100
|
+
focusVisible
|
|
85
101
|
} = this.state;
|
|
86
102
|
const {
|
|
87
103
|
className,
|
|
@@ -100,11 +116,11 @@ class Switch extends _baseComponent.default {
|
|
|
100
116
|
[_constants.cssClasses.DISABLED]: nativeControlDisabled,
|
|
101
117
|
[_constants.cssClasses.LARGE]: size === 'large',
|
|
102
118
|
[_constants.cssClasses.SMALL]: size === 'small',
|
|
103
|
-
[_constants.cssClasses.LOADING]: loading
|
|
119
|
+
[_constants.cssClasses.LOADING]: loading,
|
|
120
|
+
[_constants.cssClasses.FOCUS]: focusVisible
|
|
104
121
|
});
|
|
105
122
|
const switchProps = {
|
|
106
123
|
type: 'checkbox',
|
|
107
|
-
role: 'switch',
|
|
108
124
|
className: _constants.cssClasses.NATIVE_CONTROL,
|
|
109
125
|
disabled: nativeControlDisabled || loading,
|
|
110
126
|
checked: nativeControlChecked || false
|
|
@@ -129,13 +145,17 @@ class Switch extends _baseComponent.default {
|
|
|
129
145
|
}, uncheckedText) : null, /*#__PURE__*/_react.default.createElement("input", (0, _assign.default)({}, switchProps, {
|
|
130
146
|
ref: this.switchRef,
|
|
131
147
|
id: id,
|
|
148
|
+
role: 'switch',
|
|
132
149
|
"aria-checked": nativeControlChecked,
|
|
133
150
|
"aria-invalid": this.props['aria-invalid'],
|
|
134
151
|
"aria-errormessage": this.props['aria-errormessage'],
|
|
135
152
|
"aria-label": this.props['aria-label'],
|
|
136
153
|
"aria-labelledby": this.props['aria-labelledby'],
|
|
137
154
|
"aria-describedby": this.props["aria-describedby"],
|
|
138
|
-
|
|
155
|
+
"aria-disabled": this.props['disabled'],
|
|
156
|
+
onChange: e => this.foundation.handleChange(e.target.checked, e),
|
|
157
|
+
onFocus: e => this.handleFocusVisible(e),
|
|
158
|
+
onBlur: e => this.handleBlur(e)
|
|
139
159
|
})));
|
|
140
160
|
}
|
|
141
161
|
|
|
@@ -52,7 +52,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
52
52
|
|
|
53
53
|
var _foundation = _interopRequireDefault(require("@douyinfe/semi-foundation/lib/cjs/transfer/foundation"));
|
|
54
54
|
|
|
55
|
-
var
|
|
55
|
+
var _transferUtils = require("@douyinfe/semi-foundation/lib/cjs/transfer/transferUtils");
|
|
56
56
|
|
|
57
57
|
var _constants = require("@douyinfe/semi-foundation/lib/cjs/transfer/constants");
|
|
58
58
|
|
|
@@ -98,13 +98,13 @@ class Transfer extends _baseComponent.default {
|
|
|
98
98
|
if (Boolean(dataSource) && (0, _isArray3.default)(dataSource)) {
|
|
99
99
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
100
100
|
// @ts-ignore Avoid reporting errors this.state.xxx is read-only
|
|
101
|
-
this.state.data = (0,
|
|
101
|
+
this.state.data = (0, _transferUtils._generateDataByType)(dataSource, type);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
if (Boolean(defaultValue) && (0, _isArray3.default)(defaultValue)) {
|
|
105
105
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
106
106
|
// @ts-ignore Avoid reporting errors this.state.xxx is read-only
|
|
107
|
-
this.state.selectedItems = (0,
|
|
107
|
+
this.state.selectedItems = (0, _transferUtils._generateSelectedItems)(defaultValue, this.state.data);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
this.onSelectOrRemove = (0, _bind.default)(_context = this.onSelectOrRemove).call(_context, this);
|
|
@@ -124,12 +124,12 @@ class Transfer extends _baseComponent.default {
|
|
|
124
124
|
let newSelectedItems = state.selectedItems;
|
|
125
125
|
|
|
126
126
|
if (Boolean(dataSource) && (0, _isArray2.default)(dataSource)) {
|
|
127
|
-
newData = (0,
|
|
127
|
+
newData = (0, _transferUtils._generateDataByType)(dataSource, type);
|
|
128
128
|
mergedState.data = newData;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
if (Boolean(value) && (0, _isArray2.default)(value)) {
|
|
132
|
-
newSelectedItems = (0,
|
|
132
|
+
newSelectedItems = (0, _transferUtils._generateSelectedItems)(value, newData);
|
|
133
133
|
mergedState.selectedItems = newSelectedItems;
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -101,7 +101,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "functi
|
|
|
101
101
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
102
102
|
|
|
103
103
|
const prefixcls = _constants.cssClasses.PREFIX;
|
|
104
|
-
const prefixTree = _constants.cssClasses.
|
|
104
|
+
const prefixTree = _constants.cssClasses.PREFIX_TREE;
|
|
105
105
|
const key = 0;
|
|
106
106
|
|
|
107
107
|
class TreeSelect extends _baseComponent.default {
|
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];
|
|
@@ -10,7 +10,7 @@ export interface ButtonGroupProps extends BaseProps {
|
|
|
10
10
|
size?: Size;
|
|
11
11
|
theme?: Theme;
|
|
12
12
|
className?: string;
|
|
13
|
-
children?: React.
|
|
13
|
+
children?: React.ReactNode;
|
|
14
14
|
'aria-label'?: React.AriaAttributes['aria-label'];
|
|
15
15
|
}
|
|
16
16
|
export default class ButtonGroup extends BaseComponent<ButtonGroupProps> {
|
|
@@ -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,70 @@
|
|
|
1
|
+
import _get from "lodash/get";
|
|
2
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
3
|
+
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
4
|
+
|
|
5
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
6
|
+
|
|
7
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
8
|
+
import React from "react";
|
|
9
|
+
import cls from 'classnames';
|
|
10
|
+
import { cssClasses } from '@douyinfe/semi-foundation/lib/es/carousel/constants';
|
|
11
|
+
import { IconChevronLeft, IconChevronRight } from "@douyinfe/semi-icons";
|
|
12
|
+
|
|
13
|
+
class CarouselArrow extends React.PureComponent {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
|
|
17
|
+
this.renderLeftIcon = () => {
|
|
18
|
+
return _get(this.props, 'arrowProps.leftArrow.children', /*#__PURE__*/React.createElement(IconChevronLeft, {
|
|
19
|
+
"aria-label": "Previous index",
|
|
20
|
+
size: "inherit"
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
this.renderRightIcon = () => {
|
|
25
|
+
return _get(this.props, 'arrowProps.rightArrow.children', /*#__PURE__*/React.createElement(IconChevronRight, {
|
|
26
|
+
"aria-label": "Next index",
|
|
27
|
+
size: "inherit"
|
|
28
|
+
}));
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
render() {
|
|
33
|
+
var _context, _context2, _context3;
|
|
34
|
+
|
|
35
|
+
const {
|
|
36
|
+
type,
|
|
37
|
+
theme,
|
|
38
|
+
prev,
|
|
39
|
+
next
|
|
40
|
+
} = this.props;
|
|
41
|
+
const classNames = cls({
|
|
42
|
+
[cssClasses.CAROUSEL_ARROW]: true,
|
|
43
|
+
[_concatInstanceProperty(_context = "".concat(cssClasses.CAROUSEL_ARROW, "-")).call(_context, theme)]: theme,
|
|
44
|
+
["".concat(cssClasses.CAROUSEL_ARROW, "-hover")]: type === 'hover'
|
|
45
|
+
});
|
|
46
|
+
const leftClassNames = cls({
|
|
47
|
+
["".concat(cssClasses.CAROUSEL_ARROW, "-prev")]: true,
|
|
48
|
+
[_concatInstanceProperty(_context2 = "".concat(cssClasses.CAROUSEL_ARROW, "-")).call(_context2, theme)]: theme
|
|
49
|
+
});
|
|
50
|
+
const rightClassNames = cls({
|
|
51
|
+
["".concat(cssClasses.CAROUSEL_ARROW, "-next")]: true,
|
|
52
|
+
[_concatInstanceProperty(_context3 = "".concat(cssClasses.CAROUSEL_ARROW, "-")).call(_context3, theme)]: theme
|
|
53
|
+
});
|
|
54
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
55
|
+
className: classNames
|
|
56
|
+
}, /*#__PURE__*/React.createElement("div", _Object$assign({
|
|
57
|
+
// role='button'
|
|
58
|
+
className: leftClassNames,
|
|
59
|
+
onClick: prev
|
|
60
|
+
}, _get(this.props, 'arrowProps.leftArrow.props')), this.renderLeftIcon()), /*#__PURE__*/React.createElement("div", _Object$assign({
|
|
61
|
+
// role='button'
|
|
62
|
+
// tabIndex={0}
|
|
63
|
+
className: rightClassNames,
|
|
64
|
+
onClick: next
|
|
65
|
+
}, _get(this.props, 'arrowProps.rightArrow.props')), this.renderRightIcon()));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
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;
|