@kolserdav/swiper 2.2.3 → 3.0.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/README.md CHANGED
@@ -14,35 +14,39 @@ npm install --save @kolserdav/swiper
14
14
 
15
15
  ```tsx
16
16
  import React, { useState, useEffect } from 'react';
17
- import { Swiper, GetSwipeHandler, Swipe } from 'swiper';
18
- import 'swiper/dist/index.css';
17
+ import { Swiper, GetSwipeHandler, Swipe } from '@kolserdav/swiper';
18
+ import 'swiper/dist/index.css'; // From version 3.0.0 is required
19
+
20
+ const COUNT = 4;
19
21
 
20
22
  const getNext: GetSwipeHandler = async (old) => {
21
- const id = old + 1;
23
+ let id = old + 1;
24
+ id = id <= COUNT ? id : 0;
22
25
  return {
23
- id: id < 7 ? id : null,
24
- children: id < 7 ? <h1>Test {id}</h1> : <div></div>,
26
+ id,
27
+ children: <h1>Test {id}</h1>,
25
28
  };
26
29
  };
27
30
 
28
31
  const getPrevios: GetSwipeHandler = async (old) => {
29
- const id = old - 1;
32
+ let id = old - 1;
33
+ id = id >= 0 ? id : COUNT;
30
34
  return {
31
- id: id > 0 ? id : null,
32
- children: id > 0 ? <h1>Test {id}</h1> : <div></div>,
35
+ id,
36
+ children: <h1>Test {id}</h1>,
33
37
  };
34
38
  };
35
39
 
36
40
  const App = (): React.ReactElement => {
37
41
  const [current, setCurrent] = useState<Swipe>();
38
-
39
42
  useEffect(() => {
40
43
  if (!current) {
41
44
  (async () => {
42
- setCurrent(await getNext(1));
45
+ setCurrent(await getNext(0));
43
46
  })();
44
47
  }
45
48
  }, []);
49
+
46
50
  return (
47
51
  <div>
48
52
  {current && (
@@ -51,6 +55,7 @@ const App = (): React.ReactElement => {
51
55
  getNext={getNext}
52
56
  getPrev={getPrevios}
53
57
  invitationAnimation={true}
58
+ durationAnimation={1000}
54
59
  />
55
60
  )}
56
61
  </div>
package/dist/index.css CHANGED
@@ -1,4 +1,4 @@
1
- ._p6aGD {
1
+ ._1Lxpd {
2
2
  position: relative;
3
3
  overflow: hidden;
4
4
  min-width: 320px;
@@ -11,18 +11,18 @@
11
11
  justify-content: center;
12
12
  }
13
13
 
14
- ._3_Zua {
14
+ ._8Yd7S {
15
15
  background-color: #fff;
16
16
  border-radius: 1rem;
17
17
  }
18
18
 
19
- ._2tyje {
19
+ ._3uH2i {
20
20
  position: relative;
21
21
  width: 100%;
22
22
  height: 100%;
23
23
  }
24
24
 
25
- ._7l_j0 {
25
+ ._xsi02 {
26
26
  position: absolute;
27
27
  max-width: inherit;
28
28
  top: 0;
@@ -31,26 +31,26 @@
31
31
  align-items: center;
32
32
  justify-content: center;
33
33
  }
34
- ._2S9j_ {
34
+ ._KqFRp {
35
35
  left: -100%;
36
36
  }
37
- ._2T1oW {
37
+ ._1uQwZ {
38
38
  left: 100%;
39
39
  }
40
- ._uQNyq {
40
+ ._18Pcq {
41
41
  transition: left 0.4s ease-in 0s;
42
42
  }
43
- ._8240d {
43
+ ._1nj1b {
44
44
  transition: left 0.4s ease-out 0s;
45
45
  }
46
46
 
47
- ._1mqCn {
47
+ ._3cLUl {
48
48
  width: 100%;
49
49
  height: 100%;
50
50
  position: relative;
51
51
  }
52
52
 
53
- ._1EOHv {
53
+ ._2jwZj {
54
54
  border-radius: 2px;
55
55
  position: relative;
56
56
  width: calc(100% - 48px);
@@ -58,7 +58,7 @@
58
58
  box-shadow: 0px 0px 5px 1px rgba(34, 60, 80, 0.14);
59
59
  }
60
60
 
61
- ._7_rsx {
61
+ ._2hTXI {
62
62
  cursor: pointer;
63
63
  position: absolute;
64
64
  width: auto;
@@ -68,11 +68,47 @@
68
68
  z-index: 12;
69
69
  }
70
70
 
71
- ._2kk22 {
71
+ ._2Z7EZ {
72
72
  right: 0;
73
73
  }
74
74
 
75
- ._B1K5l {
75
+ ._2Xedt {
76
76
  left: 0;
77
77
  transform: rotate(180deg);
78
78
  }
79
+
80
+ ._2J4XS {
81
+ display: inline-flex;
82
+ align-items: center;
83
+ justify-content: center;
84
+ position: relative;
85
+ box-sizing: border-box;
86
+ background-color: transparent;
87
+ outline: 0;
88
+ border: 0;
89
+ margin: 0;
90
+ border-radius: 0;
91
+ padding: 0;
92
+ cursor: pointer;
93
+ -webkit-user-select: none;
94
+ -moz-user-select: none;
95
+ -ms-user-select: none;
96
+ user-select: none;
97
+ vertical-align: middle;
98
+ text-decoration: none;
99
+ color: inherit;
100
+ text-align: center;
101
+ flex: 0 0 auto;
102
+ font-size: 1.5rem;
103
+ padding: 8px;
104
+ border-radius: 50%;
105
+ overflow: visible;
106
+ color: rgba(0, 0, 0, 0.54);
107
+ transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
108
+ }
109
+ ._2J4XS:hover {
110
+ background-color: rgba(0, 0, 0, 0.054);
111
+ }
112
+ ._2J4XS:active {
113
+ background-color: rgba(0, 0, 0, 0.007);
114
+ }
package/dist/index.d.ts CHANGED
@@ -53,6 +53,10 @@ interface SwiperProps {
53
53
  * On swipe callback
54
54
  */
55
55
  onSwipe?: (currentId: number | null | undefined) => void;
56
+ /**
57
+ * Auto slide if provieded
58
+ */
59
+ durationAnimation?: number;
56
60
  }
57
61
  /**
58
62
  * Swiper component
package/dist/index.js CHANGED
@@ -2,11 +2,7 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
2
2
 
3
3
  var React = require('react');
4
4
  var React__default = _interopDefault(React);
5
- var material = require('@mui/material');
6
- var styles = require('@mui/styles');
7
5
  var clsx = _interopDefault(require('clsx'));
8
- var StopIcon = _interopDefault(require('@mui/icons-material/StopScreenShare'));
9
- var NavigateNextIcon = _interopDefault(require('@mui/icons-material/NavigateNext'));
10
6
 
11
7
  function _extends() {
12
8
  _extends = Object.assign || function (target) {
@@ -201,67 +197,8 @@ function _switch(discriminant, cases) {
201
197
  }
202
198
  }
203
199
 
204
- var useStyles = styles.makeStyles(function () {
205
- return {
206
- go: {
207
- transition: 'left 0.4s ease-out 0s'
208
- },
209
- back: {
210
- transition: 'left 0.4s ease-in 0s'
211
- },
212
- container: {
213
- position: 'relative',
214
- overflow: 'hidden',
215
- minWidth: '320px',
216
- width: '100%',
217
- height: '100%',
218
- minHeight: 'calc(100vh - 2rem)',
219
- maxWidth: '100vw',
220
- display: 'flex',
221
- alignItems: 'center',
222
- justifyContent: 'center',
223
- marginBlockStart: '2rem'
224
- },
225
- button: {
226
- cursor: 'pointer',
227
- position: 'absolute',
228
- width: 'auto',
229
- height: 'auto',
230
- display: 'flex',
231
- alignItems: 'center',
232
- zIndex: '12'
233
- },
234
- button__prev: {
235
- left: 0,
236
- transform: 'rotate(180deg)'
237
- },
238
- button__next: {
239
- right: 0
240
- },
241
- content: {
242
- position: 'relative',
243
- width: 'calc(100% - 48px)',
244
- maxHeight: 'calc(100% - 48px)',
245
- minHeight: '20%',
246
- background: 'white'
247
- },
248
- card: {
249
- position: 'absolute',
250
- maxWidth: 'inherit',
251
- top: 0,
252
- left: 0,
253
- display: 'flex',
254
- alignItems: 'center',
255
- justifyContent: 'center'
256
- },
257
- card__prev: {
258
- left: '-100%'
259
- },
260
- card__next: {
261
- left: '100%'
262
- }
263
- };
264
- });
200
+ var s = {"container":"_1Lxpd","paper":"_8Yd7S","pipe":"_3uH2i","card":"_xsi02","prev":"_KqFRp","next":"_1uQwZ","back":"_18Pcq","go":"_1nj1b","card__stop":"_3cLUl","content":"_2jwZj","button":"_2hTXI","button__next":"_2Z7EZ","button__prev":"_2Xedt","icon__button":"_2J4XS"};
201
+
265
202
  var SWIPE_TRANSITION_TIMEOUT = 400;
266
203
 
267
204
  var getSwipes = function getSwipes(prev, current, next, swipes) {
@@ -300,19 +237,8 @@ var Swiper = function Swiper(props) {
300
237
  getPrev = props.getPrev,
301
238
  onSwipe = props.onSwipe,
302
239
  className = props.className,
303
- invitationAnimation = props.invitationAnimation;
304
-
305
- var _useStyles = useStyles(),
306
- go = _useStyles.go,
307
- card = _useStyles.card,
308
- card__next = _useStyles.card__next,
309
- card__prev = _useStyles.card__prev,
310
- button = _useStyles.button,
311
- button__next = _useStyles.button__next,
312
- button__prev = _useStyles.button__prev,
313
- back = _useStyles.back,
314
- container = _useStyles.container,
315
- content = _useStyles.content;
240
+ invitationAnimation = props.invitationAnimation,
241
+ durationAnimation = props.durationAnimation;
316
242
 
317
243
  var _useState = React.useState(),
318
244
  current = _useState[0],
@@ -373,30 +299,30 @@ var Swiper = function Swiper(props) {
373
299
  var setGoClassHandler = function setGoClassHandler() {
374
300
  var _getRef$current, _getRef$current2, _getRef$current3;
375
301
 
376
- (_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);
377
- (_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);
378
- (_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);
302
+ (_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(s.go);
303
+ (_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(s.go);
304
+ (_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(s.go);
379
305
  setTimeout(function () {
380
306
  var _getRef$current4, _getRef$current5, _getRef$current6;
381
307
 
382
- (_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);
383
- (_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);
384
- (_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);
308
+ (_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(s.go);
309
+ (_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(s.go);
310
+ (_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(s.go);
385
311
  }, SWIPE_TRANSITION_TIMEOUT);
386
312
  };
387
313
 
388
314
  var setBackClassHandler = function setBackClassHandler() {
389
315
  var _getRef$current7, _getRef$current8, _getRef$current9;
390
316
 
391
- (_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);
392
- (_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);
393
- (_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);
317
+ (_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(s.back);
318
+ (_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(s.back);
319
+ (_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(s.back);
394
320
  setTimeout(function () {
395
321
  var _getRef$current10, _getRef$current11, _getRef$current12;
396
322
 
397
- (_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);
398
- (_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);
399
- (_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);
323
+ (_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(s.back);
324
+ (_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(s.back);
325
+ (_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(s.back);
400
326
  }, SWIPE_TRANSITION_TIMEOUT);
401
327
  };
402
328
 
@@ -671,6 +597,14 @@ var Swiper = function Swiper(props) {
671
597
  React.useEffect(function () {
672
598
  var _containerRef$current10, _containerRef$current11, _containerRef$current12, _containerRef$current13, _containerRef$current14, _containerRef$current15, _containerRef$current16, _containerRef$current17, _containerRef$current18, _current$nextRef, _current$closeRef;
673
599
 
600
+ var clearAnimate;
601
+
602
+ if (durationAnimation) {
603
+ clearAnimate = setInterval(function () {
604
+ clickNextHandler();
605
+ }, durationAnimation);
606
+ }
607
+
674
608
  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;
675
609
 
676
610
  var _height = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current13 = containerRef.current) === null || _containerRef$current13 === void 0 ? void 0 : (_containerRef$current14 = _containerRef$current13.parentElement) === null || _containerRef$current14 === void 0 ? void 0 : (_containerRef$current15 = _containerRef$current14.getBoundingClientRect()) === null || _containerRef$current15 === void 0 ? void 0 : _containerRef$current15.height;
@@ -749,26 +683,32 @@ var Swiper = function Swiper(props) {
749
683
  }
750
684
 
751
685
  if (typeof isMobile === 'undefined') {
752
- setIsMobile('ontouchstart' in window || typeof navigator.msMaxTouchPoints !== 'undefined');
686
+ var _navigator;
687
+
688
+ setIsMobile('ontouchstart' in window || typeof ((_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.msMaxTouchPoints) !== 'undefined');
753
689
  }
754
690
 
755
691
  setPreValues(prev, next);
756
692
  window.addEventListener('resize', resizeHandler);
757
693
  return function () {
694
+ if (clearAnimate) {
695
+ clearInterval(clearAnimate);
696
+ }
697
+
758
698
  window.removeEventListener('resize', resizeHandler);
759
699
  buttonNext === null || buttonNext === void 0 ? void 0 : buttonNext.removeEventListener('click', clickNextHandler);
760
700
  buttonClose === null || buttonClose === void 0 ? void 0 : buttonClose.removeEventListener('click', clickNextHandler);
761
701
  };
762
702
  }, [next, defaultCurrent]);
763
703
  return React__default.createElement("div", {
764
- className: container,
704
+ className: s.container,
765
705
  ref: containerRef
766
706
  }, swipes.map(function (item) {
767
707
  var _item$id;
768
708
 
769
709
  return React__default.createElement("div", {
770
710
  key: item.id
771
- }, React__default.createElement(React.Fragment, null, item.id !== null && width && React__default.createElement("div", {
711
+ }, React__default.createElement(React.Fragment, null, item.id !== null && item.children !== null && width && React__default.createElement("div", {
772
712
  onTouchMove: onTouchWrapper('onTouchMove'),
773
713
  onTouchStart: onTouchWrapper('onTouchStart'),
774
714
  onTouchEnd: onTouchWrapper('onTouchEnd'),
@@ -786,10 +726,10 @@ var Swiper = function Swiper(props) {
786
726
  height: height,
787
727
  left: left + window.innerWidth
788
728
  },
789
- className: clsx(card, item.type === 'prev' ? card__prev : item.type === 'next' ? card__next : ''),
729
+ className: clsx(s.card, item.type === 'prev' ? s.prev : item.type === 'next' ? s.next : ''),
790
730
  ref: getRef(item.id)
791
731
  }, React__default.createElement("div", {
792
- className: clsx(content, className)
732
+ className: clsx(s.content, className)
793
733
  }, item.children)), item.id === null && React__default.createElement("div", {
794
734
  style: item.type === 'current' ? {
795
735
  width: width,
@@ -804,21 +744,55 @@ var Swiper = function Swiper(props) {
804
744
  height: height,
805
745
  left: left + windowWidth
806
746
  },
807
- className: clsx(card, item.type === 'prev' ? card__prev : item.type === 'next' ? card__next : '')
808
- }, React__default.createElement(material.IconButton, {
747
+ className: clsx(s.card, item.type === 'prev' ? s.prev : item.type === 'next' ? s.next : '')
748
+ }, React__default.createElement("button", {
809
749
  disabled: true
810
- }, React__default.createElement(StopIcon, null)))));
750
+ }, React__default.createElement("svg", {
751
+ xmlns: "http://www.w3.org/2000/svg",
752
+ width: "16",
753
+ height: "16",
754
+ fill: "currentColor",
755
+ viewBox: "0 0 16 16"
756
+ }, React__default.createElement("path", {
757
+ d: "M5 3.5h6A1.5 1.5 0 0 1 12.5 5v6a1.5 1.5 0 0 1-1.5 1.5H5A1.5 1.5 0 0 1 3.5 11V5A1.5 1.5 0 0 1 5 3.5z"
758
+ }))))));
811
759
  }), typeof isMobile !== 'undefined' && !isMobile && (prev === null || prev === void 0 ? void 0 : prev.id) !== null && React__default.createElement("div", {
812
- className: clsx(button, button__prev)
813
- }, React__default.createElement(material.IconButton, {
760
+ className: clsx(s.button, s.button__prev)
761
+ }, React__default.createElement("button", {
762
+ className: s.icon__button,
763
+ type: "button",
814
764
  disabled: load || isMobile,
815
765
  onClick: clickPrevHandler
816
- }, React__default.createElement(NavigateNextIcon, null))), typeof isMobile !== 'undefined' && !isMobile && (next === null || next === void 0 ? void 0 : next.id) !== null && React__default.createElement("div", {
817
- className: clsx(button, button__next)
818
- }, React__default.createElement(material.IconButton, {
766
+ }, React__default.createElement("svg", {
767
+ xmlns: "http://www.w3.org/2000/svg",
768
+ height: "24px",
769
+ viewBox: "0 0 24 24",
770
+ width: "24px",
771
+ fill: "#000000"
772
+ }, React__default.createElement("path", {
773
+ d: "M0 0h24v24H0V0z",
774
+ fill: "none"
775
+ }), React__default.createElement("path", {
776
+ d: "M10.02 6L8.61 7.41 13.19 12l-4.58 4.59L10.02 18l6-6-6-6z"
777
+ })))), typeof isMobile !== 'undefined' && !isMobile && (next === null || next === void 0 ? void 0 : next.id) !== null && React__default.createElement("div", {
778
+ className: clsx(s.button, s.button__next)
779
+ }, React__default.createElement("button", {
780
+ className: s.icon__button,
781
+ type: "button",
819
782
  disabled: load || isMobile,
820
783
  onClick: clickNextHandler
821
- }, React__default.createElement(NavigateNextIcon, null))));
784
+ }, React__default.createElement("svg", {
785
+ xmlns: "http://www.w3.org/2000/svg",
786
+ height: "24px",
787
+ viewBox: "0 0 24 24",
788
+ width: "24px",
789
+ fill: "#000000"
790
+ }, React__default.createElement("path", {
791
+ d: "M0 0h24v24H0V0z",
792
+ fill: "none"
793
+ }), React__default.createElement("path", {
794
+ d: "M10.02 6L8.61 7.41 13.19 12l-4.58 4.59L10.02 18l6-6-6-6z"
795
+ })))));
822
796
  };
823
797
  Swiper.defaultProps = {
824
798
  className: ''