web/Toggle: accommodate for rtl layouts

This commit is contained in:
wukko 2024-11-20 15:33:09 +06:00
parent 6e81c55fc1
commit 94e5aad6c0
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -1,8 +1,8 @@
<script lang="ts">
export let enabled;
export let enabled: boolean;
</script>
<div class="toggle" class:enabled={enabled}>
<div class="toggle" class:enabled>
<div class="toggle-switcher"></div>
</div>
@ -10,6 +10,7 @@
.toggle {
--base-size: 22px;
--ratio-factor: 0.9;
--enabled-pos: calc(100% * var(--ratio-factor));
display: flex;
justify-content: start;
@ -23,6 +24,10 @@
transition: background 0.2s;
}
.toggle:dir(rtl) {
--enabled-pos: calc(-100% * var(--ratio-factor));
}
.toggle-switcher {
height: var(--base-size);
width: var(--base-size);
@ -37,6 +42,7 @@
}
.toggle.enabled .toggle-switcher {
transform: translateX(calc(100% * var(--ratio-factor)));
transform: translateX(var(--enabled-pos));
}
}
</style>