@kolserdav/swiper 2.3.0 → 3.0.1

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 '@kolserdav/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.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) {
@@ -303,18 +240,6 @@ var Swiper = function Swiper(props) {
303
240
  invitationAnimation = props.invitationAnimation,
304
241
  durationAnimation = props.durationAnimation;
305
242
 
306
- var _useStyles = useStyles(),
307
- go = _useStyles.go,
308
- card = _useStyles.card,
309
- card__next = _useStyles.card__next,
310
- card__prev = _useStyles.card__prev,
311
- button = _useStyles.button,
312
- button__next = _useStyles.button__next,
313
- button__prev = _useStyles.button__prev,
314
- back = _useStyles.back,
315
- container = _useStyles.container,
316
- content = _useStyles.content;
317
-
318
243
  var _useState = React.useState(),
319
244
  current = _useState[0],
320
245
  setCurrent = _useState[1];
@@ -374,30 +299,30 @@ var Swiper = function Swiper(props) {
374
299
  var setGoClassHandler = function setGoClassHandler() {
375
300
  var _getRef$current, _getRef$current2, _getRef$current3;
376
301
 
377
- (_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);
378
- (_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);
379
- (_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);
380
305
  setTimeout(function () {
381
306
  var _getRef$current4, _getRef$current5, _getRef$current6;
382
307
 
383
- (_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);
384
- (_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);
385
- (_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);
386
311
  }, SWIPE_TRANSITION_TIMEOUT);
387
312
  };
388
313
 
389
314
  var setBackClassHandler = function setBackClassHandler() {
390
315
  var _getRef$current7, _getRef$current8, _getRef$current9;
391
316
 
392
- (_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);
393
- (_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);
394
- (_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);
395
320
  setTimeout(function () {
396
321
  var _getRef$current10, _getRef$current11, _getRef$current12;
397
322
 
398
- (_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);
399
- (_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);
400
- (_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);
401
326
  }, SWIPE_TRANSITION_TIMEOUT);
402
327
  };
403
328
 
@@ -758,7 +683,9 @@ var Swiper = function Swiper(props) {
758
683
  }
759
684
 
760
685
  if (typeof isMobile === 'undefined') {
761
- 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');
762
689
  }
763
690
 
764
691
  setPreValues(prev, next);
@@ -774,14 +701,14 @@ var Swiper = function Swiper(props) {
774
701
  };
775
702
  }, [next, defaultCurrent]);
776
703
  return React__default.createElement("div", {
777
- className: container,
704
+ className: s.container,
778
705
  ref: containerRef
779
706
  }, swipes.map(function (item) {
780
707
  var _item$id;
781
708
 
782
709
  return React__default.createElement("div", {
783
710
  key: item.id
784
- }, 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", {
785
712
  onTouchMove: onTouchWrapper('onTouchMove'),
786
713
  onTouchStart: onTouchWrapper('onTouchStart'),
787
714
  onTouchEnd: onTouchWrapper('onTouchEnd'),
@@ -799,10 +726,10 @@ var Swiper = function Swiper(props) {
799
726
  height: height,
800
727
  left: left + window.innerWidth
801
728
  },
802
- 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 : ''),
803
730
  ref: getRef(item.id)
804
731
  }, React__default.createElement("div", {
805
- className: clsx(content, className)
732
+ className: clsx(s.content, className)
806
733
  }, item.children)), item.id === null && React__default.createElement("div", {
807
734
  style: item.type === 'current' ? {
808
735
  width: width,
@@ -817,21 +744,55 @@ var Swiper = function Swiper(props) {
817
744
  height: height,
818
745
  left: left + windowWidth
819
746
  },
820
- className: clsx(card, item.type === 'prev' ? card__prev : item.type === 'next' ? card__next : '')
821
- }, 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", {
822
749
  disabled: true
823
- }, 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
+ }))))));
824
759
  }), typeof isMobile !== 'undefined' && !isMobile && (prev === null || prev === void 0 ? void 0 : prev.id) !== null && React__default.createElement("div", {
825
- className: clsx(button, button__prev)
826
- }, 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",
827
764
  disabled: load || isMobile,
828
765
  onClick: clickPrevHandler
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)
831
- }, 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",
832
782
  disabled: load || isMobile,
833
783
  onClick: clickNextHandler
834
- }, 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
+ })))));
835
796
  };
836
797
  Swiper.defaultProps = {
837
798
  className: ''