@kolserdav/swiper 4.1.2 → 4.1.5

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,124 +1,124 @@
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
- * Auto slide if provieded
104
- */
105
- durationAnimation?: number;
106
-
107
- /**
108
- * Blocked swipe event
109
- */
110
- blockSwipe?: boolean;
111
-
112
- /**
113
- * Show dots
114
- */
115
- dots?: {
116
- list: number[];
117
- active: number;
118
- };
119
- }
120
- ```
121
-
122
- ## License
123
-
124
- 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
+ * Auto slide if provieded
104
+ */
105
+ durationAnimation?: number;
106
+
107
+ /**
108
+ * Blocked swipe event
109
+ */
110
+ blockSwipe?: boolean;
111
+
112
+ /**
113
+ * Show dots
114
+ */
115
+ dots?: {
116
+ list: number[];
117
+ active: number;
118
+ };
119
+ }
120
+ ```
121
+
122
+ ## License
123
+
124
+ MIT © [kolserdav](https://github.com/kolserdav)
package/dist/index.css CHANGED
@@ -1,137 +1,137 @@
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
- flex-direction: column;
34
- }
35
- ._KqFRp {
36
- left: -100%;
37
- }
38
- ._1uQwZ {
39
- left: 100%;
40
- }
41
- ._18Pcq {
42
- transition: left 0.4s ease-in 0s;
43
- }
44
- ._1nj1b {
45
- transition: left 0.4s ease-out 0s;
46
- }
47
-
48
- ._3cLUl {
49
- width: 100%;
50
- height: 100%;
51
- position: relative;
52
- }
53
-
54
- ._2jwZj {
55
- border-radius: 2px;
56
- position: relative;
57
- width: calc(100% - 48px);
58
- height: calc(100% - 48px);
59
- box-shadow: 0px 0px 5px 1px rgba(34, 60, 80, 0.14);
60
- }
61
-
62
- ._2hTXI {
63
- cursor: pointer;
64
- position: absolute;
65
- width: auto;
66
- height: auto;
67
- display: flex;
68
- align-items: center;
69
- z-index: 12;
70
- }
71
-
72
- ._2Z7EZ {
73
- right: 0;
74
- }
75
-
76
- ._2Xedt {
77
- left: 0;
78
- transform: rotate(180deg);
79
- }
80
-
81
- ._2J4XS {
82
- display: inline-flex;
83
- align-items: center;
84
- justify-content: center;
85
- position: relative;
86
- box-sizing: border-box;
87
- background-color: transparent;
88
- outline: 0;
89
- border: 0;
90
- margin: 0;
91
- border-radius: 0;
92
- padding: 0;
93
- cursor: pointer;
94
- -webkit-user-select: none;
95
- -moz-user-select: none;
96
- -ms-user-select: none;
97
- user-select: none;
98
- vertical-align: middle;
99
- text-decoration: none;
100
- color: inherit;
101
- text-align: center;
102
- flex: 0 0 auto;
103
- font-size: 1.5rem;
104
- padding: 8px;
105
- border-radius: 50%;
106
- overflow: visible;
107
- color: rgba(0, 0, 0, 0.54);
108
- transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
109
- }
110
- ._2J4XS:hover {
111
- background-color: rgba(0, 0, 0, 0.054);
112
- }
113
- ._2J4XS:active {
114
- background-color: rgba(0, 0, 0, 0.007);
115
- }
116
-
117
- ._3MuXE {
118
- position: absolute;
119
- display: flex;
120
- flex-direction: row;
121
- bottom: 0;
122
- }
123
-
124
- ._3U2py {
125
- cursor: pointer;
126
- position: relative;
127
- width: 8px;
128
- height: 8px;
129
- margin: 2px;
130
- border: 1px solid gray;
131
- border-radius: 50%;
132
- }
133
-
134
- ._3U2py._3sodH {
135
- cursor: default;
136
- background-color: gray;
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
+ flex-direction: column;
34
+ }
35
+ ._KqFRp {
36
+ left: -100%;
37
+ }
38
+ ._1uQwZ {
39
+ left: 100%;
40
+ }
41
+ ._18Pcq {
42
+ transition: left 0.4s ease-in 0s;
43
+ }
44
+ ._1nj1b {
45
+ transition: left 0.4s ease-out 0s;
46
+ }
47
+
48
+ ._3cLUl {
49
+ width: 100%;
50
+ height: 100%;
51
+ position: relative;
52
+ }
53
+
54
+ ._2jwZj {
55
+ border-radius: 2px;
56
+ position: relative;
57
+ width: calc(100% - 48px);
58
+ height: calc(100% - 48px);
59
+ box-shadow: 0px 0px 5px 1px rgba(34, 60, 80, 0.14);
60
+ }
61
+
62
+ ._2hTXI {
63
+ cursor: pointer;
64
+ position: absolute;
65
+ width: auto;
66
+ height: auto;
67
+ display: flex;
68
+ align-items: center;
69
+ z-index: 12;
70
+ }
71
+
72
+ ._2Z7EZ {
73
+ right: 0;
74
+ }
75
+
76
+ ._2Xedt {
77
+ left: 0;
78
+ transform: rotate(180deg);
79
+ }
80
+
81
+ ._2J4XS {
82
+ display: inline-flex;
83
+ align-items: center;
84
+ justify-content: center;
85
+ position: relative;
86
+ box-sizing: border-box;
87
+ background-color: transparent;
88
+ outline: 0;
89
+ border: 0;
90
+ margin: 0;
91
+ border-radius: 0;
92
+ padding: 0;
93
+ cursor: pointer;
94
+ -webkit-user-select: none;
95
+ -moz-user-select: none;
96
+ -ms-user-select: none;
97
+ user-select: none;
98
+ vertical-align: middle;
99
+ text-decoration: none;
100
+ color: inherit;
101
+ text-align: center;
102
+ flex: 0 0 auto;
103
+ font-size: 1.5rem;
104
+ padding: 8px;
105
+ border-radius: 50%;
106
+ overflow: visible;
107
+ color: rgba(0, 0, 0, 0.54);
108
+ transition: background-color 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
109
+ }
110
+ ._2J4XS:hover {
111
+ background-color: rgba(0, 0, 0, 0.054);
112
+ }
113
+ ._2J4XS:active {
114
+ background-color: rgba(0, 0, 0, 0.007);
115
+ }
116
+
117
+ ._3MuXE {
118
+ position: absolute;
119
+ display: flex;
120
+ flex-direction: row;
121
+ bottom: 0;
122
+ }
123
+
124
+ ._3U2py {
125
+ cursor: pointer;
126
+ position: relative;
127
+ width: 8px;
128
+ height: 8px;
129
+ margin: 2px;
130
+ border: 1px solid gray;
131
+ border-radius: 50%;
132
+ }
133
+
134
+ ._3U2py._3sodH {
135
+ cursor: default;
136
+ background-color: gray;
137
137
  }
package/dist/index.d.ts CHANGED
@@ -12,6 +12,10 @@ import React, { RefObject } from 'react';
12
12
  * Time to miliseconds of change animation by card left value
13
13
  */
14
14
  export declare const SWIPE_TRANSITION_TIMEOUT = 400;
15
+ /**
16
+ * Minimum swipe speed regardless of distance
17
+ */
18
+ export declare const SWIPE_ON_EVENT_SPEED = 0.7;
15
19
  /**
16
20
  * One of swipe card
17
21
  */