@kolserdav/swiper 3.0.1 → 4.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
@@ -1,106 +1,106 @@
1
- # swiper
2
-
3
- > Simple and powerfull dynamic react swiper component
4
-
5
- [![NPM](https://img.shields.io/npm/v/swiper.svg)](https://www.npmjs.com/package/swiper) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
6
-
7
- ## Install
8
-
9
- ```bash
10
- npm install --save @kolserdav/swiper
11
- ```
12
-
13
- ## Usage
14
-
15
- ```tsx
16
- import React, { useState, useEffect } from 'react';
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;
21
-
22
- const getNext: GetSwipeHandler = async (old) => {
23
- let id = old + 1;
24
- id = id <= COUNT ? id : 0;
25
- return {
26
- id,
27
- children: <h1>Test {id}</h1>,
28
- };
29
- };
30
-
31
- const getPrevios: GetSwipeHandler = async (old) => {
32
- let id = old - 1;
33
- id = id >= 0 ? id : COUNT;
34
- return {
35
- id,
36
- children: <h1>Test {id}</h1>,
37
- };
38
- };
39
-
40
- const App = (): React.ReactElement => {
41
- const [current, setCurrent] = useState<Swipe>();
42
- useEffect(() => {
43
- if (!current) {
44
- (async () => {
45
- setCurrent(await getNext(0));
46
- })();
47
- }
48
- }, []);
49
-
50
- return (
51
- <div>
52
- {current && (
53
- <Swiper
54
- defaultCurrent={current}
55
- getNext={getNext}
56
- getPrev={getPrevios}
57
- invitationAnimation={true}
58
- durationAnimation={1000}
59
- />
60
- )}
61
- </div>
62
- );
63
- };
64
-
65
- export default App;
66
- ```
67
-
68
- ## Properties
69
-
70
- ```tsx
71
- interface SwiperProps {
72
- /**
73
- * Current card content
74
- */
75
- defaultCurrent: Swipe;
76
-
77
- /**
78
- * Get next card handler
79
- */
80
- getNext: GetSwipeHandler;
81
-
82
- /**
83
- * Get previous card handler
84
- */
85
- getPrev: GetSwipeHandler;
86
-
87
- /**
88
- * Class name for content block
89
- */
90
- className?: string;
91
-
92
- /**
93
- * invitation animation
94
- */
95
- invitationAnimation?: boolean;
96
-
97
- /**
98
- * On swipe callback
99
- */
100
- onSwipe?: (currentId: number) => void;
101
- }
102
- ```
103
-
104
- ## License
105
-
106
- MIT © [kolserdav](https://github.com/kolserdav)
1
+ # swiper
2
+
3
+ > Simple and powerfull dynamic react swiper component
4
+
5
+ [![NPM](https://img.shields.io/npm/v/swiper.svg)](https://www.npmjs.com/package/swiper) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install --save @kolserdav/swiper
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import React, { useState, useEffect } from 'react';
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;
21
+
22
+ const getNext: GetSwipeHandler = async (old) => {
23
+ let id = old + 1;
24
+ id = id <= COUNT ? id : 0;
25
+ return {
26
+ id,
27
+ children: <h1>Test {id}</h1>,
28
+ };
29
+ };
30
+
31
+ const getPrevios: GetSwipeHandler = async (old) => {
32
+ let id = old - 1;
33
+ id = id >= 0 ? id : COUNT;
34
+ return {
35
+ id,
36
+ children: <h1>Test {id}</h1>,
37
+ };
38
+ };
39
+
40
+ const App = (): React.ReactElement => {
41
+ const [current, setCurrent] = useState<Swipe>();
42
+ useEffect(() => {
43
+ if (!current) {
44
+ (async () => {
45
+ setCurrent(await getNext(0));
46
+ })();
47
+ }
48
+ }, []);
49
+
50
+ return (
51
+ <div>
52
+ {current && (
53
+ <Swiper
54
+ defaultCurrent={current}
55
+ getNext={getNext}
56
+ getPrev={getPrevios}
57
+ invitationAnimation={true}
58
+ durationAnimation={1000}
59
+ />
60
+ )}
61
+ </div>
62
+ );
63
+ };
64
+
65
+ export default App;
66
+ ```
67
+
68
+ ## Properties
69
+
70
+ ```tsx
71
+ interface SwiperProps {
72
+ /**
73
+ * Current card content
74
+ */
75
+ defaultCurrent: Swipe;
76
+
77
+ /**
78
+ * Get next card handler
79
+ */
80
+ getNext: GetSwipeHandler;
81
+
82
+ /**
83
+ * Get previous card handler
84
+ */
85
+ getPrev: GetSwipeHandler;
86
+
87
+ /**
88
+ * Class name for content block
89
+ */
90
+ className?: string;
91
+
92
+ /**
93
+ * invitation animation
94
+ */
95
+ invitationAnimation?: boolean;
96
+
97
+ /**
98
+ * On swipe callback
99
+ */
100
+ onSwipe?: (currentId: number) => void;
101
+ }
102
+ ```
103
+
104
+ ## License
105
+
106
+ MIT © [kolserdav](https://github.com/kolserdav)
package/dist/index.css CHANGED
@@ -1,114 +1,114 @@
1
- ._1Lxpd {
2
- position: relative;
3
- overflow: hidden;
4
- min-width: 320px;
5
- width: 100%;
6
- height: 100%;
7
- min-height: 80vh;
8
- max-width: 100vw;
9
- display: flex;
10
- align-items: center;
11
- justify-content: center;
12
- }
13
-
14
- ._8Yd7S {
15
- background-color: #fff;
16
- border-radius: 1rem;
17
- }
18
-
19
- ._3uH2i {
20
- position: relative;
21
- width: 100%;
22
- height: 100%;
23
- }
24
-
25
- ._xsi02 {
26
- position: absolute;
27
- max-width: inherit;
28
- top: 0;
29
- left: 0;
30
- display: flex;
31
- align-items: center;
32
- justify-content: center;
33
- }
34
- ._KqFRp {
35
- left: -100%;
36
- }
37
- ._1uQwZ {
38
- left: 100%;
39
- }
40
- ._18Pcq {
41
- transition: left 0.4s ease-in 0s;
42
- }
43
- ._1nj1b {
44
- transition: left 0.4s ease-out 0s;
45
- }
46
-
47
- ._3cLUl {
48
- width: 100%;
49
- height: 100%;
50
- position: relative;
51
- }
52
-
53
- ._2jwZj {
54
- border-radius: 2px;
55
- position: relative;
56
- width: calc(100% - 48px);
57
- height: calc(100% - 48px);
58
- box-shadow: 0px 0px 5px 1px rgba(34, 60, 80, 0.14);
59
- }
60
-
61
- ._2hTXI {
62
- cursor: pointer;
63
- position: absolute;
64
- width: auto;
65
- height: auto;
66
- display: flex;
67
- align-items: center;
68
- z-index: 12;
69
- }
70
-
71
- ._2Z7EZ {
72
- right: 0;
73
- }
74
-
75
- ._2Xedt {
76
- left: 0;
77
- transform: rotate(180deg);
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
- }
1
+ ._1Lxpd {
2
+ position: relative;
3
+ overflow: hidden;
4
+ min-width: 320px;
5
+ width: 100%;
6
+ height: 100%;
7
+ min-height: 20vh;
8
+ max-width: 100vw;
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: center;
12
+ }
13
+
14
+ ._8Yd7S {
15
+ background-color: #fff;
16
+ border-radius: 1rem;
17
+ }
18
+
19
+ ._3uH2i {
20
+ position: relative;
21
+ width: 100%;
22
+ height: 100%;
23
+ }
24
+
25
+ ._xsi02 {
26
+ position: absolute;
27
+ max-width: inherit;
28
+ top: 0;
29
+ left: 0;
30
+ display: flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ }
34
+ ._KqFRp {
35
+ left: -100%;
36
+ }
37
+ ._1uQwZ {
38
+ left: 100%;
39
+ }
40
+ ._18Pcq {
41
+ transition: left 0.4s ease-in 0s;
42
+ }
43
+ ._1nj1b {
44
+ transition: left 0.4s ease-out 0s;
45
+ }
46
+
47
+ ._3cLUl {
48
+ width: 100%;
49
+ height: 100%;
50
+ position: relative;
51
+ }
52
+
53
+ ._2jwZj {
54
+ border-radius: 2px;
55
+ position: relative;
56
+ width: calc(100% - 48px);
57
+ height: calc(100% - 48px);
58
+ box-shadow: 0px 0px 5px 1px rgba(34, 60, 80, 0.14);
59
+ }
60
+
61
+ ._2hTXI {
62
+ cursor: pointer;
63
+ position: absolute;
64
+ width: auto;
65
+ height: auto;
66
+ display: flex;
67
+ align-items: center;
68
+ z-index: 12;
69
+ }
70
+
71
+ ._2Z7EZ {
72
+ right: 0;
73
+ }
74
+
75
+ ._2Xedt {
76
+ left: 0;
77
+ transform: rotate(180deg);
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
@@ -594,6 +594,52 @@ var Swiper = function Swiper(props) {
594
594
  }
595
595
  };
596
596
 
597
+ var setStartCards = function setStartCards() {
598
+ try {
599
+ return Promise.resolve(getNext(defaultCurrent.id || 0)).then(function (_n) {
600
+ return Promise.resolve(getPrev(defaultCurrent.id || 0)).then(function (_p) {
601
+ setCurrent(defaultCurrent);
602
+ setPrev(_p);
603
+ setNext(_n);
604
+ return Promise.resolve(getPrev(_p.id || 0)).then(function (_getPrev) {
605
+ prePrev = _getPrev;
606
+ return Promise.resolve(getNext(_n.id || 0)).then(function (_getNext) {
607
+ postNext = _getNext;
608
+ _defaultCurrent = defaultCurrent;
609
+ setLoad(false);
610
+ });
611
+ });
612
+ });
613
+ });
614
+ } catch (e) {
615
+ return Promise.reject(e);
616
+ }
617
+ };
618
+
619
+ var startInvitationAnimation = function startInvitationAnimation(prev, next) {
620
+ try {
621
+ var _temp18 = function _temp18() {
622
+ var _temp15 = function () {
623
+ if (next.id) {
624
+ return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5 * -1)).then(function () {});
625
+ }
626
+ }();
627
+
628
+ if (_temp15 && _temp15.then) return _temp15.then(function () {});
629
+ };
630
+
631
+ var _temp19 = function () {
632
+ if (prev.id) {
633
+ return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5)).then(function () {});
634
+ }
635
+ }();
636
+
637
+ return Promise.resolve(_temp19 && _temp19.then ? _temp19.then(_temp18) : _temp18(_temp19));
638
+ } catch (e) {
639
+ return Promise.reject(e);
640
+ }
641
+ };
642
+
597
643
  React.useEffect(function () {
598
644
  var _containerRef$current10, _containerRef$current11, _containerRef$current12, _containerRef$current13, _containerRef$current14, _containerRef$current15, _containerRef$current16, _containerRef$current17, _containerRef$current18, _current$nextRef, _current$closeRef;
599
645
 
@@ -631,54 +677,13 @@ var Swiper = function Swiper(props) {
631
677
  }
632
678
 
633
679
  if (!current || !prev || !next || _defaultCurrent !== defaultCurrent) {
634
- try {
635
- return Promise.resolve(getNext(defaultCurrent.id || 0)).then(function (_n) {
636
- return Promise.resolve(getPrev(defaultCurrent.id || 0)).then(function (_p) {
637
- setCurrent(defaultCurrent);
638
- setPrev(_p);
639
- setNext(_n);
640
- return Promise.resolve(getPrev(_p.id || 0)).then(function (_getPrev) {
641
- prePrev = _getPrev;
642
- return Promise.resolve(getNext(_n.id || 0)).then(function (_getNext) {
643
- postNext = _getNext;
644
- _defaultCurrent = defaultCurrent;
645
- setLoad(false);
646
- });
647
- });
648
- });
649
- });
650
- } catch (e) {
651
- Promise.reject(e);
652
- }
680
+ setStartCards();
653
681
  }
654
682
 
655
683
  if (invitationAnimation && width && !animated) {
656
684
  if (prev && next) {
657
685
  animated = true;
658
-
659
- (function () {
660
- try {
661
- var _temp18 = function _temp18() {
662
- var _temp15 = function () {
663
- if (next.id) {
664
- return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5 * -1)).then(function () {});
665
- }
666
- }();
667
-
668
- if (_temp15 && _temp15.then) return _temp15.then(function () {});
669
- };
670
-
671
- var _temp19 = function () {
672
- if (prev.id) {
673
- return Promise.resolve(infitationAnimationHandler(windowWidth / 5.5)).then(function () {});
674
- }
675
- }();
676
-
677
- return _temp19 && _temp19.then ? _temp19.then(_temp18) : _temp18(_temp19);
678
- } catch (e) {
679
- Promise.reject(e);
680
- }
681
- })();
686
+ startInvitationAnimation(prev, next);
682
687
  }
683
688
  }
684
689
 
@@ -706,9 +711,9 @@ var Swiper = function Swiper(props) {
706
711
  }, swipes.map(function (item) {
707
712
  var _item$id;
708
713
 
709
- return React__default.createElement("div", {
714
+ return React__default.createElement(React.Fragment, {
710
715
  key: item.id
711
- }, React__default.createElement(React.Fragment, null, item.id !== null && item.children !== null && width && React__default.createElement("div", {
716
+ }, item.id !== null && item.children !== null && width && React__default.createElement("div", {
712
717
  onTouchMove: onTouchWrapper('onTouchMove'),
713
718
  onTouchStart: onTouchWrapper('onTouchStart'),
714
719
  onTouchEnd: onTouchWrapper('onTouchEnd'),
@@ -755,7 +760,7 @@ var Swiper = function Swiper(props) {
755
760
  viewBox: "0 0 16 16"
756
761
  }, React__default.createElement("path", {
757
762
  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
- }))))));
763
+ })))));
759
764
  }), typeof isMobile !== 'undefined' && !isMobile && (prev === null || prev === void 0 ? void 0 : prev.id) !== null && React__default.createElement("div", {
760
765
  className: clsx(s.button, s.button__prev)
761
766
  }, React__default.createElement("button", {