Skip to content

Commit 7fa2846

Browse files
Carousel content auto-updates + realised I was zoomed in in my browser for literally 5 hours or smth so all my css was off but i fixed it ;-;
1 parent b49fe1c commit 7fa2846

File tree

3 files changed

+53
-15
lines changed

3 files changed

+53
-15
lines changed

src/components/HomepageCarousel.svelte

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,56 @@
55
import HomepageCarouselItem from "@/components/HomepageCarouselItem.svelte";
66
interface Props {
77
slides: {
8-
title: string;
98
image: {
10-
path:string;
11-
alt?:string;
9+
path: string;
10+
alt?: string;
1211
};
12+
title: string;
1313
text: string;
1414
actionLabel: string;
1515
actionTo: string;
1616
}[];
1717
}
18-
let {slides}: Props = $props();
18+
let { slides }: Props = $props();
19+
20+
let currentSlide: number = $state(0); // TODO: make check for actual value here. Could break if not starting at 0
21+
22+
let api: CarouselAPI = $state();
23+
24+
$effect(() => {
25+
if (api) {
26+
api.on("scroll", (e) => { // Yes this gets spammed as the slide slides, but `settle` from the embla docs doesnt seem to be working.
27+
currentSlide = e.slidesInView()[0]
28+
// console.log(currentSlide)
29+
});
30+
}
31+
});
1932
</script>
2033

21-
<Carousel.Root opts={{
22-
loop: true,
23-
}} class="w-full h-fit">
34+
<Carousel.Root
35+
opts={{
36+
loop: true,
37+
}}
38+
class="w-full h-fit"
39+
bind:api
40+
>
2441
<Carousel.Content class="bg-red-400">
2542
{#each slides as slide}
26-
<HomepageCarouselItem src={slide.image.path} alt={slide.image.alt} />
43+
<HomepageCarouselItem
44+
src={slide.image.path}
45+
alt={slide.image.alt}
46+
/>
2747
{/each}
2848
</Carousel.Content>
2949
<div
30-
class="w-4/5 sm:w-72 bg-background absolute bottom-12 left-8 px-4 py-2"
50+
class="m-12 w-auto sm:w-72 bg-background absolute bottom-0 sm:bottom-4 px-8 py-6"
3151
>
32-
<h1 class="font-display text-lg">Title</h1>
33-
<div class="text-xs">body text</div>
34-
<Button class="h-6">Action</Button>
52+
<h1 class="font-display text-xl">{slides[currentSlide].title}</h1>
53+
<div class="text-base font-sans">{slides[currentSlide].text}</div>
54+
<Button class="h-8 mt-2 text-lg p-5 font-mono font-semibold" href={slides[currentSlide].actionTo}>{slides[currentSlide].actionLabel}</Button>
3555
</div>
36-
<Carousel.Previous class="top-auto -bottom-2 scale-75 left-10" />
56+
<Carousel.Previous class="top-auto -bottom-0 left-14 hidden sm:flex" />
3757
<Carousel.Next
38-
class="top-auto -bottom-2 scale-75 right-auto left-[4.5rem]"
58+
class="top-auto -bottom-0 right-auto left-[6.6rem] hidden sm:flex"
3959
/>
4060
</Carousel.Root>

src/pages/index.astro

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ import HomepageCarousel from '@/components/HomepageCarousel.svelte';
1919
text:"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis erat in ante dignissim euismod id quis diam.",
2020
actionLabel:"Click",
2121
actionTo:"/"
22+
},
23+
{
24+
title:"2 Lorem Ipsum",
25+
image:{
26+
path:"/images/IMG_7294.JPG",
27+
},
28+
text:"2 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis erat in ante dignissim euismod id quis diam.",
29+
actionLabel:"Click 2",
30+
actionTo:"/"
31+
},
32+
{
33+
title:"3 Lorem Ipsum",
34+
image:{
35+
path:"/images/IMG_7311.JPG",
36+
},
37+
text:"3 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis erat in ante dignissim euismod id quis diam.",
38+
actionLabel:"Click 3",
39+
actionTo:"/"
2240
}
2341
]}/>
2442
</main>

tailwind.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const config = {
5757
fontFamily: {
5858
sans: [...fontFamily.sans],
5959
display:["Rubik Mono One", ...fontFamily.sans],
60-
60+
mono:["Overpass Mono","mono"]
6161
}
6262
}
6363
},

0 commit comments

Comments
 (0)