|
| 1 | +<template> |
| 2 | + <div |
| 3 | + class="control-wrapper" |
| 4 | + v-if="appStore.overrideControlTemplate && visible" |
| 5 | + :class="[styles?.control.root, { 'focused-wrapper': isFocused }]" |
| 6 | + :id="id" |
| 7 | + > |
| 8 | + <label :for="id">{{ label }} {{ required ? '(required)' : '' }}</label> |
| 9 | + <template v-for="vnode in processedSlot"> |
| 10 | + <component :is="vnode" /> |
| 11 | + </template> |
| 12 | + </div> |
| 13 | + |
| 14 | + <default-control-wrapper v-else v-bind="props"> |
| 15 | + <slot></slot> |
| 16 | + </default-control-wrapper> |
| 17 | +</template> |
| 18 | + |
| 19 | +<script setup lang="ts"> |
| 20 | +import DefaultControlWrapper from '@/controls/components/DefaultControlWrapper.vue'; |
| 21 | +import type { ControlWrapperProps } from '@/util'; |
| 22 | +import { cloneVNode, computed, defineProps, useSlots } from 'vue'; |
| 23 | +import { useAppStore } from '../store'; |
| 24 | +const appStore = useAppStore(); |
| 25 | +
|
| 26 | +const props = defineProps<ControlWrapperProps>(); |
| 27 | +const slots = useSlots(); |
| 28 | +
|
| 29 | +/** |
| 30 | + * Recursively clones a VNode and removes 'label' prop from Vuetify input components. |
| 31 | + */ |
| 32 | +function stripLabel(vnode: any) { |
| 33 | + if (!vnode) return vnode; |
| 34 | +
|
| 35 | + const hasLabel = vnode.props && 'label' in vnode.props; |
| 36 | + if (hasLabel) { |
| 37 | + vnode = cloneVNode(vnode, { label: undefined }); |
| 38 | + } |
| 39 | +
|
| 40 | + if (vnode.children && Array.isArray(vnode.children)) { |
| 41 | + vnode.children = vnode.children.map(stripLabel); |
| 42 | + } |
| 43 | +
|
| 44 | + return vnode; |
| 45 | +} |
| 46 | +
|
| 47 | +const processedSlot = computed(() => { |
| 48 | + if (!slots.default) return []; |
| 49 | + return slots.default().map(stripLabel); |
| 50 | +}); |
| 51 | +</script> |
| 52 | + |
| 53 | +<style scoped> |
| 54 | +.control-wrapper { |
| 55 | + position: relative; |
| 56 | + padding: 8px; |
| 57 | + transition: |
| 58 | + background-color 0.2s ease, |
| 59 | + box-shadow 0.2s ease; |
| 60 | + border-radius: 6px; |
| 61 | +} |
| 62 | +
|
| 63 | +/* Subtle focus effect */ |
| 64 | +.focused-wrapper { |
| 65 | + background-color: rgba(25, 118, 210, 0.05); /* soft glow */ |
| 66 | + box-shadow: 0 0 8px rgba(25, 118, 210, 0.3); |
| 67 | +} |
| 68 | +</style> |
0 commit comments