2021-04-10 19:45:11 +02:00
|
|
|
<template>
|
2024-06-28 10:23:42 +02:00
|
|
|
<label class="flex flex-col group" :for="id" :class="sizes[size]">
|
|
|
|
<span v-if="label" class="font-semibold leading-none text-gray-400 group-[.field-base]:text-sm group-[.field-sm]:text-xs">
|
2021-08-22 16:15:16 +02:00
|
|
|
{{ label }}
|
|
|
|
<span v-show="required" class="text-red-800"> *</span>
|
|
|
|
</span>
|
2024-06-28 10:23:42 +02:00
|
|
|
<div class="relative flex-none flex">
|
|
|
|
<select
|
|
|
|
v-model="inner"
|
|
|
|
:disabled="disabled"
|
|
|
|
:name="name"
|
|
|
|
class="group-[.field-base]:h-[35px] group-[.field-sm]:h-[23px] group-[.field-base]:border-2 group-[.field-sm]:border border-gray-600 border-solid text-gray-300 bg-gray-700 leading-none rounded-lg group-[.field-base]:text-sm group-[.field-sm]:text-xs py-0 pr-8 group-[.field-base]:pl-2 group-[.field-sm]:pl-1 w-full"
|
|
|
|
>
|
2024-04-26 23:20:03 +02:00
|
|
|
<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>
|
2024-06-28 10:23:42 +02:00
|
|
|
<div class="h-full items-center flex absolute top-0 right-0">
|
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>
|
2021-04-10 19:45:11 +02:00
|
|
|
</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-06-28 10:23:42 +02:00
|
|
|
const sizes = ref({
|
|
|
|
sm: 'field-sm',
|
|
|
|
base: 'field-base',
|
|
|
|
lg: 'field-lg',
|
|
|
|
});
|
|
|
|
|
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>
|