11<script setup lang="ts">
22import TooltipApp from ' ~/components/Tooltip/App.vue'
33
4- withDefaults (
4+ const props = withDefaults (
55 defineProps <{
66 label? : string
77 description? : string
@@ -11,9 +11,11 @@ withDefaults(
1111 tooltipPosition? : ' top' | ' bottom' | ' left' | ' right'
1212 tooltipTo? : string
1313 tooltipOffset? : number
14+ reverseOrder? : boolean
1415 }>(),
1516 {
1617 justify: ' between' ,
18+ reverseOrder: false ,
1719 },
1820)
1921
@@ -31,40 +33,72 @@ const checked = defineModel<boolean>({
3133 :aria-checked =" checked"
3234 @click =" checked = !checked"
3335 >
34- <TooltipApp
35- v-if =" tooltip && label"
36- :text =" tooltip"
37- :position =" tooltipPosition ?? 'top'"
38- :to =" tooltipTo"
39- :offset =" tooltipOffset"
40- >
41- <span class =" text-sm text-fg font-medium text-start" >
36+ <template v-if =" props .reverseOrder " >
37+ <span
38+ class =" inline-flex items-center h-6 w-11 shrink-0 rounded-full border p-0.25 transition-colors duration-200 shadow-sm ease-in-out motion-reduce:transition-none group-focus-visible:(outline-accent/70 outline-offset-2 outline-solid)"
39+ :class ="
40+ checked
41+ ? 'bg-accent border-accent group-hover:bg-accent/80'
42+ : 'bg-fg/50 border-fg/50 group-hover:bg-fg/70'
43+ "
44+ aria-hidden =" true"
45+ >
46+ <span
47+ class =" block h-5 w-5 rounded-full bg-bg shadow-sm transition-transform duration-200 ease-in-out motion-reduce:transition-none"
48+ />
49+ </span >
50+ <TooltipApp
51+ v-if =" tooltip && label"
52+ :text =" tooltip"
53+ :position =" tooltipPosition ?? 'top'"
54+ :to =" tooltipTo"
55+ :offset =" tooltipOffset"
56+ >
57+ <span class =" text-sm text-fg font-medium text-start" >
58+ {{ label }}
59+ </span >
60+ </TooltipApp >
61+ <span v-else-if =" label" class =" text-sm text-fg font-medium text-start" >
62+ {{ label }}
63+ </span >
64+ </template >
65+ <template v-else >
66+ <TooltipApp
67+ v-if =" tooltip && label"
68+ :text =" tooltip"
69+ :position =" tooltipPosition ?? 'top'"
70+ :to =" tooltipTo"
71+ :offset =" tooltipOffset"
72+ >
73+ <span class =" text-sm text-fg font-medium text-start" >
74+ {{ label }}
75+ </span >
76+ </TooltipApp >
77+ <span v-else-if =" label" class =" text-sm text-fg font-medium text-start" >
4278 {{ label }}
4379 </span >
44- </TooltipApp >
45- <span v-else-if =" label" class =" text-sm text-fg font-medium text-start" >
46- {{ label }}
47- </span >
48- <span
49- class =" inline-flex items-center h-6 w-11 shrink-0 rounded-full border p-0.25 transition-colors duration-200 shadow-sm ease-in-out motion-reduce:transition-none group-focus-visible:(outline-accent/70 outline-offset-2 outline-solid)"
50- :class ="
51- checked
52- ? 'bg-accent border-accent group-hover:bg-accent/80'
53- : 'bg-fg/50 border-fg/50 group-hover:bg-fg/70'
54- "
55- aria-hidden =" true"
56- >
5780 <span
58- class =" block h-5 w-5 rounded-full bg-bg shadow-sm transition-transform duration-200 ease-in-out motion-reduce:transition-none"
59- />
60- </span >
81+ class =" inline-flex items-center h-6 w-11 shrink-0 rounded-full border p-0.25 transition-colors duration-200 shadow-sm ease-in-out motion-reduce:transition-none group-focus-visible:(outline-accent/70 outline-offset-2 outline-solid)"
82+ :class ="
83+ checked
84+ ? 'bg-accent border-accent group-hover:bg-accent/80'
85+ : 'bg-fg/50 border-fg/50 group-hover:bg-fg/70'
86+ "
87+ aria-hidden =" true"
88+ >
89+ <span
90+ class =" block h-5 w-5 rounded-full bg-bg shadow-sm transition-transform duration-200 ease-in-out motion-reduce:transition-none"
91+ />
92+ </span >
93+ </template >
6194 </button >
6295 <p v-if =" description" class =" text-sm text-fg-muted mt-2" >
6396 {{ description }}
6497 </p >
6598</template >
6699
67100<style scoped>
101+ /* Default order: label first, toggle last */
68102button [aria-checked = ' false' ] > span :last-of-type > span {
69103 translate : 0 ;
70104}
@@ -75,14 +109,27 @@ html[dir='rtl'] button[aria-checked='true'] > span:last-of-type > span {
75109 translate : calc (-100% );
76110}
77111
112+ /* Reverse order: toggle first, label last */
113+ button [aria-checked = ' false' ] > span :first-of-type > span {
114+ translate : 0 ;
115+ }
116+ button [aria-checked = ' true' ] > span :first-of-type > span {
117+ translate : calc (100% );
118+ }
119+ html [dir = ' rtl' ] button [aria-checked = ' true' ] > span :first-of-type > span {
120+ translate : calc (-100% );
121+ }
122+
78123@media (forced-colors: active) {
79124 /* make toggle tracks and thumb visible in forced colors. */
80125 button [role = ' switch' ] {
81- & > span :last-of-type {
126+ & > span :last-of-type,
127+ & > span:first-of-type {
82128 forced-color-adjust: none ;
83129 }
84130
85- &[aria-checked = ' false' ] > span :last-of-type {
131+ &[aria-checked = ' false' ] > span :last-of-type ,
132+ &[aria-checked = ' false' ] > span :first-of-type {
86133 background : Canvas;
87134 border-color : CanvasText;
88135
@@ -91,7 +138,8 @@ html[dir='rtl'] button[aria-checked='true'] > span:last-of-type > span {
91138 }
92139 }
93140
94- &[aria-checked = ' true' ] > span :last-of-type {
141+ &[aria-checked = ' true' ] > span :last-of-type ,
142+ &[aria-checked = ' true' ] > span :first-of-type {
95143 background : Highlight ;
96144 border-color : Highlight ;
97145
0 commit comments