aboutsummaryrefslogtreecommitdiff
path: root/apps/website/src/components/base/Slider.astro
blob: c1b32d10d16afeb3b30b41ef84d9f45825803be7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
---
import type { HTMLAttributes } from 'astro/types';

interface Props extends HTMLAttributes<'div'> {
	dir?: string;
	wrapperClass?: string;
}

const {
	dir = "left",
	wrapperClass = ""
} = Astro.props;
---

<div class={
	`w-full bg-blue-100 flex flex-row gap-2.5 overflow-hidden slider
	${dir === "right" ? "reverse" : ""}
	${wrapperClass}`}>
	<slot />
</div>

<!-- might be cheating a bit using global styles here but at least it lets you use slots -->
<style is:global lang="scss">
	$sliderNum: 7; /* TODO: figure out a way to make this either automatic or settable via component var */
	@for $i from 1 through $sliderNum {
		.slider > *:nth-child(#{$i}) {
			animation: #{"slide" + $i} 10s linear infinite;
		}
		@keyframes #{"slide" + $i} {
			0% {
				transform: translateX(0);
			}
			#{calc(99.999% / $sliderNum * $i)} {
				transform: translateX(calc((-100% - 10px) * $i));
			}
			#{calc(99.999% / $sliderNum * $i + 0.001%)} {
				transform: translateX(calc((100% + 10px) * ($sliderNum - $i)));
			}
			100% {
				transform: translateX(0);
			}
		}
	}
	.slider.reverse > * {
		animation-direction: reverse;
	}
</style>