Created
January 13, 2023 02:32
-
-
Save anatoliy-t7/7758c924b1266f2d8b76add0a17a9117 to your computer and use it in GitHub Desktop.
Vue 3 composition components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<label | |
v-if="label" | |
:for="id" | |
class="form-label"> | |
{{ label }} | |
</label> | |
<select | |
:id="id" | |
:disabled="disabled" | |
@change="$emit('update:modelValue', $event.target.value)" | |
:value="modelValue" | |
:class="[{ 'border-red-500': error }, size, $attrs.class]" | |
class="focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 disabled:bg-slate-50 disabled:cursor-not-allowed border-slate-300 block rounded-md"> | |
<slot /> | |
</select> | |
<div | |
v-if="error" | |
class="form-error"> | |
{{ error }} | |
</div> | |
</div> | |
</template> | |
<script setup> | |
import { v4 as uuid } from 'uuid'; | |
const props = defineProps({ | |
id: { | |
type: String, | |
default() { | |
return `select-input-${uuid()}`; | |
} | |
}, | |
disabled: false, | |
size: { | |
type: String, | |
default: 'text-base' | |
}, | |
error: String, | |
label: String, | |
modelValue: { | |
type: [String, Number, Boolean, Object], | |
default: 0 | |
} | |
}); | |
defineEmits(['update:modelValue']); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment