@antify/ui 3.1.22 → 3.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import AntAccordionItem from './AntAccordionItem.vue';
|
|
3
3
|
import {
|
|
4
|
-
onMounted,
|
|
4
|
+
onMounted,
|
|
5
5
|
} from 'vue';
|
|
6
6
|
import {
|
|
7
|
-
CollapseStrategy,
|
|
7
|
+
CollapseStrategy, type AccordionItem,
|
|
8
8
|
} from './__types/AntAccordion.types';
|
|
9
9
|
import AntSkeleton from './AntSkeleton.vue';
|
|
10
10
|
|
|
11
11
|
const props = withDefaults(defineProps<{
|
|
12
|
-
items:
|
|
13
|
-
label?: string;
|
|
14
|
-
content?: string;
|
|
15
|
-
isOpen?: boolean;
|
|
16
|
-
iconLeft?: boolean;
|
|
17
|
-
contentPadding?: boolean;
|
|
18
|
-
activeLabelClasses?: string;
|
|
19
|
-
activeIconClasses?: string;
|
|
20
|
-
inactiveLabelClasses?: string;
|
|
21
|
-
inactiveIconClasses?: string;
|
|
22
|
-
}[];
|
|
12
|
+
items: AccordionItem[];
|
|
23
13
|
collapseStrategy?: CollapseStrategy;
|
|
24
14
|
skeleton?: boolean;
|
|
25
15
|
}>(), {
|
|
@@ -27,22 +17,24 @@ const props = withDefaults(defineProps<{
|
|
|
27
17
|
skeleton: false,
|
|
28
18
|
});
|
|
29
19
|
|
|
30
|
-
const
|
|
20
|
+
const _openItems = defineModel<number[]>('openItems', {
|
|
21
|
+
default: [],
|
|
22
|
+
});
|
|
31
23
|
|
|
32
24
|
onMounted(() => {
|
|
33
|
-
|
|
25
|
+
_openItems.value = props.items
|
|
34
26
|
.map((item, index) => item.isOpen ? index : -1)
|
|
35
27
|
.filter((index) => index !== -1);
|
|
36
28
|
});
|
|
37
29
|
|
|
38
30
|
function onOpen(index: number) {
|
|
39
31
|
if (props.collapseStrategy === CollapseStrategy.single) {
|
|
40
|
-
|
|
32
|
+
_openItems.value = [
|
|
41
33
|
index,
|
|
42
34
|
];
|
|
43
35
|
} else {
|
|
44
|
-
|
|
45
|
-
...
|
|
36
|
+
_openItems.value = [
|
|
37
|
+
..._openItems.value,
|
|
46
38
|
index,
|
|
47
39
|
];
|
|
48
40
|
}
|
|
@@ -50,9 +42,9 @@ function onOpen(index: number) {
|
|
|
50
42
|
|
|
51
43
|
function onClose(index: number) {
|
|
52
44
|
if (props.collapseStrategy === CollapseStrategy.single) {
|
|
53
|
-
|
|
45
|
+
_openItems.value = [];
|
|
54
46
|
} else {
|
|
55
|
-
|
|
47
|
+
_openItems.value = _openItems.value.filter((item) => item !== index);
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
50
|
</script>
|
|
@@ -64,7 +56,7 @@ function onClose(index: number) {
|
|
|
64
56
|
v-for="(item, index) in items"
|
|
65
57
|
:key="`accordion-item-${index}`"
|
|
66
58
|
:label="item.label"
|
|
67
|
-
:is-open="
|
|
59
|
+
:is-open="_openItems.includes(index)"
|
|
68
60
|
:icon-left="item.iconLeft"
|
|
69
61
|
:content-padding="item.contentPadding"
|
|
70
62
|
:active-label-classes="item.activeLabelClasses"
|
|
@@ -2,3 +2,14 @@ export declare enum CollapseStrategy {
|
|
|
2
2
|
single = "single",
|
|
3
3
|
multiple = "multiple"
|
|
4
4
|
}
|
|
5
|
+
export interface AccordionItem {
|
|
6
|
+
label?: string;
|
|
7
|
+
content?: string;
|
|
8
|
+
isOpen?: boolean;
|
|
9
|
+
iconLeft?: boolean;
|
|
10
|
+
contentPadding?: boolean;
|
|
11
|
+
activeLabelClasses?: string;
|
|
12
|
+
activeIconClasses?: string;
|
|
13
|
+
inactiveLabelClasses?: string;
|
|
14
|
+
inactiveIconClasses?: string;
|
|
15
|
+
}
|