Skip to content

Commit cd35aaf

Browse files
committed
fix: toggle horizontal movement isnt relative to size
1 parent 2a73807 commit cd35aaf

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

resources/js/components/inputs/ToggleBase.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,35 @@ export interface ToggleProps {
66
title?: string;
77
knobStyle?: string;
88
class?: string;
9+
knobHorizontalMargin?: number;
910
}
1011
1112
const model = defineModel<boolean>();
12-
const props = withDefaults(defineProps<ToggleProps>(), { name: 'toggle' });
13+
const props = withDefaults(defineProps<ToggleProps>(), { name: 'toggle', knobHorizontalMargin: 1 });
1314
</script>
1415

1516
<template>
1617
<label
1718
:class="
1819
cn(
19-
'group hover:bg-primary-dark-600 hover:has-[input:checked]:bg-primary-800 relative inline-flex h-8 w-16 cursor-pointer items-center rounded-lg border-2 border-zinc-800 bg-zinc-800 transition-colors duration-300 has-checked:bg-white',
20+
'group hover:bg-primary-dark-600 hover:has-[input:checked]:bg-primary-800 @container relative inline-flex h-8 w-16 cursor-pointer items-center rounded-lg border-2 border-zinc-800 bg-zinc-800 transition-colors duration-300 has-checked:bg-white',
2021
props.class,
2122
)
2223
"
2324
:title="title ?? name"
2425
:for="name"
26+
:style="{
27+
'--knob-margin': knobHorizontalMargin,
28+
}"
2529
>
26-
<input type="checkbox" :id="name" :name="name" v-model="model" class="peer sr-only" />
30+
<input type="checkbox" :id="name" :name="name" v-model="model" class="peer sr-only absolute" />
2731

2832
<span
2933
:class="
3034
cn(
31-
'group-hover:bg-primary-dark-600 absolute top-1/4 left-1/8 aspect-square h-1/2 rounded-full bg-zinc-800 shadow-[inset_16px_0_0_0_#fff]',
35+
'group-hover:bg-primary-dark-600 absolute top-1/4 left-[calc(var(--spacing)*var(--knob-margin))] aspect-square h-1/2 rounded-full bg-zinc-800 shadow-[inset_16px_0_0_0_#fff]',
3236
'transition-all duration-300',
33-
'peer-checked:translate-x-8 peer-checked:overflow-hidden peer-checked:shadow-none',
37+
'peer-checked:translate-x-[calc(100cqw-100%-var(--spacing)*var(--knob-margin)*2)] peer-checked:overflow-hidden peer-checked:shadow-none',
3438
knobStyle,
3539
)
3640
"

0 commit comments

Comments
 (0)