@kolserdav/swiper 4.1.4 → 4.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Sergey Kolmiller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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';
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.d.ts CHANGED
@@ -1,81 +1,85 @@
1
- /******************************************************************************************
2
- * Repository: https://github.com/kolserdav/swiper.git
3
- * Author: Sergey Kolmiller
4
- * Email: <serega12101983@gmail.com>
5
- * License: MIT
6
- * License Text: The code is distributed as is. There are no guarantees regarding the functionality of the code or parts of it.
7
- * Copyright: kolserdav, All rights reserved (c)
8
- * Create date: Mon Nov 29 2021 16:18:08 GMT+0700 (Krasnoyarsk Standard Time)
9
- ******************************************************************************************/
10
- import React, { RefObject } from 'react';
11
- /**
12
- * Time to miliseconds of change animation by card left value
13
- */
14
- export declare const SWIPE_TRANSITION_TIMEOUT = 400;
15
- /**
16
- * One of swipe card
17
- */
18
- export interface Swipe {
19
- id: number | null;
20
- nextRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
21
- closeRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
22
- children: React.ReactElement | React.ReactElement[];
23
- }
24
- /**
25
- * Callback for get next or previous card content
26
- */
27
- export declare type GetSwipeHandler = (oldId: number) => Promise<Swipe>;
28
- /**
29
- * Props of Swiper component
30
- */
31
- interface SwiperProps {
32
- /**
33
- * Current card content
34
- */
35
- defaultCurrent: Swipe;
36
- /**
37
- * Get next card handler
38
- */
39
- getNext: GetSwipeHandler;
40
- /**
41
- * Get previous card handler
42
- */
43
- getPrev: GetSwipeHandler;
44
- /**
45
- * Class name for content block
46
- */
47
- className?: string;
48
- /**
49
- * invitation animation
50
- */
51
- invitationAnimation?: boolean;
52
- /**
53
- * On swipe callback
54
- */
55
- onSwipe?: (currentId: number | null | undefined) => void;
56
- /**
57
- * Auto slide if provieded
58
- */
59
- durationAnimation?: number;
60
- /**
61
- * Blocked swipe event
62
- */
63
- blockSwipe?: boolean;
64
- /**
65
- * Show dots
66
- */
67
- dots?: {
68
- list: number[];
69
- active: number;
70
- };
71
- }
72
- /**
73
- * Swiper component
74
- */
75
- export declare const Swiper: {
76
- (props: SwiperProps): React.ReactElement;
77
- defaultProps: {
78
- className: string;
79
- };
80
- };
81
- export {};
1
+ /******************************************************************************************
2
+ * Repository: https://github.com/kolserdav/swiper.git
3
+ * Author: Sergey Kolmiller
4
+ * Email: <serega12101983@gmail.com>
5
+ * License: MIT
6
+ * License Text: The code is distributed as is. There are no guarantees regarding the functionality of the code or parts of it.
7
+ * Copyright: kolserdav, All rights reserved (c)
8
+ * Create date: Mon Nov 29 2021 16:18:08 GMT+0700 (Krasnoyarsk Standard Time)
9
+ ******************************************************************************************/
10
+ import React, { RefObject } from 'react';
11
+ /**
12
+ * Time to miliseconds of change animation by card left value
13
+ */
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;
19
+ /**
20
+ * One of swipe card
21
+ */
22
+ export interface Swipe {
23
+ id: number | null;
24
+ nextRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
25
+ closeRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
26
+ children: React.ReactElement | React.ReactElement[];
27
+ }
28
+ /**
29
+ * Callback for get next or previous card content
30
+ */
31
+ export type GetSwipeHandler = (oldId: number) => Promise<Swipe>;
32
+ /**
33
+ * Props of Swiper component
34
+ */
35
+ interface SwiperProps {
36
+ /**
37
+ * Current card content
38
+ */
39
+ defaultCurrent: Swipe;
40
+ /**
41
+ * Get next card handler
42
+ */
43
+ getNext: GetSwipeHandler;
44
+ /**
45
+ * Get previous card handler
46
+ */
47
+ getPrev: GetSwipeHandler;
48
+ /**
49
+ * Class name for content block
50
+ */
51
+ className?: string;
52
+ /**
53
+ * invitation animation
54
+ */
55
+ invitationAnimation?: boolean;
56
+ /**
57
+ * On swipe callback
58
+ */
59
+ onSwipe?: (currentId: number | null | undefined) => void;
60
+ /**
61
+ * Auto slide if provieded
62
+ */
63
+ durationAnimation?: number;
64
+ /**
65
+ * Blocked swipe event
66
+ */
67
+ blockSwipe?: boolean;
68
+ /**
69
+ * Show dots
70
+ */
71
+ dots?: {
72
+ list: number[];
73
+ active: number;
74
+ };
75
+ }
76
+ /**
77
+ * Swiper component
78
+ */
79
+ export declare const Swiper: {
80
+ (props: SwiperProps): React.ReactElement;
81
+ defaultProps: {
82
+ className: string;
83
+ };
84
+ };
85
+ export {};