2021-04-10 19:45:11 +02:00
|
|
|
<template>
|
2021-08-22 16:15:16 +02:00
|
|
|
<label class="field-wrap" :for="id" :class="`field-wrap-${size}`">
|
|
|
|
<span v-if="label" class="field-label">
|
|
|
|
{{ label }}
|
|
|
|
<span v-show="required" class="text-red-800"> *</span>
|
|
|
|
</span>
|
|
|
|
<div class="real-field-wrap" :class="`size-${size}`">
|
2023-07-06 13:56:19 +02:00
|
|
|
<select :disabled="disabled" :name="name" :value="modelValue" @change="trigger">
|
|
|
|
<option v-if="placeholder" value="">{{ placeholder }}</option>
|
2021-04-10 19:45:11 +02:00
|
|
|
|
2023-07-06 13:56:19 +02:00
|
|
|
<option v-for="option in parsedOptions" :key="option.id" :value="option.id">{{ option.name }}</option>
|
2021-08-22 16:15:16 +02:00
|
|
|
</select>
|
2021-08-22 16:49:38 +02:00
|
|
|
<div class="info-wrap">
|
2021-08-22 16:15:16 +02:00
|
|
|
<div v-if="hint" v-tooltip="hint">
|
2023-07-06 13:56:19 +02:00
|
|
|
<ui-sprite src="info-button" class="info-button"></ui-sprite>
|
2021-08-22 16:15:16 +02:00
|
|
|
</div>
|
2023-07-27 14:00:27 +02:00
|
|
|
<div v-if="size != 'xs'" class="px-1 relative">
|
|
|
|
<ui-sprite class="chevron w-3 h-3 fill-current" src="chevron"></ui-sprite>
|
2021-08-22 16:15:16 +02:00
|
|
|
</div>
|
2023-07-27 14:00:27 +02:00
|
|
|
<div v-if="size == 'xs'" class="px-1 relative">
|
|
|
|
<ui-sprite class="chevron w-2 h-2 fill-current" src="chevron"></ui-sprite>
|
2021-04-10 19:45:11 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-08-22 16:15:16 +02:00
|
|
|
import map from 'lodash/map';
|
|
|
|
|
2021-04-10 19:45:11 +02:00
|
|
|
export default {
|
|
|
|
props: {
|
2021-08-22 16:15:16 +02:00
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
2022-05-17 00:04:00 +02:00
|
|
|
default: function () {
|
|
|
|
return false;
|
|
|
|
},
|
2021-08-22 16:15:16 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
id: {},
|
|
|
|
inset: {
|
|
|
|
type: Boolean,
|
2022-05-17 00:04:00 +02:00
|
|
|
default: false,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
size: {
|
2022-05-17 00:04:00 +02:00
|
|
|
default: function () {
|
|
|
|
return 'base';
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
emptyLabel: {
|
|
|
|
default: false,
|
2022-05-17 00:04:00 +02:00
|
|
|
type: Boolean,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
2023-07-06 13:56:19 +02:00
|
|
|
modelValue: {
|
2022-05-17 00:04:00 +02:00
|
|
|
default: undefined,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
label: {
|
2022-05-17 00:04:00 +02:00
|
|
|
default: null,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
required: {
|
|
|
|
type: Boolean,
|
2022-05-17 00:04:00 +02:00
|
|
|
default: false,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
placeholder: {
|
|
|
|
default: '--kein--',
|
2022-05-17 00:04:00 +02:00
|
|
|
type: String,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
def: {
|
|
|
|
required: false,
|
|
|
|
type: Number,
|
2022-05-17 00:04:00 +02:00
|
|
|
default: -1,
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
2022-08-23 23:49:19 +02:00
|
|
|
name: {
|
|
|
|
required: true,
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
hint: {},
|
|
|
|
options: {
|
2022-05-17 00:04:00 +02:00
|
|
|
default: function () {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
2023-07-27 14:00:27 +02:00
|
|
|
emits: ['update:modelValue'],
|
2021-04-10 19:45:11 +02:00
|
|
|
computed: {
|
|
|
|
parsedOptions() {
|
2021-08-22 16:15:16 +02:00
|
|
|
return Array.isArray(this.options)
|
|
|
|
? this.options
|
|
|
|
: map(this.options, (value, key) => {
|
2023-12-25 19:34:30 +01:00
|
|
|
return {name: value, id: key};
|
|
|
|
});
|
2022-05-17 00:04:00 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
|
|
|
mounted() {
|
2023-07-06 13:56:19 +02:00
|
|
|
if (this.def !== -1 && typeof this.modelValue === 'undefined') {
|
|
|
|
this.$emit('update:modelValue', this.def);
|
2021-04-10 19:45:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-06 13:56:19 +02:00
|
|
|
if (this.placeholder && typeof this.modelValue === 'undefined') {
|
|
|
|
this.$emit('update:modelValue', null);
|
2021-04-10 19:45:11 +02:00
|
|
|
}
|
2022-05-17 00:04:00 +02:00
|
|
|
},
|
2023-07-27 14:00:27 +02:00
|
|
|
methods: {
|
|
|
|
trigger(v) {
|
|
|
|
this.$emit('update:modelValue', /^[0-9]+$/.test(v.target.value) ? parseInt(v.target.value) : v.target.value ? v.target.value : null);
|
|
|
|
},
|
|
|
|
clear() {
|
|
|
|
this.$emit('update:modelValue', null);
|
|
|
|
},
|
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scope>
|
|
|
|
.inset-bg {
|
2023-06-14 23:20:13 +02:00
|
|
|
background: linear-gradient(to bottom, hsl(247.5, 66.7%, 97.6%) 0%, hsl(247.5, 66.7%, 97.6%) 41%, hsl(0deg 0% 100%) 41%, hsl(180deg 0% 100%) 100%);
|
2021-04-10 19:45:11 +02:00
|
|
|
}
|
|
|
|
</style>
|