Skip to content

Commit 8f6d4fe

Browse files
authored
Merge pull request #97 from rmbarley/80-hero-fixes
[80] Fixes for Hero component
2 parents 536780a + d2ae4b1 commit 8f6d4fe

File tree

3 files changed

+87
-65
lines changed

3 files changed

+87
-65
lines changed

src/components/HeroSection.jsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
import { LinkButton, Slider } from "./ui";
2+
import { useSliderAutoplay } from "../hooks/useSliderAutoplay";
23

34
import { heroJoin, heroCorex, heroUnlock, heroSales } from "../assets/hero";
45

56
const slides = [
6-
{
7-
image: heroJoin,
8-
buttonLabel: "Join Us",
9-
href: "/about-corex",
10-
alt: "Join the CoreX community - Premium supplements for serious athletes"
11-
},
127
{
138
image: heroCorex,
149
buttonLabel: "Shop Now",
1510
href: "/products",
1611
alt: "CoreX Nutrition - Science-backed supplements for peak performance"
1712
},
1813
{
19-
image: heroUnlock,
14+
image: heroSales,
2015
buttonLabel: "Shop Now",
2116
href: "/products",
22-
alt: "Unlock your potential with CoreX performance supplements"
17+
alt: "Special offer - CoreX supplements on 40% off sale now"
2318
},
2419
{
25-
image: heroSales,
20+
image: heroUnlock,
2621
buttonLabel: "Shop Now",
2722
href: "/products",
28-
alt: "Special offer - CoreX supplements on 40% off sale now"
29-
}
23+
alt: "Unlock your potential with CoreX performance supplements"
24+
},
25+
{
26+
image: heroJoin,
27+
buttonLabel: "Join Us",
28+
href: "/about-corex",
29+
alt: "Join the CoreX community - Premium supplements for serious athletes"
30+
},
3031
];
3132

3233
function HeroSection() {
34+
const sliderRef = useSliderAutoplay(8000);
35+
3336
return (
3437
<section className="hero-section" aria-label="Hero carousel" id="hero-section">
3538
<Slider
39+
ref={sliderRef}
3640
className="hero-slider"
37-
autoplay
38-
autoplaySpeed={4000}
41+
autoplay={false}
3942
speed={1000}
4043
fade
4144
dots
Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,101 @@
1-
2-
.slick-dots li button {
3-
position: relative;
4-
border-radius: 50%;
5-
}
6-
7-
.slick-dots li button:focus,
81
.slick-dots li button:focus-visible {
92
outline: none;
103
box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3), 0 0 0 4px rgba(255, 255, 255, 0.8);
114
}
125

6+
.slick-dots li {
7+
margin: 0 !important;
8+
}
9+
1310
.hero-slider {
1411
--dot-size: 1rem;
15-
--dot-active-inner-size: 0.75rem;
16-
--header-height: 4rem;
12+
--dot-gap: 0.75rem;
13+
--animation-duration: 12s;
14+
--dot-color: white;
15+
--dot-bottom-min: 1rem;
16+
--dot-bottom-max: 4.5rem;
1717

1818
height: auto;
19-
max-height: calc(100vh - var(--header-height));
19+
max-height: calc(100vh - 4rem);
20+
container-type: inline-size;
2021
}
2122

22-
/* Height constraints for slider internals */
2323
.hero-slider .slick-list,
24-
.hero-slider .slick-track {
25-
height: auto;
26-
max-height: calc(100vh - var(--header-height));
27-
}
28-
24+
.hero-slider .slick-track,
2925
.hero-slider .slick-slide,
3026
.hero-slider .slick-slide > div,
3127
.hero-slider .slick-slide > div > div {
32-
width: 100%;
3328
height: auto;
34-
max-height: calc(100vh - var(--header-height));
29+
max-height: calc(100vh - 4rem);
3530
}
3631

3732
.hero-slider .slick-dots {
3833
position: absolute;
39-
bottom: 1.5rem;
34+
inset-block-end: clamp(var(--dot-bottom-min), 5vw, var(--dot-bottom-max));
4035
z-index: 1;
36+
display: flex !important;
37+
gap: var(--dot-gap);
38+
justify-content: center;
39+
width: 100%;
4140
}
4241

43-
@media (min-width: 640px) {
44-
.hero-slider .slick-dots {
45-
bottom: 0.5rem;
46-
}
42+
.hero-slider .slick-dots li {
43+
width: var(--dot-size);
44+
height: var(--dot-size);
45+
aspect-ratio: 1;
46+
border-radius: 50%;
4747
}
4848

4949
.hero-slider .slick-dots li button {
50-
width: var(--dot-size);
51-
height: var(--dot-size);
50+
position: relative;
51+
width: 100%;
52+
height: 100%;
53+
border: none;
54+
background: none;
55+
cursor: pointer;
5256
}
5357

5458
.hero-slider .slick-dots li button:before {
5559
content: '';
5660
position: absolute;
57-
top: 50%;
58-
left: 50%;
59-
transform: translate(-50%, -50%);
60-
width: var(--dot-size);
61-
height: var(--dot-size);
61+
inset-block-start: 0;
62+
inset-inline-start: 0;
63+
width: 100%;
64+
height: 100%;
6265
border-radius: 50%;
63-
background-color: white;
66+
background-color: var(--dot-color);
6467
opacity: 1;
68+
transition: all 0.2s ease;
6569
}
6670

6771
.hero-slider .slick-dots li.slick-active button:before {
68-
background-color: transparent !important;
69-
border: 2px solid white;
70-
overflow: hidden;
72+
background-color: transparent;
73+
border: 1px solid white;
7174
}
7275

7376
.hero-slider .slick-dots li.slick-active button:after {
7477
content: '';
7578
position: absolute;
76-
top: 50%;
77-
left: 50%;
78-
transform: translate(-50%, -50%);
79+
inset-block-start: 0;
80+
inset-inline-start: 0;
81+
width: 100%;
82+
height: 100%;
7983
border-radius: 50%;
80-
background-color: white;
81-
animation: dotGrow 5s ease-out forwards;
82-
will-change: width, height;
84+
background-color: var(--dot-color);
85+
transform: scale(0);
86+
animation: simpleGrow var(--animation-duration) cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
8387
}
8488

85-
@keyframes dotGrow {
86-
0% {
87-
width: 0;
88-
height: 0;
89-
opacity: 0.8;
90-
}
91-
5% {
92-
opacity: 1;
89+
.hero-slider .slick-dots li button:hover:before {
90+
transform: scale(1.2);
91+
box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
92+
}
93+
94+
@keyframes simpleGrow {
95+
0% {
96+
transform: scale(0);
9397
}
94-
100% {
95-
width: var(--dot-active-inner-size);
96-
height: var(--dot-active-inner-size);
97-
opacity: 1;
98+
100% {
99+
transform: scale(1);
98100
}
99101
}

src/hooks/useSliderAutoplay.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useEffect, useRef } from 'react';
2+
3+
export function useSliderAutoplay(interval = 8000) {
4+
const sliderRef = useRef(null);
5+
6+
useEffect(() => {
7+
const timer = setInterval(() => {
8+
if (sliderRef.current) {
9+
sliderRef.current.slickNext();
10+
}
11+
}, interval);
12+
13+
return () => clearInterval(timer);
14+
}, [interval]);
15+
16+
return sliderRef;
17+
}

0 commit comments

Comments
 (0)