@kolserdav/swiper 1.0.7 → 2.0.0-beta
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 +68 -39
- package/dist/index.css +13 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.js +226 -140
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +230 -145
- package/dist/index.modern.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# swiper
|
|
2
2
|
|
|
3
|
-
> Simple and powerfull react swiper component
|
|
3
|
+
> Simple and powerfull dynamic react swiper component
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/swiper) [](https://standardjs.com)
|
|
6
6
|
|
|
@@ -13,39 +13,46 @@ npm install --save @kolserdav/swiper
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
|
-
import React from 'react';
|
|
17
|
-
import Swiper,
|
|
16
|
+
import React, { useState, useEffect } from 'react';
|
|
17
|
+
import { Swiper, GetSwipeHandler, Swipe } from 'swiper';
|
|
18
18
|
import 'swiper/dist/index.css';
|
|
19
19
|
|
|
20
|
-
const getNext: GetSwipeHandler = (old) => {
|
|
20
|
+
const getNext: GetSwipeHandler = async (old) => {
|
|
21
21
|
const id = old + 1;
|
|
22
22
|
return {
|
|
23
|
-
id,
|
|
24
|
-
children: id <
|
|
23
|
+
id: id < 7 ? id : null,
|
|
24
|
+
children: id < 7 ? <h1>Test {id}</h1> : <div></div>,
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const getPrevios: GetSwipeHandler = async (old) => {
|
|
29
29
|
const id = old - 1;
|
|
30
30
|
return {
|
|
31
|
-
id,
|
|
32
|
-
children: id > 0 ? <h1>Test {id}</h1> :
|
|
31
|
+
id: id > 0 ? id : null,
|
|
32
|
+
children: id > 0 ? <h1>Test {id}</h1> : <div></div>,
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
* Typescript syntetic method
|
|
38
|
-
* */
|
|
39
|
-
const _getNext = (id: number): Swipe => {
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
-
const res: any = getNext(id);
|
|
42
|
-
return res;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
36
|
const App = (): React.ReactElement => {
|
|
37
|
+
const [current, setCurrent] = useState<Swipe>();
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!current) {
|
|
41
|
+
(async () => {
|
|
42
|
+
setCurrent(await getNext(1));
|
|
43
|
+
})();
|
|
44
|
+
}
|
|
45
|
+
}, []);
|
|
46
46
|
return (
|
|
47
47
|
<div>
|
|
48
|
-
|
|
48
|
+
{current && (
|
|
49
|
+
<Swiper
|
|
50
|
+
defaultCurrent={current}
|
|
51
|
+
getNext={getNext}
|
|
52
|
+
getPrev={getPrevios}
|
|
53
|
+
invitationAnimation={true}
|
|
54
|
+
/>
|
|
55
|
+
)}
|
|
49
56
|
</div>
|
|
50
57
|
);
|
|
51
58
|
};
|
|
@@ -53,28 +60,50 @@ const App = (): React.ReactElement => {
|
|
|
53
60
|
export default App;
|
|
54
61
|
```
|
|
55
62
|
|
|
56
|
-
##
|
|
63
|
+
## Properties
|
|
57
64
|
|
|
58
65
|
```tsx
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
66
|
+
interface SwiperProps {
|
|
67
|
+
/**
|
|
68
|
+
* Current card content
|
|
69
|
+
*/
|
|
70
|
+
defaultCurrent: Swipe;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get next card handler
|
|
74
|
+
*/
|
|
75
|
+
getNext: GetSwipeHandler;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Get previous card handler
|
|
79
|
+
*/
|
|
80
|
+
getPrev: GetSwipeHandler;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Class name for content block
|
|
84
|
+
*/
|
|
85
|
+
className?: string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Button for swipe to next
|
|
89
|
+
*/
|
|
90
|
+
nextButtonRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Button for swipe to previous
|
|
94
|
+
*/
|
|
95
|
+
prevButtonRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* invitation animation
|
|
99
|
+
*/
|
|
100
|
+
invitationAnimation?: boolean;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* On swipe callback
|
|
104
|
+
*/
|
|
105
|
+
onSwipe?: (currentId: number) => void;
|
|
106
|
+
}
|
|
78
107
|
```
|
|
79
108
|
|
|
80
109
|
## License
|
package/dist/index.css
CHANGED
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
border-radius: 1rem;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
._2tyje {
|
|
20
|
+
position: relative;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
}
|
|
24
|
+
|
|
19
25
|
._7l_j0 {
|
|
20
26
|
position: absolute;
|
|
21
27
|
max-width: inherit;
|
|
@@ -38,6 +44,12 @@
|
|
|
38
44
|
transition: left 0.4s ease-out 0s;
|
|
39
45
|
}
|
|
40
46
|
|
|
47
|
+
._1mqCn {
|
|
48
|
+
width: 100%;
|
|
49
|
+
height: 100%;
|
|
50
|
+
position: relative;
|
|
51
|
+
}
|
|
52
|
+
|
|
41
53
|
._1EOHv {
|
|
42
54
|
border-radius: 2px;
|
|
43
55
|
position: relative;
|
|
@@ -53,6 +65,7 @@
|
|
|
53
65
|
height: auto;
|
|
54
66
|
display: flex;
|
|
55
67
|
align-items: center;
|
|
68
|
+
z-index: 12;
|
|
56
69
|
}
|
|
57
70
|
|
|
58
71
|
._2kk22 {
|
package/dist/index.d.ts
CHANGED
|
@@ -16,13 +16,13 @@ export declare const SWIPE_TRANSITION_TIMEOUT = 400;
|
|
|
16
16
|
* One of swipe card
|
|
17
17
|
*/
|
|
18
18
|
export interface Swipe {
|
|
19
|
-
id: number;
|
|
20
|
-
children: React.ReactElement | React.ReactElement[]
|
|
19
|
+
id: number | null;
|
|
20
|
+
children: React.ReactElement | React.ReactElement[];
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Callback for get next or previous card content
|
|
24
24
|
*/
|
|
25
|
-
export declare type GetSwipeHandler = (oldId: number) =>
|
|
25
|
+
export declare type GetSwipeHandler = (oldId: number) => Promise<Swipe>;
|
|
26
26
|
/**
|
|
27
27
|
* Props of Swiper component
|
|
28
28
|
*/
|
|
@@ -55,14 +55,18 @@ interface SwiperProps {
|
|
|
55
55
|
* invitation animation
|
|
56
56
|
*/
|
|
57
57
|
invitationAnimation?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* On swipe callback
|
|
60
|
+
*/
|
|
61
|
+
onSwipe?: (currentId: number) => void;
|
|
58
62
|
}
|
|
59
63
|
/**
|
|
60
64
|
* Swiper component
|
|
61
65
|
*/
|
|
62
|
-
declare const Swiper: {
|
|
66
|
+
export declare const Swiper: {
|
|
63
67
|
(props: SwiperProps): React.ReactElement;
|
|
64
68
|
defaultProps: {
|
|
65
69
|
className: string;
|
|
66
70
|
};
|
|
67
71
|
};
|
|
68
|
-
export
|
|
72
|
+
export {};
|