@@ -2,6 +2,7 @@ import React, { useCallback, useState } from 'react';
2
2
import Card from './components/Card' ;
3
3
import styles from './styles.module.css' ;
4
4
import BulletItem from './components/BulletItem' ;
5
+ import { useWindowSize } from '../../../../../../hooks/useWindowSize' ;
5
6
6
7
export interface CardInterface {
7
8
title : string ;
@@ -18,9 +19,8 @@ const Cards: React.FC<Props> = (props) => {
18
19
props . startIndex && props . startIndex < cards . length
19
20
? props . startIndex
20
21
: Math . round ( cards . length / 2 ) ;
21
-
22
+ const { windowWidth } = useWindowSize ( ) ;
22
23
const [ index , setIndex ] = useState ( startIndex ) ;
23
-
24
24
const [ cardDimensions ] = useState < { width : number ; height : number } > ( {
25
25
width : 400 ,
26
26
height : 600 ,
@@ -41,7 +41,7 @@ const Cards: React.FC<Props> = (props) => {
41
41
return {
42
42
translateX : - width / 2 - width / 40 ,
43
43
zIndex : - 1 ,
44
- opacity : 1 ,
44
+ opacity : 0 ,
45
45
scale : 0.75 ,
46
46
} ;
47
47
}
@@ -50,7 +50,7 @@ const Cards: React.FC<Props> = (props) => {
50
50
return {
51
51
translateX : - width / 2 - width / 40 ,
52
52
zIndex : 0 ,
53
- opacity : 1 ,
53
+ opacity : windowWidth > 996 ? 1 : 0 ,
54
54
scale : 0.75 ,
55
55
} ;
56
56
}
@@ -59,7 +59,7 @@ const Cards: React.FC<Props> = (props) => {
59
59
return {
60
60
translateX : - width / 4 ,
61
61
zIndex : 1 ,
62
- opacity : 1 ,
62
+ opacity : windowWidth > width + width / 2 ? 1 : 0 ,
63
63
scale : 0.85 ,
64
64
} ;
65
65
}
@@ -77,7 +77,7 @@ const Cards: React.FC<Props> = (props) => {
77
77
return {
78
78
translateX : width / 4 ,
79
79
zIndex : 1 ,
80
- opacity : 1 ,
80
+ opacity : windowWidth > width + width / 2 ? 1 : 0 ,
81
81
scale : 0.85 ,
82
82
} ;
83
83
}
@@ -86,7 +86,7 @@ const Cards: React.FC<Props> = (props) => {
86
86
return {
87
87
translateX : width / 2 + width / 40 ,
88
88
zIndex : 0 ,
89
- opacity : 1 ,
89
+ opacity : windowWidth > 996 ? 1 : 0 ,
90
90
scale : 0.75 ,
91
91
} ;
92
92
}
@@ -95,21 +95,25 @@ const Cards: React.FC<Props> = (props) => {
95
95
return {
96
96
translateX : width / 2 + width / 40 ,
97
97
zIndex : - 1 ,
98
- opacity : 1 ,
98
+ opacity : 0 ,
99
99
scale : 0.75 ,
100
100
} ;
101
101
}
102
102
} ,
103
- [ index , cardDimensions ]
103
+ [ index , cardDimensions , windowWidth ]
104
104
) ;
105
105
106
106
return (
107
107
< div className = { styles . Container } >
108
108
< div
109
109
className = { styles . Slider }
110
110
style = { {
111
+ // Sizes of Card to properly center them, because the Cards are absolute
111
112
height : cardDimensions . height ,
112
- width : cardDimensions . width || '100%' ,
113
+ width :
114
+ windowWidth * 0.95 > cardDimensions . width
115
+ ? cardDimensions . width || '100%'
116
+ : '100%' ,
113
117
} } >
114
118
{ cards . map ( ( card , i ) => {
115
119
const cardProps = getCardProps ( i ) ;
@@ -120,7 +124,6 @@ const Cards: React.FC<Props> = (props) => {
120
124
transform : `translateX(${ cardProps . translateX } px) scale(${ cardProps . scale } )` ,
121
125
opacity : cardProps . opacity ,
122
126
zIndex : cardProps . zIndex ,
123
- width : cardDimensions . width || '100%' ,
124
127
cursor : i === index ? 'auto' : 'pointer' ,
125
128
} }
126
129
onClick = { ( ) => {
@@ -129,7 +132,11 @@ const Cards: React.FC<Props> = (props) => {
129
132
< Card
130
133
data = { card }
131
134
active = { i === index }
132
- width = { cardDimensions . width }
135
+ width = {
136
+ windowWidth * 0.95 > cardDimensions . width
137
+ ? cardDimensions . width || '100%'
138
+ : '100%'
139
+ }
133
140
height = { cardDimensions . height }
134
141
/>
135
142
</ div >
0 commit comments