@kolserdav/swiper 1.0.0 → 1.0.4
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 -9
- package/dist/index.css +20 -2
- package/dist/index.d.ts +25 -8
- package/dist/index.js +197 -47
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +200 -50
- package/dist/index.modern.js.map +1 -1
- package/dist/navigate_next_black_24dp~NBZptwCk.svg +1 -0
- package/dist/navigate_next_black_24dp~kmANFsMv.svg +1 -0
- package/dist/navigate_next_black_48dp~bfNeNKBt.svg +1 -0
- package/dist/navigate_next_black_48dp~kmANFsMv.svg +1 -0
- package/package.json +29 -4
package/README.md
CHANGED
|
@@ -7,22 +7,71 @@
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install --save swiper
|
|
10
|
+
npm install --save @kolserdav/swiper
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
|
-
import React
|
|
16
|
+
import React from 'react';
|
|
17
|
+
import Swiper, { GetSwipeHandler } from 'swiper';
|
|
18
|
+
import 'swiper/dist/index.css';
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
const getNext: GetSwipeHandler = (old) => {
|
|
21
|
+
const id = old + 1;
|
|
22
|
+
return {
|
|
23
|
+
id,
|
|
24
|
+
children: id < 5 ? <h1>Test {id}</h1> : null,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
28
|
+
const getPrevious: GetSwipeHandler = (old) => {
|
|
29
|
+
const id = old - 1;
|
|
30
|
+
return {
|
|
31
|
+
id,
|
|
32
|
+
children: id > 0 ? <h1>Test {id}</h1> : null,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const App = (): React.ReactElement => {
|
|
37
|
+
return (
|
|
38
|
+
<div>
|
|
39
|
+
<Swiper
|
|
40
|
+
defaultCurrent={getNext(0)}
|
|
41
|
+
defaultPrev={getPrevious(1)}
|
|
42
|
+
defaultNext={getNext(1)}
|
|
43
|
+
getNext={getNext}
|
|
44
|
+
getPrev={getPrevious}
|
|
45
|
+
/>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default App;
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Additional properties
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
/**
|
|
57
|
+
* Class name for content block
|
|
58
|
+
*/
|
|
59
|
+
className?: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Button for swipe to next
|
|
63
|
+
*/
|
|
64
|
+
nextButtonRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Button for swipe to previous
|
|
68
|
+
*/
|
|
69
|
+
prevButtonRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* invitation animation
|
|
73
|
+
*/
|
|
74
|
+
invitationAnimation?: boolean;
|
|
26
75
|
```
|
|
27
76
|
|
|
28
77
|
## License
|
package/dist/index.css
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
._3_Zua {
|
|
15
|
-
background-color:
|
|
15
|
+
background-color: #fff;
|
|
16
16
|
border-radius: 1rem;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
left: 100%;
|
|
33
33
|
}
|
|
34
34
|
._uQNyq {
|
|
35
|
-
transition: left 0.
|
|
35
|
+
transition: left 0.4s ease-in 0s;
|
|
36
36
|
}
|
|
37
37
|
._8240d {
|
|
38
38
|
transition: left 0.4s ease-out 0s;
|
|
@@ -45,3 +45,21 @@
|
|
|
45
45
|
height: calc(100% - 48px);
|
|
46
46
|
box-shadow: 0px 0px 5px 1px rgba(34, 60, 80, 0.14);
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
._7_rsx {
|
|
50
|
+
cursor: pointer;
|
|
51
|
+
position: absolute;
|
|
52
|
+
width: auto;
|
|
53
|
+
height: auto;
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
._2kk22 {
|
|
59
|
+
right: 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
._B1K5l {
|
|
63
|
+
left: 0;
|
|
64
|
+
transform: rotate(180deg);
|
|
65
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
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
|
+
******************************************************************************************/
|
|
1
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;
|
|
2
15
|
/**
|
|
3
16
|
* One of swipe card
|
|
4
17
|
*/
|
|
5
18
|
export interface Swipe {
|
|
6
19
|
id: number;
|
|
7
|
-
children: React.ReactElement | React.ReactElement[];
|
|
20
|
+
children: React.ReactElement | React.ReactElement[] | null;
|
|
8
21
|
}
|
|
9
22
|
/**
|
|
10
23
|
* Callback for get next or previous card content
|
|
11
24
|
*/
|
|
12
|
-
export declare type GetSwipeHandler = (oldId: number) => Swipe | Promise<Swipe>;
|
|
25
|
+
export declare type GetSwipeHandler = (oldId: number) => Swipe | null | Promise<Swipe | null>;
|
|
13
26
|
/**
|
|
14
27
|
* Props of Swiper component
|
|
15
28
|
*/
|
|
@@ -17,15 +30,15 @@ interface SwiperProps {
|
|
|
17
30
|
/**
|
|
18
31
|
* Current card content
|
|
19
32
|
*/
|
|
20
|
-
|
|
33
|
+
defaultCurrent: Swipe;
|
|
21
34
|
/**
|
|
22
35
|
* Next card content
|
|
23
36
|
*/
|
|
24
|
-
|
|
37
|
+
defaultNext: Swipe;
|
|
25
38
|
/**
|
|
26
39
|
* Previous card content
|
|
27
40
|
*/
|
|
28
|
-
|
|
41
|
+
defaultPrev: Swipe;
|
|
29
42
|
/**
|
|
30
43
|
* Get next card handler
|
|
31
44
|
*/
|
|
@@ -41,17 +54,21 @@ interface SwiperProps {
|
|
|
41
54
|
/**
|
|
42
55
|
* Button for swipe to next
|
|
43
56
|
*/
|
|
44
|
-
nextButtonRef?: RefObject<HTMLButtonElement | undefined>;
|
|
57
|
+
nextButtonRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
|
|
45
58
|
/**
|
|
46
59
|
* Button for swipe to previous
|
|
47
60
|
*/
|
|
48
|
-
prevButtonRef?: RefObject<HTMLButtonElement | undefined>;
|
|
61
|
+
prevButtonRef?: RefObject<HTMLButtonElement | HTMLDivElement | undefined>;
|
|
62
|
+
/**
|
|
63
|
+
* invitation animation
|
|
64
|
+
*/
|
|
65
|
+
invitationAnimation?: boolean;
|
|
49
66
|
}
|
|
50
67
|
/**
|
|
51
68
|
* Swiper component
|
|
52
69
|
*/
|
|
53
70
|
declare const Swiper: {
|
|
54
|
-
(props: SwiperProps):
|
|
71
|
+
(props: SwiperProps): React.ReactElement;
|
|
55
72
|
defaultProps: {
|
|
56
73
|
className: string;
|
|
57
74
|
};
|
package/dist/index.js
CHANGED
|
@@ -197,9 +197,76 @@ function _switch(discriminant, cases) {
|
|
|
197
197
|
}
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
var styles = {"container":"_p6aGD","paper":"_3_Zua","card":"_7l_j0","prev":"_2S9j_","next":"_2T1oW","back":"_uQNyq","go":"_8240d","content":"_1EOHv"};
|
|
200
|
+
var styles = {"container":"_p6aGD","paper":"_3_Zua","card":"_7l_j0","prev":"_2S9j_","next":"_2T1oW","back":"_uQNyq","go":"_8240d","content":"_1EOHv","button":"_7_rsx","button_next":"_2kk22","button_prev":"_B1K5l"};
|
|
201
201
|
|
|
202
|
-
var
|
|
202
|
+
var _path, _path2;
|
|
203
|
+
|
|
204
|
+
function _extends$1() {
|
|
205
|
+
_extends$1 = Object.assign || function (target) {
|
|
206
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
207
|
+
var source = arguments[i];
|
|
208
|
+
|
|
209
|
+
for (var key in source) {
|
|
210
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
211
|
+
target[key] = source[key];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return target;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
return _extends$1.apply(this, arguments);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function SvgNavigateNextBlack24Dp(props) {
|
|
223
|
+
return /*#__PURE__*/React.createElement("svg", _extends$1({
|
|
224
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
225
|
+
height: 24,
|
|
226
|
+
width: 24
|
|
227
|
+
}, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
|
|
228
|
+
d: "M0 0h24v24H0V0z",
|
|
229
|
+
fill: "none"
|
|
230
|
+
})), _path2 || (_path2 = /*#__PURE__*/React.createElement("path", {
|
|
231
|
+
d: "M10.02 6L8.61 7.41 13.19 12l-4.58 4.59L10.02 18l6-6-6-6z"
|
|
232
|
+
})));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
var _path$1, _path2$1;
|
|
236
|
+
|
|
237
|
+
function _extends$2() {
|
|
238
|
+
_extends$2 = Object.assign || function (target) {
|
|
239
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
240
|
+
var source = arguments[i];
|
|
241
|
+
|
|
242
|
+
for (var key in source) {
|
|
243
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
244
|
+
target[key] = source[key];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return target;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
return _extends$2.apply(this, arguments);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function SvgNavigateNextBlack48Dp(props) {
|
|
256
|
+
return /*#__PURE__*/React.createElement("svg", _extends$2({
|
|
257
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
258
|
+
height: 48,
|
|
259
|
+
viewBox: "0 0 24 24",
|
|
260
|
+
width: 48
|
|
261
|
+
}, props), _path$1 || (_path$1 = /*#__PURE__*/React.createElement("path", {
|
|
262
|
+
d: "M0 0h24v24H0V0z",
|
|
263
|
+
fill: "none"
|
|
264
|
+
})), _path2$1 || (_path2$1 = /*#__PURE__*/React.createElement("path", {
|
|
265
|
+
d: "M10.02 6L8.61 7.41 13.19 12l-4.58 4.59L10.02 18l6-6-6-6z"
|
|
266
|
+
})));
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
var SWIPE_TRANSITION_TIMEOUT = 400;
|
|
203
270
|
|
|
204
271
|
var getSwipes = function getSwipes(__prev, __current, __next) {
|
|
205
272
|
var result = [1, 2, 3].map(function (id) {
|
|
@@ -213,27 +280,29 @@ var getSwipes = function getSwipes(__prev, __current, __next) {
|
|
|
213
280
|
var refs = {};
|
|
214
281
|
var startClientX;
|
|
215
282
|
var lastLeft;
|
|
283
|
+
var animated = false;
|
|
216
284
|
|
|
217
285
|
var Swiper = function Swiper(props) {
|
|
218
|
-
var
|
|
219
|
-
|
|
220
|
-
|
|
286
|
+
var defaultCurrent = props.defaultCurrent,
|
|
287
|
+
defaultNext = props.defaultNext,
|
|
288
|
+
defaultPrev = props.defaultPrev,
|
|
221
289
|
getNext = props.getNext,
|
|
222
290
|
getPrev = props.getPrev,
|
|
223
291
|
className = props.className,
|
|
224
292
|
prevButtonRef = props.prevButtonRef,
|
|
225
|
-
nextButtonRef = props.nextButtonRef
|
|
293
|
+
nextButtonRef = props.nextButtonRef,
|
|
294
|
+
invitationAnimation = props.invitationAnimation;
|
|
226
295
|
|
|
227
296
|
var _useState = React.useState(),
|
|
228
|
-
|
|
297
|
+
current = _useState[0],
|
|
229
298
|
setCurrent = _useState[1];
|
|
230
299
|
|
|
231
300
|
var _useState2 = React.useState(),
|
|
232
|
-
|
|
301
|
+
prev = _useState2[0],
|
|
233
302
|
setPrev = _useState2[1];
|
|
234
303
|
|
|
235
304
|
var _useState3 = React.useState(),
|
|
236
|
-
|
|
305
|
+
next = _useState3[0],
|
|
237
306
|
setNext = _useState3[1];
|
|
238
307
|
|
|
239
308
|
var _useState4 = React.useState(0),
|
|
@@ -256,10 +325,19 @@ var Swiper = function Swiper(props) {
|
|
|
256
325
|
left = _useState8[0],
|
|
257
326
|
setLeft = _useState8[1];
|
|
258
327
|
|
|
259
|
-
var
|
|
328
|
+
var _useState9 = React.useState(),
|
|
329
|
+
isMobile = _useState9[0],
|
|
330
|
+
setIsMobile = _useState9[1];
|
|
331
|
+
|
|
332
|
+
var containerRef = React.useRef(null);
|
|
333
|
+
|
|
334
|
+
var _buttonPrevRef = React.useRef(null);
|
|
335
|
+
|
|
336
|
+
var _buttonNextRef = React.useRef(null);
|
|
337
|
+
|
|
260
338
|
var swipes = React.useMemo(function () {
|
|
261
|
-
return getSwipes(
|
|
262
|
-
}, [
|
|
339
|
+
return getSwipes(prev || defaultPrev, current || defaultCurrent, next || defaultNext);
|
|
340
|
+
}, [next]);
|
|
263
341
|
|
|
264
342
|
var getRef = function getRef(id) {
|
|
265
343
|
refs[id] = refs[id] ? refs[id] : React.createRef();
|
|
@@ -269,39 +347,42 @@ var Swiper = function Swiper(props) {
|
|
|
269
347
|
var setGoClass = function setGoClass() {
|
|
270
348
|
var _getRef$current, _getRef$current2, _getRef$current3;
|
|
271
349
|
|
|
272
|
-
(_getRef$current = getRef((
|
|
273
|
-
(_getRef$current2 = getRef((
|
|
274
|
-
(_getRef$current3 = getRef((
|
|
350
|
+
(_getRef$current = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current === void 0 ? void 0 : _getRef$current.classList.add(styles.go);
|
|
351
|
+
(_getRef$current2 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current2 === void 0 ? void 0 : _getRef$current2.classList.add(styles.go);
|
|
352
|
+
(_getRef$current3 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current3 === void 0 ? void 0 : _getRef$current3.classList.add(styles.go);
|
|
275
353
|
setTimeout(function () {
|
|
276
354
|
var _getRef$current4, _getRef$current5, _getRef$current6;
|
|
277
355
|
|
|
278
|
-
(_getRef$current4 = getRef((
|
|
279
|
-
(_getRef$current5 = getRef((
|
|
280
|
-
(_getRef$current6 = getRef((
|
|
281
|
-
},
|
|
356
|
+
(_getRef$current4 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current4 === void 0 ? void 0 : _getRef$current4.classList.remove(styles.go);
|
|
357
|
+
(_getRef$current5 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current5 === void 0 ? void 0 : _getRef$current5.classList.remove(styles.go);
|
|
358
|
+
(_getRef$current6 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current6 === void 0 ? void 0 : _getRef$current6.classList.remove(styles.go);
|
|
359
|
+
}, SWIPE_TRANSITION_TIMEOUT);
|
|
282
360
|
};
|
|
283
361
|
|
|
284
362
|
var setBackClass = function setBackClass() {
|
|
285
363
|
var _getRef$current7, _getRef$current8, _getRef$current9;
|
|
286
364
|
|
|
287
|
-
(_getRef$current7 = getRef((
|
|
288
|
-
(_getRef$current8 = getRef((
|
|
289
|
-
(_getRef$current9 = getRef((
|
|
365
|
+
(_getRef$current7 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current7 === void 0 ? void 0 : _getRef$current7.classList.add(styles.back);
|
|
366
|
+
(_getRef$current8 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current8 === void 0 ? void 0 : _getRef$current8.classList.add(styles.back);
|
|
367
|
+
(_getRef$current9 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current9 === void 0 ? void 0 : _getRef$current9.classList.add(styles.back);
|
|
290
368
|
setLeft(0);
|
|
291
369
|
setTimeout(function () {
|
|
292
370
|
var _getRef$current10, _getRef$current11, _getRef$current12;
|
|
293
371
|
|
|
294
|
-
(_getRef$current10 = getRef((
|
|
295
|
-
(_getRef$current11 = getRef((
|
|
296
|
-
(_getRef$current12 = getRef((
|
|
297
|
-
},
|
|
372
|
+
(_getRef$current10 = getRef((next === null || next === void 0 ? void 0 : next.id) || 0).current) === null || _getRef$current10 === void 0 ? void 0 : _getRef$current10.classList.remove(styles.back);
|
|
373
|
+
(_getRef$current11 = getRef((prev === null || prev === void 0 ? void 0 : prev.id) || 0).current) === null || _getRef$current11 === void 0 ? void 0 : _getRef$current11.classList.remove(styles.back);
|
|
374
|
+
(_getRef$current12 = getRef((current === null || current === void 0 ? void 0 : current.id) || 0).current) === null || _getRef$current12 === void 0 ? void 0 : _getRef$current12.classList.remove(styles.back);
|
|
375
|
+
}, SWIPE_TRANSITION_TIMEOUT);
|
|
298
376
|
};
|
|
299
377
|
|
|
300
378
|
var swipe = function swipe(_lastLeft) {
|
|
301
379
|
try {
|
|
380
|
+
var _exit2 = false;
|
|
381
|
+
|
|
302
382
|
var _temp4 = function () {
|
|
303
383
|
if (Math.abs(_lastLeft) > width / 3) {
|
|
304
|
-
var _temp5 = function _temp5() {
|
|
384
|
+
var _temp5 = function _temp5(_result) {
|
|
385
|
+
if (_exit2) return _result;
|
|
305
386
|
setGoClass();
|
|
306
387
|
};
|
|
307
388
|
|
|
@@ -309,16 +390,28 @@ var Swiper = function Swiper(props) {
|
|
|
309
390
|
|
|
310
391
|
var _temp6 = function () {
|
|
311
392
|
if (_lastLeft < 0) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
393
|
+
if ((next === null || next === void 0 ? void 0 : next.children) === null) {
|
|
394
|
+
setBackClass();
|
|
395
|
+
_exit2 = true;
|
|
396
|
+
return 1;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
setPrev(current);
|
|
400
|
+
setCurrent(next);
|
|
401
|
+
return Promise.resolve(getNext((next === null || next === void 0 ? void 0 : next.id) || 0)).then(function (_getNext) {
|
|
315
402
|
setNext(_getNext);
|
|
316
403
|
});
|
|
317
404
|
} else {
|
|
318
|
-
|
|
405
|
+
if ((prev === null || prev === void 0 ? void 0 : prev.children) === null) {
|
|
406
|
+
setBackClass();
|
|
407
|
+
_exit2 = true;
|
|
408
|
+
return 1;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return Promise.resolve(getPrev((prev === null || prev === void 0 ? void 0 : prev.id) || 0)).then(function (_getPrev) {
|
|
319
412
|
setPrev(_getPrev);
|
|
320
|
-
setCurrent(
|
|
321
|
-
setNext(
|
|
413
|
+
setCurrent(prev);
|
|
414
|
+
setNext(current);
|
|
322
415
|
});
|
|
323
416
|
}
|
|
324
417
|
}();
|
|
@@ -329,7 +422,9 @@ var Swiper = function Swiper(props) {
|
|
|
329
422
|
}
|
|
330
423
|
}();
|
|
331
424
|
|
|
332
|
-
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(function () {
|
|
425
|
+
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(function (_result2) {
|
|
426
|
+
return _exit2 ? _result2 : 0;
|
|
427
|
+
}) : _exit2 ? _temp4 : 0);
|
|
333
428
|
} catch (e) {
|
|
334
429
|
return Promise.reject(e);
|
|
335
430
|
}
|
|
@@ -401,7 +496,7 @@ var Swiper = function Swiper(props) {
|
|
|
401
496
|
}
|
|
402
497
|
|
|
403
498
|
setLeft(leftVal);
|
|
404
|
-
return Promise.resolve(wait(
|
|
499
|
+
return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT / 2)).then(function () {
|
|
405
500
|
return Promise.resolve(swipe(leftVal)).then(function () {});
|
|
406
501
|
});
|
|
407
502
|
} catch (e) {
|
|
@@ -412,7 +507,8 @@ var Swiper = function Swiper(props) {
|
|
|
412
507
|
|
|
413
508
|
var clickNextHandler = clickHandler('next');
|
|
414
509
|
var clickPrevHandler = clickHandler('prev');
|
|
415
|
-
|
|
510
|
+
|
|
511
|
+
var resizeHandler = function resizeHandler() {
|
|
416
512
|
var _containerRef$current, _containerRef$current2, _containerRef$current3, _containerRef$current4, _containerRef$current5, _containerRef$current6, _containerRef$current7, _containerRef$current8, _containerRef$current9;
|
|
417
513
|
|
|
418
514
|
var _width = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : (_containerRef$current2 = _containerRef$current.parentElement) === null || _containerRef$current2 === void 0 ? void 0 : (_containerRef$current3 = _containerRef$current2.getBoundingClientRect()) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.width;
|
|
@@ -421,8 +517,33 @@ var Swiper = function Swiper(props) {
|
|
|
421
517
|
|
|
422
518
|
var __left = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current7 = containerRef.current) === null || _containerRef$current7 === void 0 ? void 0 : (_containerRef$current8 = _containerRef$current7.parentElement) === null || _containerRef$current8 === void 0 ? void 0 : (_containerRef$current9 = _containerRef$current8.getBoundingClientRect()) === null || _containerRef$current9 === void 0 ? void 0 : _containerRef$current9.left;
|
|
423
519
|
|
|
424
|
-
var
|
|
425
|
-
|
|
520
|
+
var _windowWidth = document.body.clientWidth;
|
|
521
|
+
|
|
522
|
+
if (_width && _height) {
|
|
523
|
+
setWidth(_width);
|
|
524
|
+
setHeight(_height);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (__left) {
|
|
528
|
+
setLeft(__left);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
if (_windowWidth) {
|
|
532
|
+
setWindowWidth(_windowWidth);
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
React.useEffect(function () {
|
|
537
|
+
var _containerRef$current10, _containerRef$current11, _containerRef$current12, _containerRef$current13, _containerRef$current14, _containerRef$current15, _containerRef$current16, _containerRef$current17, _containerRef$current18;
|
|
538
|
+
|
|
539
|
+
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;
|
|
540
|
+
|
|
541
|
+
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;
|
|
542
|
+
|
|
543
|
+
var __left = containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current16 = containerRef.current) === null || _containerRef$current16 === void 0 ? void 0 : (_containerRef$current17 = _containerRef$current16.parentElement) === null || _containerRef$current17 === void 0 ? void 0 : (_containerRef$current18 = _containerRef$current17.getBoundingClientRect()) === null || _containerRef$current18 === void 0 ? void 0 : _containerRef$current18.left;
|
|
544
|
+
|
|
545
|
+
var prevButton = prevButtonRef ? prevButtonRef === null || prevButtonRef === void 0 ? void 0 : prevButtonRef.current : _buttonPrevRef.current;
|
|
546
|
+
var nextButton = nextButtonRef ? nextButtonRef === null || nextButtonRef === void 0 ? void 0 : nextButtonRef.current : _buttonNextRef.current;
|
|
426
547
|
var _windowWidth = document.body.clientWidth;
|
|
427
548
|
|
|
428
549
|
if (_width && !width && _height && !height) {
|
|
@@ -438,28 +559,50 @@ var Swiper = function Swiper(props) {
|
|
|
438
559
|
setWindowWidth(_windowWidth);
|
|
439
560
|
}
|
|
440
561
|
|
|
441
|
-
if (!
|
|
442
|
-
setCurrent(
|
|
443
|
-
setNext(
|
|
444
|
-
setPrev(
|
|
562
|
+
if (!current || !prev || !next) {
|
|
563
|
+
setCurrent(defaultCurrent);
|
|
564
|
+
setNext(defaultNext);
|
|
565
|
+
setPrev(defaultPrev);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if (invitationAnimation && width && !animated) {
|
|
569
|
+
animated = true;
|
|
570
|
+
|
|
571
|
+
try {
|
|
572
|
+
setGoClass();
|
|
573
|
+
setLeft(-200);
|
|
574
|
+
return Promise.resolve(wait(SWIPE_TRANSITION_TIMEOUT)).then(function () {
|
|
575
|
+
setBackClass();
|
|
576
|
+
setLeft(_left);
|
|
577
|
+
});
|
|
578
|
+
} catch (e) {
|
|
579
|
+
Promise.reject(e);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if (typeof isMobile === 'undefined') {
|
|
584
|
+
setIsMobile('ontouchstart' in window || typeof navigator.msMaxTouchPoints !== 'undefined');
|
|
445
585
|
}
|
|
446
586
|
|
|
447
587
|
prevButton === null || prevButton === void 0 ? void 0 : prevButton.addEventListener('click', clickPrevHandler);
|
|
448
588
|
nextButton === null || nextButton === void 0 ? void 0 : nextButton.addEventListener('click', clickNextHandler);
|
|
589
|
+
window.addEventListener('resize', resizeHandler);
|
|
449
590
|
return function () {
|
|
450
591
|
prevButton === null || prevButton === void 0 ? void 0 : prevButton.removeEventListener('click', clickPrevHandler);
|
|
451
592
|
nextButton === null || nextButton === void 0 ? void 0 : nextButton.removeEventListener('click', clickNextHandler);
|
|
593
|
+
window.removeEventListener('resize', resizeHandler);
|
|
452
594
|
};
|
|
453
|
-
}, [
|
|
595
|
+
}, [next]);
|
|
454
596
|
return React__default.createElement("div", {
|
|
455
597
|
className: styles.container,
|
|
456
598
|
ref: containerRef
|
|
457
599
|
}, swipes.map(function (item) {
|
|
458
600
|
return React__default.createElement("div", {
|
|
601
|
+
key: item.id
|
|
602
|
+
}, item.children && width ? React__default.createElement("div", {
|
|
459
603
|
onTouchMove: onTouchWrapper('onTouchMove'),
|
|
460
604
|
onTouchStart: onTouchWrapper('onTouchStart'),
|
|
461
605
|
onTouchEnd: onTouchWrapper('onTouchEnd'),
|
|
462
|
-
key: item.id,
|
|
463
606
|
id: item.id.toString(),
|
|
464
607
|
style: item.type === 'current' ? {
|
|
465
608
|
width: width,
|
|
@@ -478,13 +621,20 @@ var Swiper = function Swiper(props) {
|
|
|
478
621
|
ref: getRef(item.id)
|
|
479
622
|
}, React__default.createElement("div", {
|
|
480
623
|
className: clsx(styles.content, className)
|
|
481
|
-
}, item.children));
|
|
482
|
-
}))
|
|
624
|
+
}, item.children)) : '');
|
|
625
|
+
}), typeof isMobile !== 'undefined' && !isMobile && !prevButtonRef && (prev === null || prev === void 0 ? void 0 : prev.children) !== null && React__default.createElement("div", {
|
|
626
|
+
className: clsx(styles.button, styles.button_prev),
|
|
627
|
+
ref: _buttonPrevRef
|
|
628
|
+
}, windowWidth < 3000 ? React__default.createElement(SvgNavigateNextBlack24Dp, null) : React__default.createElement(SvgNavigateNextBlack48Dp, null)), typeof isMobile !== 'undefined' && !isMobile && !nextButtonRef && (next === null || next === void 0 ? void 0 : next.children) !== null && React__default.createElement("div", {
|
|
629
|
+
className: clsx(styles.button, styles.button_next),
|
|
630
|
+
ref: _buttonNextRef
|
|
631
|
+
}, windowWidth < 3000 ? React__default.createElement(SvgNavigateNextBlack24Dp, null) : React__default.createElement(SvgNavigateNextBlack48Dp, null)));
|
|
483
632
|
};
|
|
484
633
|
|
|
485
634
|
Swiper.defaultProps = {
|
|
486
635
|
className: ''
|
|
487
636
|
};
|
|
488
637
|
|
|
489
|
-
|
|
638
|
+
exports.SWIPE_TRANSITION_TIMEOUT = SWIPE_TRANSITION_TIMEOUT;
|
|
639
|
+
exports.default = Swiper;
|
|
490
640
|
//# sourceMappingURL=index.js.map
|