@kolserdav/swiper 1.0.8 → 2.0.1-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 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
  [![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
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 < 5 ? <h1>Test {id}</h1> : null,
23
+ id: id < 7 ? id : null,
24
+ children: id < 7 ? <h1>Test {id}</h1> : <div></div>,
25
25
  };
26
26
  };
27
27
 
28
- const getPrevious: GetSwipeHandler = (old) => {
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> : null,
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
- <Swiper defaultCurrent={_getNext(0)} getNext={getNext} getPrev={getPrevious} />
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
- ## Additional properties
63
+ ## Properties
57
64
 
58
65
  ```tsx
59
- /**
60
- * Class name for content block
61
- */
62
- className?: string;
63
-
64
- /**
65
- * Button for swipe to next
66
- */
67
- nextButtonRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
68
-
69
- /**
70
- * Button for swipe to previous
71
- */
72
- prevButtonRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
73
-
74
- /**
75
- * invitation animation
76
- */
77
- invitationAnimation?: boolean;
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[] | null;
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) => Swipe | Promise<Swipe>;
25
+ export declare type GetSwipeHandler = (oldId: number) => Promise<Swipe>;
26
26
  /**
27
27
  * Props of Swiper component
28
28
  */
@@ -55,6 +55,10 @@ 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