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}`">
|
2024-04-26 23:20:03 +02:00
|
|
|
<select v-model="inner" :disabled="disabled" :name="name">
|
|
|
|
<option v-if="placeholder" :value="def">{{ 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>
|
|
|
|
|
2024-04-26 23:20:03 +02:00
|
|
|
<script setup>
|
|
|
|
import {computed, ref} from 'vue';
|
2021-08-22 16:15:16 +02:00
|
|
|
import map from 'lodash/map';
|
|
|
|
|
2024-04-26 23:20:03 +02:00
|
|
|
const emit = defineEmits(['update:modelValue']);
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
nullValue: {
|
|
|
|
required: false,
|
|
|
|
default: () => null,
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: function () {
|
|
|
|
return false;
|
2022-08-23 23:49:19 +02:00
|
|
|
},
|
2024-04-26 23:20:03 +02:00
|
|
|
},
|
|
|
|
id: {},
|
|
|
|
inset: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
size: {
|
|
|
|
default: function () {
|
|
|
|
return 'base';
|
2022-05-17 00:04:00 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
2024-04-26 23:20:03 +02:00
|
|
|
emptyLabel: {
|
|
|
|
default: false,
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
modelValue: {
|
|
|
|
default: undefined,
|
|
|
|
},
|
|
|
|
label: {
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
required: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
placeholder: {
|
|
|
|
default: '--kein--',
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
def: {
|
|
|
|
required: false,
|
|
|
|
type: Number,
|
|
|
|
default: -1,
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
hint: {},
|
|
|
|
options: {
|
|
|
|
default: function () {
|
|
|
|
return [];
|
2022-05-17 00:04:00 +02:00
|
|
|
},
|
2021-04-10 19:45:11 +02:00
|
|
|
},
|
2024-04-26 23:20:03 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const parsedOptions = computed(() => {
|
|
|
|
return Array.isArray(props.options)
|
|
|
|
? props.options
|
|
|
|
: map(props.options, (value, key) => {
|
|
|
|
return {name: value, id: key};
|
|
|
|
});
|
|
|
|
});
|
2021-04-10 19:45:11 +02:00
|
|
|
|
2024-04-26 23:20:03 +02:00
|
|
|
const def = ref('iu1Feixah5AeKai3ewooJahjeaegee0eiD4maeth1oul4Hei7u');
|
|
|
|
|
|
|
|
const inner = computed({
|
|
|
|
get: () => {
|
|
|
|
return props.modelValue === props.nullValue ? def.value : props.modelValue;
|
2022-05-17 00:04:00 +02:00
|
|
|
},
|
2024-04-26 23:20:03 +02:00
|
|
|
set: (v) => {
|
|
|
|
emit('update:modelValue', v === def.value ? props.nullValue : v);
|
2023-07-27 14:00:27 +02:00
|
|
|
},
|
2024-04-26 23:20:03 +02:00
|
|
|
});
|
2021-04-10 19:45:11 +02:00
|
|
|
</script>
|