@helpdice/ui 1.7.8 → 1.8.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/dist/breadcrumbs/index.js +10 -7
- package/dist/card/index.js +10 -7
- package/dist/carousal/CSSTranslate.d.ts +2 -0
- package/dist/carousal/component/Arrow.d.ts +9 -0
- package/dist/carousal/component/Indicator.d.ts +9 -0
- package/dist/carousal/component/Thumbs.d.ts +65 -0
- package/dist/carousal/component/animations.d.ts +27 -0
- package/dist/carousal/component/index.d.ts +87 -0
- package/dist/carousal/component/types.d.ts +79 -0
- package/dist/carousal/component/utils.d.ts +15 -0
- package/dist/carousal/cssClasses.d.ts +11 -0
- package/dist/carousal/dimensions.d.ts +1 -0
- package/dist/carousal/index.d.ts +3 -0
- package/dist/carousal/index.js +16085 -0
- package/dist/carousal/shims/document.d.ts +2 -0
- package/dist/carousal/shims/window.d.ts +2 -0
- package/dist/image/index.js +10 -7
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2793 -197
- package/dist/link/index.js +10 -7
- package/dist/link/link.d.ts +2 -1
- package/dist/swipe/index.d.ts +4 -0
- package/dist/swipe/index.js +1314 -0
- package/dist/swipe/react-swipe.d.ts +58 -0
- package/dist/user/index.js +10 -7
- package/esm/carousal/CSSTranslate.d.ts +2 -0
- package/esm/carousal/CSSTranslate.js +7 -0
- package/esm/carousal/component/Arrow.d.ts +9 -0
- package/esm/carousal/component/Arrow.js +21 -0
- package/esm/carousal/component/Indicator.d.ts +9 -0
- package/esm/carousal/component/Indicator.js +23 -0
- package/esm/carousal/component/Thumbs.d.ts +65 -0
- package/esm/carousal/{Thumbs.js → component/Thumbs.js} +41 -12
- package/esm/carousal/component/animations.d.ts +27 -0
- package/esm/carousal/{animations.js → component/animations.js} +1 -1
- package/esm/carousal/component/index.d.ts +87 -0
- package/esm/carousal/component/index.js +698 -0
- package/esm/carousal/component/types.d.ts +79 -0
- package/esm/carousal/component/utils.d.ts +15 -0
- package/esm/carousal/{utils.js → component/utils.js} +1 -1
- package/esm/carousal/cssClasses.d.ts +11 -0
- package/esm/carousal/cssClasses.js +56 -0
- package/esm/carousal/dimensions.d.ts +1 -0
- package/esm/carousal/dimensions.js +6 -0
- package/esm/carousal/index.d.ts +3 -0
- package/esm/carousal/index.js +2 -683
- package/esm/carousal/main.js +59 -0
- package/esm/carousal/shims/document.d.ts +2 -0
- package/esm/carousal/shims/document.js +3 -0
- package/esm/carousal/shims/window.d.ts +2 -0
- package/esm/carousal/shims/window.js +3 -0
- package/esm/index.d.ts +4 -0
- package/esm/index.js +6 -1
- package/esm/link/link.d.ts +2 -1
- package/esm/link/link.js +10 -7
- package/esm/login-with/index.js +0 -2
- package/esm/swipe/demo.js +57 -0
- package/esm/swipe/index.d.ts +4 -0
- package/esm/swipe/index.js +2 -0
- package/esm/swipe/react-swipe.d.ts +58 -0
- package/esm/swipe/react-swipe.js +246 -0
- package/package.json +4 -3
- package/esm/carousal/Arrow.js +0 -18
- package/esm/carousal/Indicator.js +0 -20
- /package/esm/carousal/{types.js → component/types.js} +0 -0
package/esm/carousal/index.js
CHANGED
|
@@ -1,683 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
-
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
|
|
5
|
-
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
|
6
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
7
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
8
|
-
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
9
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
10
|
-
import React, { Children } from 'react';
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
import Swipe from 'react-easy-swipe';
|
|
13
|
-
import klass from '../../cssClasses';
|
|
14
|
-
import Thumbs from '../Thumbs';
|
|
15
|
-
import getDocument from '../../shims/document';
|
|
16
|
-
import getWindow from '../../shims/window';
|
|
17
|
-
import { noop, defaultStatusFormatter, isKeyboardEvent } from './utils';
|
|
18
|
-
import Arrow from './Arrow';
|
|
19
|
-
import Indicator from './Indicator';
|
|
20
|
-
import { slideAnimationHandler, slideSwipeAnimationHandler, slideStopSwipingHandler, fadeAnimationHandler } from './animations';
|
|
21
|
-
var Carousel = /*#__PURE__*/function (_React$Component) {
|
|
22
|
-
function Carousel(props) {
|
|
23
|
-
var _this;
|
|
24
|
-
_classCallCheck(this, Carousel);
|
|
25
|
-
_this = _callSuper(this, Carousel, [props]);
|
|
26
|
-
_defineProperty(_this, "setThumbsRef", function (node) {
|
|
27
|
-
_this.thumbsRef = node;
|
|
28
|
-
});
|
|
29
|
-
_defineProperty(_this, "setCarouselWrapperRef", function (node) {
|
|
30
|
-
_this.carouselWrapperRef = node;
|
|
31
|
-
});
|
|
32
|
-
_defineProperty(_this, "setListRef", function (node) {
|
|
33
|
-
_this.listRef = node;
|
|
34
|
-
});
|
|
35
|
-
_defineProperty(_this, "setItemsRef", function (node, index) {
|
|
36
|
-
if (!_this.itemsRef) {
|
|
37
|
-
_this.itemsRef = [];
|
|
38
|
-
}
|
|
39
|
-
_this.itemsRef[index] = node;
|
|
40
|
-
});
|
|
41
|
-
_defineProperty(_this, "autoPlay", function () {
|
|
42
|
-
if (Children.count(_this.props.children) <= 1) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
_this.clearAutoPlay();
|
|
46
|
-
if (!_this.props.autoPlay) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
_this.timer = setTimeout(function () {
|
|
50
|
-
_this.increment();
|
|
51
|
-
}, _this.props.interval);
|
|
52
|
-
});
|
|
53
|
-
_defineProperty(_this, "clearAutoPlay", function () {
|
|
54
|
-
if (_this.timer) clearTimeout(_this.timer);
|
|
55
|
-
});
|
|
56
|
-
_defineProperty(_this, "resetAutoPlay", function () {
|
|
57
|
-
_this.clearAutoPlay();
|
|
58
|
-
_this.autoPlay();
|
|
59
|
-
});
|
|
60
|
-
_defineProperty(_this, "stopOnHover", function () {
|
|
61
|
-
_this.setState({
|
|
62
|
-
isMouseEntered: true
|
|
63
|
-
}, _this.clearAutoPlay);
|
|
64
|
-
});
|
|
65
|
-
_defineProperty(_this, "startOnLeave", function () {
|
|
66
|
-
_this.setState({
|
|
67
|
-
isMouseEntered: false
|
|
68
|
-
}, _this.autoPlay);
|
|
69
|
-
});
|
|
70
|
-
_defineProperty(_this, "isFocusWithinTheCarousel", function () {
|
|
71
|
-
if (!_this.carouselWrapperRef) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
if (getDocument().activeElement === _this.carouselWrapperRef || _this.carouselWrapperRef.contains(getDocument().activeElement)) {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
return false;
|
|
78
|
-
});
|
|
79
|
-
_defineProperty(_this, "navigateWithKeyboard", function (e) {
|
|
80
|
-
if (!_this.isFocusWithinTheCarousel()) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
var axis = _this.props.axis;
|
|
84
|
-
var isHorizontal = axis === 'horizontal';
|
|
85
|
-
var keyNames = {
|
|
86
|
-
ArrowUp: 38,
|
|
87
|
-
ArrowRight: 39,
|
|
88
|
-
ArrowDown: 40,
|
|
89
|
-
ArrowLeft: 37
|
|
90
|
-
};
|
|
91
|
-
var nextKey = isHorizontal ? keyNames.ArrowRight : keyNames.ArrowDown;
|
|
92
|
-
var prevKey = isHorizontal ? keyNames.ArrowLeft : keyNames.ArrowUp;
|
|
93
|
-
if (nextKey === e.keyCode) {
|
|
94
|
-
_this.increment();
|
|
95
|
-
} else if (prevKey === e.keyCode) {
|
|
96
|
-
_this.decrement();
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
_defineProperty(_this, "updateSizes", function () {
|
|
100
|
-
if (!_this.state.initialized || !_this.itemsRef || _this.itemsRef.length === 0) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
var isHorizontal = _this.props.axis === 'horizontal';
|
|
104
|
-
var firstItem = _this.itemsRef[0];
|
|
105
|
-
if (!firstItem) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
var itemSize = isHorizontal ? firstItem.clientWidth : firstItem.clientHeight;
|
|
109
|
-
_this.setState({
|
|
110
|
-
itemSize: itemSize
|
|
111
|
-
});
|
|
112
|
-
if (_this.thumbsRef) {
|
|
113
|
-
_this.thumbsRef.updateSizes();
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
_defineProperty(_this, "setMountState", function () {
|
|
117
|
-
_this.setState({
|
|
118
|
-
hasMount: true
|
|
119
|
-
});
|
|
120
|
-
_this.updateSizes();
|
|
121
|
-
});
|
|
122
|
-
_defineProperty(_this, "handleClickItem", function (index, item) {
|
|
123
|
-
if (Children.count(_this.props.children) === 0) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (_this.state.cancelClick) {
|
|
127
|
-
_this.setState({
|
|
128
|
-
cancelClick: false
|
|
129
|
-
});
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
_this.props.onClickItem(index, item);
|
|
133
|
-
if (index !== _this.state.selectedItem) {
|
|
134
|
-
_this.setState({
|
|
135
|
-
selectedItem: index
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
/**
|
|
140
|
-
* On Change handler, Passes the index and React node to the supplied onChange prop
|
|
141
|
-
* @param index of the carousel item
|
|
142
|
-
* @param item React node of the item being changed
|
|
143
|
-
*/
|
|
144
|
-
_defineProperty(_this, "handleOnChange", function (index, item) {
|
|
145
|
-
if (Children.count(_this.props.children) <= 1) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
_this.props.onChange(index, item);
|
|
149
|
-
});
|
|
150
|
-
_defineProperty(_this, "handleClickThumb", function (index, item) {
|
|
151
|
-
_this.props.onClickThumb(index, item);
|
|
152
|
-
_this.moveTo(index);
|
|
153
|
-
});
|
|
154
|
-
_defineProperty(_this, "onSwipeStart", function (event) {
|
|
155
|
-
_this.setState({
|
|
156
|
-
swiping: true
|
|
157
|
-
});
|
|
158
|
-
_this.props.onSwipeStart(event);
|
|
159
|
-
});
|
|
160
|
-
_defineProperty(_this, "onSwipeEnd", function (event) {
|
|
161
|
-
_this.setState({
|
|
162
|
-
swiping: false,
|
|
163
|
-
cancelClick: false,
|
|
164
|
-
swipeMovementStarted: false
|
|
165
|
-
});
|
|
166
|
-
_this.props.onSwipeEnd(event);
|
|
167
|
-
_this.clearAutoPlay();
|
|
168
|
-
if (_this.state.autoPlay) {
|
|
169
|
-
_this.autoPlay();
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
_defineProperty(_this, "onSwipeMove", function (delta, event) {
|
|
173
|
-
_this.props.onSwipeMove(event);
|
|
174
|
-
var animationHandlerResponse = _this.props.swipeAnimationHandler(delta, _this.props, _this.state, _this.setState.bind(_this));
|
|
175
|
-
_this.setState(_extends({}, animationHandlerResponse));
|
|
176
|
-
|
|
177
|
-
// If we have not moved, we should have an empty object returned
|
|
178
|
-
// Return false to allow scrolling when not swiping
|
|
179
|
-
return !!Object.keys(animationHandlerResponse).length;
|
|
180
|
-
});
|
|
181
|
-
/**
|
|
182
|
-
* Decrements the selectedItem index a number of positions through the children list
|
|
183
|
-
* @param positions
|
|
184
|
-
* @param fromSwipe
|
|
185
|
-
*/
|
|
186
|
-
_defineProperty(_this, "decrement", function () {
|
|
187
|
-
var positions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
188
|
-
_this.moveTo(_this.state.selectedItem - (typeof positions === 'number' ? positions : 1));
|
|
189
|
-
});
|
|
190
|
-
/**
|
|
191
|
-
* Increments the selectedItem index a number of positions through the children list
|
|
192
|
-
* @param positions
|
|
193
|
-
* @param fromSwipe
|
|
194
|
-
*/
|
|
195
|
-
_defineProperty(_this, "increment", function () {
|
|
196
|
-
var positions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
197
|
-
_this.moveTo(_this.state.selectedItem + (typeof positions === 'number' ? positions : 1));
|
|
198
|
-
});
|
|
199
|
-
/**
|
|
200
|
-
* Moves the selected item to the position provided
|
|
201
|
-
* @param position
|
|
202
|
-
* @param fromSwipe
|
|
203
|
-
*/
|
|
204
|
-
_defineProperty(_this, "moveTo", function (position) {
|
|
205
|
-
if (typeof position !== 'number') {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
var lastPosition = Children.count(_this.props.children) - 1;
|
|
209
|
-
if (position < 0) {
|
|
210
|
-
position = _this.props.infiniteLoop ? lastPosition : 0;
|
|
211
|
-
}
|
|
212
|
-
if (position > lastPosition) {
|
|
213
|
-
position = _this.props.infiniteLoop ? 0 : lastPosition;
|
|
214
|
-
}
|
|
215
|
-
_this.selectItem({
|
|
216
|
-
// if it's not a slider, we don't need to set position here
|
|
217
|
-
selectedItem: position
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// don't reset auto play when stop on hover is enabled, doing so will trigger a call to auto play more than once
|
|
221
|
-
// and will result in the interval function not being cleared correctly.
|
|
222
|
-
if (_this.state.autoPlay && _this.state.isMouseEntered === false) {
|
|
223
|
-
_this.resetAutoPlay();
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
_defineProperty(_this, "onClickNext", function () {
|
|
227
|
-
_this.increment(1);
|
|
228
|
-
});
|
|
229
|
-
_defineProperty(_this, "onClickPrev", function () {
|
|
230
|
-
_this.decrement(1);
|
|
231
|
-
});
|
|
232
|
-
_defineProperty(_this, "onSwipeForward", function () {
|
|
233
|
-
_this.increment(1);
|
|
234
|
-
if (_this.props.emulateTouch) {
|
|
235
|
-
_this.setState({
|
|
236
|
-
cancelClick: true
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
_defineProperty(_this, "onSwipeBackwards", function () {
|
|
241
|
-
_this.decrement(1);
|
|
242
|
-
if (_this.props.emulateTouch) {
|
|
243
|
-
_this.setState({
|
|
244
|
-
cancelClick: true
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
_defineProperty(_this, "changeItem", function (newIndex) {
|
|
249
|
-
return function (e) {
|
|
250
|
-
if (!isKeyboardEvent(e) || e.key === 'Enter') {
|
|
251
|
-
_this.moveTo(newIndex);
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
});
|
|
255
|
-
/**
|
|
256
|
-
* This function is called when you want to 'select' a new item, or rather move to a 'selected' item
|
|
257
|
-
* It also handles the onChange callback wrapper
|
|
258
|
-
* @param state state object with updated selected item, and swiping bool if relevant
|
|
259
|
-
*/
|
|
260
|
-
_defineProperty(_this, "selectItem", function (state) {
|
|
261
|
-
// Merge in the new state while updating updating previous item
|
|
262
|
-
_this.setState(_extends({
|
|
263
|
-
previousItem: _this.state.selectedItem
|
|
264
|
-
}, state), function () {
|
|
265
|
-
// Run animation handler and update styles based on it
|
|
266
|
-
_this.setState(_this.animationHandler(_this.props, _this.state));
|
|
267
|
-
});
|
|
268
|
-
_this.handleOnChange(state.selectedItem, Children.toArray(_this.props.children)[state.selectedItem]);
|
|
269
|
-
});
|
|
270
|
-
_defineProperty(_this, "getInitialImage", function () {
|
|
271
|
-
var selectedItem = _this.props.selectedItem;
|
|
272
|
-
var item = _this.itemsRef && _this.itemsRef[selectedItem];
|
|
273
|
-
var images = item && item.getElementsByTagName('img') || [];
|
|
274
|
-
return images[0];
|
|
275
|
-
});
|
|
276
|
-
_defineProperty(_this, "getVariableItemHeight", function (position) {
|
|
277
|
-
var item = _this.itemsRef && _this.itemsRef[position];
|
|
278
|
-
if (_this.state.hasMount && item && item.children.length) {
|
|
279
|
-
var slideImages = item.children[0].getElementsByTagName('img') || [];
|
|
280
|
-
if (slideImages.length > 0) {
|
|
281
|
-
var image = slideImages[0];
|
|
282
|
-
if (!image.complete) {
|
|
283
|
-
// if the image is still loading, the size won't be available so we trigger a new render after it's done
|
|
284
|
-
var _onImageLoad = function onImageLoad() {
|
|
285
|
-
_this.forceUpdate();
|
|
286
|
-
image.removeEventListener('load', _onImageLoad);
|
|
287
|
-
};
|
|
288
|
-
image.addEventListener('load', _onImageLoad);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// try to get img first, if img not there find first display tag
|
|
293
|
-
var displayItem = slideImages[0] || item.children[0];
|
|
294
|
-
var height = displayItem.clientHeight;
|
|
295
|
-
return height > 0 ? height : null;
|
|
296
|
-
}
|
|
297
|
-
return null;
|
|
298
|
-
});
|
|
299
|
-
var initState = {
|
|
300
|
-
initialized: false,
|
|
301
|
-
previousItem: props.selectedItem,
|
|
302
|
-
selectedItem: props.selectedItem,
|
|
303
|
-
hasMount: false,
|
|
304
|
-
isMouseEntered: false,
|
|
305
|
-
autoPlay: props.autoPlay,
|
|
306
|
-
swiping: false,
|
|
307
|
-
swipeMovementStarted: false,
|
|
308
|
-
cancelClick: false,
|
|
309
|
-
itemSize: 1,
|
|
310
|
-
itemListStyle: {},
|
|
311
|
-
slideStyle: {},
|
|
312
|
-
selectedStyle: {},
|
|
313
|
-
prevStyle: {}
|
|
314
|
-
};
|
|
315
|
-
_this.animationHandler = typeof props.animationHandler === 'function' && props.animationHandler || props.animationHandler === 'fade' && fadeAnimationHandler || slideAnimationHandler;
|
|
316
|
-
_this.state = _extends({}, initState, _this.animationHandler(props, initState));
|
|
317
|
-
return _this;
|
|
318
|
-
}
|
|
319
|
-
_inherits(Carousel, _React$Component);
|
|
320
|
-
return _createClass(Carousel, [{
|
|
321
|
-
key: "componentDidMount",
|
|
322
|
-
value: function componentDidMount() {
|
|
323
|
-
if (!this.props.children) {
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
this.setupCarousel();
|
|
327
|
-
}
|
|
328
|
-
}, {
|
|
329
|
-
key: "componentDidUpdate",
|
|
330
|
-
value: function componentDidUpdate(prevProps, prevState) {
|
|
331
|
-
if (!prevProps.children && this.props.children && !this.state.initialized) {
|
|
332
|
-
this.setupCarousel();
|
|
333
|
-
}
|
|
334
|
-
if (!prevProps.autoFocus && this.props.autoFocus) {
|
|
335
|
-
this.forceFocus();
|
|
336
|
-
}
|
|
337
|
-
if (prevState.swiping && !this.state.swiping) {
|
|
338
|
-
// We stopped swiping, ensure we are heading to the new/current slide and not stuck
|
|
339
|
-
|
|
340
|
-
this.setState(_extends({}, this.props.stopSwipingHandler(this.props, this.state)));
|
|
341
|
-
}
|
|
342
|
-
if (prevProps.selectedItem !== this.props.selectedItem || prevProps.centerMode !== this.props.centerMode) {
|
|
343
|
-
this.updateSizes();
|
|
344
|
-
this.moveTo(this.props.selectedItem);
|
|
345
|
-
}
|
|
346
|
-
if (prevProps.autoPlay !== this.props.autoPlay) {
|
|
347
|
-
if (this.props.autoPlay) {
|
|
348
|
-
this.setupAutoPlay();
|
|
349
|
-
} else {
|
|
350
|
-
this.destroyAutoPlay();
|
|
351
|
-
}
|
|
352
|
-
this.setState({
|
|
353
|
-
autoPlay: this.props.autoPlay
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}, {
|
|
358
|
-
key: "componentWillUnmount",
|
|
359
|
-
value: function componentWillUnmount() {
|
|
360
|
-
this.destroyCarousel();
|
|
361
|
-
}
|
|
362
|
-
}, {
|
|
363
|
-
key: "setupCarousel",
|
|
364
|
-
value: function setupCarousel() {
|
|
365
|
-
var _this2 = this;
|
|
366
|
-
this.bindEvents();
|
|
367
|
-
if (this.state.autoPlay && Children.count(this.props.children) > 1) {
|
|
368
|
-
this.setupAutoPlay();
|
|
369
|
-
}
|
|
370
|
-
if (this.props.autoFocus) {
|
|
371
|
-
this.forceFocus();
|
|
372
|
-
}
|
|
373
|
-
this.setState({
|
|
374
|
-
initialized: true
|
|
375
|
-
}, function () {
|
|
376
|
-
var initialImage = _this2.getInitialImage();
|
|
377
|
-
if (initialImage && !initialImage.complete) {
|
|
378
|
-
// if it's a carousel of images, we set the mount state after the first image is loaded
|
|
379
|
-
initialImage.addEventListener('load', _this2.setMountState);
|
|
380
|
-
} else {
|
|
381
|
-
_this2.setMountState();
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
}, {
|
|
386
|
-
key: "destroyCarousel",
|
|
387
|
-
value: function destroyCarousel() {
|
|
388
|
-
if (this.state.initialized) {
|
|
389
|
-
this.unbindEvents();
|
|
390
|
-
this.destroyAutoPlay();
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}, {
|
|
394
|
-
key: "setupAutoPlay",
|
|
395
|
-
value: function setupAutoPlay() {
|
|
396
|
-
this.autoPlay();
|
|
397
|
-
var carouselWrapper = this.carouselWrapperRef;
|
|
398
|
-
if (this.props.stopOnHover && carouselWrapper) {
|
|
399
|
-
carouselWrapper.addEventListener('mouseenter', this.stopOnHover);
|
|
400
|
-
carouselWrapper.addEventListener('mouseleave', this.startOnLeave);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}, {
|
|
404
|
-
key: "destroyAutoPlay",
|
|
405
|
-
value: function destroyAutoPlay() {
|
|
406
|
-
this.clearAutoPlay();
|
|
407
|
-
var carouselWrapper = this.carouselWrapperRef;
|
|
408
|
-
if (this.props.stopOnHover && carouselWrapper) {
|
|
409
|
-
carouselWrapper.removeEventListener('mouseenter', this.stopOnHover);
|
|
410
|
-
carouselWrapper.removeEventListener('mouseleave', this.startOnLeave);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}, {
|
|
414
|
-
key: "bindEvents",
|
|
415
|
-
value: function bindEvents() {
|
|
416
|
-
// as the widths are calculated, we need to resize
|
|
417
|
-
// the carousel when the window is resized
|
|
418
|
-
getWindow().addEventListener('resize', this.updateSizes);
|
|
419
|
-
// issue #2 - image loading smaller
|
|
420
|
-
getWindow().addEventListener('DOMContentLoaded', this.updateSizes);
|
|
421
|
-
if (this.props.useKeyboardArrows) {
|
|
422
|
-
getDocument().addEventListener('keydown', this.navigateWithKeyboard);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}, {
|
|
426
|
-
key: "unbindEvents",
|
|
427
|
-
value: function unbindEvents() {
|
|
428
|
-
// removing listeners
|
|
429
|
-
getWindow().removeEventListener('resize', this.updateSizes);
|
|
430
|
-
getWindow().removeEventListener('DOMContentLoaded', this.updateSizes);
|
|
431
|
-
var initialImage = this.getInitialImage();
|
|
432
|
-
if (initialImage) {
|
|
433
|
-
initialImage.removeEventListener('load', this.setMountState);
|
|
434
|
-
}
|
|
435
|
-
if (this.props.useKeyboardArrows) {
|
|
436
|
-
getDocument().removeEventListener('keydown', this.navigateWithKeyboard);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}, {
|
|
440
|
-
key: "forceFocus",
|
|
441
|
-
value: function forceFocus() {
|
|
442
|
-
var _this$carouselWrapper;
|
|
443
|
-
(_this$carouselWrapper = this.carouselWrapperRef) === null || _this$carouselWrapper === void 0 || _this$carouselWrapper.focus();
|
|
444
|
-
}
|
|
445
|
-
}, {
|
|
446
|
-
key: "renderItems",
|
|
447
|
-
value: function renderItems(isClone) {
|
|
448
|
-
var _this3 = this;
|
|
449
|
-
if (!this.props.children) {
|
|
450
|
-
return [];
|
|
451
|
-
}
|
|
452
|
-
return Children.map(this.props.children, function (item, index) {
|
|
453
|
-
var isSelected = index === _this3.state.selectedItem;
|
|
454
|
-
var isPrevious = index === _this3.state.previousItem;
|
|
455
|
-
var style = isSelected && _this3.state.selectedStyle || isPrevious && _this3.state.prevStyle || _this3.state.slideStyle || {};
|
|
456
|
-
if (_this3.props.centerMode && _this3.props.axis === 'horizontal') {
|
|
457
|
-
style = _extends({}, style, {
|
|
458
|
-
minWidth: _this3.props.centerSlidePercentage + '%'
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
if (_this3.state.swiping && _this3.state.swipeMovementStarted) {
|
|
462
|
-
style = _extends({}, style, {
|
|
463
|
-
pointerEvents: 'none'
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
var slideProps = {
|
|
467
|
-
ref: function ref(e) {
|
|
468
|
-
return _this3.setItemsRef(e, index);
|
|
469
|
-
},
|
|
470
|
-
key: 'itemKey' + index + (isClone ? 'clone' : ''),
|
|
471
|
-
className: klass.ITEM(true, index === _this3.state.selectedItem, index === _this3.state.previousItem),
|
|
472
|
-
onClick: _this3.handleClickItem.bind(_this3, index, item),
|
|
473
|
-
style: style
|
|
474
|
-
};
|
|
475
|
-
return /*#__PURE__*/React.createElement("li", slideProps, _this3.props.renderItem(item, {
|
|
476
|
-
isSelected: index === _this3.state.selectedItem,
|
|
477
|
-
isPrevious: index === _this3.state.previousItem
|
|
478
|
-
}));
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
}, {
|
|
482
|
-
key: "renderControls",
|
|
483
|
-
value: function renderControls() {
|
|
484
|
-
var _this4 = this;
|
|
485
|
-
var _this$props = this.props,
|
|
486
|
-
showIndicators = _this$props.showIndicators,
|
|
487
|
-
labels = _this$props.labels,
|
|
488
|
-
renderIndicator = _this$props.renderIndicator,
|
|
489
|
-
children = _this$props.children;
|
|
490
|
-
if (!showIndicators) {
|
|
491
|
-
return null;
|
|
492
|
-
}
|
|
493
|
-
return /*#__PURE__*/React.createElement("ul", {
|
|
494
|
-
className: "control-dots"
|
|
495
|
-
}, Children.map(children, function (_, index) {
|
|
496
|
-
return renderIndicator && renderIndicator(_this4.changeItem(index), index === _this4.state.selectedItem, index, labels.item);
|
|
497
|
-
}));
|
|
498
|
-
}
|
|
499
|
-
}, {
|
|
500
|
-
key: "renderStatus",
|
|
501
|
-
value: function renderStatus() {
|
|
502
|
-
if (!this.props.showStatus) {
|
|
503
|
-
return null;
|
|
504
|
-
}
|
|
505
|
-
return /*#__PURE__*/React.createElement("p", {
|
|
506
|
-
className: "carousel-status"
|
|
507
|
-
}, this.props.statusFormatter(this.state.selectedItem + 1, Children.count(this.props.children)));
|
|
508
|
-
}
|
|
509
|
-
}, {
|
|
510
|
-
key: "renderThumbs",
|
|
511
|
-
value: function renderThumbs() {
|
|
512
|
-
if (!this.props.showThumbs || !this.props.children || Children.count(this.props.children) === 0) {
|
|
513
|
-
return null;
|
|
514
|
-
}
|
|
515
|
-
return /*#__PURE__*/React.createElement(Thumbs, {
|
|
516
|
-
ref: this.setThumbsRef,
|
|
517
|
-
onSelectItem: this.handleClickThumb,
|
|
518
|
-
selectedItem: this.state.selectedItem,
|
|
519
|
-
transitionTime: this.props.transitionTime,
|
|
520
|
-
thumbWidth: this.props.thumbWidth,
|
|
521
|
-
labels: this.props.labels,
|
|
522
|
-
emulateTouch: this.props.emulateTouch
|
|
523
|
-
}, this.props.renderThumbs(this.props.children));
|
|
524
|
-
}
|
|
525
|
-
}, {
|
|
526
|
-
key: "render",
|
|
527
|
-
value: function render() {
|
|
528
|
-
var _this5 = this;
|
|
529
|
-
if (!this.props.children || Children.count(this.props.children) === 0) {
|
|
530
|
-
return null;
|
|
531
|
-
}
|
|
532
|
-
var isSwipeable = this.props.swipeable && Children.count(this.props.children) > 1;
|
|
533
|
-
var isHorizontal = this.props.axis === 'horizontal';
|
|
534
|
-
var canShowArrows = this.props.showArrows && Children.count(this.props.children) > 1;
|
|
535
|
-
|
|
536
|
-
// show left arrow?
|
|
537
|
-
var hasPrev = canShowArrows && (this.state.selectedItem > 0 || this.props.infiniteLoop) || false;
|
|
538
|
-
// show right arrow
|
|
539
|
-
var hasNext = canShowArrows && (this.state.selectedItem < Children.count(this.props.children) - 1 || this.props.infiniteLoop) || false;
|
|
540
|
-
var itemsClone = this.renderItems(true);
|
|
541
|
-
var firstClone = itemsClone.shift();
|
|
542
|
-
var lastClone = itemsClone.pop();
|
|
543
|
-
var swiperProps = {
|
|
544
|
-
className: klass.SLIDER(true, this.state.swiping),
|
|
545
|
-
onSwipeMove: this.onSwipeMove,
|
|
546
|
-
onSwipeStart: this.onSwipeStart,
|
|
547
|
-
onSwipeEnd: this.onSwipeEnd,
|
|
548
|
-
style: this.state.itemListStyle,
|
|
549
|
-
tolerance: this.props.swipeScrollTolerance
|
|
550
|
-
};
|
|
551
|
-
var containerStyles = {};
|
|
552
|
-
if (isHorizontal) {
|
|
553
|
-
swiperProps.onSwipeLeft = this.onSwipeForward;
|
|
554
|
-
swiperProps.onSwipeRight = this.onSwipeBackwards;
|
|
555
|
-
if (this.props.dynamicHeight) {
|
|
556
|
-
var itemHeight = this.getVariableItemHeight(this.state.selectedItem);
|
|
557
|
-
// swiperProps.style.height = itemHeight || 'auto';
|
|
558
|
-
containerStyles.height = itemHeight || 'auto';
|
|
559
|
-
}
|
|
560
|
-
} else {
|
|
561
|
-
swiperProps.onSwipeUp = this.props.verticalSwipe === 'natural' ? this.onSwipeBackwards : this.onSwipeForward;
|
|
562
|
-
swiperProps.onSwipeDown = this.props.verticalSwipe === 'natural' ? this.onSwipeForward : this.onSwipeBackwards;
|
|
563
|
-
swiperProps.style = _extends({}, swiperProps.style, {
|
|
564
|
-
height: this.state.itemSize
|
|
565
|
-
});
|
|
566
|
-
containerStyles.height = this.state.itemSize;
|
|
567
|
-
}
|
|
568
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
569
|
-
"aria-label": this.props.ariaLabel,
|
|
570
|
-
className: klass.ROOT(this.props.className),
|
|
571
|
-
ref: this.setCarouselWrapperRef,
|
|
572
|
-
tabIndex: this.props.useKeyboardArrows ? 0 : undefined
|
|
573
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
574
|
-
className: klass.CAROUSEL(true),
|
|
575
|
-
style: {
|
|
576
|
-
width: this.props.width
|
|
577
|
-
}
|
|
578
|
-
}, this.renderControls(), this.props.renderArrowPrev(this.onClickPrev, hasPrev, this.props.labels.leftArrow), /*#__PURE__*/React.createElement("div", {
|
|
579
|
-
className: klass.WRAPPER(true, this.props.axis),
|
|
580
|
-
style: containerStyles
|
|
581
|
-
}, isSwipeable ? /*#__PURE__*/React.createElement(Swipe, _extends({
|
|
582
|
-
tagName: "ul",
|
|
583
|
-
innerRef: this.setListRef
|
|
584
|
-
}, swiperProps, {
|
|
585
|
-
allowMouseEvents: this.props.emulateTouch
|
|
586
|
-
}), this.props.infiniteLoop && lastClone, this.renderItems(), this.props.infiniteLoop && firstClone) : /*#__PURE__*/React.createElement("ul", {
|
|
587
|
-
className: klass.SLIDER(true, this.state.swiping),
|
|
588
|
-
ref: function ref(node) {
|
|
589
|
-
return _this5.setListRef(node);
|
|
590
|
-
},
|
|
591
|
-
style: this.state.itemListStyle || {}
|
|
592
|
-
}, this.props.infiniteLoop && lastClone, this.renderItems(), this.props.infiniteLoop && firstClone)), this.props.renderArrowNext(this.onClickNext, hasNext, this.props.labels.rightArrow), this.renderStatus()), this.renderThumbs());
|
|
593
|
-
}
|
|
594
|
-
}]);
|
|
595
|
-
}(React.Component);
|
|
596
|
-
// @ts-ignore
|
|
597
|
-
_defineProperty(Carousel, "displayName", 'Carousel');
|
|
598
|
-
_defineProperty(Carousel, "defaultProps", {
|
|
599
|
-
ariaLabel: undefined,
|
|
600
|
-
axis: 'horizontal',
|
|
601
|
-
centerSlidePercentage: 80,
|
|
602
|
-
interval: 3000,
|
|
603
|
-
labels: {
|
|
604
|
-
leftArrow: 'previous slide / item',
|
|
605
|
-
rightArrow: 'next slide / item',
|
|
606
|
-
item: 'slide item'
|
|
607
|
-
},
|
|
608
|
-
onClickItem: noop,
|
|
609
|
-
onClickThumb: noop,
|
|
610
|
-
onChange: noop,
|
|
611
|
-
onSwipeStart: function onSwipeStart() {},
|
|
612
|
-
onSwipeEnd: function onSwipeEnd() {},
|
|
613
|
-
onSwipeMove: function onSwipeMove() {
|
|
614
|
-
return false;
|
|
615
|
-
},
|
|
616
|
-
preventMovementUntilSwipeScrollTolerance: false,
|
|
617
|
-
renderArrowPrev: function renderArrowPrev(onClickHandler, hasPrev, label) {
|
|
618
|
-
return /*#__PURE__*/React.createElement(Arrow, {
|
|
619
|
-
direction: "prev",
|
|
620
|
-
onClickHandler: onClickHandler,
|
|
621
|
-
enabled: hasPrev,
|
|
622
|
-
label: label
|
|
623
|
-
});
|
|
624
|
-
},
|
|
625
|
-
renderArrowNext: function renderArrowNext(onClickHandler, hasNext, label) {
|
|
626
|
-
return /*#__PURE__*/React.createElement(Arrow, {
|
|
627
|
-
direction: "next",
|
|
628
|
-
onClickHandler: onClickHandler,
|
|
629
|
-
enabled: hasNext,
|
|
630
|
-
label: label
|
|
631
|
-
});
|
|
632
|
-
},
|
|
633
|
-
renderIndicator: function renderIndicator(onClickHandler, isSelected, index, label) {
|
|
634
|
-
return /*#__PURE__*/React.createElement(Indicator, {
|
|
635
|
-
onClickHandler: onClickHandler,
|
|
636
|
-
isSelected: isSelected,
|
|
637
|
-
index: index,
|
|
638
|
-
label: label
|
|
639
|
-
});
|
|
640
|
-
},
|
|
641
|
-
renderItem: function renderItem(item) {
|
|
642
|
-
return item;
|
|
643
|
-
},
|
|
644
|
-
renderThumbs: function renderThumbs(children) {
|
|
645
|
-
var images = Children.map(children, function (item) {
|
|
646
|
-
var img = item;
|
|
647
|
-
|
|
648
|
-
// if the item is not an image, try to find the first image in the item's children.
|
|
649
|
-
if (item.type !== 'img') {
|
|
650
|
-
img = Children.toArray(item.props.children).find(function (children) {
|
|
651
|
-
return children.type === 'img';
|
|
652
|
-
});
|
|
653
|
-
}
|
|
654
|
-
if (!img) {
|
|
655
|
-
return undefined;
|
|
656
|
-
}
|
|
657
|
-
return img;
|
|
658
|
-
});
|
|
659
|
-
if (images.filter(function (image) {
|
|
660
|
-
return image;
|
|
661
|
-
}).length === 0) {
|
|
662
|
-
console.warn("No images found! Can't build the thumb list without images. If you don't need thumbs, set showThumbs={false} in the Carousel. Note that it's not possible to get images rendered inside custom components. More info at https://github.com/leandrowd/react-responsive-carousel/blob/master/TROUBLESHOOTING.md");
|
|
663
|
-
return [];
|
|
664
|
-
}
|
|
665
|
-
return images;
|
|
666
|
-
},
|
|
667
|
-
statusFormatter: defaultStatusFormatter,
|
|
668
|
-
selectedItem: 0,
|
|
669
|
-
showArrows: true,
|
|
670
|
-
showIndicators: true,
|
|
671
|
-
showStatus: true,
|
|
672
|
-
showThumbs: true,
|
|
673
|
-
stopOnHover: true,
|
|
674
|
-
swipeScrollTolerance: 5,
|
|
675
|
-
swipeable: true,
|
|
676
|
-
transitionTime: 350,
|
|
677
|
-
verticalSwipe: 'standard',
|
|
678
|
-
width: '100%',
|
|
679
|
-
animationHandler: 'slide',
|
|
680
|
-
swipeAnimationHandler: slideSwipeAnimationHandler,
|
|
681
|
-
stopSwipingHandler: slideStopSwipingHandler
|
|
682
|
-
});
|
|
683
|
-
export { Carousel as default };
|
|
1
|
+
export { default as Carousel } from './component';
|
|
2
|
+
export { default as Thumbs } from './component/Thumbs';
|