tethys.backend/resources/js/Components/FormField.vue

50 lines
1.1 KiB
Vue
Raw Permalink Normal View History

2023-03-03 15:54:28 +00:00
<script setup>
import { computed, useSlots } from 'vue';
2023-03-03 15:54:28 +00:00
defineProps({
2023-03-17 15:13:37 +00:00
label: {
type: String,
default: null,
},
labelFor: {
type: String,
default: null,
},
help: {
type: String,
default: null,
},
2023-03-03 15:54:28 +00:00
});
const slots = useSlots();
const wrapperClass = computed(() => {
2023-03-17 15:13:37 +00:00
const base = [];
const slotsLength = slots.default().length;
2023-03-03 15:54:28 +00:00
2023-03-17 15:13:37 +00:00
if (slotsLength > 1) {
base.push('grid grid-cols-1 gap-3');
}
2023-03-03 15:54:28 +00:00
2023-03-17 15:13:37 +00:00
if (slotsLength === 2) {
base.push('md:grid-cols-2');
}
2023-03-03 15:54:28 +00:00
2023-03-17 15:13:37 +00:00
return base;
2023-03-03 15:54:28 +00:00
});
</script>
<template>
2023-03-17 15:13:37 +00:00
<div class="mb-6 last:mb-0">
<!-- <label v-if="label" :for="labelFor" class="block font-bold mb-2">{{ label }}</label> -->
<label v-if="label" :for="labelFor" class="font-bold h-6 mt-3 text-xs leading-8 uppercase">{{ label }}</label>
<div v-bind:class="wrapperClass">
<slot />
</div>
<div v-if="help" class="text-xs text-gray-500 dark:text-slate-400 mt-1">
{{ help }}
</div>
</div>
2023-03-03 15:54:28 +00:00
</template>