Skip to content
This repository was archived by the owner on Feb 15, 2025. It is now read-only.

Commit 11b2e43

Browse files
committed
optimized cards on smaller devices
1 parent 2edc430 commit 11b2e43

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/_pages/LandingPage/components/OtherFeaturesView/components/Cards/components/Card/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Props = {
88
data: CardInterface;
99
active: boolean;
1010
className?: string;
11-
width?: number;
11+
width?: number | string;
1212
height?: number;
1313
};
1414

src/_pages/LandingPage/components/OtherFeaturesView/components/Cards/index.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useCallback, useState } from 'react';
22
import Card from './components/Card';
33
import styles from './styles.module.css';
44
import BulletItem from './components/BulletItem';
5+
import { useWindowSize } from '../../../../../../hooks/useWindowSize';
56

67
export interface CardInterface {
78
title: string;
@@ -18,9 +19,8 @@ const Cards: React.FC<Props> = (props) => {
1819
props.startIndex && props.startIndex < cards.length
1920
? props.startIndex
2021
: Math.round(cards.length / 2);
21-
22+
const { windowWidth } = useWindowSize();
2223
const [index, setIndex] = useState(startIndex);
23-
2424
const [cardDimensions] = useState<{ width: number; height: number }>({
2525
width: 400,
2626
height: 600,
@@ -41,7 +41,7 @@ const Cards: React.FC<Props> = (props) => {
4141
return {
4242
translateX: -width / 2 - width / 40,
4343
zIndex: -1,
44-
opacity: 1,
44+
opacity: 0,
4545
scale: 0.75,
4646
};
4747
}
@@ -50,7 +50,7 @@ const Cards: React.FC<Props> = (props) => {
5050
return {
5151
translateX: -width / 2 - width / 40,
5252
zIndex: 0,
53-
opacity: 1,
53+
opacity: windowWidth > 996 ? 1 : 0,
5454
scale: 0.75,
5555
};
5656
}
@@ -59,7 +59,7 @@ const Cards: React.FC<Props> = (props) => {
5959
return {
6060
translateX: -width / 4,
6161
zIndex: 1,
62-
opacity: 1,
62+
opacity: windowWidth > width + width / 2 ? 1 : 0,
6363
scale: 0.85,
6464
};
6565
}
@@ -77,7 +77,7 @@ const Cards: React.FC<Props> = (props) => {
7777
return {
7878
translateX: width / 4,
7979
zIndex: 1,
80-
opacity: 1,
80+
opacity: windowWidth > width + width / 2 ? 1 : 0,
8181
scale: 0.85,
8282
};
8383
}
@@ -86,7 +86,7 @@ const Cards: React.FC<Props> = (props) => {
8686
return {
8787
translateX: width / 2 + width / 40,
8888
zIndex: 0,
89-
opacity: 1,
89+
opacity: windowWidth > 996 ? 1 : 0,
9090
scale: 0.75,
9191
};
9292
}
@@ -95,21 +95,25 @@ const Cards: React.FC<Props> = (props) => {
9595
return {
9696
translateX: width / 2 + width / 40,
9797
zIndex: -1,
98-
opacity: 1,
98+
opacity: 0,
9999
scale: 0.75,
100100
};
101101
}
102102
},
103-
[index, cardDimensions]
103+
[index, cardDimensions, windowWidth]
104104
);
105105

106106
return (
107107
<div className={styles.Container}>
108108
<div
109109
className={styles.Slider}
110110
style={{
111+
// Sizes of Card to properly center them, because the Cards are absolute
111112
height: cardDimensions.height,
112-
width: cardDimensions.width || '100%',
113+
width:
114+
windowWidth * 0.95 > cardDimensions.width
115+
? cardDimensions.width || '100%'
116+
: '100%',
113117
}}>
114118
{cards.map((card, i) => {
115119
const cardProps = getCardProps(i);
@@ -120,7 +124,6 @@ const Cards: React.FC<Props> = (props) => {
120124
transform: `translateX(${cardProps.translateX}px) scale(${cardProps.scale})`,
121125
opacity: cardProps.opacity,
122126
zIndex: cardProps.zIndex,
123-
width: cardDimensions.width || '100%',
124127
cursor: i === index ? 'auto' : 'pointer',
125128
}}
126129
onClick={() => {
@@ -129,7 +132,11 @@ const Cards: React.FC<Props> = (props) => {
129132
<Card
130133
data={card}
131134
active={i === index}
132-
width={cardDimensions.width}
135+
width={
136+
windowWidth * 0.95 > cardDimensions.width
137+
? cardDimensions.width || '100%'
138+
: '100%'
139+
}
133140
height={cardDimensions.height}
134141
/>
135142
</div>

src/_pages/LandingPage/components/OtherFeaturesView/components/Cards/styles.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
align-items: center;
55

66
width: 100%;
7+
overflow: hidden;
78
}
89

910
.Slider {

src/_pages/LandingPage/components/StatsView/styles.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.Container {
2-
padding: 8rem 0;
2+
padding: 10rem 0;
33
}
44

55
.Content {

0 commit comments

Comments
 (0)