@@ -4,25 +4,17 @@ const props = defineProps<{
44 description? : string
55 class? : string
66}>()
7-
7+ defineEmits ([ ' update:modelValue ' ])
88const checked = defineModel <boolean >({
9- default: false ,
9+ required: true ,
1010})
1111const id = ' toggle-' + props .label
1212 </script >
1313
1414<template >
1515 <label :for =" id" >
1616 <span class =" toggle--label-text" >{{ label }}</span >
17- <input
18- role =" switch"
19- type =" checkbox"
20- :id
21- class =" toggle--checkbox"
22- :aria-checked =" checked"
23- :checked =" checked"
24- @click =" checked = !checked"
25- />
17+ <input role =" switch" type =" checkbox" :id class =" toggle--checkbox" v-model =" checked" />
2618 <span class =" toggle--background" ></span >
2719 </label >
2820 <p v-if =" description" class =" text-sm text-fg-muted mt-2" >
@@ -31,34 +23,6 @@ const id = 'toggle-' + props.label
3123</template >
3224
3325<style scoped>
34- @keyframes reverse {
35- 0% {
36- left : 20px ;
37- width : 20px ;
38- }
39- 60% {
40- left : 3px ;
41- width : 40px ;
42- }
43- 100% {
44- left : 3px ;
45- }
46- }
47-
48- @keyframes switch {
49- 0% {
50- left : 3px ;
51- }
52- 60% {
53- left : 3px ;
54- width : 40px ;
55- }
56- 100% {
57- left : 20px ;
58- width : 20px ;
59- }
60- }
61-
6226.toggle--label-text {
6327 grid-area : label-text;
6428}
@@ -84,51 +48,50 @@ input {
8448}
8549
8650label :has (input :focus ) .toggle--background {
87- outline : solid 1 px #030712 ;
51+ outline : solid 2 px #030712 ;
8852 outline-offset : 2px ;
89- transition : outline 100ms ease-in ;
9053}
54+
55+ label :has (input :checked ) .toggle--background {
56+ background : #030712 ;
57+ border-color : #030712 ;
58+ }
59+
9160label :has (input :hover ) .toggle--background {
9261 background : #6b7280 ;
9362}
9463
9564/* background */
9665.toggle--background {
97- width : 44 px ;
98- height : 24 px ;
66+ width : 46 px ;
67+ height : 26 px ;
9968 background : #9ca3af ;
100- border-radius : 100 px ;
69+ border-radius : 9999 px ;
10170 border : 1px solid #030712 ;
10271 display : flex ;
10372 position : relative ;
104- transition : all 350ms ease-in ;
105- }
106-
107- label :has (input :checked ) .toggle--background {
108- background : #030712 ;
109- border-color : #030712 ;
11073}
11174
11275/* Circle that moves */
11376.toggle--checkbox :checked + .toggle--background :before {
114- animation-name : reverse ;
115- animation-duration : 350ms ;
77+ animation-name : switch;
11678 animation-fill-mode : forwards ;
117- transition : all 360ms ease-in ;
79+ transform : translate (21px );
80+ transition : transform 200ms ease-in-out ;
11881 background : #f9fafb ;
11982}
12083
12184.toggle--background :before {
122- animation-name : switch;
123- animation-duration : 350ms ;
85+ animation-name : reverse ;
12486 animation-fill-mode : forwards ;
87+ transition : transform 200ms ease-in-out ;
12588 content : ' ' ;
12689 width : 20px ;
12790 height : 20px ;
128- top : 1 px ;
129- left : 3 px ;
91+ left : 2 px ;
92+ top : 2 px ;
13093 position : absolute ;
131- border-radius : 20 px ;
94+ border-radius : 9999 px ;
13295 background : #f9fafb ;
13396}
13497 </style >
0 commit comments