2025-07-21 14:42:41 +02:00
|
|
|
<script setup lang="ts">
|
|
|
|
import Accordion from 'primevue/accordion';
|
|
|
|
import VAccordionChild from './VAccordionChild.vue';
|
2025-07-31 01:54:58 +02:00
|
|
|
import type IVAccordion from './IVAccordion.type.js';
|
2025-07-21 16:22:24 +02:00
|
|
|
import { ref, watch } from 'vue';
|
2025-07-21 14:42:41 +02:00
|
|
|
|
|
|
|
const props = withDefaults(defineProps<IVAccordion>(), {
|
2025-07-21 16:22:24 +02:00
|
|
|
value: null,
|
|
|
|
});
|
|
|
|
|
2025-07-21 17:00:18 +02:00
|
|
|
// Define the event emitter for v-model binding
|
2025-07-21 16:22:24 +02:00
|
|
|
const emit = defineEmits([
|
|
|
|
'update:value',
|
|
|
|
])
|
|
|
|
|
2025-07-21 17:00:18 +02:00
|
|
|
// Local reactive value to sync with the parent v-model
|
2025-07-21 16:22:24 +02:00
|
|
|
const localValue = ref(props.value);
|
2025-07-21 17:00:18 +02:00
|
|
|
|
|
|
|
// Watch for external changes to the prop and update localValue accordingly
|
2025-07-21 16:22:24 +02:00
|
|
|
watch(() => props.value, (newVal) => {
|
|
|
|
if(localValue.value !== newVal) {
|
|
|
|
localValue.value = newVal;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2025-07-21 17:00:18 +02:00
|
|
|
// Watch for internal changes to localValue and emit them to the parent
|
2025-07-21 16:22:24 +02:00
|
|
|
watch(localValue, (newVal) => {
|
|
|
|
if(props.value !== newVal){
|
|
|
|
emit('update:value', newVal);
|
|
|
|
}
|
2025-07-21 14:42:41 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2025-07-21 16:22:24 +02:00
|
|
|
<Accordion
|
|
|
|
v-model:value="localValue"
|
|
|
|
class="p-accordion"
|
|
|
|
style="width: 100%;"
|
|
|
|
@update:value="emit('update:value', $event)"
|
|
|
|
>
|
2025-07-21 14:42:41 +02:00
|
|
|
<slot>
|
|
|
|
<VAccordionChild/>
|
|
|
|
</slot>
|
|
|
|
</Accordion>
|
|
|
|
</template>
|