frontend/src/components/input/fancycheckbox.vue

100 lines
1.8 KiB
Vue
Raw Normal View History

<template>
2023-03-07 16:59:12 +00:00
<BaseCheckbox
class="fancycheckbox"
:class="{
'is-disabled': disabled,
'is-block': isBlock,
}"
:disabled="disabled"
:model-value="modelValue"
@update:model-value="value => emit('update:modelValue', value)"
>
<CheckboxIcon class="fancycheckbox__icon" />
2023-03-29 11:31:20 +00:00
<span v-if="$slots.default" class="fancycheckbox__content">
2023-03-07 16:59:12 +00:00
<slot/>
</span>
</BaseCheckbox>
</template>
<script setup lang="ts">
2023-03-07 16:59:12 +00:00
import CheckboxIcon from '@/assets/checkbox.svg?component'
2022-02-15 12:07:59 +00:00
2023-03-07 16:59:12 +00:00
import BaseCheckbox from '@/components/base/BaseCheckbox.vue'
2023-03-07 16:59:12 +00:00
defineProps({
modelValue: {
type: Boolean,
},
disabled: {
type: Boolean,
2023-03-07 16:59:12 +00:00
},
isBlock: {
type: Boolean,
default: false,
},
2022-02-15 12:07:59 +00:00
})
2023-03-07 16:59:12 +00:00
const emit = defineEmits<{
(event: 'update:modelValue', value: boolean): void
}>()
</script>
<style lang="scss" scoped>
.fancycheckbox {
display: inline-block;
padding-right: 5px;
padding-top: 3px;
&.is-block {
2023-03-07 16:59:12 +00:00
display: block;
margin: .5rem .2rem;
}
}
2023-03-07 16:59:12 +00:00
.fancycheckbox__content {
font-size: 0.8rem;
vertical-align: top;
padding-left: .5rem;
}
2023-03-29 11:31:20 +00:00
.fancycheckbox__icon:deep() {
position: relative;
z-index: 1;
2023-03-29 11:31:20 +00:00
stroke: var(--stroke-color, #c8ccd4);
transform: translate3d(0, 0, 0);
transition: all 0.2s ease;
2023-03-29 11:31:20 +00:00
path,
polyline {
2023-03-07 16:59:12 +00:00
transition: all 0.2s linear, color 0.2s ease;
}
}
2023-03-29 11:31:20 +00:00
.fancycheckbox:not(:has(input:disabled)):hover .fancycheckbox__icon,
.fancycheckbox:has(input:checked) .fancycheckbox__icon {
2023-03-07 16:59:12 +00:00
--stroke-color: var(--primary);
}
2023-03-29 11:31:20 +00:00
</style>
2023-03-29 11:31:20 +00:00
<style lang="scss">
// Since css-has-pseudo doesn't work with deep classes,
// the following rules can't be scoped
.fancycheckbox:has(:not(input:checked)) .fancycheckbox__icon {
path {
transition-delay: 0.05s;
}
}
2023-03-29 11:31:20 +00:00
.fancycheckbox:has(input:checked) .fancycheckbox__icon {
path {
stroke-dashoffset: 60;
}
polyline {
stroke-dashoffset: 42;
transition-delay: 0.15s;
}
}
</style>