2020-04-01 22:13:57 +02:00
|
|
|
<template>
|
2020-09-05 22:35:52 +02:00
|
|
|
<div :class="{'is-disabled': disabled}" class="fancycheckbox">
|
2020-07-07 21:38:38 +02:00
|
|
|
<input
|
2020-09-05 22:35:52 +02:00
|
|
|
:checked="checked"
|
2021-10-17 18:52:05 +02:00
|
|
|
:disabled="disabled || null"
|
2020-09-05 22:35:52 +02:00
|
|
|
:id="checkBoxId"
|
2021-09-10 00:25:08 +02:00
|
|
|
@change="(event) => updateData(event.target.checked)"
|
2020-09-05 22:35:52 +02:00
|
|
|
type="checkbox"/>
|
2020-04-01 22:13:57 +02:00
|
|
|
<label :for="checkBoxId" class="check">
|
2020-09-05 22:35:52 +02:00
|
|
|
<svg height="18px" viewBox="0 0 18 18" width="18px">
|
|
|
|
<path
|
|
|
|
d="M1,9 L1,3.5 C1,2 2,1 3.5,1 L14.5,1 C16,1 17,2 17,3.5 L17,14.5 C17,16 16,17 14.5,17 L3.5,17 C2,17 1,16 1,14.5 L1,9 Z"></path>
|
2020-04-01 22:13:57 +02:00
|
|
|
<polyline points="1 9 7 14 15 4"></polyline>
|
|
|
|
</svg>
|
|
|
|
<span>
|
|
|
|
<slot></slot>
|
|
|
|
</span>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-10-04 14:20:29 +02:00
|
|
|
import {createRandomID} from '@/helpers/randomId'
|
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'fancycheckbox',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
checked: false,
|
2021-10-04 14:20:29 +02:00
|
|
|
checkBoxId: `fancycheckbox_${createRandomID()}`,
|
2020-09-05 22:35:52 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
props: {
|
2021-08-23 21:18:12 +02:00
|
|
|
modelValue: {
|
2020-09-05 22:35:52 +02:00
|
|
|
required: false,
|
2020-04-01 22:13:57 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
2020-04-01 22:13:57 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2021-08-23 21:18:12 +02:00
|
|
|
emits: ['update:modelValue', 'change'],
|
2020-09-05 22:35:52 +02:00
|
|
|
watch: {
|
2021-08-23 21:18:12 +02:00
|
|
|
modelValue: {
|
|
|
|
handler(modelValue) {
|
|
|
|
this.checked = modelValue
|
2021-09-08 11:59:38 +02:00
|
|
|
|
|
|
|
},
|
|
|
|
immediate: true,
|
2020-04-01 22:13:57 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
methods: {
|
2021-09-10 00:25:08 +02:00
|
|
|
updateData(checked) {
|
|
|
|
this.checked = checked
|
2021-08-23 21:18:12 +02:00
|
|
|
this.$emit('update:modelValue', checked)
|
2021-09-10 00:25:08 +02:00
|
|
|
this.$emit('change', checked)
|
2020-04-01 22:13:57 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
}
|
2020-04-01 22:13:57 +02:00
|
|
|
</script>
|
2021-10-18 14:19:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.fancycheckbox {
|
|
|
|
display: inline-block;
|
|
|
|
padding-right: 5px;
|
|
|
|
padding-top: 3px;
|
|
|
|
|
|
|
|
// FIXME: should be a prop
|
|
|
|
&.is-block {
|
|
|
|
margin: .5rem .2rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type=checkbox] {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.check {
|
|
|
|
cursor: pointer;
|
|
|
|
position: relative;
|
|
|
|
margin: auto;
|
|
|
|
width: 18px;
|
|
|
|
height: 18px;
|
|
|
|
-webkit-tap-highlight-color: transparent;
|
|
|
|
transform: translate3d(0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
span {
|
|
|
|
font-size: 0.8rem;
|
|
|
|
vertical-align: top;
|
|
|
|
padding-left: .5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
svg {
|
|
|
|
position: relative;
|
|
|
|
z-index: 1;
|
|
|
|
fill: none;
|
|
|
|
stroke-linecap: round;
|
|
|
|
stroke-linejoin: round;
|
|
|
|
stroke: #c8ccd4;
|
|
|
|
stroke-width: 1.5;
|
|
|
|
transform: translate3d(0, 0, 0);
|
|
|
|
transition: all 0.2s ease;
|
|
|
|
}
|
|
|
|
|
|
|
|
.check:hover svg {
|
|
|
|
stroke: $primary;
|
|
|
|
}
|
|
|
|
|
|
|
|
.is-disabled .check:hover svg {
|
|
|
|
stroke: #c8ccd4;
|
|
|
|
}
|
|
|
|
|
|
|
|
path {
|
|
|
|
stroke-dasharray: 60;
|
|
|
|
stroke-dashoffset: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
polyline {
|
|
|
|
stroke-dasharray: 22;
|
|
|
|
stroke-dashoffset: 66;
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type=checkbox]:checked + .check {
|
|
|
|
svg {
|
|
|
|
stroke: $primary;
|
|
|
|
}
|
|
|
|
|
|
|
|
path {
|
|
|
|
stroke-dashoffset: 60;
|
|
|
|
transition: all 0.3s linear;
|
|
|
|
}
|
|
|
|
|
|
|
|
polyline {
|
|
|
|
stroke-dashoffset: 42;
|
|
|
|
transition: all 0.2s linear;
|
|
|
|
transition-delay: 0.15s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|