@kolserdav/swiper 2.0.1-beta → 2.1.3-beta

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.
@@ -1,5 +1,6 @@
1
- import React, { useState, useRef, useMemo, useEffect, createRef } from 'react';
1
+ import React, { useState, useRef, useMemo, useEffect, Fragment, createRef } from 'react';
2
2
  import { IconButton } from '@mui/material';
3
+ import { makeStyles } from '@mui/styles';
3
4
  import clsx from 'clsx';
4
5
  import StopIcon from '@mui/icons-material/StopScreenShare';
5
6
  import NavigateNextIcon from '@mui/icons-material/NavigateNext';
@@ -197,8 +198,68 @@ function _switch(discriminant, cases) {
197
198
  }
198
199
  }
199
200
 
200
- var styles = {"container":"_p6aGD","paper":"_3_Zua","pipe":"_2tyje","card":"_7l_j0","prev":"_2S9j_","next":"_2T1oW","back":"_uQNyq","go":"_8240d","card__stop":"_1mqCn","content":"_1EOHv","button":"_7_rsx","button_next":"_2kk22","button_prev":"_B1K5l"};
201
-
201
+ var useStyles = makeStyles(function () {
202
+ return {
203
+ go: {
204
+ transition: 'left 0.4s ease-out 0s'
205
+ },
206
+ back: {
207
+ transition: 'left 0.4s ease-in 0s'
208
+ },
209
+ container: {
210
+ position: 'relative',
211
+ overflow: 'hidden',
212
+ minWidth: '320px',
213
+ width: '100%',
214
+ height: '100%',
215
+ minHeight: '80vh',
216
+ maxWidth: '100vw',
217
+ display: 'flex',
218
+ alignItems: 'center',
219
+ justifyContent: 'center'
220
+ },
221
+ button: {
222
+ cursor: 'pointer',
223
+ position: 'absolute',
224
+ width: 'auto',
225
+ height: 'auto',
226
+ display: 'flex',
227
+ alignItems: 'center',
228
+ zIndex: '12'
229
+ },
230
+ button__prev: {
231
+ left: 0,
232
+ transform: 'rotate(180deg)'
233
+ },
234
+ button__next: {
235
+ right: 0
236
+ },
237
+ content: {
238
+ borderRadius: '2px',
239
+ position: 'relative',
240
+ width: 'calc(100% - 48px)',
241
+ height: 'calc(100% - 48px)',
242
+ '-webkit-box-shadow': '0px 0px 5px 1px rgba(34, 60, 80, 0.14)',
243
+ '-moz-box-shadow': '0px 0px 5px 1px rgba(34, 60, 80, 0.14)',
244
+ boxShadow: '0px 0px 5px 1px rgba(34, 60, 80, 0.14)'
245
+ },
246
+ card: {
247
+ position: 'absolute',
248
+ maxWidth: 'inherit',
249
+ top: 0,
250
+ left: 0,
251
+ display: 'flex',
252
+ alignItems: 'center',
253
+ justifyContent: 'center'
254
+ },
255
+ card__prev: {
256
+ left: '-100%'
257
+ },
258
+ card__next: {
259
+ left: '100%'
260
+ }
261
+ };
262
+ });
202
263
  var SWIPE_TRANSITION_TIMEOUT = 400;
203
264
 
