@qsxy/element-plus-react 1.0.0-next.4 → 1.0.0-next.5
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/dist/Carousel/Carousel.d.ts +4 -0
- package/dist/Carousel/Carousel.js +168 -0
- package/dist/Carousel/CarouselContext.d.ts +4 -0
- package/dist/Carousel/CarouselContext.js +52 -0
- package/dist/Carousel/CarouselItem.d.ts +4 -0
- package/dist/Carousel/CarouselItem.js +75 -0
- package/dist/Carousel/hooks/useCarousel.d.ts +37 -0
- package/dist/Carousel/hooks/useCarousel.js +348 -0
- package/dist/Carousel/hooks/useCarouselItem.d.ts +8 -0
- package/dist/Carousel/hooks/useCarouselItem.js +161 -0
- package/dist/Carousel/index.d.ts +3 -0
- package/dist/Carousel/index.js +42 -0
- package/dist/Carousel/typings.d.ts +83 -0
- package/dist/Carousel/typings.js +17 -0
- package/dist/DatePicker/DatePicker.js +1 -1
- package/dist/DateTimePicker/DateTimePicker.d.ts +1 -1
- package/dist/Dialog/Dialog.js +2 -2
- package/dist/Drawer/Drawer.js +8 -8
- package/dist/Form/utils/classUtil.js +2 -2
- package/dist/Input/InputRange.js +3 -3
- package/dist/MessageBox/MessageBox.js +1 -1
- package/dist/Popper/Popper.js +7 -7
- package/dist/Progress/Progress.js +1 -1
- package/dist/Table/hooks/useSelection.d.ts +1 -8
- package/dist/Table/util.js +2 -2
- package/dist/TimePicker/TimePicker.js +1 -1
- package/dist/hooks/prefix.d.ts +1 -1
- package/dist/hooks/prefix.js +4 -4
- package/dist/hooks/useClassNames.js +1 -1
- package/dist/index.css +222 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/theme-chalk/carousel/index.scss +237 -0
- package/dist/theme-chalk/dev.scss +2 -0
- package/dist/theme-chalk/index.scss +1 -1
- package/package.json +1 -1
- package/dist/theme-chalk/build.scss +0 -64
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/Carousel/hooks/useCarousel.ts
|
|
30
|
+
var useCarousel_exports = {};
|
|
31
|
+
__export(useCarousel_exports, {
|
|
32
|
+
useCarousel: () => useCarousel
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(useCarousel_exports);
|
|
35
|
+
var import_ahooks = require("ahooks");
|
|
36
|
+
var import_throttle = __toESM(require("lodash/throttle"));
|
|
37
|
+
var import_react = require("react");
|
|
38
|
+
var import_base = require("../../Util/base");
|
|
39
|
+
var THROTTLE_TIME = 300;
|
|
40
|
+
var useCarousel = (props) => {
|
|
41
|
+
const { direction, arrow, height, type, autoplay, loop, interval, pauseOnHover, trigger, initialIndex, onChange } = props;
|
|
42
|
+
const [items, setItem] = (0, import_react.useState)([]);
|
|
43
|
+
const addItem = (item) => setItem((pre) => [...pre, item]);
|
|
44
|
+
const removeItem = (uid) => setItem((pre) => pre.filter((children) => children.uid !== uid));
|
|
45
|
+
const [activeIndex, setActiveIndex] = (0, import_react.useState)(-1);
|
|
46
|
+
const [hover, setHover] = (0, import_react.useState)(false);
|
|
47
|
+
const [containerHeight, setHeight] = (0, import_react.useState)(0);
|
|
48
|
+
const [isTransitioning, setIsTransitioning] = (0, import_react.useState)(false);
|
|
49
|
+
const preActiveIndex = (0, import_ahooks.usePrevious)(activeIndex);
|
|
50
|
+
const timer = (0, import_react.useRef)(null);
|
|
51
|
+
const root = (0, import_react.useRef)();
|
|
52
|
+
const isItemsTwoLength = (0, import_react.useRef)(true);
|
|
53
|
+
const isTransition = (0, import_react.useRef)(false);
|
|
54
|
+
const resizeObserver = (0, import_react.useRef)();
|
|
55
|
+
const isFirstCall = (0, import_react.useRef)(true);
|
|
56
|
+
const itemLen = (0, import_react.useRef)(0);
|
|
57
|
+
const activeIndexRef = (0, import_react.useRef)(-1);
|
|
58
|
+
const isVertical = (0, import_react.useMemo)(() => direction === "vertical", [direction]);
|
|
59
|
+
const arrowDisplay = (0, import_react.useMemo)(() => arrow !== "never" && !isVertical, [arrow, isVertical]);
|
|
60
|
+
const hasLabel = (0, import_react.useMemo)(() => {
|
|
61
|
+
return items.some((item) => {
|
|
62
|
+
var _a, _b, _c;
|
|
63
|
+
return ((_c = (_b = (_a = item.props) == null ? void 0 : _a.label) == null ? void 0 : _b.toString()) == null ? void 0 : _c.length) > 0;
|
|
64
|
+
});
|
|
65
|
+
}, [items]);
|
|
66
|
+
const isCardType = (0, import_react.useMemo)(() => type === "card", [type]);
|
|
67
|
+
const containerStyle = (0, import_react.useMemo)(() => {
|
|
68
|
+
if (height !== "auto") {
|
|
69
|
+
return {
|
|
70
|
+
height
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
height: containerHeight,
|
|
75
|
+
overflow: "hidden"
|
|
76
|
+
};
|
|
77
|
+
}, [containerHeight, height]);
|
|
78
|
+
const resetItemPosition = (0, import_react.useCallback)(
|
|
79
|
+
(oldIndex) => {
|
|
80
|
+
items.forEach((item, index) => {
|
|
81
|
+
item.translateItem(index, activeIndex, oldIndex);
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
[activeIndex, items]
|
|
85
|
+
);
|
|
86
|
+
const playSlides = (0, import_react.useCallback)(() => {
|
|
87
|
+
if (!isFirstCall.current && !isTransition.current) {
|
|
88
|
+
isTransition.current = true;
|
|
89
|
+
setIsTransitioning(true);
|
|
90
|
+
}
|
|
91
|
+
isFirstCall.current = false;
|
|
92
|
+
if (activeIndexRef.current < itemLen.current - 1) {
|
|
93
|
+
setActiveIndex((pre) => pre + 1);
|
|
94
|
+
} else if (loop) {
|
|
95
|
+
setActiveIndex(0);
|
|
96
|
+
} else {
|
|
97
|
+
isTransition.current = false;
|
|
98
|
+
setIsTransitioning(false);
|
|
99
|
+
}
|
|
100
|
+
}, [loop]);
|
|
101
|
+
const startTimer = (0, import_react.useCallback)(() => {
|
|
102
|
+
if (interval <= 0 || !autoplay || timer.current) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
timer.current = setInterval(() => playSlides(), interval);
|
|
106
|
+
}, [autoplay, interval, playSlides]);
|
|
107
|
+
const pauseTimer = (0, import_react.useCallback)(() => {
|
|
108
|
+
if (timer.current) {
|
|
109
|
+
clearInterval(timer.current);
|
|
110
|
+
timer.current = null;
|
|
111
|
+
}
|
|
112
|
+
}, []);
|
|
113
|
+
const resetTimer = (0, import_react.useCallback)(() => {
|
|
114
|
+
pauseTimer();
|
|
115
|
+
if (!pauseOnHover) {
|
|
116
|
+
startTimer();
|
|
117
|
+
}
|
|
118
|
+
}, [pauseOnHover, pauseTimer, startTimer]);
|
|
119
|
+
const setActiveItem = (0, import_react.useCallback)(
|
|
120
|
+
(index) => {
|
|
121
|
+
if (!isFirstCall.current) {
|
|
122
|
+
isTransition.current = true;
|
|
123
|
+
setIsTransitioning(true);
|
|
124
|
+
}
|
|
125
|
+
isFirstCall.current = false;
|
|
126
|
+
if ((0, import_base.isString)(index)) {
|
|
127
|
+
const filteredItems = items.filter((item) => item.props.name === index);
|
|
128
|
+
if (filteredItems.length > 0) {
|
|
129
|
+
index = items.indexOf(filteredItems[0]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
index = Number(index);
|
|
133
|
+
if (Number.isNaN(index) || index !== Math.floor(index)) {
|
|
134
|
+
(0, import_base.warning)(false, "component ElCarouselItem: index must be integer.");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const itemCount = items.length;
|
|
138
|
+
const oldIndex = activeIndex;
|
|
139
|
+
if (index < 0) {
|
|
140
|
+
setActiveIndex(loop ? itemCount - 1 : 0);
|
|
141
|
+
} else if (index >= itemCount) {
|
|
142
|
+
setActiveIndex(loop ? 0 : itemCount - 1);
|
|
143
|
+
} else {
|
|
144
|
+
setActiveIndex(index);
|
|
145
|
+
}
|
|
146
|
+
if (oldIndex === activeIndex) {
|
|
147
|
+
resetItemPosition(oldIndex);
|
|
148
|
+
}
|
|
149
|
+
resetTimer();
|
|
150
|
+
},
|
|
151
|
+
[activeIndex, isFirstCall, items, loop, resetItemPosition, resetTimer]
|
|
152
|
+
);
|
|
153
|
+
const throttledArrowClick = (0, import_react.useCallback)(
|
|
154
|
+
(index) => {
|
|
155
|
+
setActiveItem(index);
|
|
156
|
+
},
|
|
157
|
+
[setActiveItem]
|
|
158
|
+
);
|
|
159
|
+
const handleIndicatorHover = (0, import_react.useCallback)(
|
|
160
|
+
(index) => {
|
|
161
|
+
if (trigger === "hover" && index !== activeIndex) {
|
|
162
|
+
setActiveIndex(index);
|
|
163
|
+
if (!isFirstCall.current) {
|
|
164
|
+
isTransition.current = true;
|
|
165
|
+
setIsTransitioning(true);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
[activeIndex, isFirstCall, trigger]
|
|
170
|
+
);
|
|
171
|
+
const throttledIndicatorHover = (0, import_react.useCallback)(
|
|
172
|
+
(index) => {
|
|
173
|
+
handleIndicatorHover(index);
|
|
174
|
+
},
|
|
175
|
+
[handleIndicatorHover]
|
|
176
|
+
);
|
|
177
|
+
const isTwoLengthShow = (0, import_react.useCallback)(
|
|
178
|
+
(index) => {
|
|
179
|
+
if (!isItemsTwoLength.current) {
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
return activeIndex <= 1 ? index <= 1 : index > 1;
|
|
183
|
+
},
|
|
184
|
+
[activeIndex]
|
|
185
|
+
);
|
|
186
|
+
const itemInStage = (0, import_react.useCallback)(
|
|
187
|
+
(item, index) => {
|
|
188
|
+
var _a, _b, _c, _d;
|
|
189
|
+
const itemCount = items.length;
|
|
190
|
+
if (itemCount === 0 || !item.states.inStage) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
const nextItemIndex = index + 1;
|
|
194
|
+
const prevItemIndex = index - 1;
|
|
195
|
+
const lastItemIndex = itemCount - 1;
|
|
196
|
+
const isLastItemActive = items[lastItemIndex].states.active;
|
|
197
|
+
const isFirstItemActive = items[0].states.active;
|
|
198
|
+
const isNextItemActive = (_b = (_a = items[nextItemIndex]) == null ? void 0 : _a.states) == null ? void 0 : _b.active;
|
|
199
|
+
const isPrevItemActive = (_d = (_c = items[prevItemIndex]) == null ? void 0 : _c.states) == null ? void 0 : _d.active;
|
|
200
|
+
if (index === lastItemIndex && isFirstItemActive || isNextItemActive) {
|
|
201
|
+
return "left";
|
|
202
|
+
} else if (index === 0 && isLastItemActive || isPrevItemActive) {
|
|
203
|
+
return "right";
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
},
|
|
207
|
+
[items]
|
|
208
|
+
);
|
|
209
|
+
const handleMouseEnter = (0, import_react.useCallback)(() => {
|
|
210
|
+
setHover(true);
|
|
211
|
+
if (pauseOnHover) {
|
|
212
|
+
pauseTimer();
|
|
213
|
+
}
|
|
214
|
+
}, [pauseOnHover, pauseTimer]);
|
|
215
|
+
const handleMouseLeave = (0, import_react.useCallback)(() => {
|
|
216
|
+
setHover(false);
|
|
217
|
+
startTimer();
|
|
218
|
+
}, [startTimer]);
|
|
219
|
+
const handleTransitionEnd = (0, import_react.useCallback)(() => {
|
|
220
|
+
isTransition.current = false;
|
|
221
|
+
setIsTransitioning(false);
|
|
222
|
+
}, []);
|
|
223
|
+
const handleButtonEnter = (0, import_react.useCallback)(
|
|
224
|
+
(_arrow) => {
|
|
225
|
+
if (isVertical) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
items.forEach((item, index) => {
|
|
229
|
+
if (_arrow === itemInStage(item, index)) {
|
|
230
|
+
item.setState({ hover: true });
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
[isVertical, itemInStage, items]
|
|
235
|
+
);
|
|
236
|
+
const handleButtonLeave = (0, import_react.useCallback)(() => {
|
|
237
|
+
if (isVertical) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
items.forEach((item) => {
|
|
241
|
+
item.setState({ hover: false });
|
|
242
|
+
});
|
|
243
|
+
}, [isVertical, items]);
|
|
244
|
+
const handleIndicatorClick = (index) => {
|
|
245
|
+
if (index !== activeIndex) {
|
|
246
|
+
if (!isFirstCall.current) {
|
|
247
|
+
isTransition.current = true;
|
|
248
|
+
setIsTransitioning(true);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
setActiveIndex(index);
|
|
252
|
+
};
|
|
253
|
+
const prev = (0, import_react.useCallback)(() => {
|
|
254
|
+
setActiveItem(activeIndex - 1);
|
|
255
|
+
}, [activeIndex, setActiveItem]);
|
|
256
|
+
const next = (0, import_react.useCallback)(() => {
|
|
257
|
+
setActiveItem(activeIndex + 1);
|
|
258
|
+
}, [activeIndex, setActiveItem]);
|
|
259
|
+
const setContainerHeight = (0, import_react.useCallback)(
|
|
260
|
+
(_height) => {
|
|
261
|
+
if (height !== "auto") {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
setHeight(_height);
|
|
265
|
+
},
|
|
266
|
+
[height]
|
|
267
|
+
);
|
|
268
|
+
(0, import_react.useEffect)(() => {
|
|
269
|
+
activeIndexRef.current = activeIndex;
|
|
270
|
+
resetItemPosition(preActiveIndex);
|
|
271
|
+
let current, _prev;
|
|
272
|
+
if (isItemsTwoLength.current) {
|
|
273
|
+
current = activeIndex % 2;
|
|
274
|
+
_prev = preActiveIndex % 2;
|
|
275
|
+
}
|
|
276
|
+
if (preActiveIndex > -1) {
|
|
277
|
+
onChange == null ? void 0 : onChange(current, _prev);
|
|
278
|
+
}
|
|
279
|
+
}, [activeIndex]);
|
|
280
|
+
(0, import_react.useEffect)(() => {
|
|
281
|
+
setActiveItem(activeIndex);
|
|
282
|
+
}, [loop]);
|
|
283
|
+
(0, import_react.useEffect)(() => {
|
|
284
|
+
resetTimer();
|
|
285
|
+
}, [interval]);
|
|
286
|
+
(0, import_react.useEffect)(() => {
|
|
287
|
+
if (items.length > 0) {
|
|
288
|
+
setActiveItem(initialIndex);
|
|
289
|
+
}
|
|
290
|
+
itemLen.current = items.length;
|
|
291
|
+
isItemsTwoLength.current = (items == null ? void 0 : items.length) === 2 && props.loop && !isCardType;
|
|
292
|
+
}, [items]);
|
|
293
|
+
(0, import_react.useEffect)(() => {
|
|
294
|
+
if (autoplay) {
|
|
295
|
+
startTimer();
|
|
296
|
+
} else {
|
|
297
|
+
pauseTimer();
|
|
298
|
+
}
|
|
299
|
+
}, [autoplay, items.length]);
|
|
300
|
+
(0, import_react.useEffect)(() => {
|
|
301
|
+
if (root.current) {
|
|
302
|
+
resizeObserver.current = new ResizeObserver(() => {
|
|
303
|
+
resetItemPosition();
|
|
304
|
+
});
|
|
305
|
+
resizeObserver.current.observe(root.current);
|
|
306
|
+
startTimer();
|
|
307
|
+
}
|
|
308
|
+
return () => {
|
|
309
|
+
pauseTimer();
|
|
310
|
+
if (resizeObserver.current) {
|
|
311
|
+
resizeObserver.current.disconnect();
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}, []);
|
|
315
|
+
return {
|
|
316
|
+
items,
|
|
317
|
+
addItem,
|
|
318
|
+
removeItem,
|
|
319
|
+
setContainerHeight,
|
|
320
|
+
root,
|
|
321
|
+
activeIndex,
|
|
322
|
+
arrowDisplay,
|
|
323
|
+
hasLabel,
|
|
324
|
+
hover,
|
|
325
|
+
isCardType,
|
|
326
|
+
isTransitioning,
|
|
327
|
+
isVertical,
|
|
328
|
+
containerStyle,
|
|
329
|
+
isItemsTwoLength,
|
|
330
|
+
handleButtonEnter,
|
|
331
|
+
handleTransitionEnd,
|
|
332
|
+
handleButtonLeave,
|
|
333
|
+
handleIndicatorClick,
|
|
334
|
+
handleMouseEnter,
|
|
335
|
+
handleMouseLeave,
|
|
336
|
+
setActiveItem,
|
|
337
|
+
prev,
|
|
338
|
+
next,
|
|
339
|
+
// PlaceholderItem,
|
|
340
|
+
isTwoLengthShow,
|
|
341
|
+
throttledArrowClick: (0, import_throttle.default)(throttledArrowClick, THROTTLE_TIME, { trailing: true }),
|
|
342
|
+
throttledIndicatorHover: (0, import_throttle.default)(throttledIndicatorHover, THROTTLE_TIME)
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
346
|
+
0 && (module.exports = {
|
|
347
|
+
useCarousel
|
|
348
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CarouselItemProps, CarouselItemStates } from '../typings';
|
|
3
|
+
export declare const useCarouselItem: (props: CarouselItemProps) => {
|
|
4
|
+
carouselItemRef: import("react").MutableRefObject<HTMLDivElement>;
|
|
5
|
+
state: CarouselItemStates;
|
|
6
|
+
setState: (_state: Partial<CarouselItemStates>) => void;
|
|
7
|
+
handleItemClick: () => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/Carousel/hooks/useCarouselItem.ts
|
|
30
|
+
var useCarouselItem_exports = {};
|
|
31
|
+
__export(useCarouselItem_exports, {
|
|
32
|
+
useCarouselItem: () => useCarouselItem
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(useCarouselItem_exports);
|
|
35
|
+
var import_omit = __toESM(require("lodash/omit"));
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var import_CarouselContext = require("../CarouselContext");
|
|
38
|
+
var useCarouselItem = (props) => {
|
|
39
|
+
const { isCardType, loop, isVertical, cardScale, root, items, addItem, removeItem, setActiveItem, setContainerHeight } = (0, import_CarouselContext.useCarouselContext)();
|
|
40
|
+
const id = (0, import_react.useId)();
|
|
41
|
+
const carouselItemRef = (0, import_react.useRef)();
|
|
42
|
+
const ref = (0, import_react.useRef)();
|
|
43
|
+
const reducer = (state2, action) => {
|
|
44
|
+
switch (action.type) {
|
|
45
|
+
case "setState":
|
|
46
|
+
return { ...state2, ...action.payload };
|
|
47
|
+
default:
|
|
48
|
+
return state2;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const [state, dispatch] = (0, import_react.useReducer)(reducer, { ready: false, hover: false, translate: 0, scale: 1, animating: false, active: false, inStage: false });
|
|
52
|
+
const setState = (_state) => dispatch({
|
|
53
|
+
type: "setState",
|
|
54
|
+
payload: _state
|
|
55
|
+
});
|
|
56
|
+
const calcCardTranslate = (0, import_react.useCallback)(
|
|
57
|
+
(index, activeIndex, inStage) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
const parentWidth = isVertical ? ((_a = root.current) == null ? void 0 : _a.offsetHeight) || 0 : ((_b = root.current) == null ? void 0 : _b.offsetWidth) || 0;
|
|
60
|
+
if (inStage) {
|
|
61
|
+
return parentWidth * ((2 - cardScale) * (index - activeIndex) + 1) / 4;
|
|
62
|
+
} else if (index < activeIndex) {
|
|
63
|
+
return -(1 + cardScale) * parentWidth / 4;
|
|
64
|
+
} else {
|
|
65
|
+
return (3 + cardScale) * parentWidth / 4;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
[cardScale, isVertical, root]
|
|
69
|
+
);
|
|
70
|
+
const calcTranslate = (0, import_react.useCallback)(
|
|
71
|
+
(index, activeIndex) => {
|
|
72
|
+
const rootEl = root.current;
|
|
73
|
+
if (!rootEl) {
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
const distance = (isVertical ? rootEl.offsetHeight : rootEl.offsetWidth) || 0;
|
|
77
|
+
return distance * (index - activeIndex);
|
|
78
|
+
},
|
|
79
|
+
[isVertical, root]
|
|
80
|
+
);
|
|
81
|
+
const translateItem = (0, import_react.useCallback)(
|
|
82
|
+
(index, activeIndex, oldIndex) => {
|
|
83
|
+
const carouselItemLength = items.length ?? Number.NaN;
|
|
84
|
+
const isActive = index === activeIndex;
|
|
85
|
+
if (!isCardType && oldIndex != void 0) {
|
|
86
|
+
setState({ animating: isActive || index === oldIndex });
|
|
87
|
+
}
|
|
88
|
+
if (!isActive && carouselItemLength > 2 && loop) {
|
|
89
|
+
index = processIndex(index, activeIndex, carouselItemLength);
|
|
90
|
+
}
|
|
91
|
+
setState({ active: isActive });
|
|
92
|
+
if (isCardType) {
|
|
93
|
+
const inStage = Math.round(Math.abs(index - activeIndex)) <= 1;
|
|
94
|
+
setState({
|
|
95
|
+
inStage,
|
|
96
|
+
translate: calcCardTranslate(index, activeIndex, inStage),
|
|
97
|
+
scale: isActive ? 1 : cardScale
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
setState({
|
|
101
|
+
translate: calcTranslate(index, activeIndex)
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
setState({
|
|
105
|
+
ready: true
|
|
106
|
+
});
|
|
107
|
+
if (isActive && carouselItemRef.current) {
|
|
108
|
+
setContainerHeight(carouselItemRef.current.offsetHeight);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
[calcCardTranslate, calcTranslate, cardScale, isCardType, items, loop, setContainerHeight]
|
|
112
|
+
);
|
|
113
|
+
const handleItemClick = (0, import_react.useCallback)(() => {
|
|
114
|
+
if (isCardType) {
|
|
115
|
+
const index = items.findIndex(({ uid }) => uid === id);
|
|
116
|
+
setActiveItem(index);
|
|
117
|
+
}
|
|
118
|
+
}, [id, isCardType, items, setActiveItem]);
|
|
119
|
+
(0, import_react.useImperativeHandle)(ref, () => ({
|
|
120
|
+
translateItem
|
|
121
|
+
}));
|
|
122
|
+
(0, import_react.useEffect)(() => {
|
|
123
|
+
addItem({
|
|
124
|
+
props: (0, import_omit.default)(props, "children"),
|
|
125
|
+
states: state,
|
|
126
|
+
setState,
|
|
127
|
+
uid: id,
|
|
128
|
+
translateItem: (...args) => {
|
|
129
|
+
var _a;
|
|
130
|
+
return (_a = ref == null ? void 0 : ref.current) == null ? void 0 : _a.translateItem(...args);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
return () => removeItem(id);
|
|
134
|
+
}, []);
|
|
135
|
+
return {
|
|
136
|
+
carouselItemRef,
|
|
137
|
+
state,
|
|
138
|
+
setState,
|
|
139
|
+
handleItemClick
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
var processIndex = (index, activeIndex, length) => {
|
|
143
|
+
const lastItemIndex = length - 1;
|
|
144
|
+
const prevItemIndex = activeIndex - 1;
|
|
145
|
+
const nextItemIndex = activeIndex + 1;
|
|
146
|
+
const halfItemIndex = length / 2;
|
|
147
|
+
if (activeIndex === 0 && index === lastItemIndex) {
|
|
148
|
+
return -1;
|
|
149
|
+
} else if (activeIndex === lastItemIndex && index === 0) {
|
|
150
|
+
return length;
|
|
151
|
+
} else if (index < prevItemIndex && activeIndex - index >= halfItemIndex) {
|
|
152
|
+
return length + 1;
|
|
153
|
+
} else if (index > nextItemIndex && index - activeIndex >= halfItemIndex) {
|
|
154
|
+
return -2;
|
|
155
|
+
}
|
|
156
|
+
return index;
|
|
157
|
+
};
|
|
158
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
159
|
+
0 && (module.exports = {
|
|
160
|
+
useCarouselItem
|
|
161
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/Carousel/index.ts
|
|
30
|
+
var Carousel_exports = {};
|
|
31
|
+
__export(Carousel_exports, {
|
|
32
|
+
Carousel: () => import_Carousel.default,
|
|
33
|
+
CarouselItem: () => import_CarouselItem.default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(Carousel_exports);
|
|
36
|
+
var import_Carousel = __toESM(require("./Carousel"));
|
|
37
|
+
var import_CarouselItem = __toESM(require("./CarouselItem"));
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
Carousel,
|
|
41
|
+
CarouselItem
|
|
42
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { BaseProps, NativeProps } from '../types/common';
|
|
3
|
+
export interface CarouselProps extends BaseProps, NativeProps {
|
|
4
|
+
/** carousel 的高度 */
|
|
5
|
+
height?: string | number;
|
|
6
|
+
/** 初始状态激活的幻灯片的索引,从 0 开始 */
|
|
7
|
+
initialIndex?: number;
|
|
8
|
+
/** 指示器的触发方式 */
|
|
9
|
+
trigger?: 'hover' | 'click';
|
|
10
|
+
/** 是否自动切换 */
|
|
11
|
+
autoplay?: boolean;
|
|
12
|
+
/** 自动切换的时间间隔,单位为毫秒 */
|
|
13
|
+
interval?: number;
|
|
14
|
+
/** 指示器的位置 */
|
|
15
|
+
indicatorPosition?: '' | 'none' | 'outside';
|
|
16
|
+
/** 切换箭头的显示时机 */
|
|
17
|
+
arrow?: 'always' | 'hover' | 'never';
|
|
18
|
+
/** carousel 的类型 */
|
|
19
|
+
type?: '' | 'card';
|
|
20
|
+
/** 当 type 为 card时,二级卡的缩放大小 */
|
|
21
|
+
cardScale?: number;
|
|
22
|
+
/** 是否循环显示 */
|
|
23
|
+
loop?: boolean;
|
|
24
|
+
/** 展示的方向 */
|
|
25
|
+
direction?: 'horizontal' | 'vertical';
|
|
26
|
+
/** 鼠标悬浮时暂停自动切换 */
|
|
27
|
+
pauseOnHover?: boolean;
|
|
28
|
+
/** 添加动态模糊以给走马灯注入活力和流畅性。 */
|
|
29
|
+
motionBlur?: boolean;
|
|
30
|
+
/** 当前展示的幻灯片切换时触发,它有两个参数, 一个是新幻灯片的索引,另一个是旧幻灯片的索引 */
|
|
31
|
+
onChange?: (current: number, prev: number) => boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface CarouselItemProps extends BaseProps, NativeProps<'--el-carousel-arrow-font-size' | '--el-carousel-arrow-size' | '--el-carousel-arrow-background' | '--el-carousel-arrow-hover-background' | '--el-carousel-indicator-width' | '--el-carousel-indicator-height' | '--el-carousel-indicator-padding-horizontal' | '--el-carousel-indicator-padding-vertical' | '--el-carousel-indicator-out-color'> {
|
|
34
|
+
/** 幻灯片的名字,可用作 setActiveItem 的参数 */
|
|
35
|
+
name?: string;
|
|
36
|
+
/** 该幻灯片所对应指示器的文本 */
|
|
37
|
+
label?: string;
|
|
38
|
+
}
|
|
39
|
+
export type CarouselRef = {
|
|
40
|
+
/** 当前幻灯片的索引 */
|
|
41
|
+
activeIndex?: number;
|
|
42
|
+
/** 手动切换幻灯片,传入需要切换的幻灯片的索引,从 0 开始;或相应 elCarouselItem 的 name 属性值 */
|
|
43
|
+
setActiveItem?: (index: string | number) => void;
|
|
44
|
+
/** 切换至上一张幻灯片 */
|
|
45
|
+
prev?: () => void;
|
|
46
|
+
/** 切换至下一张幻灯片 */
|
|
47
|
+
next?: () => void;
|
|
48
|
+
};
|
|
49
|
+
export type CarouselItemStates = {
|
|
50
|
+
hover: boolean;
|
|
51
|
+
translate: number;
|
|
52
|
+
scale: number;
|
|
53
|
+
active: boolean;
|
|
54
|
+
ready: boolean;
|
|
55
|
+
inStage: boolean;
|
|
56
|
+
animating: boolean;
|
|
57
|
+
};
|
|
58
|
+
export type CarouselItemContext = {
|
|
59
|
+
props: CarouselItemProps;
|
|
60
|
+
states: CarouselItemStates;
|
|
61
|
+
setState: (_state: Partial<CarouselItemStates>) => void;
|
|
62
|
+
uid: string;
|
|
63
|
+
translateItem: (index: number, activeIndex: number, oldIndex?: number) => void;
|
|
64
|
+
};
|
|
65
|
+
export type CarouselContextProps = {
|
|
66
|
+
root: RefObject<HTMLDivElement>;
|
|
67
|
+
isCardType: boolean;
|
|
68
|
+
isVertical: boolean;
|
|
69
|
+
items: CarouselItemContext[];
|
|
70
|
+
loop: boolean;
|
|
71
|
+
cardScale: number;
|
|
72
|
+
addItem: (child: CarouselItemContext) => void;
|
|
73
|
+
removeItem: (uid: string) => void;
|
|
74
|
+
setActiveItem: (index: number | string) => void;
|
|
75
|
+
setContainerHeight: (height: number) => void;
|
|
76
|
+
};
|
|
77
|
+
export interface CarouselItemAction {
|
|
78
|
+
type: 'setState';
|
|
79
|
+
payload: Partial<CarouselItemStates>;
|
|
80
|
+
}
|
|
81
|
+
export type CarouselItemRef = {
|
|
82
|
+
translateItem: (index: number, activeIndex: number, oldIndex?: number) => void;
|
|
83
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/Carousel/typings.ts
|
|
16
|
+
var typings_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(typings_exports);
|
|
@@ -171,7 +171,7 @@ var DatePicker = (0, import_react.memo)(
|
|
|
171
171
|
value,
|
|
172
172
|
onChange: import_noop.default,
|
|
173
173
|
onClear: () => handleChange == null ? void 0 : handleChange(null),
|
|
174
|
-
className: (0, import_classnames.default)({ [`${import_prefix.
|
|
174
|
+
className: (0, import_classnames.default)({ [`${import_prefix.namespace}-date`]: readonly, "is-active": visible }),
|
|
175
175
|
style: props.style,
|
|
176
176
|
error,
|
|
177
177
|
warning,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DateTimePickerRef } from './typings';
|
|
3
|
-
declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<import("..").DatePickerProps, "
|
|
3
|
+
declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<import("..").DatePickerProps, "name" | "value" | "type" | "defaultValue" | "onChange"> & {
|
|
4
4
|
name?: string;
|
|
5
5
|
value?: string;
|
|
6
6
|
defaultValue?: string;
|