-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSlideToggle.vue
43 lines (36 loc) · 1.11 KB
/
SlideToggle.vue
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
<script setup lang="ts">
const isToggled = defineModel<boolean>("isToggled");
</script>
<template>
<div class="slide-toggle" @click="isToggled = !isToggled" :class="{ toggled: isToggled }">
<div class="thumb"></div>
</div>
</template>
<style scoped>
.slide-toggle {
--slide-toggle-height: 14px;
position: relative;
width: calc(var(--slide-toggle-height) * 2);
height: var(--slide-toggle-height);
border-radius: var(--slide-toggle-height);
background-color: hsl(from var(--color-background-branding) h s calc(l + 15));
transition: background-color var(--animation-duration) var(--animation-easing);
& .thumb {
--thumb-size: calc(var(--slide-toggle-height) - 2px);
position: absolute;
top: 1px;
left: 1px;
width: var(--thumb-size);
height: var(--thumb-size);
border-radius: var(--thumb-size);
background-color: white;
transition: left var(--animation-duration) var(--animation-easing);
}
&.toggled {
background-color: var(--color-background-branding);
& .thumb {
left: calc((var(--slide-toggle-height) * 2) - 1px - var(--thumb-size));
}
}
}
</style>