@kolserdav/swiper 2.2.2 → 2.3.1
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 +106 -101
- package/dist/index.d.ts +5 -1
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +21 -8
- package/dist/index.modern.js.map +1 -1
- package/package.json +102 -102
- package/dist/index.css +0 -78
- package/dist/navigate_next_black_24dp~NBZptwCk.svg +0 -1
- package/dist/navigate_next_black_24dp~kmANFsMv.svg +0 -1
- package/dist/navigate_next_black_48dp~bfNeNKBt.svg +0 -1
- package/dist/navigate_next_black_48dp~kmANFsMv.svg +0 -1
package/README.md
CHANGED
|
@@ -1,101 +1,106 @@
|
|
|
1
|
-
# swiper
|
|
2
|
-
|
|
3
|
-
> Simple and powerfull dynamic react swiper component
|
|
4
|
-
|
|
5
|
-
[](https://www.npmjs.com/package/swiper) [](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 'swiper';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
*
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Get
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
*
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
*
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
*
|
|
94
|
-
*/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
1
|
+
# swiper
|
|
2
|
+
|
|
3
|
+
> Simple and powerfull dynamic react swiper component
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/swiper) [](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
|
+
|
|
19
|
+
const COUNT = 4;
|
|
20
|
+
|
|
21
|
+
const getNext: GetSwipeHandler = async (old) => {
|
|
22
|
+
let id = old + 1;
|
|
23
|
+
id = id <= COUNT ? id : 0;
|
|
24
|
+
return {
|
|
25
|
+
id,
|
|
26
|
+
children: <h1>Test {id}</h1>,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getPrevios: GetSwipeHandler = async (old) => {
|
|
31
|
+
let id = old - 1;
|
|
32
|
+
id = id >= 0 ? id : COUNT;
|
|
33
|
+
return {
|
|
34
|
+
id,
|
|
35
|
+
children: <h1>Test {id}</h1>,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const App = (): React.ReactElement => {
|
|
40
|
+
const [current, setCurrent] = useState<Swipe>();
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!current) {
|
|
43
|
+
(async () => {
|
|
44
|
+
setCurrent(await getNext(0));
|
|
45
|
+
})();
|
|
46
|
+
}
|
|
47
|
+
}, []);
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div>
|
|
51
|
+
{current && (
|
|
52
|
+
<Swiper
|
|
53
|
+
defaultCurrent={current}
|
|
54
|
+
getNext={getNext}
|
|
55
|
+
getPrev={getPrevios}
|
|
56
|
+
invitationAnimation={true}
|
|
57
|
+
durationAnimation={1000}
|
|
58
|
+
/>
|
|
59
|
+
)}
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default App;
|
|
65
|
+
|
|
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
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT © [kolserdav](https://github.com/kolserdav)
|
package/dist/index.d.ts
CHANGED
|
@@ -52,7 +52,11 @@ interface SwiperProps {
|
|
|
52
52
|
/**
|
|
53
53
|
* On swipe callback
|
|
54
54
|
*/
|
|
55
|
-
onSwipe?: (currentId: number) => void;
|
|
55
|
+
onSwipe?: (currentId: number | null | undefined) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Auto slide if provieded
|
|
58
|
+
*/
|
|
59
|
+
durationAnimation?: number;
|
|
56
60
|
}
|
|
57
61
|
/**
|
|
58
62
|
* Swiper component
|
package/dist/index.js
CHANGED
|
@@ -300,7 +300,8 @@ var Swiper = function Swiper(props) {
|
|
|
300
300
|
getPrev = props.getPrev,
|
|
301
301
|
onSwipe = props.onSwipe,
|
|
302
302
|
className = props.className,
|
|
303
|
-
invitationAnimation = props.invitationAnimation
|
|
303
|
+
invitationAnimation = props.invitationAnimation,
|
|
304
|
+
durationAnimation = props.durationAnimation;
|
|
304
305
|
|
|
305
306
|
var _useStyles = useStyles(),
|
|
306
307
|
go = _useStyles.go,
|
|
@@ -452,7 +453,7 @@ var Swiper = function Swiper(props) {
|
|
|
452
453
|
});
|
|
453
454
|
};
|
|
454
455
|
|
|
455
|
-
if (
|
|
456
|
+
if ((next === null || next === void 0 ? void 0 : next.id) === null) {
|
|
456
457
|
setBackClassHandler();
|
|
457
458
|
setLeft(0);
|
|
458
459
|
setLoad(false);
|
|
@@ -498,7 +499,7 @@ var Swiper = function Swiper(props) {
|
|
|
498
499
|
});
|
|
499
500
|
};
|
|
500
501
|
|
|
501
|
-
if (
|
|
502
|
+
if ((prev === null || prev === void 0 ? void 0 : prev.id) === null) {
|
|
502
503
|
setBackClassHandler();
|
|
503
504
|
setLeft(0);
|
|
504
505
|
setLoad(false);
|
|
@@ -506,7 +507,7 @@ var Swiper = function Swiper(props) {
|
|
|
506
507
|
return 1;
|
|
507
508
|
}
|
|
508
509
|
|
|
509
|
-
currentId = prev.id;
|
|
510
|
+
currentId = prev === null || prev === void 0 ? void 0 : prev.id;
|
|
510
511
|
|
|
511
512
|
if (onSwipe !== undefined) {
|
|
512
513
|
onSwipe(currentId);
|
|
@@ -671,6 +672,14 @@ var Swiper = function Swiper(props) {
|
|
|
671
672
|
React.useEffect(function () {
|
|
672
673
|
var _containerRef$current10, _containerRef$current11, _containerRef$current12, _containerRef$current13, _containerRef$current14, _containerRef$current15, _containerRef$current16, _containerRef$current17, _containerRef$current18, _current$nextRef, _current$closeRef;
|
|
673
674
|
|
|
675
|
+
var clearAnimate;
|
|
676
|
+
|
|
677
|
+
if (durationAnimation) {
|
|
678
|
+
clearAnimate = setInterval(function () {
|
|
679
|
+
clickNextHandler();
|
|
680
|
+
}, durationAnimation);
|
|
681
|
+
}
|
|
682
|
+
|
|
674
683
|
var _width = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current10 = containerRef.current) === null || _containerRef$current10 === void 0 ? void 0 : (_containerRef$current11 = _containerRef$current10.parentElement) === null || _containerRef$current11 === void 0 ? void 0 : (_containerRef$current12 = _containerRef$current11.getBoundingClientRect()) === null || _containerRef$current12 === void 0 ? void 0 : _containerRef$current12.width;
|
|
675
684
|
|
|
676
685
|
var _height = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current13 = containerRef.current) === null || _containerRef$current13 === void 0 ? void 0 : (_containerRef$current14 = _containerRef$current13.parentElement) === null || _containerRef$current14 === void 0 ? void 0 : (_containerRef$current15 = _containerRef$current14.getBoundingClientRect()) === null || _containerRef$current15 === void 0 ? void 0 : _containerRef$current15.height;
|
|
@@ -755,6 +764,10 @@ var Swiper = function Swiper(props) {
|
|
|
755
764
|
setPreValues(prev, next);
|
|
756
765
|
window.addEventListener('resize', resizeHandler);
|
|
757
766
|
return function () {
|
|
767
|
+
if (clearAnimate) {
|
|
768
|
+
clearInterval(clearAnimate);
|
|
769
|
+
}
|
|
770
|
+
|
|
758
771
|
window.removeEventListener('resize', resizeHandler);
|
|
759
772
|
buttonNext === null || buttonNext === void 0 ? void 0 : buttonNext.removeEventListener('click', clickNextHandler);
|
|
760
773
|
buttonClose === null || buttonClose === void 0 ? void 0 : buttonClose.removeEventListener('click', clickNextHandler);
|
|
@@ -768,7 +781,7 @@ var Swiper = function Swiper(props) {
|
|
|
768
781
|
|
|
769
782
|
return React__default.createElement("div", {
|
|
770
783
|
key: item.id
|
|
771
|
-
}, React__default.createElement(React.Fragment, null, item.id && width && React__default.createElement("div", {
|
|
784
|
+
}, React__default.createElement(React.Fragment, null, item.id !== null && width && React__default.createElement("div", {
|
|
772
785
|
onTouchMove: onTouchWrapper('onTouchMove'),
|
|
773
786
|
onTouchStart: onTouchWrapper('onTouchStart'),
|
|
774
787
|
onTouchEnd: onTouchWrapper('onTouchEnd'),
|
|
@@ -790,7 +803,7 @@ var Swiper = function Swiper(props) {
|
|
|
790
803
|
ref: getRef(item.id)
|
|
791
804
|
}, React__default.createElement("div", {
|
|
792
805
|
className: clsx(content, className)
|
|
793
|
-
}, item.children)),
|
|
806
|
+
}, item.children)), item.id === null && React__default.createElement("div", {
|
|
794
807
|
style: item.type === 'current' ? {
|
|
795
808
|
width: width,
|
|
796
809
|
height: height,
|
|
@@ -808,12 +821,12 @@ var Swiper = function Swiper(props) {
|
|
|
808
821
|
}, React__default.createElement(material.IconButton, {
|
|
809
822
|
disabled: true
|
|
810
823
|
}, React__default.createElement(StopIcon, null)))));
|
|
811
|
-
}), typeof isMobile !== 'undefined' && !isMobile && (prev === null || prev === void 0 ? void 0 : prev.id) && React__default.createElement("div", {
|
|
824
|
+
}), typeof isMobile !== 'undefined' && !isMobile && (prev === null || prev === void 0 ? void 0 : prev.id) !== null && React__default.createElement("div", {
|
|
812
825
|
className: clsx(button, button__prev)
|
|
813
826
|
}, React__default.createElement(material.IconButton, {
|
|
814
827
|
disabled: load || isMobile,
|
|
815
828
|
onClick: clickPrevHandler
|
|
816
|
-
}, React__default.createElement(NavigateNextIcon, null))), typeof isMobile !== 'undefined' && !isMobile && (next === null || next === void 0 ? void 0 : next.id) && React__default.createElement("div", {
|
|
829
|
+
}, React__default.createElement(NavigateNextIcon, null))), typeof isMobile !== 'undefined' && !isMobile && (next === null || next === void 0 ? void 0 : next.id) !== null && React__default.createElement("div", {
|
|
817
830
|
className: clsx(button, button__next)
|
|
818
831
|
}, React__default.createElement(material.IconButton, {
|
|
819
832
|
disabled: load || isMobile,
|