Refactor app architecture and clean local artifacts
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<select
|
||||
:value="modelValue ?? ''"
|
||||
class="h-11 w-full rounded-2xl border border-violet-200 bg-white px-4 text-sm text-slate-900 outline-none transition focus:border-violet-400 focus:ring-4 focus:ring-violet-100"
|
||||
@change="onChange"
|
||||
>
|
||||
<option
|
||||
v-for="option in options"
|
||||
:key="`${option.value}`"
|
||||
:value="stringifyValue(option.value)"
|
||||
>
|
||||
{{ option.label }}
|
||||
</option>
|
||||
</select>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
type SelectOptionValue = string | number | null
|
||||
|
||||
type SelectOption = {
|
||||
label: string
|
||||
value: SelectOptionValue
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: SelectOptionValue
|
||||
options: SelectOption[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: SelectOptionValue]
|
||||
}>()
|
||||
|
||||
function stringifyValue(value: SelectOptionValue) {
|
||||
return value === null ? '' : String(value)
|
||||
}
|
||||
|
||||
function onChange(event: Event) {
|
||||
const rawValue = (event.target as HTMLSelectElement).value
|
||||
const selectedOption = props.options.find((option) => stringifyValue(option.value) === rawValue)
|
||||
emit('update:modelValue', selectedOption?.value ?? null)
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user