22const props = defineProps <{
33 label: string
44 description? : string
5- class? : string
65}>()
7- defineEmits ([' update:modelValue' ])
86const checked = defineModel <boolean >({
97 required: true ,
108})
@@ -13,26 +11,26 @@ const id = useId()
1311
1412<template >
1513 <label :for =" id" >
16- <span class =" toggle-- label-text" >{{ label }}</span >
17- <input role =" switch" type =" checkbox" :id class =" toggle-- checkbox" v-model =" checked" />
18- <span class =" toggle-- background" ></span >
14+ <span class =" label-text" >{{ label }}</span >
15+ <input role =" switch" type =" checkbox" :id class =" checkbox" v-model =" checked" />
16+ <span class =" background" ></span >
1917 </label >
2018 <p v-if =" description" class =" text-sm text-fg-muted mt-2" >
2119 {{ description }}
2220 </p >
2321</template >
2422
2523<style scoped>
26- .toggle-- label-text {
24+ .label-text {
2725 grid-area : label-text;
2826}
2927
30- .toggle-- background {
28+ .background {
3129 grid-area : toggle-background;
3230 justify-self : end ;
3331}
3432
35- .toggle-- checkbox {
33+ .checkbox {
3634 opacity : 0 ;
3735}
3836
@@ -48,7 +46,7 @@ input {
4846}
4947
5048/* background */
51- .toggle-- background {
49+ .background {
5250 width : 44px ;
5351 height : 24px ;
5452 background : var (--fg-subtle );
@@ -58,22 +56,22 @@ input {
5856 position : relative ;
5957}
6058
61- label :has (input :focus-visible ) .toggle-- background {
59+ label :has (input :focus-visible ) .background {
6260 outline : solid 2px var (--fg );
6361 outline-offset : 2px ;
6462}
6563
66- label :has (input :checked ) .toggle-- background {
64+ label :has (input :checked ) .background {
6765 background : var (--fg );
6866 border-color : var (--fg );
6967}
7068
71- label :has (input :hover ) .toggle-- background {
69+ label :has (input :hover ) .background {
7270 background : var (--fg-muted );
7371}
7472
7573/* Circle that moves */
76- .toggle-- background ::before {
74+ .background ::before {
7775 transition : transform 200ms ease-in-out ;
7876 content : ' ' ;
7977 width : 20px ;
@@ -86,11 +84,11 @@ label:has(input:hover) .toggle--background {
8684}
8785
8886/* Support rtl locales */
89- :dir (ltr ) .toggle-- checkbox :checked + .toggle-- background ::before {
87+ :dir (ltr ) .checkbox :checked + .background ::before {
9088 transform : translate (20px );
9189}
9290
93- :dir (rtl ) .toggle-- checkbox :checked + .toggle-- background ::before {
91+ :dir (rtl ) .checkbox :checked + .background ::before {
9492 transform : translate (-20px );
9593}
9694 </style >
0 commit comments