204
265
  var getSwipes = function getSwipes(prev, current, next, swipes) {
@@ -237,10 +298,20 @@ var Swiper = function Swiper(props) {
237
298
  getPrev = props.getPrev,
238
299
  onSwipe = props.onSwipe,
239
300
  className = props.className,
240
- prevButtonRef = props.prevButtonRef,
241
- nextButtonRef = props.nextButtonRef,
242
301
  invitationAnimation = props.invitationAnimation;
243
302
 
303
+ var _useStyles = useStyles(),
304
+ go = _useStyles.go,
305
+ card = _useStyles.card,
306
+ card__next = _useStyles.card__next,
307
+ card__prev = _useStyles.card__prev,
308
+ button = _useStyles.button,
309
+ button__next = _useStyles.button__next,
310
+ button__prev = _useStyles.button__prev,
311
+ back = _useStyles.back,
312
+ container = _useStyles.container,
313
+ content = _useStyles.content;
314
+
244
315
  var _useState = useState(),
245
316
  current = _useState[0],
246
317
  setCurrent = _useState[1];
@@ -277,6 +348,10 @@ var Swiper = function Swiper(props) {
277
348
  isMobile = _useState9[0],
278
349
  setIsMobile = _useState9[1];
279
350
 
351
+ var _useState10 = useState(true),
352
+ load = _useState10[0],
353
+ setLoad = _useState10[1];
354
+
280
355
  var containerRef = useRef(null);
281
356
 
282
357
  var _buttonPrevRef = useRef(null);
@@ -297,33 +372,33 @@ var Swiper = function Swiper(props) {
297
372
  return refs[id];
298
373
  };
299
374
 
300
- var setGoClass = function setGoClass() {
375
+ var setGoClassHandler = function setGoClassHandler() {
301
376
  var _getRef$current, _getRef$current2, _getRef$current3;
302
377
 
303
- (_getRef$current = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current === void 0 ? void 0 : _getRef$current.classList.add(styles.go);
304
- (_getRef$current2 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current2 === void 0 ? void 0 : _getRef$current2.classList.add(styles.go);
305
- (_getRef$current3 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current3 === void 0 ? void 0 : _getRef$current3.classList.add(styles.go);
378
+ (_getRef$current = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current === void 0 ? void 0 : _getRef$current.classList.add(go);
379
+ (_getRef$current2 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current2 === void 0 ? void 0 : _getRef$current2.classList.add(go);
380
+ (_getRef$current3 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current3 === void 0 ? void 0 : _getRef$current3.classList.add(go);
306
381
  setTimeout(function () {
307
382
  var _getRef$current4, _getRef$current5, _getRef$current6;
308
383
 
309
- (_getRef$current4 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current4 === void 0 ? void 0 : _getRef$current4.classList.remove(styles.go);
310
- (_getRef$current5 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current5 === void 0 ? void 0 : _getRef$current5.classList.remove(styles.go);
311
- (_getRef$current6 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current6 === void 0 ? void 0 : _getRef$current6.classList.remove(styles.go);
384
+ (_getRef$current4 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current4 === void 0 ? void 0 : _getRef$current4.classList.remove(go);
385
+ (_getRef$current5 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current5 === void 0 ? void 0 : _getRef$current5.classList.remove(go);
386
+ (_getRef$current6 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current6 === void 0 ? void 0 : _getRef$current6.classList.remove(go);
312
387
  }, SWIPE_TRANSITION_TIMEOUT);
313
388
  };
314
389
 
315
- var setBackClass = function setBackClass() {
390
+ var setBackClassHandler = function setBackClassHandler() {
316
391
  var _getRef$current7, _getRef$current8, _getRef$current9;
317
392
 
318
- (_getRef$current7 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current7 === void 0 ? void 0 : _getRef$current7.classList.add(styles.back);
319
- (_getRef$current8 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current8 === void 0 ? void 0 : _getRef$current8.classList.add(styles.back);
320
- (_getRef$current9 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current9 === void 0 ? void 0 : _getRef$current9.classList.add(styles.back);
393
+ (_getRef$current7 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current7 === void 0 ? void 0 : _getRef$current7.classList.add(back);
394
+ (_getRef$current8 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current8 === void 0 ? void 0 : _getRef$current8.classList.add(back);
395
+ (_getRef$current9 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current9 === void 0 ? void 0 : _getRef$current9.classList.add(back);
321
396
  setTimeout(function () {
322
397
  var _getRef$current10, _getRef$current11, _getRef$current12;
323
398
 
324
- (_getRef$current10 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current10 === void 0 ? void 0 : _getRef$current10.classList.remove(styles.back);
325
- (_getRef$current11 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current11 === void 0 ? void 0 : _getRef$current11.classList.remove(styles.back);
326
- (_getRef$current12 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current12 === void 0 ? void 0 : _getRef$current12.classList.remove(styles.back);
399
+ (_getRef$current10 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current10 === void 0 ? void 0 : _getRef$current10.classList.remove(back);
400
+ (_getRef$current11 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current11 === void 0 ? void 0 : _getRef$current11.classList.remove(back);
401
+ (_getRef$current12 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current12 === void 0 ? void 0 : _getRef$current12.classList.remove(back);
327
402
  }, SWIPE_TRANSITION_TIMEOUT);
328
403
  };
329
404
 
@@ -362,10 +437,12 @@ var Swiper = function Swiper(props) {
362
437
  onSwipe(currentId);
363
438
  }
364
439
 
440
+ setLoad(false);
365
441
  return 0;
366
442
  };
367
443
 
368
444
  var _exit2 = false;
445
+ setLoad(true);
369
446
  var startTime;
370
447
  var currentId = 0;
371
448
 
@@ -384,13 +461,14 @@ var Swiper = function Swiper(props) {
384
461
  };
385
462
 
386
463
  if (!(next !== null && next !== void 0 && next.id)) {
387
- setBackClass();
464
+ setBackClassHandler();
388
465
  setLeft(0);
466
+ setLoad(false);
389
467
  _exit2 = true;
390
468
  return 1;
391
469
  }
392
470
 
393
- setGoClass();
471
+ setGoClassHandler();
394
472
  setLeft(windowWidth * -1);
395
473
  startTime = new Date().getTime();
396
474
 
@@ -424,13 +502,14 @@ var Swiper = function Swiper(props) {
424
502
  };
425
503
 
426
504
  if (!(prev !== null && prev !== void 0 && prev.id)) {
427
- setBackClass();
505
+ setBackClassHandler();
428
506
  setLeft(0);
507
+ setLoad(false);
429
508
  _exit2 = true;
430
509
  return 1;
431
510
  }
432
511
 
433
- setGoClass();
512
+ setGoClassHandler();
434
513
  setLeft(windowWidth);
435
514
  startTime = new Date().getTime();
436
515
 
@@ -455,8 +534,9 @@ var Swiper = function Swiper(props) {
455
534
  }
456
535
  }();
457
536
  } else {
458
- setBackClass();
537
+ setBackClassHandler();
459
538
  setLeft(0);
539
+ setLoad(false);
460
540
  _exit2 = true;
461
541
  return 1;
462
542
  }
@@ -512,18 +592,23 @@ var Swiper = function Swiper(props) {
512
592
  var isNext = origin === 'next';
513
593
  return function () {
514
594
  try {
595
+ if (load) {
596
+ return Promise.resolve(1);
597
+ }
598
+
515
599
  var coeff = isNext ? -1 : 1;
516
600
  var leftVal = width * coeff;
517
601
 
518
602
  if (isNext) {
519
- setGoClass();
603
+ setGoClassHandler();
520
604
  } else {
521
- setBackClass();
605
+ setBackClassHandler();
522
606
  }
523
607
 
524
- setLeft(leftVal);
525
608
  return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT / 2)).then(function () {
526
- return Promise.resolve(swipe(leftVal)).then(function () {});
609
+ return Promise.resolve(swipe(leftVal)).then(function () {
610
+ return 0;
611
+ });
527
612
  });
528
613
  } catch (e) {
529
614
  return Promise.reject(e);
@@ -562,20 +647,21 @@ var Swiper = function Swiper(props) {
562
647
  var infitationAnimationHandler = function infitationAnimationHandler(shift) {
563
648
  try {
564
649
  if (shift < 0) {
565
- setGoClass();
650
+ setGoClassHandler();
566
651
  } else {
567
- setBackClass();
652
+ setBackClassHandler();
568
653
  }
569
654
 
570
655
  setLeft(shift);
571
656
  return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT)).then(function () {
572
657
  if (shift < 0) {
573
- setBackClass();
658
+ setBackClassHandler();
574
659
  } else {
575
- setGoClass();
660
+ setGoClassHandler();
576
661
  }
577
662
 
578
663
  setLeft(0);
664
+ return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT)).then(function () {});
579
665
  });
580
666
  } catch (e) {
581
667
  return Promise.reject(e);
@@ -591,8 +677,6 @@ var Swiper = function Swiper(props) {
591
677
 
592
678
  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;
593
679
 
594
- var prevButton = prevButtonRef ? prevButtonRef === null || prevButtonRef === void 0 ? void 0 : prevButtonRef.current : _buttonPrevRef.current;
595
- var nextButton = nextButtonRef ? nextButtonRef === null || nextButtonRef === void 0 ? void 0 : nextButtonRef.current : _buttonNextRef.current;
596
680
  var _windowWidth = document.body.clientWidth;
597
681
 
598
682
  if (_width && !width && _height && !height) {
@@ -615,12 +699,12 @@ var Swiper = function Swiper(props) {
615
699
  setCurrent(defaultCurrent);
616
700
  setPrev(_p);
617
701
  setNext(_n);
618
- setLeft(_left);
619
702
  return Promise.resolve(getPrev(_p.id || 0)).then(function (_getPrev) {
620
703
  prePrev = _getPrev;
621
704
  return Promise.resolve(getNext(_n.id || 0)).then(function (_getNext) {
622
705
  postNext = _getNext;
623
706
  _defaultCurrent = defaultCurrent;
707
+ setLoad(false);
624
708
  });
625
709
  });
626
710
  });
@@ -638,7 +722,7 @@ var Swiper = function Swiper(props) {
638
722
  var _temp18 = function _temp18() {
639
723
  var _temp15 = function () {
640
724
  if (next !== null && next !== void 0 && next.id) {
641
- return Promise.resolve(infitationAnimationHandler(-100)).then(function () {});
725
+ return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5 * -1)).then(function () {});
642
726
  }
643
727
  }();
644
728
 
@@ -647,7 +731,7 @@ var Swiper = function Swiper(props) {
647
731
 
648
732
  var _temp19 = function () {
649
733
  if (prev !== null && prev !== void 0 && prev.id) {
650
- return Promise.resolve(infitationAnimationHandler(100)).then(function () {});
734
+ return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5)).then(function () {});
651
735
  }
652
736
  }();
653
737
 
@@ -663,24 +747,20 @@ var Swiper = function Swiper(props) {
663
747
  }
664
748
 
665
749
  setPreValues(prev, next);
666
- prevButton === null || prevButton === void 0 ? void 0 : prevButton.addEventListener('click', clickPrevHandler);
667
- nextButton === null || nextButton === void 0 ? void 0 : nextButton.addEventListener('click', clickNextHandler);
668
750
  window.addEventListener('resize', resizeHandler);
669
751
  return function () {
670
- prevButton === null || prevButton === void 0 ? void 0 : prevButton.removeEventListener('click', clickPrevHandler);
671
- nextButton === null || nextButton === void 0 ? void 0 : nextButton.removeEventListener('click', clickNextHandler);
672
752
  window.removeEventListener('resize', resizeHandler);
673
753
  };
674
754
  }, [next, defaultCurrent]);
675
755
  return React.createElement("div", {
676
- className: styles.container,
756
+ className: container,
677
757
  ref: containerRef
678
758
  }, swipes.map(function (item) {
679
759
  var _item$id;
680
760
 
681
761
  return React.createElement("div", {
682
762
  key: item.id
683
- }, React.createElement(React.Fragment, null, item.id && width && React.createElement("div", {
763
+ }, React.createElement(Fragment, null, item.id && width && React.createElement("div", {
684
764
  onTouchMove: onTouchWrapper('onTouchMove'),
685
765
  onTouchStart: onTouchWrapper('onTouchStart'),
686
766
  onTouchEnd: onTouchWrapper('onTouchEnd'),
@@ -698,10 +778,10 @@ var Swiper = function Swiper(props) {
698
778
  height: height,
699
779
  left: left + windowWidth
700
780
  },
701
- className: clsx(styles.card, item.type === 'prev' ? styles.prev : item.type === 'next' ? styles.next : ''),
781
+ className: clsx(card, item.type === 'prev' ? card__prev : item.type === 'next' ? card__next : ''),
702
782
  ref: getRef(item.id)
703
783
  }, React.createElement("div", {
704
- className: clsx(styles.content, className)
784
+ className: clsx(content, className)
705
785
  }, item.children)), !item.id && React.createElement("div", {
706
786
  style: item.type === 'current' ? {
707
787
  width: width,
@@ -716,17 +796,23 @@ var Swiper = function Swiper(props) {
716
796
  height: height,
717
797
  left: left + windowWidth
718
798
  },
719
- className: clsx(styles.card, item.type === 'prev' ? styles.prev : item.type === 'next' ? styles.next : '')
799
+ className: clsx(card, item.type === 'prev' ? card__prev : item.type === 'next' ? card__next : '')
720
800
  }, React.createElement(IconButton, {
721
801
  disabled: true
722
802
  }, React.createElement(StopIcon, null)))));
723
- }), typeof isMobile !== 'undefined' && !isMobile && !prevButtonRef && (prev === null || prev === void 0 ? void 0 : prev.id) && React.createElement("div", {
724
- className: clsx(styles.button, styles.button_prev),
803
+ }), typeof isMobile !== 'undefined' && !isMobile && (prev === null || prev === void 0 ? void 0 : prev.id) && React.createElement("div", {
804
+ className: clsx(button, button__prev),
725
805
  ref: _buttonPrevRef
726
- }, React.createElement(IconButton, null, React.createElement(NavigateNextIcon, null))), typeof isMobile !== 'undefined' && !isMobile && !nextButtonRef && (next === null || next === void 0 ? void 0 : next.id) && React.createElement("div", {
727
- className: clsx(styles.button, styles.button_next),
806
+ }, React.createElement(IconButton, {
807
+ disabled: load,
808
+ onClick: clickPrevHandler
809
+ }, React.createElement(NavigateNextIcon, null))), typeof isMobile !== 'undefined' && !isMobile && (next === null || next === void 0 ? void 0 : next.id) && React.createElement("div", {
810
+ className: clsx(button, button__next),
728
811
  ref: _buttonNextRef
729
- }, React.createElement(IconButton, null, React.createElement(NavigateNextIcon, null))));
812
+ }, React.createElement(IconButton, {
813
+ disabled: load,
814
+ onClick: clickNextHandler
815
+ }, React.createElement(NavigateNextIcon, null))));
730
816
  };
731
817
  Swiper.defaultProps = {
732
818
  className: ''