Skip to content

Commit 76e59dc

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 cf2c13a commit 76e59dc

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

src/components/HomepageCarousel.svelte

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,58 @@
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();
19-
</script>
18+
let { slides }: Props = $props();
2019
21-
<Carousel.Root opts={{
22-
loop: true,
23-
}} class="w-full h-fit">
20+
let currentSlide: number = $state(0); // TODO: make check for actual value here. Could break if not starting at 0
21+
22+
// Theres probably a less hacky way but my ts only started working after I had written all this so hey.
23+
// Type safety by "Trust me bro"
24+
//@ts-ignore
25+
let api: CarouselAPI = $state();
26+
27+
$effect(() => {
28+
if (api) {
29+
api.on("scroll", (el) => { // Yes this gets spammed as the slide slides, but `settle` from the embla docs doesnt seem to be working.
30+
currentSlide = el.slidesInView()[0] ?? 0 // default to 0 if no slides in view (something has gone horrible wrong)
31+
// console.log(currentSlide)
32+
});
33+
}
34+
});
35+
</script>
36+
<Carousel.Root
37+
opts={{
38+
loop: true,
39+
}}
40+
class="w-full h-fit"
41+
bind:api
42+
>
2443
<Carousel.Content class="bg-red-400">
2544
{#each slides as slide}
26-
<HomepageCarouselItem src={slide.image.path} alt={slide.image.alt} />
45+
<HomepageCarouselItem
46+
src={slide.image.path}
47+
alt={slide.image.alt ?? ""}
48+
/>
2749
{/each}
2850
</Carousel.Content>
2951
<div
30-
class="w-4/5 sm:w-72 bg-background absolute bottom-12 left-8 px-4 py-2"
52+
class="m-12 w-auto sm:w-72 bg-background absolute bottom-0 sm:bottom-4 px-8 py-6"
3153
>
32-
<h1 class="font-display text-lg">Title</h1>
33-
<div class="text-xs">body text</div>
34-
<Button class="h-6">Action</Button>
54+
<h1 class="font-display text-xl">{slides[currentSlide]?.title ?? "Error"}</h1>
55+
<div class="text-base font-sans">{slides[currentSlide]?.text ?? "It looks like something went wrong. Try refreshing"}</div>
56+
<Button class="h-8 mt-2 text-lg p-5 font-mono font-semibold" href={slides[currentSlide]?.actionTo ?? "/"}>{slides[currentSlide]?.actionLabel ?? ":("}</Button>
3557
</div>
36-
<Carousel.Previous class="top-auto -bottom-2 scale-75 left-10" />
58+
<Carousel.Previous class="top-auto -bottom-0 left-14 hidden sm:flex" />
3759
<Carousel.Next
38-
class="top-auto -bottom-2 scale-75 right-auto left-[4.5rem]"
60+
class="top-auto -bottom-0 right-auto left-[6.6rem] hidden sm:flex"
3961
/>
4062
</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)