Skip to content

Commit f5fb2cc

Browse files
committed
VueUiAccordion improved features
1 parent 1ccd1d1 commit f5fb2cc

File tree

7 files changed

+38
-19
lines changed

7 files changed

+38
-19
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-data-ui",
33
"private": false,
4-
"version": "2.0.96",
4+
"version": "2.0.97",
55
"type": "module",
66
"description": "A user-empowering data visualization Vue components library",
77
"keywords": [

src/App.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,13 +3404,13 @@ const tableHeatmapDataset = ref([
34043404
<BaseIcon name="fullscreen" stroke="#5f8bee"/> -->
34053405
</template>
34063406
<template #dev>
3407-
<AccordionTest>
3407+
<AccordionTest :config="{ open: true}">
34083408
<template #arrow>
34093409
<BaseIcon name="arrowRight"/>
34103410
</template>
3411-
<template #title>
3411+
<template #title="{ isOpen }">
34123412
<div style="font-size: 16px; font-weight: bold">
3413-
TITLE
3413+
TITLE {{ isOpen }}
34143414
</div>
34153415
</template>
34163416
<template #content>
@@ -3423,9 +3423,9 @@ const tableHeatmapDataset = ref([
34233423
<template #arrow>
34243424
<BaseIcon name="arrowRight"/>
34253425
</template>
3426-
<template #title>
3426+
<template #title="{ isOpen }">
34273427
<div style="font-size: 16px; font-weight: bold">
3428-
TITLE
3428+
TITLE {{ isOpen }}
34293429
</div>
34303430
</template>
34313431
<template #content>

src/components/vue-data-ui.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,14 @@ defineExpose({
351351
</div>
352352

353353
<VueUiAccordion v-if="component === 'VueUiAccordion'" :config="config">
354-
<template #arrow="{ backgroundColor, color, iconColor }">
355-
<slot name="arrow" v-bind="{ backgroundColor, color, iconColor }"/>
354+
<template #arrow="{ backgroundColor, color, iconColor, isOpen }">
355+
<slot name="arrow" v-bind="{ backgroundColor, color, iconColor, isOpen }"/>
356356
</template>
357-
<template #title="{ color }">
358-
<slot name="title" v-bind="{ color }"/>
357+
<template #title="{ color, isOpen }">
358+
<slot name="title" v-bind="{ color, isOpen }"/>
359359
</template>
360-
<template #content="{ backgroundColor, color }">
361-
<slot name="content" v-bind="{ backgroundColor, color }"/>
360+
<template #content="{ backgroundColor, color, isOpen }">
361+
<slot name="content" v-bind="{ backgroundColor, color, isOpen }"/>
362362
</template>
363363
</VueUiAccordion>
364364

src/components/vue-ui-accordion.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script setup>
2-
import { ref, computed } from "vue";
2+
import { ref, computed, watch, onMounted } from "vue";
33
import BaseIcon from "../atoms/BaseIcon.vue";
44
import { useNestedProp } from "../useNestedProp";
55
import mainConfig from "../default_configs.json";
6+
import { createUid } from "../lib";
67
78
const props = defineProps({
89
config: {
@@ -22,22 +23,38 @@ const accordionConfig = computed(() => {
2223
});
2324
});
2425
26+
const isOpen = ref(props.config.open);
27+
const uid = ref(createUid())
28+
const details = ref(null);
29+
const init = ref(0)
30+
31+
onMounted(() => {
32+
details.value.open = accordionConfig.value.open;
33+
})
34+
35+
function toggleDetails() {
36+
if(init.value > 0 || !accordionConfig.value.open) {
37+
isOpen.value = !isOpen.value;
38+
}
39+
init.value += 1;
40+
}
41+
2542
</script>
2643

2744
<template>
28-
<details>
45+
<details :id="`details_${uid}`" ref="details" @toggle="toggleDetails">
2946
<summary>
3047
<div class="vue-ui-accordion-head" :style="`background:${accordionConfig.head.backgroundColor};padding:${accordionConfig.head.padding};`">
3148
<div class="vue-ui-accordion-arrow">
32-
<slot name="arrow" v-if="accordionConfig.head.useArrowSlot" v-bind="{ backgroundColor: accordionConfig.head.backgroundColor, color: accordionConfig.head.color, iconColor: accordionConfig.head.iconColor }" />
49+
<slot name="arrow" v-if="accordionConfig.head.useArrowSlot" v-bind="{ backgroundColor: accordionConfig.head.backgroundColor, color: accordionConfig.head.color, iconColor: accordionConfig.head.iconColor, isOpen }" />
3350
<BaseIcon name="arrowRight" v-else :stroke="accordionConfig.head.iconColor" />
3451
</div>
35-
<slot name="title" v-bind="{ color: accordionConfig.head.color }"/>
52+
<slot name="title" v-bind="{ color: accordionConfig.head.color, isOpen }"/>
3653
</div>
3754
</summary>
3855
</details>
3956
<div class="vue-ui-accordion-content" :style="`background:${accordionConfig.body.backgroundColor};color:${accordionConfig.body.color}`">
40-
<slot name="content" v-bind="{ backgroundColor: accordionConfig.body.backgroundColor, color: accordionConfig.body.color }"/>
57+
<slot name="content" v-bind="{ backgroundColor: accordionConfig.body.backgroundColor, color: accordionConfig.body.color, isOpen }"/>
4158
</div>
4259
</template>
4360

src/default_configs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,6 +3639,7 @@
36393639
}
36403640
},
36413641
"vue_ui_accordion": {
3642+
"open": false,
36423643
"head": {
36433644
"useArrowSlot": false,
36443645
"backgroundColor": "#FFFFFF",

types/vue-data-ui.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4650,6 +4650,7 @@ declare module 'vue-data-ui' {
46504650
}>
46514651

46524652
export type VueUiAccordionConfig = {
4653+
open?: boolean;
46534654
head?: {
46544655
useArrowSlot?: boolean;
46554656
backgroundColor?: string;

0 commit comments

Comments
 (0)