2021-04-10 19:45:11 +02:00
|
|
|
<template>
|
2023-05-08 15:11:16 +02:00
|
|
|
<label
|
|
|
|
class="flex relative field-switch cursor-pointer"
|
|
|
|
:for="id"
|
|
|
|
:class="{
|
|
|
|
'items-center flex-row-reverse space-x-3 space-x-reverse justify-end': inline,
|
|
|
|
'flex-col': !inline,
|
|
|
|
[sizes[size].wrap]: true,
|
|
|
|
}"
|
|
|
|
>
|
2022-05-20 01:18:11 +02:00
|
|
|
<span
|
|
|
|
v-if="label"
|
|
|
|
class="font-semibold leading-none text-gray-400"
|
|
|
|
:class="{
|
|
|
|
'text-xs': size == 'sm',
|
2022-12-02 00:42:06 +01:00
|
|
|
'text-sm': size === 'base',
|
2022-05-20 01:18:11 +02:00
|
|
|
}"
|
|
|
|
>{{ label }}</span
|
|
|
|
>
|
2023-05-08 15:11:16 +02:00
|
|
|
<div class="relative flex items-center inner-field mt-1" :class="`h-field-${fieldSize}`">
|
|
|
|
<span>
|
|
|
|
<input :id="id" type="checkbox" :name="name" :value="value" v-model="v" :disabled="disabled" class="absolute peer" @keypress="$emit('keypress', $event)" />
|
|
|
|
<span class="relative cursor-pointer peer-focus:bg-red-500 flex grow display" :class="{'bg-switch': v === true, 'bg-gray-700': v === false}">
|
2023-07-06 13:56:19 +02:00
|
|
|
<span><ui-sprite class="relative text-gray-400 flex-none" :class="{'w-2 h-2': size === 'sm' || size == 'xs', 'w-4 h-4': size === 'base'}" src="check"></ui-sprite></span>
|
|
|
|
<span><ui-sprite class="relative text-gray-400 flex-none" :class="{'w-2 h-2': size === 'sm' || size == 'xs', 'w-4 h-4': size === 'base'}" src="close"></ui-sprite></span>
|
2023-05-08 15:11:16 +02:00
|
|
|
<var class="absolute overlay bg-gray-400 rounded top-0"></var>
|
|
|
|
</span>
|
2021-04-10 19:45:11 +02:00
|
|
|
</span>
|
2023-05-08 15:11:16 +02:00
|
|
|
<div v-if="hint" class="ml-2 info-wrap">
|
|
|
|
<div v-tooltip="hint">
|
2023-07-06 13:56:19 +02:00
|
|
|
<ui-sprite src="info-button" class="info-button w-4 h-4 text-primary-700"></ui-sprite>
|
2023-05-08 15:11:16 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-04-10 19:45:11 +02:00
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
2023-07-06 13:56:19 +02:00
|
|
|
emits: ['update:modelValue'],
|
2022-12-02 00:42:06 +01:00
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
sizes: {
|
|
|
|
sm: {
|
|
|
|
wrap: 'field-wrap-sm',
|
|
|
|
field: 'size-sm',
|
|
|
|
},
|
|
|
|
base: {
|
|
|
|
wrap: 'field-wrap-base',
|
|
|
|
field: 'size-base',
|
|
|
|
},
|
|
|
|
lg: {
|
|
|
|
wrap: 'field-wrap-lg',
|
|
|
|
field: 'size-lg',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
props: {
|
2023-05-08 15:11:16 +02:00
|
|
|
hint: {
|
|
|
|
default: null,
|
|
|
|
},
|
2023-02-25 17:19:17 +01:00
|
|
|
inline: {
|
2022-05-20 01:18:11 +02:00
|
|
|
default: false,
|
2023-02-25 17:19:17 +01:00
|
|
|
type: Boolean,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
size: {
|
2022-12-02 00:42:06 +01:00
|
|
|
default: 'base',
|
2022-05-20 01:18:11 +02:00
|
|
|
required: false,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
id: {
|
2022-05-20 01:18:11 +02:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
default: '',
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
2022-05-20 01:18:11 +02:00
|
|
|
default: false,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
value: {
|
2022-05-20 01:18:11 +02:00
|
|
|
default: false,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
label: {
|
2022-05-20 01:18:11 +02:00
|
|
|
default: false,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
2023-07-06 13:56:19 +02:00
|
|
|
modelValue: {
|
2022-05-20 01:18:11 +02:00
|
|
|
default: undefined,
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
v: {
|
|
|
|
set(v) {
|
|
|
|
if (this.disabled === true) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-06 13:56:19 +02:00
|
|
|
if (typeof this.modelValue === 'boolean') {
|
|
|
|
this.$emit('update:modelValue', v);
|
2021-04-10 19:45:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-06 13:56:19 +02:00
|
|
|
var a = this.modelValue.filter((i) => i !== this.value);
|
2021-04-10 19:45:11 +02:00
|
|
|
if (v) {
|
|
|
|
a.push(this.value);
|
|
|
|
}
|
|
|
|
|
2023-07-06 13:56:19 +02:00
|
|
|
this.$emit('update:modelValue', a);
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
get() {
|
2023-07-06 13:56:19 +02:00
|
|
|
if (typeof this.modelValue === 'boolean') {
|
|
|
|
return this.modelValue;
|
2021-04-10 19:45:11 +02:00
|
|
|
}
|
|
|
|
|
2023-07-06 13:56:19 +02:00
|
|
|
if (typeof this.modelValue === 'undefined') {
|
|
|
|
return this.$emit('update:modelValue', false);
|
2021-04-10 19:45:11 +02:00
|
|
|
}
|
|
|
|
|
2023-07-06 13:56:19 +02:00
|
|
|
return this.modelValue.indexOf(this.value) !== -1;
|
2022-05-20 01:18:11 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
fieldSize() {
|
|
|
|
var sizes = ['xxs', 'xs', 'sm', 'md', 'lg'];
|
|
|
|
|
2022-05-20 01:18:11 +02:00
|
|
|
var sizeIndex = sizes.findIndex((s) => s === this.size);
|
2023-02-25 17:19:17 +01:00
|
|
|
return sizes[sizeIndex - 1];
|
2022-05-20 01:18:11 +02:00
|
|
|
},
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
};
|
|
|
|
</script>
|