@kolserdav/swiper 1.0.9 → 2.1.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 +58 -39
- package/dist/index.css +13 -0
- package/dist/index.d.ts +6 -10
- package/dist/index.js +225 -147
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +230 -152
- package/dist/index.modern.js.map +1 -1
- package/package.json +6 -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, GetSwipeHandler } from '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,40 @@ 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
|
+
* invitation animation
|
|
89
|
+
*/
|
|
90
|
+
invitationAnimation?: boolean;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* On swipe callback
|
|
94
|
+
*/
|
|
95
|
+
onSwipe?: (currentId: number) => void;
|
|
96
|
+
}
|
|
78
97
|
```
|
|
79
98
|
|
|
80
99
|
## 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
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Copyright: kolserdav, All rights reserved (c)
|
|
8
8
|
* Create date: Mon Nov 29 2021 16:18:08 GMT+0700 (Krasnoyarsk Standard Time)
|
|
9
9
|
******************************************************************************************/
|
|
10
|
-
import React
|
|
10
|
+
import React from 'react';
|
|
11
11
|
/**
|
|
12
12
|
* Time to miliseconds of change animation by card left value
|
|
13
13
|
*/
|
|
@@ -22,7 +22,7 @@ export interface Swipe {
|
|
|
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
|
*/
|
|
@@ -43,18 +43,14 @@ interface SwiperProps {
|
|
|
43
43
|
* Class name for content block
|
|
44
44
|
*/
|
|
45
45
|
className?: string;
|
|
46
|
-
/**
|
|
47
|
-
* Button for swipe to next
|
|
48
|
-
*/
|
|
49
|
-
nextButtonRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
|
|
50
|
-
/**
|
|
51
|
-
* Button for swipe to previous
|
|
52
|
-
*/
|
|
53
|
-
prevButtonRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
|
|
54
46
|
/**
|
|
55
47
|
* invitation animation
|
|
56
48
|
*/
|
|
57
49
|
invitationAnimation?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* On swipe callback
|
|
52
|
+
*/
|
|
53
|
+
onSwipe?: (currentId: number) => void;
|
|
58
54
|
}
|
|
59
55
|
/**
|
|
60
56
|
* Swiper component
|