@volverjs/ui-vue 0.0.10-beta.22 → 0.0.10-beta.24
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 +250 -119
- package/dist/components/VvAccordionGroup/VvAccordionGroup.umd.js +1 -1
- package/dist/components/VvAccordionGroup/VvAccordionGroup.vue.d.ts +18 -6
- package/dist/components/VvAccordionGroup/index.d.ts +3 -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 +199 -169
- package/dist/components/VvInputFile/VvInputFile.umd.js +1 -1
- package/dist/components/VvInputFile/VvInputFile.vue.d.ts +55 -9
- package/dist/components/VvInputFile/index.d.ts +24 -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 +478 -324
- 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 +38 -14
- package/dist/stories/AccordionGroup/AccordionGroupSlots.stories.d.ts +259 -101
- 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 +140 -41
- package/src/components/VvAccordionGroup/index.ts +3 -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 +72 -47
- package/src/components/VvInputFile/index.ts +22 -3
- 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.test.ts +15 -9
- 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,8 +5,11 @@
|
|
|
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 '.'
|
|
@@ -16,67 +19,157 @@
|
|
|
16
19
|
const emit = defineEmits(VvAccordionGroupEvents)
|
|
17
20
|
|
|
18
21
|
// data
|
|
19
|
-
const { disabled,
|
|
20
|
-
toRefs(props)
|
|
22
|
+
const { disabled, modifiers, itemModifiers, items } = toRefs(props)
|
|
21
23
|
watchEffect(() => {
|
|
22
|
-
if (typeof props.modelValue === 'string' && collapse
|
|
23
|
-
// eslint-disable-next-line
|
|
24
|
+
if (typeof props.modelValue === 'string' && props.collapse) {
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
24
26
|
console.warn(
|
|
25
27
|
`[VvAccordionGroup]: modelValue is a string but collapse is true.`,
|
|
26
28
|
)
|
|
27
29
|
}
|
|
28
30
|
})
|
|
29
|
-
|
|
31
|
+
|
|
32
|
+
const accordionNames = reactive(new Set<string>())
|
|
33
|
+
let modelValue = ref(new Set<string>())
|
|
30
34
|
watch(
|
|
31
35
|
() => props.storeKey,
|
|
32
|
-
(newKey) => {
|
|
36
|
+
(newKey, oldKey) => {
|
|
37
|
+
if (oldKey && oldKey !== newKey) {
|
|
38
|
+
localStorage.removeItem(oldKey)
|
|
39
|
+
}
|
|
33
40
|
if (newKey) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
localModelValue = ref([])
|
|
41
|
+
modelValue = useLocalStorage(newKey, modelValue.value)
|
|
42
|
+
return
|
|
37
43
|
}
|
|
44
|
+
modelValue = ref(new Set<string>(modelValue.value))
|
|
38
45
|
},
|
|
39
46
|
{ immediate: true },
|
|
40
47
|
)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
watch(
|
|
49
|
+
[modelValue, accordionNames, () => props.not, () => props.collapse],
|
|
50
|
+
() => {
|
|
51
|
+
if (props.not) {
|
|
52
|
+
emit(
|
|
53
|
+
'update:modelValue',
|
|
54
|
+
[...accordionNames].filter(
|
|
55
|
+
(name) => !modelValue.value.has(name),
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
return
|
|
50
59
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
if (props.collapse) {
|
|
61
|
+
emit('update:modelValue', [...modelValue.value])
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
emit('update:modelValue', modelValue.value.values().next().value)
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
deep: true,
|
|
68
|
+
immediate: true,
|
|
54
69
|
},
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
70
|
+
)
|
|
71
|
+
watch(
|
|
72
|
+
() => props.modelValue,
|
|
73
|
+
(newValue, oldValue) => {
|
|
74
|
+
if (
|
|
75
|
+
newValue === undefined ||
|
|
76
|
+
newValue === null ||
|
|
77
|
+
JSON.stringify(newValue) === JSON.stringify(oldValue)
|
|
78
|
+
) {
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
let toReturn = new Set<string>()
|
|
82
|
+
if (props.not) {
|
|
83
|
+
if (typeof newValue === 'string') {
|
|
84
|
+
toReturn = new Set<string>(
|
|
85
|
+
[...accordionNames].filter((name) => name !== newValue),
|
|
86
|
+
)
|
|
87
|
+
} else if (Array.isArray(newValue)) {
|
|
88
|
+
toReturn = new Set<string>(
|
|
89
|
+
[...accordionNames].filter(
|
|
90
|
+
(name) => !newValue.includes(name),
|
|
91
|
+
),
|
|
92
|
+
)
|
|
62
93
|
}
|
|
63
|
-
|
|
94
|
+
} else if (typeof newValue === 'string') {
|
|
95
|
+
toReturn = new Set<string>([newValue])
|
|
96
|
+
} else if (Array.isArray(newValue)) {
|
|
97
|
+
toReturn = new Set<string>(newValue)
|
|
98
|
+
}
|
|
99
|
+
for (const name of accordionNames) {
|
|
100
|
+
bus.emit('toggle', { name, value: toReturn.has(name) })
|
|
64
101
|
}
|
|
65
|
-
|
|
66
|
-
? newValue
|
|
67
|
-
: [newValue]
|
|
102
|
+
modelValue.value = toReturn
|
|
68
103
|
},
|
|
69
|
-
|
|
104
|
+
{
|
|
105
|
+
immediate: true,
|
|
106
|
+
},
|
|
107
|
+
)
|
|
70
108
|
|
|
71
109
|
// provide
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
modelValue,
|
|
110
|
+
const bus = mitt<AccordionGroupBusEvents>()
|
|
111
|
+
useProvideGroupState<AccordionGroupState>(INJECTION_KEY_ACCORDION_GROUP, {
|
|
75
112
|
disabled,
|
|
76
|
-
collapse,
|
|
77
113
|
modifiers: itemModifiers,
|
|
78
|
-
|
|
114
|
+
bus,
|
|
115
|
+
})
|
|
116
|
+
bus.on('register', ({ name }) => {
|
|
117
|
+
accordionNames.add(name)
|
|
79
118
|
})
|
|
119
|
+
bus.on('unregister', ({ name }) => {
|
|
120
|
+
accordionNames.delete(name)
|
|
121
|
+
})
|
|
122
|
+
bus.on('toggle', ({ name, value }) => {
|
|
123
|
+
if (value) {
|
|
124
|
+
if (!props.collapse) {
|
|
125
|
+
for (const item of modelValue.value) {
|
|
126
|
+
if (item !== name) {
|
|
127
|
+
bus.emit('toggle', { name: item, value: false })
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
modelValue.value.clear()
|
|
131
|
+
}
|
|
132
|
+
modelValue.value.add(name)
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
modelValue.value.delete(name)
|
|
136
|
+
})
|
|
137
|
+
const expand = (name?: string | string[]) => {
|
|
138
|
+
if (typeof name === 'string') {
|
|
139
|
+
bus.emit('toggle', { name, value: true })
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
if (Array.isArray(name)) {
|
|
143
|
+
for (const item of name) {
|
|
144
|
+
bus.emit('toggle', { name: item, value: true })
|
|
145
|
+
}
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
for (const item of accordionNames) {
|
|
149
|
+
bus.emit('toggle', { name: item, value: true })
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
bus.on('expand', ({ name }) => expand(name))
|
|
153
|
+
|
|
154
|
+
const collapse = (name?: string | string[]) => {
|
|
155
|
+
if (typeof name === 'string') {
|
|
156
|
+
bus.emit('toggle', { name, value: false })
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
if (Array.isArray(name)) {
|
|
160
|
+
for (const item of name) {
|
|
161
|
+
bus.emit('toggle', { name: item, value: false })
|
|
162
|
+
}
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
for (const item of accordionNames) {
|
|
166
|
+
bus.emit('toggle', { name: item, value: false })
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
bus.on('collapse', ({ name }) => collapse(name))
|
|
170
|
+
|
|
171
|
+
// expose
|
|
172
|
+
defineExpose({ modelValue, expand, collapse })
|
|
80
173
|
|
|
81
174
|
// styles
|
|
82
175
|
const bemCssClasses = useModifiers(
|
|
@@ -91,7 +184,13 @@
|
|
|
91
184
|
<template>
|
|
92
185
|
<div :class="bemCssClasses">
|
|
93
186
|
<!-- @slot Default slot -->
|
|
94
|
-
<slot
|
|
187
|
+
<slot
|
|
188
|
+
v-bind="{
|
|
189
|
+
modelValue,
|
|
190
|
+
expand,
|
|
191
|
+
collapse,
|
|
192
|
+
}"
|
|
193
|
+
>
|
|
95
194
|
<VvAccordion
|
|
96
195
|
v-for="item in items"
|
|
97
196
|
:key="item.title"
|
|
@@ -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,
|