@volverjs/ui-vue 0.0.10-beta.23 → 0.0.10-beta.25
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.
- package/dist/components/VvAccordion/VvAccordion.es.js +119 -79
- package/dist/components/VvAccordion/VvAccordion.umd.js +1 -1
- package/dist/components/VvAccordion/VvAccordion.vue.d.ts +18 -4
- package/dist/components/VvAccordion/index.d.ts +4 -8
- package/dist/components/VvAccordionGroup/VvAccordionGroup.es.js +282 -124
- package/dist/components/VvAccordionGroup/VvAccordionGroup.umd.js +1 -1
- package/dist/components/VvAccordionGroup/VvAccordionGroup.vue.d.ts +34 -7
- package/dist/components/VvAccordionGroup/index.d.ts +4 -1
- package/dist/components/VvAction/VvAction.vue.d.ts +1 -1
- package/dist/components/VvAlert/VvAlert.vue.d.ts +1 -1
- package/dist/components/VvButton/VvButton.es.js +92 -98
- package/dist/components/VvButton/VvButton.umd.js +1 -1
- package/dist/components/VvButton/VvButton.vue.d.ts +7 -7
- package/dist/components/VvButton/index.d.ts +11 -11
- package/dist/components/VvButtonGroup/VvButtonGroup.es.js +7 -13
- package/dist/components/VvButtonGroup/VvButtonGroup.umd.js +1 -1
- package/dist/components/VvButtonGroup/VvButtonGroup.vue.d.ts +3 -3
- package/dist/components/VvCheckbox/VvCheckbox.es.js +81 -87
- package/dist/components/VvCheckbox/VvCheckbox.umd.js +1 -1
- package/dist/components/VvCheckbox/VvCheckbox.vue.d.ts +6 -6
- package/dist/components/VvCheckbox/index.d.ts +2 -2
- package/dist/components/VvCheckboxGroup/VvCheckboxGroup.es.js +15 -29
- package/dist/components/VvCheckboxGroup/VvCheckboxGroup.umd.js +1 -1
- package/dist/components/VvCheckboxGroup/VvCheckboxGroup.vue.d.ts +5 -5
- package/dist/components/VvCombobox/VvCombobox.es.js +13 -16
- package/dist/components/VvCombobox/VvCombobox.umd.js +1 -1
- package/dist/components/VvCombobox/VvCombobox.vue.d.ts +11 -11
- package/dist/components/VvCombobox/index.d.ts +1 -1
- package/dist/components/VvDropdown/VvDropdown.vue.d.ts +5 -5
- package/dist/components/VvDropdown/VvDropdownAction.vue.d.ts +1 -1
- package/dist/components/VvDropdown/VvDropdownOption.vue.d.ts +1 -1
- package/dist/components/VvDropdown/index.d.ts +1 -1
- package/dist/components/VvInputFile/VvInputFile.es.js +183 -168
- package/dist/components/VvInputFile/VvInputFile.umd.js +1 -1
- package/dist/components/VvInputFile/VvInputFile.vue.d.ts +16 -9
- package/dist/components/VvInputFile/index.d.ts +12 -3
- package/dist/components/VvInputText/VvInputClearAction.d.ts +1 -1
- package/dist/components/VvInputText/VvInputStepAction.d.ts +1 -1
- package/dist/components/VvInputText/VvInputText.vue.d.ts +6 -6
- package/dist/components/VvProgress/VvProgress.vue.d.ts +1 -1
- package/dist/components/VvRadio/VvRadio.es.js +64 -70
- package/dist/components/VvRadio/VvRadio.umd.js +1 -1
- package/dist/components/VvRadio/VvRadio.vue.d.ts +6 -6
- package/dist/components/VvRadio/index.d.ts +6 -6
- package/dist/components/VvRadioGroup/VvRadioGroup.es.js +15 -29
- package/dist/components/VvRadioGroup/VvRadioGroup.umd.js +1 -1
- package/dist/components/VvRadioGroup/VvRadioGroup.vue.d.ts +5 -5
- package/dist/components/VvSelect/VvSelect.vue.d.ts +8 -8
- package/dist/components/VvTextarea/VvTextarea.vue.d.ts +5 -5
- package/dist/components/VvTooltip/VvTooltip.vue.d.ts +3 -3
- package/dist/components/VvTooltip/index.d.ts +1 -1
- package/dist/components/index.es.js +494 -328
- package/dist/components/index.umd.js +1 -1
- package/dist/composables/alert/useInjectAlert.d.ts +1 -6
- package/dist/composables/group/useInjectedGroupState.d.ts +4 -5
- package/dist/composables/group/useProvideGroupState.d.ts +3 -3
- package/dist/constants.d.ts +6 -10
- package/dist/icons.es.js +3 -3
- package/dist/icons.umd.js +1 -1
- package/dist/index.es.js +3 -2
- package/dist/index.umd.js +1 -1
- package/dist/props/index.d.ts +1 -1
- package/dist/resolvers/unplugin.es.js +3 -2
- package/dist/resolvers/unplugin.umd.js +1 -1
- package/dist/stories/AccordionGroup/AccordionGroup.stories.d.ts +58 -15
- package/dist/stories/AccordionGroup/AccordionGroupSlots.stories.d.ts +381 -107
- package/dist/types/group.d.ts +37 -15
- package/package.json +37 -36
- package/src/assets/icons/detailed.json +1 -1
- package/src/assets/icons/normal.json +1 -1
- package/src/assets/icons/simple.json +1 -1
- package/src/components/VvAccordion/VvAccordion.vue +119 -56
- package/src/components/VvAccordion/index.ts +8 -23
- package/src/components/VvAccordionGroup/VvAccordionGroup.vue +164 -42
- package/src/components/VvAccordionGroup/index.ts +4 -1
- package/src/components/VvButton/index.ts +7 -12
- package/src/components/VvButtonGroup/VvButtonGroup.vue +1 -2
- package/src/components/VvCheckbox/index.ts +2 -2
- package/src/components/VvCheckboxGroup/VvCheckboxGroup.vue +1 -2
- package/src/components/VvInputFile/VvInputFile.vue +71 -47
- package/src/components/VvInputFile/index.ts +5 -4
- package/src/components/VvRadio/index.ts +5 -5
- package/src/components/VvRadioGroup/VvRadioGroup.vue +1 -2
- package/src/composables/group/useInjectedGroupState.ts +20 -16
- package/src/composables/group/useProvideGroupState.ts +10 -15
- package/src/constants.ts +19 -14
- package/src/stories/AccordionGroup/AccordionGroup.settings.ts +2 -2
- package/src/stories/AccordionGroup/AccordionGroup.test.ts +16 -10
- package/src/stories/AccordionGroup/AccordionGroupSlots.stories.ts +1 -1
- package/src/types/group.ts +22 -14
|
@@ -12,65 +12,114 @@
|
|
|
12
12
|
const props = defineProps(VvAccordionProps)
|
|
13
13
|
const attrs = useAttrs()
|
|
14
14
|
const emit = defineEmits(VvAccordionEvents)
|
|
15
|
+
const modelValue = useVModel(props, 'modelValue', emit)
|
|
15
16
|
|
|
16
17
|
// data
|
|
17
18
|
const accordionName = computed(
|
|
18
19
|
() => props.name || (attrs?.id as string) || uid(),
|
|
19
20
|
)
|
|
20
|
-
const {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
const { title, content, not } = toRefs(props)
|
|
22
|
+
const { isInGroup, modifiers, disabled, bus } = useGroupProps(props)
|
|
23
|
+
|
|
24
|
+
// state
|
|
25
|
+
const isExpanded = ref(false)
|
|
26
|
+
watch(
|
|
26
27
|
modelValue,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const localModelValue = ref(false)
|
|
31
|
-
const isOpen = computed({
|
|
32
|
-
get: () => {
|
|
33
|
-
let toReturn = modelValue.value as boolean
|
|
34
|
-
if (isInGroup.value) {
|
|
35
|
-
if (collapse.value && Array.isArray(modelValue.value)) {
|
|
36
|
-
toReturn = modelValue.value.includes(accordionName.value)
|
|
37
|
-
} else {
|
|
38
|
-
toReturn = modelValue.value === accordionName.value
|
|
39
|
-
}
|
|
40
|
-
} else if (modelValue.value === undefined) {
|
|
41
|
-
// localModelValue is used when the accordion is not in a group
|
|
42
|
-
toReturn = localModelValue.value
|
|
28
|
+
(newValue) => {
|
|
29
|
+
if (typeof newValue === 'boolean') {
|
|
30
|
+
isExpanded.value = not.value ? !newValue : newValue
|
|
43
31
|
}
|
|
44
|
-
return not.value ? !toReturn : toReturn
|
|
45
32
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
33
|
+
{ immediate: true },
|
|
34
|
+
)
|
|
35
|
+
watch(isExpanded, (newValue) => {
|
|
36
|
+
modelValue.value = not.value ? !newValue : newValue
|
|
37
|
+
})
|
|
38
|
+
bus?.on('toggle', ({ name, value }) => {
|
|
39
|
+
if (name !== accordionName.value) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
isExpanded.value = value
|
|
43
|
+
})
|
|
44
|
+
const onClick = () => {
|
|
45
|
+
if (disabled.value) {
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
if (isInGroup.value) {
|
|
49
|
+
bus?.emit('toggle', {
|
|
50
|
+
name: accordionName.value,
|
|
51
|
+
value: !isExpanded.value,
|
|
52
|
+
})
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
isExpanded.value = !isExpanded.value
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// register / unregister
|
|
59
|
+
watch(
|
|
60
|
+
accordionName,
|
|
61
|
+
(newValue, oldValue) => {
|
|
62
|
+
if (bus) {
|
|
63
|
+
if (oldValue && oldValue !== newValue) {
|
|
64
|
+
bus.emit('unregister', { name: oldValue })
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
// localModelValue is used when the accordion is not in a group
|
|
65
|
-
if (
|
|
66
|
-
modelValue.value === undefined &&
|
|
67
|
-
typeof newValue === 'boolean'
|
|
68
|
-
) {
|
|
69
|
-
localModelValue.value = newValue
|
|
70
|
-
return
|
|
66
|
+
bus.emit('register', { name: newValue })
|
|
71
67
|
}
|
|
72
|
-
modelValue.value = newValue
|
|
73
68
|
},
|
|
69
|
+
{
|
|
70
|
+
immediate: true,
|
|
71
|
+
},
|
|
72
|
+
)
|
|
73
|
+
onBeforeUnmount(() => {
|
|
74
|
+
if (bus) {
|
|
75
|
+
bus.emit('unregister', { name: accordionName.value })
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
// methods
|
|
80
|
+
const expand = () => {
|
|
81
|
+
if (isExpanded.value) {
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
onClick()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const collapse = () => {
|
|
88
|
+
if (!isExpanded.value) {
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
onClick()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const groupExpand = (name?: string | string[]) => {
|
|
95
|
+
if (!bus) {
|
|
96
|
+
// eslint-disable-next-line no-console
|
|
97
|
+
console.warn(
|
|
98
|
+
`[VvAccordion]: You are trying to expand accordion group of "${accordionName.value}" but it is not in a group`,
|
|
99
|
+
)
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
bus.emit('expand', { name })
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const groupCollapse = (name?: string | string[]) => {
|
|
106
|
+
if (!bus) {
|
|
107
|
+
// eslint-disable-next-line no-console
|
|
108
|
+
console.warn(
|
|
109
|
+
`[VvAccordion]: You are trying to collapse accordion group of "${accordionName.value}" but it is not in a group`,
|
|
110
|
+
)
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
bus?.emit('collapse', { name })
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// expose
|
|
117
|
+
defineExpose({
|
|
118
|
+
isExpanded,
|
|
119
|
+
expand,
|
|
120
|
+
collapse,
|
|
121
|
+
groupExpand,
|
|
122
|
+
groupCollapse,
|
|
74
123
|
})
|
|
75
124
|
|
|
76
125
|
// styles
|
|
@@ -81,27 +130,41 @@
|
|
|
81
130
|
disabled: disabled.value,
|
|
82
131
|
})),
|
|
83
132
|
)
|
|
84
|
-
|
|
85
|
-
// methods
|
|
86
|
-
const onClick = useToggle(isOpen)
|
|
87
133
|
</script>
|
|
88
134
|
|
|
89
135
|
<template>
|
|
90
|
-
<details :id="accordionName" :class="bemCssClasses" :open="
|
|
136
|
+
<details :id="accordionName" :class="bemCssClasses" :open="isExpanded">
|
|
91
137
|
<summary
|
|
92
138
|
:aria-controls="accordionName"
|
|
93
|
-
:aria-expanded="
|
|
139
|
+
:aria-expanded="isExpanded"
|
|
94
140
|
class="vv-accordion__summary"
|
|
95
141
|
@click.prevent="onClick()"
|
|
96
142
|
>
|
|
97
143
|
<!-- @slot Slot for title -->
|
|
98
|
-
<slot
|
|
144
|
+
<slot
|
|
145
|
+
name="summary"
|
|
146
|
+
v-bind="{
|
|
147
|
+
isExpanded,
|
|
148
|
+
expand,
|
|
149
|
+
collapse,
|
|
150
|
+
groupExpand,
|
|
151
|
+
groupCollapse,
|
|
152
|
+
}"
|
|
153
|
+
>
|
|
99
154
|
{{ title }}
|
|
100
155
|
</slot>
|
|
101
156
|
</summary>
|
|
102
|
-
<div :aria-hidden="!
|
|
157
|
+
<div :aria-hidden="!isExpanded" class="vv-accordion__content">
|
|
103
158
|
<!-- @slot Slot for content -->
|
|
104
|
-
<slot
|
|
159
|
+
<slot
|
|
160
|
+
v-bind="{
|
|
161
|
+
isExpanded,
|
|
162
|
+
expand,
|
|
163
|
+
collapse,
|
|
164
|
+
groupExpand,
|
|
165
|
+
groupCollapse,
|
|
166
|
+
}"
|
|
167
|
+
>
|
|
105
168
|
{{ content }}
|
|
106
169
|
</slot>
|
|
107
170
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExtractPropTypes
|
|
1
|
+
import type { ExtractPropTypes } from 'vue'
|
|
2
2
|
import type { AccordionGroupState } from '../../types/group'
|
|
3
3
|
import { INJECTION_KEY_ACCORDION_GROUP } from '../../constants'
|
|
4
4
|
import { ModifiersProps } from '@/props'
|
|
@@ -40,29 +40,19 @@ export type VvAccordionPropsTypes = ExtractPropTypes<typeof VvAccordionProps>
|
|
|
40
40
|
/**
|
|
41
41
|
* Merges local and group props
|
|
42
42
|
*/
|
|
43
|
-
export function useGroupProps(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
)
|
|
47
|
-
const { group, isInGroup, getGroupOrLocalRef } =
|
|
48
|
-
useInjectedGroupState<AccordionGroupState>(
|
|
49
|
-
INJECTION_KEY_ACCORDION_GROUP,
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
// local props
|
|
53
|
-
const { title, content } = toRefs(props)
|
|
43
|
+
export function useGroupProps(props: VvAccordionPropsTypes) {
|
|
44
|
+
const { group, isInGroup } = useInjectedGroupState<AccordionGroupState>(
|
|
45
|
+
INJECTION_KEY_ACCORDION_GROUP,
|
|
46
|
+
)
|
|
54
47
|
|
|
55
48
|
// group props
|
|
56
|
-
const modelValue = getGroupOrLocalRef('modelValue', props, emit)
|
|
57
|
-
const not = getGroupOrLocalRef('not', props) as Ref<boolean>
|
|
58
|
-
const collapse = getGroupOrLocalRef('collapse', props) as Ref<boolean>
|
|
59
49
|
const disabled = computed(() =>
|
|
60
|
-
Boolean(props.disabled || group?.
|
|
50
|
+
Boolean(props.disabled || group?.disabled.value),
|
|
61
51
|
)
|
|
62
52
|
// merge local and group modifiers
|
|
63
53
|
const modifiers = computed(() => {
|
|
64
54
|
let localModifiers = props.modifiers
|
|
65
|
-
let groupModifiers = group?.
|
|
55
|
+
let groupModifiers = group?.modifiers.value
|
|
66
56
|
|
|
67
57
|
const toReturn = new Set<string>()
|
|
68
58
|
if (localModifiers) {
|
|
@@ -82,15 +72,10 @@ export function useGroupProps(
|
|
|
82
72
|
|
|
83
73
|
return {
|
|
84
74
|
// group props
|
|
85
|
-
modelValue,
|
|
86
|
-
not,
|
|
87
75
|
isInGroup,
|
|
88
76
|
group,
|
|
89
|
-
collapse,
|
|
90
77
|
modifiers,
|
|
91
78
|
disabled,
|
|
92
|
-
|
|
93
|
-
title,
|
|
94
|
-
content,
|
|
79
|
+
bus: group?.bus,
|
|
95
80
|
}
|
|
96
81
|
}
|
|
@@ -5,78 +5,188 @@
|
|
|
5
5
|
</script>
|
|
6
6
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
|
-
import
|
|
9
|
-
import type {
|
|
8
|
+
import mitt from 'mitt'
|
|
9
|
+
import type {
|
|
10
|
+
AccordionGroupState,
|
|
11
|
+
AccordionGroupBusEvents,
|
|
12
|
+
} from '../../types/group'
|
|
10
13
|
import { INJECTION_KEY_ACCORDION_GROUP } from '../../constants'
|
|
11
14
|
import VvAccordion from '../VvAccordion/VvAccordion.vue'
|
|
12
15
|
import { VvAccordionGroupProps, VvAccordionGroupEvents } from '.'
|
|
13
16
|
|
|
14
17
|
// props and emit
|
|
15
18
|
const props = defineProps(VvAccordionGroupProps)
|
|
19
|
+
// eslint-disable-next-line
|
|
16
20
|
const emit = defineEmits(VvAccordionGroupEvents)
|
|
17
21
|
|
|
18
22
|
// data
|
|
19
|
-
const { disabled,
|
|
20
|
-
toRefs(props)
|
|
23
|
+
const { disabled, modifiers, itemModifiers, items } = toRefs(props)
|
|
21
24
|
watchEffect(() => {
|
|
22
|
-
if (typeof props.modelValue === 'string' && collapse
|
|
23
|
-
// eslint-disable-next-line
|
|
25
|
+
if (typeof props.modelValue === 'string' && props.collapse) {
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
24
27
|
console.warn(
|
|
25
28
|
`[VvAccordionGroup]: modelValue is a string but collapse is true.`,
|
|
26
29
|
)
|
|
27
30
|
}
|
|
28
31
|
})
|
|
29
|
-
|
|
32
|
+
|
|
33
|
+
const accordionNames = reactive(new Set<string>())
|
|
34
|
+
let storeModelValue: Ref<string | string[] | undefined> = ref()
|
|
30
35
|
watch(
|
|
31
36
|
() => props.storeKey,
|
|
32
|
-
(newKey) => {
|
|
37
|
+
(newKey, oldKey) => {
|
|
38
|
+
if (oldKey && oldKey !== newKey) {
|
|
39
|
+
localStorage.removeItem(oldKey)
|
|
40
|
+
}
|
|
33
41
|
if (newKey) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
localModelValue = ref([])
|
|
42
|
+
storeModelValue = useLocalStorage(newKey, storeModelValue.value)
|
|
43
|
+
return
|
|
37
44
|
}
|
|
45
|
+
storeModelValue = ref(storeModelValue.value)
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
immediate: true,
|
|
38
49
|
},
|
|
39
|
-
{ immediate: true },
|
|
40
50
|
)
|
|
41
|
-
const
|
|
51
|
+
const localModelValue = computed({
|
|
42
52
|
get: () => {
|
|
43
|
-
if (props.modelValue !== undefined) {
|
|
44
|
-
if (!collapse.value) {
|
|
45
|
-
return Array.isArray(props.modelValue)
|
|
46
|
-
? props.modelValue[0]
|
|
47
|
-
: props.modelValue
|
|
48
|
-
}
|
|
53
|
+
if (props.modelValue !== null && props.modelValue !== undefined) {
|
|
49
54
|
return props.modelValue
|
|
50
55
|
}
|
|
51
|
-
return
|
|
52
|
-
? localModelValue.value?.[0]
|
|
53
|
-
: localModelValue.value
|
|
56
|
+
return storeModelValue.value
|
|
54
57
|
},
|
|
55
58
|
set: (newValue) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
emit('update:modelValue', newValue)
|
|
60
|
+
storeModelValue.value = newValue
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
const expandedAccordions = computed<Set<string>>({
|
|
64
|
+
get: () => {
|
|
65
|
+
if (localModelValue.value === undefined) {
|
|
66
|
+
return new Set<string>()
|
|
67
|
+
}
|
|
68
|
+
let toReturn = new Set<string>()
|
|
69
|
+
if (props.not) {
|
|
70
|
+
if (typeof localModelValue.value === 'string') {
|
|
71
|
+
toReturn = new Set<string>(
|
|
72
|
+
[...accordionNames].filter(
|
|
73
|
+
(name) => name !== localModelValue.value,
|
|
74
|
+
),
|
|
75
|
+
)
|
|
76
|
+
} else if (Array.isArray(localModelValue.value)) {
|
|
77
|
+
toReturn = new Set<string>(
|
|
78
|
+
[...accordionNames].filter(
|
|
79
|
+
(name) =>
|
|
80
|
+
!(localModelValue.value as string[]).includes(
|
|
81
|
+
name,
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
)
|
|
62
85
|
}
|
|
63
|
-
|
|
86
|
+
} else if (typeof localModelValue.value === 'string') {
|
|
87
|
+
toReturn = new Set<string>([localModelValue.value])
|
|
88
|
+
} else if (Array.isArray(localModelValue.value)) {
|
|
89
|
+
toReturn = new Set<string>(localModelValue.value)
|
|
64
90
|
}
|
|
65
|
-
|
|
66
|
-
? newValue
|
|
67
|
-
: [newValue]
|
|
91
|
+
return toReturn
|
|
68
92
|
},
|
|
93
|
+
set: (newValue) => {
|
|
94
|
+
if (props.not) {
|
|
95
|
+
localModelValue.value = [...accordionNames].filter(
|
|
96
|
+
(name) => !newValue.has(name),
|
|
97
|
+
)
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
if (props.collapse) {
|
|
101
|
+
localModelValue.value = [...newValue]
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
localModelValue.value = newValue.values().next().value
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
onMounted(() => {
|
|
108
|
+
if (props.not && localModelValue.value === undefined) {
|
|
109
|
+
localModelValue.value = props.collapse
|
|
110
|
+
? []
|
|
111
|
+
: [...accordionNames.values()].splice(1, accordionNames.size)
|
|
112
|
+
}
|
|
113
|
+
nextTick(() => {
|
|
114
|
+
for (const name of accordionNames) {
|
|
115
|
+
bus.emit('toggle', {
|
|
116
|
+
name,
|
|
117
|
+
value: expandedAccordions.value.has(name),
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
})
|
|
69
121
|
})
|
|
70
122
|
|
|
71
123
|
// provide
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
modelValue,
|
|
124
|
+
const bus = mitt<AccordionGroupBusEvents>()
|
|
125
|
+
useProvideGroupState<AccordionGroupState>(INJECTION_KEY_ACCORDION_GROUP, {
|
|
75
126
|
disabled,
|
|
76
|
-
collapse,
|
|
77
127
|
modifiers: itemModifiers,
|
|
78
|
-
|
|
128
|
+
bus,
|
|
129
|
+
})
|
|
130
|
+
bus.on('register', ({ name }) => {
|
|
131
|
+
accordionNames.add(name)
|
|
132
|
+
})
|
|
133
|
+
bus.on('unregister', ({ name }) => {
|
|
134
|
+
accordionNames.delete(name)
|
|
79
135
|
})
|
|
136
|
+
bus.on('toggle', ({ name, value }) => {
|
|
137
|
+
const newValue = new Set<string>(expandedAccordions.value)
|
|
138
|
+
if (value) {
|
|
139
|
+
if (!props.collapse) {
|
|
140
|
+
for (const item of newValue) {
|
|
141
|
+
if (item !== name) {
|
|
142
|
+
bus.emit('toggle', { name: item, value: false })
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
newValue.clear()
|
|
146
|
+
}
|
|
147
|
+
newValue.add(name)
|
|
148
|
+
expandedAccordions.value = newValue
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
newValue.delete(name)
|
|
152
|
+
expandedAccordions.value = newValue
|
|
153
|
+
})
|
|
154
|
+
const expand = (name?: string | string[]) => {
|
|
155
|
+
if (typeof name === 'string') {
|
|
156
|
+
bus.emit('toggle', { name, value: true })
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
if (Array.isArray(name)) {
|
|
160
|
+
for (const item of name) {
|
|
161
|
+
bus.emit('toggle', { name: item, value: true })
|
|
162
|
+
}
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
for (const item of accordionNames) {
|
|
166
|
+
bus.emit('toggle', { name: item, value: true })
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
bus.on('expand', ({ name }) => expand(name))
|
|
170
|
+
|
|
171
|
+
const collapse = (name?: string | string[]) => {
|
|
172
|
+
if (typeof name === 'string') {
|
|
173
|
+
bus.emit('toggle', { name, value: false })
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
if (Array.isArray(name)) {
|
|
177
|
+
for (const item of name) {
|
|
178
|
+
bus.emit('toggle', { name: item, value: false })
|
|
179
|
+
}
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
for (const item of accordionNames) {
|
|
183
|
+
bus.emit('toggle', { name: item, value: false })
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
bus.on('collapse', ({ name }) => collapse(name))
|
|
187
|
+
|
|
188
|
+
// expose
|
|
189
|
+
defineExpose({ expandedAccordions, expand, collapse })
|
|
80
190
|
|
|
81
191
|
// styles
|
|
82
192
|
const bemCssClasses = useModifiers(
|
|
@@ -91,7 +201,13 @@
|
|
|
91
201
|
<template>
|
|
92
202
|
<div :class="bemCssClasses">
|
|
93
203
|
<!-- @slot Default slot -->
|
|
94
|
-
<slot
|
|
204
|
+
<slot
|
|
205
|
+
v-bind="{
|
|
206
|
+
expandedAccordions,
|
|
207
|
+
expand,
|
|
208
|
+
collapse,
|
|
209
|
+
}"
|
|
210
|
+
>
|
|
95
211
|
<VvAccordion
|
|
96
212
|
v-for="item in items"
|
|
97
213
|
:key="item.title"
|
|
@@ -101,13 +217,19 @@
|
|
|
101
217
|
content: item.content,
|
|
102
218
|
}"
|
|
103
219
|
>
|
|
104
|
-
<template
|
|
220
|
+
<template
|
|
221
|
+
v-if="$slots[`summary::${item.name}`]"
|
|
222
|
+
#summary="data"
|
|
223
|
+
>
|
|
105
224
|
<!-- @slot Slot for accordion header -->
|
|
106
|
-
<slot v-bind="data" :name="`
|
|
225
|
+
<slot v-bind="data" :name="`summary::${item.name}`" />
|
|
107
226
|
</template>
|
|
108
|
-
<template
|
|
227
|
+
<template
|
|
228
|
+
v-if="$slots[`content::${item.name}`]"
|
|
229
|
+
#default="data"
|
|
230
|
+
>
|
|
109
231
|
<!-- @slot Slot for accordion details -->
|
|
110
|
-
<slot v-bind="data" :name="`
|
|
232
|
+
<slot v-bind="data" :name="`content::${item.name}`" />
|
|
111
233
|
</template>
|
|
112
234
|
</VvAccordion>
|
|
113
235
|
</slot>
|
|
@@ -13,7 +13,10 @@ export const VvAccordionGroupProps = {
|
|
|
13
13
|
/**
|
|
14
14
|
* VModel
|
|
15
15
|
*/
|
|
16
|
-
modelValue:
|
|
16
|
+
modelValue: {
|
|
17
|
+
type: [String, Array] as PropType<string | string[] | undefined>,
|
|
18
|
+
default: undefined,
|
|
19
|
+
},
|
|
17
20
|
/**
|
|
18
21
|
* Accordion items
|
|
19
22
|
* @type VvAccordionGroupItem
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PropType, ExtractPropTypes } from 'vue'
|
|
2
2
|
import type { ButtonGroupState } from '../../types/group'
|
|
3
3
|
import {
|
|
4
4
|
ActionProps,
|
|
@@ -77,19 +77,14 @@ export function useGroupProps(
|
|
|
77
77
|
const { id, iconPosition, icon, label, pressed } = toRefs(props)
|
|
78
78
|
|
|
79
79
|
// group props
|
|
80
|
-
const modelValue = getGroupOrLocalRef('modelValue', props, emit)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const unselectable = getGroupOrLocalRef(
|
|
85
|
-
'unselectable',
|
|
86
|
-
props,
|
|
87
|
-
) as Ref<boolean>
|
|
88
|
-
const multiple = computed(() => group?.value.multiple.value ?? false)
|
|
80
|
+
const modelValue = getGroupOrLocalRef('modelValue', props, emit)
|
|
81
|
+
const toggle = getGroupOrLocalRef('toggle', props)
|
|
82
|
+
const unselectable = getGroupOrLocalRef('unselectable', props)
|
|
83
|
+
const multiple = computed(() => group?.multiple.value ?? false)
|
|
89
84
|
// merge local and group modifiers
|
|
90
85
|
const modifiers = computed(() => {
|
|
91
86
|
let localModifiers = props.modifiers
|
|
92
|
-
let groupModifiers = group?.
|
|
87
|
+
let groupModifiers = group?.modifiers.value
|
|
93
88
|
|
|
94
89
|
const toReturn = new Set<string>()
|
|
95
90
|
if (localModifiers) {
|
|
@@ -107,7 +102,7 @@ export function useGroupProps(
|
|
|
107
102
|
return Array.from(toReturn)
|
|
108
103
|
})
|
|
109
104
|
const disabled = computed(() =>
|
|
110
|
-
Boolean(props.disabled || group?.
|
|
105
|
+
Boolean(props.disabled || group?.disabled.value),
|
|
111
106
|
)
|
|
112
107
|
|
|
113
108
|
return {
|
|
@@ -42,10 +42,10 @@ export function useGroupProps(
|
|
|
42
42
|
const valid = getGroupOrLocalRef('valid', props) as Ref<boolean>
|
|
43
43
|
const invalid = getGroupOrLocalRef('invalid', props) as Ref<boolean>
|
|
44
44
|
const readonly = computed(() =>
|
|
45
|
-
Boolean(props.readonly || group?.
|
|
45
|
+
Boolean(props.readonly || group?.readonly.value),
|
|
46
46
|
)
|
|
47
47
|
const disabled = computed(() =>
|
|
48
|
-
Boolean(props.disabled || group?.
|
|
48
|
+
Boolean(props.disabled || group?.disabled.value),
|
|
49
49
|
)
|
|
50
50
|
|
|
51
51
|
return {
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
const { disabled, readonly, vertical, valid, invalid, modifiers } =
|
|
30
30
|
toRefs(props)
|
|
31
31
|
|
|
32
|
-
useProvideGroupState<InputGroupState>({
|
|
33
|
-
key: INJECTION_KEY_CHECK_GROUP,
|
|
32
|
+
useProvideGroupState<InputGroupState>(INJECTION_KEY_CHECK_GROUP, {
|
|
34
33
|
modelValue,
|
|
35
34
|
disabled,
|
|
36
35
|
readonly,
|