schon/storefront/app/components/ui/checkbox.vue
2026-02-27 21:59:51 +03:00

92 lines
No EOL
1.6 KiB
Vue

<template>
<label class="checkbox" :class="{ isAccent }">
<input
:id="id"
class="checkbox__input"
type="checkbox"
:checked="modelValue"
@change="onChange"
/>
<span class="checkbox__block"></span>
<span class="checkbox__label">
<slot/>
</span>
</label>
</template>
<script setup lang="ts">
const props = defineProps<{
id?: string;
modelValue: boolean;
isAccent?: boolean;
}>();
const emit = defineEmits<{
(e: 'update:modelValue', v: boolean): void;
}>();
function onChange(e: Event) {
const checked = (e.target as HTMLInputElement).checked;
emit('update:modelValue', checked);
}
</script>
<style lang="scss" scoped>
.checkbox {
display: flex;
align-items: center;
gap: 5px;
cursor: pointer;
&.isAccent {
& .checkbox__block {
border: 2px solid $accentDark;
border-radius: $default_border_radius;
}
& .checkbox__label {
color: $accentDark;
font-weight: 600;
}
}
&__input {
display: none;
opacity: 0;
}
&__block {
cursor: pointer;
display: inline-block;
width: 16px;
height: 16px;
border: 0.5px solid $black;
border-radius: 1px;
position: relative;
&::after {
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 10px;
height: 10px;
background-color: $black;
border-radius: 2px;
opacity: 0;
}
}
&__label {
cursor: pointer;
color: #374151;
font-size: 14px;
font-weight: 400;
letter-spacing: -0.5px;
}
}
.checkbox__input:checked + .checkbox__block::after {
opacity: 1;
}
</style>