Skip to content

Commit ba69ed5

Browse files
committed
added close button for dog message on small screens
1 parent 5c31172 commit ba69ed5

2 files changed

Lines changed: 71 additions & 3 deletions

File tree

src/sections/About/AboutSection.jsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,20 @@ export default function AboutSection() {
5656

5757
const [isBubbleHidden, setIsBubbleHidden] = useState(false);
5858

59+
//add a mobile flag (updates on resize)
60+
const [isMobile, setIsMobile] = useState(window.innerWidth <= 768);
61+
useEffect(() => {
62+
const onResize = () => setIsMobile(window.innerWidth <= 768);
63+
window.addEventListener("resize", onResize);
64+
return () => window.removeEventListener("resize", onResize);
65+
}, []);
66+
5967
//Handle dog scale according to the width of the screen
6068
const [dogScale, setDogScale] = useState(getScaleForWidth(window.innerWidth));
6169
function getScaleForWidth(width) {
62-
if (width < 480) {
70+
if (width <= 480) {
6371
return 1.5;
64-
} else if (width < 768) {
72+
} else if (width <= 768) {
6573
return 2.0;
6674
} else {
6775
return 2.5;
@@ -185,12 +193,26 @@ export default function AboutSection() {
185193
data-direction={direction}
186194
style={
187195
direction === 1
188-
? window.innerWidth < 768
196+
? window.innerWidth <= 768
189197
? { left: `${MOUTH_X - 100}px` }
190198
: { left: `${MOUTH_X}px` }
191199
: { left: `${MOUTH_X - 48}px` }
192200
}
193201
>
202+
{/* close button (only shown on small screens) */}
203+
<button
204+
type="button"
205+
className={styles.bubbleClose}
206+
aria-label={
207+
isBubbleHidden ? "Show message" : "Hide message"
208+
}
209+
onClick={(e) => {
210+
e.stopPropagation();
211+
setIsBubbleHidden((v) => !v);
212+
}}
213+
>
214+
×
215+
</button>
194216
<strong style={{ fontSize: 15 }}>
195217
{dogBubbles[selectedPanel].title}
196218
</strong>

src/sections/About/AboutSection.module.css

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@
116116
text-align: center;
117117
font-size: 0.875rem;
118118
line-height: 1.2;
119+
120+
/* make children absolute (i.e., close button) */
121+
position: absolute;
119122
}
120123

121124
.bubble p {
@@ -142,6 +145,49 @@
142145
left: 80%;
143146
}
144147

148+
/* close button */
149+
.bubbleClose {
150+
position: absolute;
151+
top: 6px;
152+
right: 6px;
153+
width: 28px;
154+
height: 28px;
155+
border: 1px solid #111827;
156+
border-radius: 6px;
157+
background: #fff;
158+
color: #111827;
159+
font-size: 20px;
160+
line-height: 24px;
161+
padding: 0;
162+
display: none;
163+
align-items: center;
164+
justify-content: center;
165+
cursor: pointer;
166+
}
167+
168+
.bubbleClose:active {
169+
transform: scale(0.96);
170+
}
171+
172+
/* show the X on mobile/tablet only */
173+
@media (max-width: 768px) {
174+
.bubbleClose {
175+
display: inline-flex;
176+
position: absolute;
177+
top: -12px;
178+
right: -12px;
179+
width: 28px;
180+
height: 28px;
181+
border-radius: 999px;
182+
border: 2px solid #111827;
183+
background: #fff;
184+
color: #111827;
185+
font-size: 18px;
186+
line-height: 1;
187+
box-shadow: 0 2px 6px rgba(0,0,0,0.15);
188+
}
189+
}
190+
145191
.panels {
146192
display: flex;
147193
gap: 2rem;

0 commit comments

Comments
 (0)