@@ -30,9 +30,11 @@ const Cards: React.FC<Props> = (props) => {
30
30
const handlers = useSwipeable ( {
31
31
onSwipedLeft : ( ) => {
32
32
if ( index < cards . length - 1 ) setIndex ( index + 1 ) ;
33
+ else setIndex ( 0 ) ;
33
34
} ,
34
35
onSwipedRight : ( ) => {
35
36
if ( index > 0 ) setIndex ( index - 1 ) ;
37
+ else setIndex ( cards . length - 1 ) ;
36
38
} ,
37
39
preventDefaultTouchmoveEvent : true ,
38
40
trackMouse : true ,
@@ -49,16 +51,8 @@ const Cards: React.FC<Props> = (props) => {
49
51
} => {
50
52
const { width } = cardDimensions ;
51
53
52
- if ( i - 3 >= index ) {
53
- return {
54
- translateX : width / 2 + width / 40 ,
55
- zIndex : - 1 ,
56
- opacity : 0 ,
57
- scale : 0.75 ,
58
- } ;
59
- }
60
-
61
- if ( i - 2 === index ) {
54
+ // Card 2 Left
55
+ if ( i - 2 === index || i + ( cards . length - 2 ) === index ) {
62
56
return {
63
57
translateX : width / 2 + width / 40 ,
64
58
zIndex : 0 ,
@@ -67,7 +61,8 @@ const Cards: React.FC<Props> = (props) => {
67
61
} ;
68
62
}
69
63
70
- if ( i - 1 === index ) {
64
+ // Card 1 Left
65
+ if ( i - 1 === index || i + ( cards . length - 1 ) === index ) {
71
66
return {
72
67
translateX : width / 4 ,
73
68
zIndex : 1 ,
@@ -76,6 +71,7 @@ const Cards: React.FC<Props> = (props) => {
76
71
} ;
77
72
}
78
73
74
+ // Centered Card
79
75
if ( i === index ) {
80
76
return {
81
77
translateX : 0 ,
@@ -85,7 +81,8 @@ const Cards: React.FC<Props> = (props) => {
85
81
} ;
86
82
}
87
83
88
- if ( i + 1 === index ) {
84
+ // Card 1 Right
85
+ if ( i + 1 === index || i - ( cards . length - 1 ) === index ) {
89
86
return {
90
87
translateX : - width / 4 ,
91
88
zIndex : 1 ,
@@ -94,7 +91,8 @@ const Cards: React.FC<Props> = (props) => {
94
91
} ;
95
92
}
96
93
97
- if ( i + 2 === index ) {
94
+ // Card 2 Right
95
+ if ( i + 2 === index || i - ( cards . length - 2 ) === index ) {
98
96
return {
99
97
translateX : - width / 2 - width / 40 ,
100
98
zIndex : 0 ,
@@ -103,14 +101,12 @@ const Cards: React.FC<Props> = (props) => {
103
101
} ;
104
102
}
105
103
106
- if ( i + 3 <= index ) {
107
- return {
108
- translateX : - width / 2 - width / 40 ,
109
- zIndex : - 1 ,
110
- opacity : 0 ,
111
- scale : 0.75 ,
112
- } ;
113
- }
104
+ return {
105
+ translateX : 0 ,
106
+ zIndex : - 1 ,
107
+ opacity : 0 ,
108
+ scale : 0.75 ,
109
+ } ;
114
110
} ,
115
111
[ index , cardDimensions , windowWidth ]
116
112
) ;
0 commit comments