Skip to content

Commit a6a084f

Browse files
committed
fix: support rtl
1 parent 439a09e commit a6a084f

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

app/components/Settings/Toggle.client.vue

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,24 @@ const checked = defineModel<boolean>({
99
required: true,
1010
})
1111
const id = 'toggle-' + props.label
12+
const { locale, locales } = useI18n()
13+
const dir = computed(() => {
14+
const localeObj = locales.value.find(item => item.code === locale.value)
15+
return localeObj?.dir ?? 'ltr'
16+
})
1217
</script>
1318

1419
<template>
1520
<label :for="id">
1621
<span class="toggle--label-text">{{ label }}</span>
17-
<input role="switch" type="checkbox" :id class="toggle--checkbox" v-model="checked" />
22+
<input
23+
role="switch"
24+
type="checkbox"
25+
:id
26+
class="toggle--checkbox"
27+
:class="dir"
28+
v-model="checked"
29+
/>
1830
<span class="toggle--background"></span>
1931
</label>
2032
<p v-if="description" class="text-sm text-fg-muted mt-2">
@@ -72,23 +84,29 @@ label:has(input:hover) .toggle--background {
7284
position: relative;
7385
}
7486
87+
.toggle--checkbox:checked.ltr + .toggle--background:before {
88+
transform: translate(21px);
89+
left: 2px;
90+
}
91+
92+
.toggle--checkbox:checked.rtl + .toggle--background:before {
93+
transform: translate(-21px);
94+
right: 2px;
95+
}
96+
7597
/* Circle that moves */
7698
.toggle--checkbox:checked + .toggle--background:before {
77-
animation-name: switch;
7899
animation-fill-mode: forwards;
79-
transform: translate(21px);
80100
transition: transform 200ms ease-in-out;
81101
background: #f9fafb;
82102
}
83103
84104
.toggle--background:before {
85-
animation-name: reverse;
86105
animation-fill-mode: forwards;
87106
transition: transform 200ms ease-in-out;
88107
content: '';
89108
width: 20px;
90109
height: 20px;
91-
left: 2px;
92110
top: 2px;
93111
position: absolute;
94112
border-radius: 9999px;

0 commit comments

Comments
 (0)