@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/form/hoc/withField.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import { Col } from '../../grid';
|
|
|
15
15
|
import { CallOpts, WithFieldOption } from '@douyinfe/semi-foundation/form/interface';
|
|
16
16
|
import { CommonFieldProps, CommonexcludeType } from '../interface';
|
|
17
17
|
import { Subtract } from 'utility-types';
|
|
18
|
+
import { noop } from "lodash";
|
|
18
19
|
|
|
19
20
|
const prefix = cssClasses.PREFIX;
|
|
20
21
|
|
|
@@ -121,6 +122,7 @@ function withField<
|
|
|
121
122
|
const [status, setStatus] = useState(validateStatus); // use props.validateStatus to init
|
|
122
123
|
|
|
123
124
|
const rulesRef = useRef(rules);
|
|
125
|
+
const validateRef = useRef(validate);
|
|
124
126
|
|
|
125
127
|
// notNotify is true means that the onChange of the Form does not need to be triggered
|
|
126
128
|
// notUpdate is true means that this operation does not need to trigger the forceUpdate
|
|
@@ -221,7 +223,7 @@ function withField<
|
|
|
221
223
|
let maybePromisedErrors;
|
|
222
224
|
// let errorThrowSync;
|
|
223
225
|
try {
|
|
224
|
-
maybePromisedErrors =
|
|
226
|
+
maybePromisedErrors = validateRef.current(val, values);
|
|
225
227
|
} catch (err) {
|
|
226
228
|
// error throw by syncValidate
|
|
227
229
|
maybePromisedErrors = err;
|
|
@@ -258,7 +260,7 @@ function withField<
|
|
|
258
260
|
if (transform) {
|
|
259
261
|
finalVal = transform(val);
|
|
260
262
|
}
|
|
261
|
-
if (
|
|
263
|
+
if (validateRef.current) {
|
|
262
264
|
return _validate(finalVal, updater.getValue(), callOpts);
|
|
263
265
|
} else if (latestRules) {
|
|
264
266
|
return _validateInternal(finalVal, callOpts);
|
|
@@ -357,7 +359,8 @@ function withField<
|
|
|
357
359
|
// avoid hooks capture value, fixed issue 346
|
|
358
360
|
useLayoutEffect(() => {
|
|
359
361
|
rulesRef.current = rules;
|
|
360
|
-
|
|
362
|
+
validateRef.current = validate;
|
|
363
|
+
}, [rules, validate]);
|
|
361
364
|
|
|
362
365
|
// exec validate once when trigger inlcude 'mount'
|
|
363
366
|
useLayoutEffect(() => {
|
|
@@ -442,11 +445,11 @@ function withField<
|
|
|
442
445
|
if (helpText) {
|
|
443
446
|
newProps['aria-describedby'] = extraText ? `${helpTextId} ${extraTextId}` : helpTextId;
|
|
444
447
|
}
|
|
445
|
-
|
|
448
|
+
|
|
446
449
|
if (extraText) {
|
|
447
450
|
newProps['aria-describedby'] = helpText ? `${helpTextId} ${extraTextId}` : extraTextId;
|
|
448
451
|
}
|
|
449
|
-
|
|
452
|
+
|
|
450
453
|
if (status === 'error') {
|
|
451
454
|
newProps['aria-errormessage'] = errorMessageId;
|
|
452
455
|
newProps['aria-invalid'] = true;
|
package/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { default as ButtonGroup } from './button/buttonGroup';
|
|
|
12
12
|
export { default as Calendar } from './calendar';
|
|
13
13
|
export { default as Card } from './card';
|
|
14
14
|
export { default as CardGroup } from './card/cardGroup';
|
|
15
|
+
export { default as Carousel } from './carousel';
|
|
15
16
|
export { default as Cascader } from './cascader';
|
|
16
17
|
export { default as Checkbox } from './checkbox';
|
|
17
18
|
export { default as CheckboxGroup } from './checkbox/checkboxGroup';
|
|
@@ -79,6 +80,7 @@ export { default as Upload } from './upload';
|
|
|
79
80
|
export { default as Typography } from './typography';
|
|
80
81
|
export { default as Transfer } from './transfer';
|
|
81
82
|
|
|
83
|
+
|
|
82
84
|
export { default as LocaleProvider } from './locale/localeProvider';
|
|
83
85
|
|
|
84
86
|
/** Form */
|
|
@@ -113,9 +113,18 @@ describe('Input', () => {
|
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
it('input password mode', () => {
|
|
116
|
-
const inputMode = mount(<Input
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
const inputMode = mount(<Input />);
|
|
117
|
+
expect(inputMode.find('input').instance().type).toEqual('text');
|
|
118
|
+
inputMode.setProps({ mode: 'password' }) ;
|
|
119
|
+
expect(inputMode.find('input').instance().type).toEqual('password');
|
|
120
|
+
inputMode.setProps({ mode: '' }) ;
|
|
121
|
+
expect(inputMode.find('input').instance().type).toEqual('text');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('input password click eyes icon', () => {
|
|
125
|
+
const inputMode = mount(<Input mode='password' defaultValue="123456" autofocus/>);
|
|
126
|
+
inputMode.simulate('mouseEnter', {}).find(`.${BASE_CLASS_PREFIX}-input-modebtn`).simulate('click');
|
|
127
|
+
expect(inputMode.find('input').instance().type).toEqual('text');
|
|
119
128
|
});
|
|
120
129
|
|
|
121
130
|
it('input controlled mode', () => {
|
|
@@ -116,4 +116,57 @@ describe('TextArea', () => {
|
|
|
116
116
|
const counter2 = textarea.find(`.${BASE_CLASS_PREFIX}-input-textarea-counter`);
|
|
117
117
|
expect(counter2.hasClass('semi-input-textarea-counter-exceed')).toEqual(false);
|
|
118
118
|
});
|
|
119
|
+
|
|
120
|
+
it('test minLength', () => {
|
|
121
|
+
let inputValue = '💖💖💖';
|
|
122
|
+
let inputValue1 = '💖💖💖💖';
|
|
123
|
+
let minLength = 4;
|
|
124
|
+
let event = { target: { value: inputValue } };
|
|
125
|
+
let event1 = { target: { value: inputValue1 } };
|
|
126
|
+
|
|
127
|
+
let onChange = value => {
|
|
128
|
+
console.log(value);
|
|
129
|
+
};
|
|
130
|
+
let spyOnChange = sinon.spy(onChange);
|
|
131
|
+
const textArea = mount(<TextArea onChange={spyOnChange} minLength={minLength} getValueLength={getValueLength} />);
|
|
132
|
+
const textAreaDom = textArea.find('textarea');
|
|
133
|
+
|
|
134
|
+
textAreaDom.simulate('change', event);
|
|
135
|
+
expect(spyOnChange.calledOnce).toBe(true);
|
|
136
|
+
expect(spyOnChange.calledWithMatch(textAreaDom)).toBe(true);
|
|
137
|
+
expect(textAreaDom.instance().minLength).toEqual(inputValue.length + (minLength - getValueLength(inputValue)));
|
|
138
|
+
|
|
139
|
+
textAreaDom.simulate('change', event1);
|
|
140
|
+
expect(spyOnChange.calledWithMatch(textAreaDom)).toBe(true);
|
|
141
|
+
expect(textAreaDom.instance().minLength).toEqual(minLength)
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('test maxLength + truncateValue', () => {
|
|
145
|
+
function truncateValue(inputValue, maxLength, getValueLength) {
|
|
146
|
+
let event = { target: { value: inputValue } };
|
|
147
|
+
let onChange = value => {
|
|
148
|
+
console.log(value);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
let spyOnChange = sinon.spy(onChange);
|
|
152
|
+
const textArea = mount(<TextArea onChange={spyOnChange} maxLength={maxLength} getValueLength={getValueLength} />);
|
|
153
|
+
const textAreaDom = textArea.find('textarea');
|
|
154
|
+
textAreaDom.simulate('change', event);
|
|
155
|
+
expect(spyOnChange.calledOnce).toBe(true);
|
|
156
|
+
return textAreaDom.instance().value;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const testCases = [
|
|
160
|
+
// 自定义valueLength
|
|
161
|
+
['Semi', 5, getValueLength, 'Semi'],
|
|
162
|
+
['Semi Design', 4, getValueLength, 'Semi'],
|
|
163
|
+
['💖💖💖💖💖💖💖💖💖💖👨👩👧👦', 10, getValueLength, '💖💖💖💖💖💖💖💖💖💖'],
|
|
164
|
+
['💖', -1, getValueLength, ''],
|
|
165
|
+
['🆗', 1, getValueLength, '🆗'],
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
for (let [value, length, fc, result] of testCases) {
|
|
169
|
+
expect(truncateValue(value, length, fc)).toBe(result);
|
|
170
|
+
}
|
|
171
|
+
})
|
|
119
172
|
})
|
package/lib/cjs/banner/index.js
CHANGED
|
@@ -92,7 +92,9 @@ class Banner extends _baseComponent.default {
|
|
|
92
92
|
const closer = /*#__PURE__*/_react.default.createElement(_iconButton.default, {
|
|
93
93
|
className: "".concat(prefixCls, "-close"),
|
|
94
94
|
onClick: this.remove,
|
|
95
|
-
icon: closeIcon || /*#__PURE__*/_react.default.createElement(_semiIcons.IconClose,
|
|
95
|
+
icon: closeIcon || /*#__PURE__*/_react.default.createElement(_semiIcons.IconClose, {
|
|
96
|
+
"aria-hidden": true
|
|
97
|
+
}),
|
|
96
98
|
theme: "borderless",
|
|
97
99
|
size: "small",
|
|
98
100
|
type: "tertiary",
|
|
@@ -109,16 +111,20 @@ class Banner extends _baseComponent.default {
|
|
|
109
111
|
} = this.props;
|
|
110
112
|
const iconMap = {
|
|
111
113
|
warning: /*#__PURE__*/_react.default.createElement(_semiIcons.IconAlertTriangle, {
|
|
112
|
-
size: "large"
|
|
114
|
+
size: "large",
|
|
115
|
+
"aria-label": 'warning'
|
|
113
116
|
}),
|
|
114
117
|
success: /*#__PURE__*/_react.default.createElement(_semiIcons.IconTickCircle, {
|
|
115
|
-
size: "large"
|
|
118
|
+
size: "large",
|
|
119
|
+
"aria-label": 'success'
|
|
116
120
|
}),
|
|
117
121
|
info: /*#__PURE__*/_react.default.createElement(_semiIcons.IconInfoCircle, {
|
|
118
|
-
size: "large"
|
|
122
|
+
size: "large",
|
|
123
|
+
"aria-label": 'info'
|
|
119
124
|
}),
|
|
120
125
|
danger: /*#__PURE__*/_react.default.createElement(_semiIcons.IconAlertCircle, {
|
|
121
|
-
size: "large"
|
|
126
|
+
size: "large",
|
|
127
|
+
"aria-label": 'danger'
|
|
122
128
|
})
|
|
123
129
|
};
|
|
124
130
|
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,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
|
+
|
|
7
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
exports.default = void 0;
|
|
12
|
+
|
|
13
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
14
|
+
|
|
15
|
+
var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
|
|
16
|
+
|
|
17
|
+
var _throttle2 = _interopRequireDefault(require("lodash/throttle"));
|
|
18
|
+
|
|
19
|
+
var _get2 = _interopRequireDefault(require("lodash/get"));
|
|
20
|
+
|
|
21
|
+
var _react = _interopRequireDefault(require("react"));
|
|
22
|
+
|
|
23
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
24
|
+
|
|
25
|
+
var _constants = require("@douyinfe/semi-foundation/lib/cjs/carousel/constants");
|
|
26
|
+
|
|
27
|
+
var _semiIcons = require("@douyinfe/semi-icons");
|
|
28
|
+
|
|
29
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
30
|
+
|
|
31
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
32
|
+
class CarouselArrow extends _react.default.PureComponent {
|
|
33
|
+
constructor() {
|
|
34
|
+
super(...arguments);
|
|
35
|
+
|
|
36
|
+
this.renderLeftIcon = () => {
|
|
37
|
+
return (0, _get2.default)(this.props, 'arrowProps.leftArrow.children', /*#__PURE__*/_react.default.createElement(_semiIcons.IconChevronLeft, {
|
|
38
|
+
"aria-label": "Previous index",
|
|
39
|
+
size: "inherit"
|
|
40
|
+
}));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
this.renderRightIcon = () => {
|
|
44
|
+
return (0, _get2.default)(this.props, 'arrowProps.rightArrow.children', /*#__PURE__*/_react.default.createElement(_semiIcons.IconChevronRight, {
|
|
45
|
+
"aria-label": "Next index",
|
|
46
|
+
size: "inherit"
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
render() {
|
|
52
|
+
var _context, _context2, _context3;
|
|
53
|
+
|
|
54
|
+
const {
|
|
55
|
+
type,
|
|
56
|
+
theme,
|
|
57
|
+
prev,
|
|
58
|
+
next,
|
|
59
|
+
timing
|
|
60
|
+
} = this.props;
|
|
61
|
+
const classNames = (0, _classnames.default)({
|
|
62
|
+
[_constants.cssClasses.CAROUSEL_ARROW]: true,
|
|
63
|
+
[(0, _concat.default)(_context = "".concat(_constants.cssClasses.CAROUSEL_ARROW, "-")).call(_context, theme)]: theme,
|
|
64
|
+
["".concat(_constants.cssClasses.CAROUSEL_ARROW, "-hover")]: type === 'hover'
|
|
65
|
+
});
|
|
66
|
+
const leftClassNames = (0, _classnames.default)({
|
|
67
|
+
["".concat(_constants.cssClasses.CAROUSEL_ARROW, "-prev")]: true,
|
|
68
|
+
[(0, _concat.default)(_context2 = "".concat(_constants.cssClasses.CAROUSEL_ARROW, "-")).call(_context2, theme)]: theme
|
|
69
|
+
});
|
|
70
|
+
const rightClassNames = (0, _classnames.default)({
|
|
71
|
+
["".concat(_constants.cssClasses.CAROUSEL_ARROW, "-next")]: true,
|
|
72
|
+
[(0, _concat.default)(_context3 = "".concat(_constants.cssClasses.CAROUSEL_ARROW, "-")).call(_context3, theme)]: theme
|
|
73
|
+
});
|
|
74
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
75
|
+
className: classNames
|
|
76
|
+
}, /*#__PURE__*/_react.default.createElement("div", (0, _assign.default)({
|
|
77
|
+
// role='button'
|
|
78
|
+
className: leftClassNames,
|
|
79
|
+
onClick: (0, _throttle2.default)(prev, timing)
|
|
80
|
+
}, (0, _get2.default)(this.props, 'arrowProps.leftArrow.props')), this.renderLeftIcon()), /*#__PURE__*/_react.default.createElement("div", (0, _assign.default)({
|
|
81
|
+
// role='button'
|
|
82
|
+
// tabIndex={0}
|
|
83
|
+
className: rightClassNames,
|
|
84
|
+
onClick: (0, _throttle2.default)(next, timing)
|
|
85
|
+
}, (0, _get2.default)(this.props, 'arrowProps.rightArrow.props')), this.renderRightIcon()));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
var _default = CarouselArrow;
|
|
91
|
+
exports.default = _default;
|
|
@@ -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,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
|
+
|
|
7
|
+
_Object$defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
exports.default = void 0;
|
|
12
|
+
|
|
13
|
+
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
14
|
+
|
|
15
|
+
var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));
|
|
16
|
+
|
|
17
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
18
|
+
|
|
19
|
+
var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
|
|
20
|
+
|
|
21
|
+
var _react = _interopRequireDefault(require("react"));
|
|
22
|
+
|
|
23
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
24
|
+
|
|
25
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
26
|
+
|
|
27
|
+
var _constants = require("@douyinfe/semi-foundation/lib/cjs/carousel/constants");
|
|
28
|
+
|
|
29
|
+
var _getDataAttr = _interopRequireDefault(require("@douyinfe/semi-foundation/lib/cjs/utils/getDataAttr"));
|
|
30
|
+
|
|
31
|
+
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
32
|
+
var t = {};
|
|
33
|
+
|
|
34
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && (0, _indexOf.default)(e).call(e, p) < 0) t[p] = s[p];
|
|
35
|
+
|
|
36
|
+
if (s != null && typeof _getOwnPropertySymbols.default === "function") for (var i = 0, p = (0, _getOwnPropertySymbols.default)(s); i < p.length; i++) {
|
|
37
|
+
if ((0, _indexOf.default)(e).call(e, p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
38
|
+
}
|
|
39
|
+
return t;
|
|
40
|
+
};
|
|
41
|
+
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
42
|
+
|
|
43
|
+
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class CarouselIndicator extends _react.default.PureComponent {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(...arguments);
|
|
49
|
+
|
|
50
|
+
this.onIndicatorChange = activeIndex => {
|
|
51
|
+
this.props.onIndicatorChange(activeIndex);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
this.handleIndicatorClick = activeIndex => {
|
|
55
|
+
const {
|
|
56
|
+
trigger
|
|
57
|
+
} = this.props;
|
|
58
|
+
|
|
59
|
+
if (trigger === 'click') {
|
|
60
|
+
this.onIndicatorChange(activeIndex);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
this.handleIndicatorHover = activeIndex => {
|
|
65
|
+
const {
|
|
66
|
+
trigger
|
|
67
|
+
} = this.props;
|
|
68
|
+
|
|
69
|
+
if (trigger === 'hover') {
|
|
70
|
+
this.onIndicatorChange(activeIndex);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
renderIndicatorContent() {
|
|
76
|
+
const {
|
|
77
|
+
total,
|
|
78
|
+
theme,
|
|
79
|
+
size,
|
|
80
|
+
activeIndex
|
|
81
|
+
} = this.props;
|
|
82
|
+
const indicatorContent = [];
|
|
83
|
+
|
|
84
|
+
for (let i = 0; i < total; i++) {
|
|
85
|
+
var _context, _context2;
|
|
86
|
+
|
|
87
|
+
indicatorContent.push( /*#__PURE__*/_react.default.createElement("span", {
|
|
88
|
+
// role='none'
|
|
89
|
+
key: i,
|
|
90
|
+
"data-index": i,
|
|
91
|
+
className: (0, _classnames.default)(["".concat(_constants.cssClasses.CAROUSEL_INDICATOR, "-item")], {
|
|
92
|
+
["".concat(_constants.cssClasses.CAROUSEL_INDICATOR, "-item-active")]: i === activeIndex,
|
|
93
|
+
[(0, _concat.default)(_context = "".concat(_constants.cssClasses.CAROUSEL_INDICATOR, "-item-")).call(_context, theme)]: theme,
|
|
94
|
+
[(0, _concat.default)(_context2 = "".concat(_constants.cssClasses.CAROUSEL_INDICATOR, "-item-")).call(_context2, size)]: size
|
|
95
|
+
}),
|
|
96
|
+
onClick: () => this.handleIndicatorClick(i),
|
|
97
|
+
onMouseEnter: () => this.handleIndicatorHover(i)
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return indicatorContent;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
render() {
|
|
105
|
+
var _context3, _context4;
|
|
106
|
+
|
|
107
|
+
const _a = this.props,
|
|
108
|
+
{
|
|
109
|
+
type,
|
|
110
|
+
size,
|
|
111
|
+
theme,
|
|
112
|
+
style,
|
|
113
|
+
className,
|
|
114
|
+
position
|
|
115
|
+
} = _a,
|
|
116
|
+
restProps = __rest(_a, ["type", "size", "theme", "style", "className", "position"]);
|
|
117
|
+
|
|
118
|
+
const classNames = (0, _classnames.default)(className, {
|
|
119
|
+
[_constants.cssClasses.CAROUSEL_INDICATOR]: true,
|
|
120
|
+
[(0, _concat.default)(_context3 = "".concat(_constants.cssClasses.CAROUSEL_INDICATOR, "-")).call(_context3, type)]: type,
|
|
121
|
+
[(0, _concat.default)(_context4 = "".concat(_constants.cssClasses.CAROUSEL_INDICATOR, "-")).call(_context4, position)]: position
|
|
122
|
+
});
|
|
123
|
+
const indicatorContent = this.renderIndicatorContent();
|
|
124
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _assign.default)({
|
|
125
|
+
className: classNames,
|
|
126
|
+
style: style
|
|
127
|
+
}, (0, _getDataAttr.default)(restProps)), indicatorContent);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
CarouselIndicator.propTypes = {
|
|
133
|
+
activeKey: _propTypes.default.number,
|
|
134
|
+
className: _propTypes.default.string,
|
|
135
|
+
position: _propTypes.default.oneOf(_constants.strings.POSITION_MAP),
|
|
136
|
+
size: _propTypes.default.oneOf(_constants.strings.SIZE),
|
|
137
|
+
style: _propTypes.default.object,
|
|
138
|
+
theme: _propTypes.default.oneOf(_constants.strings.THEME_MAP),
|
|
139
|
+
total: _propTypes.default.number,
|
|
140
|
+
onIndicatorChange: _propTypes.default.func,
|
|
141
|
+
type: _propTypes.default.oneOf(_constants.strings.TYPE_MAP),
|
|
142
|
+
trigger: _propTypes.default.oneOf(_constants.strings.TRIGGER)
|
|
143
|
+
};
|
|
144
|
+
var _default = CarouselIndicator;
|
|
145
|
+
exports.default = _default;
|
|
@@ -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/cjs/carousel/foundation';
|
|
6
|
+
import '@douyinfe/semi-foundation/lib/cjs/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;
|