forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggle.server.vue
More file actions
134 lines (119 loc) · 2.64 KB
/
Toggle.server.vue
File metadata and controls
134 lines (119 loc) · 2.64 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<script setup lang="ts">
const props = withDefaults(
defineProps<{
label: string
description?: string
justify?: 'between' | 'start'
reverseOrder?: boolean
}>(),
{
justify: 'between',
reverseOrder: false,
},
)
</script>
<template>
<div
class="grid items-center gap-4 py-1 -my-1 grid-cols-[auto_1fr_auto]"
:class="[justify === 'start' ? 'justify-start' : '']"
:style="
props.reverseOrder
? 'grid-template-areas: \'toggle . label-text\''
: 'grid-template-areas: \'label-text . toggle\''
"
>
<template v-if="props.reverseOrder">
<SkeletonBlock class="h-6 w-11 shrink-0 rounded-full" style="grid-area: toggle" />
<span
v-if="label"
class="text-sm text-fg font-medium text-start"
style="grid-area: label-text"
>
{{ label }}
</span>
</template>
<template v-else>
<span
v-if="label"
class="text-sm text-fg font-medium text-start"
style="grid-area: label-text"
>
{{ label }}
</span>
<SkeletonBlock
class="h-6 w-11 shrink-0 rounded-full"
style="grid-area: toggle; justify-self: end"
/>
</template>
</div>
<p v-if="description" class="text-sm text-fg-muted mt-2">
{{ description }}
</p>
</template>
<style scoped>
/* Thumb position: logical property for RTL support */
.toggle::before {
inset-inline-start: 1px;
}
/* Track transition */
.toggle {
transition:
background-color 200ms ease-in-out,
border-color 100ms ease-in-out;
}
.toggle::before {
transition:
background-color 200ms ease-in-out,
translate 200ms ease-in-out;
}
/* Hover states */
.toggle:hover:not(:checked) {
background: var(--fg-muted);
}
.toggle:checked:hover {
background: var(--fg-muted);
border-color: var(--fg-muted);
}
/* RTL-aware checked thumb position */
:dir(ltr) .toggle:checked::before {
translate: 20px;
}
:dir(rtl) .toggle:checked::before {
translate: -20px;
}
@media (prefers-reduced-motion: reduce) {
.toggle,
.toggle::before {
transition: none;
}
}
/* Support forced colors */
@media (forced-colors: active) {
label > span {
background: Canvas;
color: Highlight;
forced-color-adjust: none;
}
label:has(.toggle:checked) > span {
background: Highlight;
color: Canvas;
}
.toggle::before {
forced-color-adjust: none;
background-color: Highlight;
}
.toggle,
.toggle:hover {
background: Canvas;
border-color: CanvasText;
}
.toggle:checked,
.toggle:checked:hover {
background: Highlight;
border-color: CanvasText;
}
.toggle:checked::before {
background: Canvas;
}
}
</style>