2021-04-10 19:45:11 +02:00
|
|
|
<template>
|
|
|
|
<label class="flex flex-col relative field-switch cursor-pointer" :for="id" :class="{[`size-${outerSize}`]: true}">
|
2021-04-11 20:35:18 +02:00
|
|
|
<span v-if="label" class="font-semibold leading-none text-gray-400" :class="{
|
2021-04-10 19:45:11 +02:00
|
|
|
'text-xs': size == 'sm',
|
|
|
|
'text-sm': size === null
|
|
|
|
}">{{ label }}</span>
|
2021-04-11 20:35:18 +02:00
|
|
|
<div class="relative inner-field mt-1" :class="`h-field-${fieldSize}`">
|
2021-04-10 19:45:11 +02:00
|
|
|
<input :id="id" type="checkbox" v-model="v" :disabled="disabled" class="invisible absolute" />
|
2022-02-10 02:18:57 +01:00
|
|
|
<span class="relative cursor-pointer flex grow display" :class="{'bg-switch': v === true, 'bg-gray-700': v === false}">
|
2021-04-11 20:35:18 +02:00
|
|
|
<span><sprite class="relative text-gray-400 flex-none" :class="{'w-2 h-2': size === 'sm' || size == 'xs', 'w-4 h-4': size === null}" src="check"></sprite></span>
|
|
|
|
<span><sprite class="relative text-gray-400 flex-none" :class="{'w-2 h-2': size === 'sm' || size == 'xs', 'w-4 h-4': size === null}" src="close"></sprite></span>
|
|
|
|
<var class="absolute overlay bg-gray-400 rounded top-0"></var>
|
2021-04-10 19:45:11 +02:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
model: {
|
|
|
|
prop: 'items',
|
|
|
|
event: 'input'
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
inset: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
size: {
|
|
|
|
default: null,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
id: {
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
label: {
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
items: {
|
|
|
|
default: undefined
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
v: {
|
|
|
|
set(v) {
|
|
|
|
if (this.disabled === true) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof this.items === 'boolean') {
|
|
|
|
this.$emit('input', v);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var a = this.items.filter(i => i !== this.value);
|
|
|
|
if (v) {
|
|
|
|
a.push(this.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('input', a);
|
|
|
|
},
|
|
|
|
get() {
|
|
|
|
if (typeof this.items === 'boolean') {
|
|
|
|
return this.items;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof this.items === 'undefined') {
|
|
|
|
return this.$emit('input', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.items.indexOf(this.value) !== -1;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fieldSize() {
|
|
|
|
var sizes = ['xxs', 'xs', 'sm', 'md', 'lg'];
|
|
|
|
|
|
|
|
var sizeIndex = sizes.findIndex(s => s === this.size);
|
|
|
|
return sizes[this.inset ? sizeIndex : sizeIndex - 1];
|
|
|
|
},
|
|
|
|
outerSize() {
|
|
|
|
var sizes = ['xxs', 'xs', 'sm', 'md', 'lg'];
|
|
|
|
|
|
|
|
var sizeIndex = sizes.findIndex(s => s === this.size);
|
|
|
|
if (!this.label || this.inset) { sizeIndex--; }
|
|
|
|
return sizes[sizeIndex];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|