@kolserdav/swiper 2.1.3-beta → 2.3.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/index.d.ts +8 -2
- package/dist/index.js +78 -62
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +78 -62
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Copyright: kolserdav, All rights reserved (c)
|
|
8
8
|
* Create date: Mon Nov 29 2021 16:18:08 GMT+0700 (Krasnoyarsk Standard Time)
|
|
9
9
|
******************************************************************************************/
|
|
10
|
-
import React from 'react';
|
|
10
|
+
import React, { RefObject } from 'react';
|
|
11
11
|
/**
|
|
12
12
|
* Time to miliseconds of change animation by card left value
|
|
13
13
|
*/
|
|
@@ -17,6 +17,8 @@ export declare const SWIPE_TRANSITION_TIMEOUT = 400;
|
|
|
17
17
|
*/
|
|
18
18
|
export interface Swipe {
|
|
19
19
|
id: number | null;
|
|
20
|
+
nextRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
|
|
21
|
+
closeRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
|
|
20
22
|
children: React.ReactElement | React.ReactElement[];
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
@@ -50,7 +52,11 @@ interface SwiperProps {
|
|
|
50
52
|
/**
|
|
51
53
|
* On swipe callback
|
|
52
54
|
*/
|
|
53
|
-
onSwipe?: (currentId: number) => void;
|
|
55
|
+
onSwipe?: (currentId: number | null | undefined) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Auto slide if provieded
|
|
58
|
+
*/
|
|
59
|
+
durationAnimation?: number;
|
|
54
60
|
}
|
|
55
61
|
/**
|
|
56
62
|
* Swiper component
|
package/dist/index.js
CHANGED
|
@@ -215,11 +215,12 @@ var useStyles = styles.makeStyles(function () {
|
|
|
215
215
|
minWidth: '320px',
|
|
216
216
|
width: '100%',
|
|
217
217
|
height: '100%',
|
|
218
|
-
minHeight: '
|
|
218
|
+
minHeight: 'calc(100vh - 2rem)',
|
|
219
219
|
maxWidth: '100vw',
|
|
220
220
|
display: 'flex',
|
|
221
221
|
alignItems: 'center',
|
|
222
|
-
justifyContent: 'center'
|
|
222
|
+
justifyContent: 'center',
|
|
223
|
+
marginBlockStart: '2rem'
|
|
223
224
|
},
|
|
224
225
|
button: {
|
|
225
226
|
cursor: 'pointer',
|
|
@@ -238,13 +239,11 @@ var useStyles = styles.makeStyles(function () {
|
|
|
238
239
|
right: 0
|
|
239
240
|
},
|
|
240
241
|
content: {
|
|
241
|
-
borderRadius: '2px',
|
|
242
242
|
position: 'relative',
|
|
243
243
|
width: 'calc(100% - 48px)',
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
boxShadow: '0px 0px 5px 1px rgba(34, 60, 80, 0.14)'
|
|
244
|
+
maxHeight: 'calc(100% - 48px)',
|
|
245
|
+
minHeight: '20%',
|
|
246
|
+
background: 'white'
|
|
248
247
|
},
|
|
249
248
|
card: {
|
|
250
249
|
position: 'absolute',
|
|
@@ -301,7 +300,8 @@ var Swiper = function Swiper(props) {
|
|
|
301
300
|
getPrev = props.getPrev,
|
|
302
301
|
onSwipe = props.onSwipe,
|
|
303
302
|
className = props.className,
|
|
304
|
-
invitationAnimation = props.invitationAnimation
|
|
303
|
+
invitationAnimation = props.invitationAnimation,
|
|
304
|
+
durationAnimation = props.durationAnimation;
|
|
305
305
|
|
|
306
306
|
var _useStyles = useStyles(),
|
|
307
307
|
go = _useStyles.go,
|
|
@@ -351,16 +351,12 @@ var Swiper = function Swiper(props) {
|
|
|
351
351
|
isMobile = _useState9[0],
|
|
352
352
|
setIsMobile = _useState9[1];
|
|
353
353
|
|
|
354
|
-
var _useState10 = React.useState(
|
|
354
|
+
var _useState10 = React.useState(false),
|
|
355
355
|
load = _useState10[0],
|
|
356
356
|
setLoad = _useState10[1];
|
|
357
357
|
|
|
358
358
|
var containerRef = React.useRef(null);
|
|
359
359
|
|
|
360
|
-
var _buttonPrevRef = React.useRef(null);
|
|
361
|
-
|
|
362
|
-
var _buttonNextRef = React.useRef(null);
|
|
363
|
-
|
|
364
360
|
if (typeof _defaultCurrent === 'undefined') {
|
|
365
361
|
_defaultCurrent = defaultCurrent;
|
|
366
362
|
}
|
|
@@ -435,11 +431,6 @@ var Swiper = function Swiper(props) {
|
|
|
435
431
|
try {
|
|
436
432
|
var _temp7 = function _temp7(_result2) {
|
|
437
433
|
if (_exit2) return _result2;
|
|
438
|
-
|
|
439
|
-
if (onSwipe !== undefined) {
|
|
440
|
-
onSwipe(currentId);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
434
|
setLoad(false);
|
|
444
435
|
return 0;
|
|
445
436
|
};
|
|
@@ -458,12 +449,11 @@ var Swiper = function Swiper(props) {
|
|
|
458
449
|
setLeft(0);
|
|
459
450
|
setPrev(current);
|
|
460
451
|
setCurrent(next);
|
|
461
|
-
currentId = next === null || next === void 0 ? void 0 : next.id;
|
|
462
452
|
setNext(postNext);
|
|
463
453
|
});
|
|
464
454
|
};
|
|
465
455
|
|
|
466
|
-
if (
|
|
456
|
+
if ((next === null || next === void 0 ? void 0 : next.id) === null) {
|
|
467
457
|
setBackClassHandler();
|
|
468
458
|
setLeft(0);
|
|
469
459
|
setLoad(false);
|
|
@@ -471,6 +461,12 @@ var Swiper = function Swiper(props) {
|
|
|
471
461
|
return 1;
|
|
472
462
|
}
|
|
473
463
|
|
|
464
|
+
currentId = next === null || next === void 0 ? void 0 : next.id;
|
|
465
|
+
|
|
466
|
+
if (onSwipe !== undefined) {
|
|
467
|
+
onSwipe(currentId);
|
|
468
|
+
}
|
|
469
|
+
|
|
474
470
|
setGoClassHandler();
|
|
475
471
|
setLeft(windowWidth * -1);
|
|
476
472
|
startTime = new Date().getTime();
|
|
@@ -499,12 +495,11 @@ var Swiper = function Swiper(props) {
|
|
|
499
495
|
setLeft(0);
|
|
500
496
|
setPrev(prePrev);
|
|
501
497
|
setCurrent(prev);
|
|
502
|
-
currentId = prev === null || prev === void 0 ? void 0 : prev.id;
|
|
503
498
|
setNext(current);
|
|
504
499
|
});
|
|
505
500
|
};
|
|
506
501
|
|
|
507
|
-
if (
|
|
502
|
+
if ((prev === null || prev === void 0 ? void 0 : prev.id) === null) {
|
|
508
503
|
setBackClassHandler();
|
|
509
504
|
setLeft(0);
|
|
510
505
|
setLoad(false);
|
|
@@ -512,6 +507,12 @@ var Swiper = function Swiper(props) {
|
|
|
512
507
|
return 1;
|
|
513
508
|
}
|
|
514
509
|
|
|
510
|
+
currentId = prev === null || prev === void 0 ? void 0 : prev.id;
|
|
511
|
+
|
|
512
|
+
if (onSwipe !== undefined) {
|
|
513
|
+
onSwipe(currentId);
|
|
514
|
+
}
|
|
515
|
+
|
|
515
516
|
setGoClassHandler();
|
|
516
517
|
setLeft(windowWidth);
|
|
517
518
|
startTime = new Date().getTime();
|
|
@@ -564,6 +565,7 @@ var Swiper = function Swiper(props) {
|
|
|
564
565
|
return 'onTouchStart';
|
|
565
566
|
}, function () {
|
|
566
567
|
startClientX = clientX;
|
|
568
|
+
lastLeft = _left;
|
|
567
569
|
_interrupt2 = true;
|
|
568
570
|
}], [function () {
|
|
569
571
|
return 'onTouchMove';
|
|
@@ -595,10 +597,6 @@ var Swiper = function Swiper(props) {
|
|
|
595
597
|
var isNext = origin === 'next';
|
|
596
598
|
return function () {
|
|
597
599
|
try {
|
|
598
|
-
if (load) {
|
|
599
|
-
return Promise.resolve(1);
|
|
600
|
-
}
|
|
601
|
-
|
|
602
600
|
var coeff = isNext ? -1 : 1;
|
|
603
601
|
var leftVal = width * coeff;
|
|
604
602
|
|
|
@@ -608,7 +606,7 @@ var Swiper = function Swiper(props) {
|
|
|
608
606
|
setBackClassHandler();
|
|
609
607
|
}
|
|
610
608
|
|
|
611
|
-
return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT
|
|
609
|
+
return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT)).then(function () {
|
|
612
610
|
return Promise.resolve(swipe(leftVal)).then(function () {
|
|
613
611
|
return 0;
|
|
614
612
|
});
|
|
@@ -672,7 +670,15 @@ var Swiper = function Swiper(props) {
|
|
|
672
670
|
};
|
|
673
671
|
|
|
674
672
|
React.useEffect(function () {
|
|
675
|
-
var _containerRef$current10, _containerRef$current11, _containerRef$current12, _containerRef$current13, _containerRef$current14, _containerRef$current15, _containerRef$current16, _containerRef$current17, _containerRef$current18;
|
|
673
|
+
var _containerRef$current10, _containerRef$current11, _containerRef$current12, _containerRef$current13, _containerRef$current14, _containerRef$current15, _containerRef$current16, _containerRef$current17, _containerRef$current18, _current$nextRef, _current$closeRef;
|
|
674
|
+
|
|
675
|
+
var clearAnimate;
|
|
676
|
+
|
|
677
|
+
if (durationAnimation) {
|
|
678
|
+
clearAnimate = setInterval(function () {
|
|
679
|
+
clickNextHandler();
|
|
680
|
+
}, durationAnimation);
|
|
681
|
+
}
|
|
676
682
|
|
|
677
683
|
var _width = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current10 = containerRef.current) === null || _containerRef$current10 === void 0 ? void 0 : (_containerRef$current11 = _containerRef$current10.parentElement) === null || _containerRef$current11 === void 0 ? void 0 : (_containerRef$current12 = _containerRef$current11.getBoundingClientRect()) === null || _containerRef$current12 === void 0 ? void 0 : _containerRef$current12.width;
|
|
678
684
|
|
|
@@ -681,6 +687,10 @@ var Swiper = function Swiper(props) {
|
|
|
681
687
|
var __left = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current16 = containerRef.current) === null || _containerRef$current16 === void 0 ? void 0 : (_containerRef$current17 = _containerRef$current16.parentElement) === null || _containerRef$current17 === void 0 ? void 0 : (_containerRef$current18 = _containerRef$current17.getBoundingClientRect()) === null || _containerRef$current18 === void 0 ? void 0 : _containerRef$current18.left;
|
|
682
688
|
|
|
683
689
|
var _windowWidth = document.body.clientWidth;
|
|
690
|
+
var buttonNext = current === null || current === void 0 ? void 0 : (_current$nextRef = current.nextRef) === null || _current$nextRef === void 0 ? void 0 : _current$nextRef.current;
|
|
691
|
+
var buttonClose = current === null || current === void 0 ? void 0 : (_current$closeRef = current.closeRef) === null || _current$closeRef === void 0 ? void 0 : _current$closeRef.current;
|
|
692
|
+
buttonNext === null || buttonNext === void 0 ? void 0 : buttonNext.addEventListener('click', clickNextHandler);
|
|
693
|
+
buttonClose === null || buttonClose === void 0 ? void 0 : buttonClose.addEventListener('click', clickNextHandler);
|
|
684
694
|
|
|
685
695
|
if (_width && !width && _height && !height) {
|
|
686
696
|
setWidth(_width);
|
|
@@ -718,31 +728,33 @@ var Swiper = function Swiper(props) {
|
|
|
718
728
|
}
|
|
719
729
|
|
|
720
730
|
if (invitationAnimation && width && !animated) {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
var
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
+
if (prev && next) {
|
|
732
|
+
animated = true;
|
|
733
|
+
|
|
734
|
+
(function () {
|
|
735
|
+
try {
|
|
736
|
+
var _temp18 = function _temp18() {
|
|
737
|
+
var _temp15 = function () {
|
|
738
|
+
if (next.id) {
|
|
739
|
+
return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5 * -1)).then(function () {});
|
|
740
|
+
}
|
|
741
|
+
}();
|
|
731
742
|
|
|
732
|
-
|
|
733
|
-
|
|
743
|
+
if (_temp15 && _temp15.then) return _temp15.then(function () {});
|
|
744
|
+
};
|
|
734
745
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
746
|
+
var _temp19 = function () {
|
|
747
|
+
if (prev.id) {
|
|
748
|
+
return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5)).then(function () {});
|
|
749
|
+
}
|
|
750
|
+
}();
|
|
740
751
|
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
752
|
+
return _temp19 && _temp19.then ? _temp19.then(_temp18) : _temp18(_temp19);
|
|
753
|
+
} catch (e) {
|
|
754
|
+
Promise.reject(e);
|
|
755
|
+
}
|
|
756
|
+
})();
|
|
757
|
+
}
|
|
746
758
|
}
|
|
747
759
|
|
|
748
760
|
if (typeof isMobile === 'undefined') {
|
|
@@ -752,7 +764,13 @@ var Swiper = function Swiper(props) {
|
|
|
752
764
|
setPreValues(prev, next);
|
|
753
765
|
window.addEventListener('resize', resizeHandler);
|
|
754
766
|
return function () {
|
|
767
|
+
if (clearAnimate) {
|
|
768
|
+
clearInterval(clearAnimate);
|
|
769
|
+
}
|
|
770
|
+
|
|
755
771
|
window.removeEventListener('resize', resizeHandler);
|
|
772
|
+
buttonNext === null || buttonNext === void 0 ? void 0 : buttonNext.removeEventListener('click', clickNextHandler);
|
|
773
|
+
buttonClose === null || buttonClose === void 0 ? void 0 : buttonClose.removeEventListener('click', clickNextHandler);
|
|
756
774
|
};
|
|
757
775
|
}, [next, defaultCurrent]);
|
|
758
776
|
return React__default.createElement("div", {
|
|
@@ -763,7 +781,7 @@ var Swiper = function Swiper(props) {
|
|
|
763
781
|
|
|
764
782
|
return React__default.createElement("div", {
|
|
765
783
|
key: item.id
|
|
766
|
-
}, React__default.createElement(React.Fragment, null, item.id && width && React__default.createElement("div", {
|
|
784
|
+
}, React__default.createElement(React.Fragment, null, item.id !== null && width && React__default.createElement("div", {
|
|
767
785
|
onTouchMove: onTouchWrapper('onTouchMove'),
|
|
768
786
|
onTouchStart: onTouchWrapper('onTouchStart'),
|
|
769
787
|
onTouchEnd: onTouchWrapper('onTouchEnd'),
|
|
@@ -775,17 +793,17 @@ var Swiper = function Swiper(props) {
|
|
|
775
793
|
} : item.type === 'prev' ? {
|
|
776
794
|
width: width,
|
|
777
795
|
height: height,
|
|
778
|
-
left: left -
|
|
796
|
+
left: left - window.innerWidth
|
|
779
797
|
} : {
|
|
780
798
|
width: width,
|
|
781
799
|
height: height,
|
|
782
|
-
left: left +
|
|
800
|
+
left: left + window.innerWidth
|
|
783
801
|
},
|
|
784
802
|
className: clsx(card, item.type === 'prev' ? card__prev : item.type === 'next' ? card__next : ''),
|
|
785
803
|
ref: getRef(item.id)
|
|
786
804
|
}, React__default.createElement("div", {
|
|
787
805
|
className: clsx(content, className)
|
|
788
|
-
}, item.children)),
|
|
806
|
+
}, item.children)), item.id === null && React__default.createElement("div", {
|
|
789
807
|
style: item.type === 'current' ? {
|
|
790
808
|
width: width,
|
|
791
809
|
height: height,
|
|
@@ -803,17 +821,15 @@ var Swiper = function Swiper(props) {
|
|
|
803
821
|
}, React__default.createElement(material.IconButton, {
|
|
804
822
|
disabled: true
|
|
805
823
|
}, React__default.createElement(StopIcon, null)))));
|
|
806
|
-
}), typeof isMobile !== 'undefined' && !isMobile && (prev === null || prev === void 0 ? void 0 : prev.id) && React__default.createElement("div", {
|
|
807
|
-
className: clsx(button, button__prev)
|
|
808
|
-
ref: _buttonPrevRef
|
|
824
|
+
}), typeof isMobile !== 'undefined' && !isMobile && (prev === null || prev === void 0 ? void 0 : prev.id) !== null && React__default.createElement("div", {
|
|
825
|
+
className: clsx(button, button__prev)
|
|
809
826
|
}, React__default.createElement(material.IconButton, {
|
|
810
|
-
disabled: load,
|
|
827
|
+
disabled: load || isMobile,
|
|
811
828
|
onClick: clickPrevHandler
|
|
812
|
-
}, React__default.createElement(NavigateNextIcon, null))), typeof isMobile !== 'undefined' && !isMobile && (next === null || next === void 0 ? void 0 : next.id) && React__default.createElement("div", {
|
|
813
|
-
className: clsx(button, button__next)
|
|
814
|
-
ref: _buttonNextRef
|
|
829
|
+
}, React__default.createElement(NavigateNextIcon, null))), typeof isMobile !== 'undefined' && !isMobile && (next === null || next === void 0 ? void 0 : next.id) !== null && React__default.createElement("div", {
|
|
830
|
+
className: clsx(button, button__next)
|
|
815
831
|
}, React__default.createElement(material.IconButton, {
|
|
816
|
-
disabled: load,
|
|
832
|
+
disabled: load || isMobile,
|
|
817
833
|
onClick: clickNextHandler
|
|
818
834
|
}, React__default.createElement(NavigateNextIcon, null))));
|
|
819
835
|
};
|