@veritree/ui 0.6.1 → 0.9.0
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/index.js +85 -51
- package/nuxt.js +21 -0
- package/package.json +1 -1
- package/src/DropdownMenu/VTDropdownMenu.vue +76 -0
- package/src/DropdownMenu/VTDropdownMenuContent.vue +92 -0
- package/src/DropdownMenu/VTDropdownMenuDivider.vue +28 -0
- package/src/DropdownMenu/VTDropdownMenuGroup.vue +9 -0
- package/src/DropdownMenu/VTDropdownMenuItem.vue +171 -0
- package/src/DropdownMenu/VTDropdownMenuLabel.vue +30 -0
- package/src/DropdownMenu/VTDropdownMenuTrigger.vue +191 -0
- package/src/Form/VTFormFeedback.vue +64 -0
- package/src/Form/VTFormGroup.vue +22 -0
- package/src/Listbox/VTListbox.vue +79 -122
- package/src/Listbox/VTListboxContent.vue +151 -0
- package/src/Listbox/VTListboxItem.vue +226 -0
- package/src/Listbox/VTListboxLabel.vue +38 -0
- package/src/Listbox/VTListboxList.vue +63 -0
- package/src/Listbox/VTListboxSearch.vue +138 -0
- package/src/Listbox/VTListboxTrigger.vue +158 -0
- package/src/Popover/VTPopover.vue +71 -0
- package/src/Popover/VTPopoverContent.vue +83 -0
- package/src/Popover/VTPopoverDivider.vue +28 -0
- package/src/Popover/VTPopoverGroup.vue +5 -0
- package/src/Popover/VTPopoverItem.vue +55 -0
- package/src/Popover/VTPopoverTrigger.vue +51 -0
- package/src/Listbox/VTListboxButton.vue +0 -81
- package/src/Listbox/VTListboxOption.vue +0 -126
- package/src/Listbox/VTListboxOptions.vue +0 -119
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
:aria-haspopup="hasPopup"
|
|
4
|
+
:aria-expanded="expanded"
|
|
5
|
+
:aria-controls="controls"
|
|
6
|
+
@keydown.down.prevent="onKeyArrowDown"
|
|
7
|
+
@keydown.up.prevent="onKeyArrowUp"
|
|
8
|
+
@keydown.esc.prevent="onKeyesc"
|
|
9
|
+
>
|
|
10
|
+
<slot></slot>
|
|
11
|
+
</div>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
15
|
+
export default {
|
|
16
|
+
name: 'VTDropdownMenuTrigger',
|
|
17
|
+
|
|
18
|
+
inject: ['api'],
|
|
19
|
+
|
|
20
|
+
data() {
|
|
21
|
+
return {
|
|
22
|
+
expanded: false,
|
|
23
|
+
hasPopup: false,
|
|
24
|
+
controls: null,
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
computed: {
|
|
29
|
+
// gets slot element
|
|
30
|
+
slotElm() {
|
|
31
|
+
return this.$slots.default[0].elm;
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
slotLength() {
|
|
35
|
+
return this.$slots.default.length;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
content() {
|
|
39
|
+
return this.api().content;
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
items() {
|
|
43
|
+
return this.api().items;
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
firstMenuItem() {
|
|
47
|
+
return this.items[0];
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
lastMenuItem() {
|
|
51
|
+
return this.items[this.items.length - 1];
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
mounted() {
|
|
56
|
+
this.api().registerTrigger(this);
|
|
57
|
+
this.addEventListenerToSlotElm();
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
destroyed() {
|
|
61
|
+
this.slotElm.removeEventListener('click', this.onClick());
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
methods: {
|
|
65
|
+
/**
|
|
66
|
+
* Add event listener to slot element
|
|
67
|
+
*
|
|
68
|
+
* The click event has to be added to the slot child element
|
|
69
|
+
* since we are not setting the onclick on the component
|
|
70
|
+
* itself.
|
|
71
|
+
*
|
|
72
|
+
* Slot must have only one child element. It avoids
|
|
73
|
+
* errors related to adding the event listener.
|
|
74
|
+
*/
|
|
75
|
+
addEventListenerToSlotElm() {
|
|
76
|
+
if (!this.slotLength) return;
|
|
77
|
+
|
|
78
|
+
if (this.slotLength > 1) {
|
|
79
|
+
throw new Error('VTPopoverButton only accepts one item in its slot');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.slotElm.addEventListener('click', (e) => {
|
|
83
|
+
e.stopImmediatePropagation();
|
|
84
|
+
this.onClick();
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Shows content/menu if not already visible
|
|
90
|
+
*/
|
|
91
|
+
showContent() {
|
|
92
|
+
if (!this.expanded) {
|
|
93
|
+
this.toggleExpanded();
|
|
94
|
+
this.content.show();
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Focus slot element if it exists and toggle expanded
|
|
100
|
+
*/
|
|
101
|
+
focus() {
|
|
102
|
+
if (!this.slotElm) return;
|
|
103
|
+
|
|
104
|
+
this.slotElm.focus();
|
|
105
|
+
this.toggleExpanded();
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Toggles aria expanded attribute/state
|
|
110
|
+
*/
|
|
111
|
+
toggleExpanded() {
|
|
112
|
+
this.expanded = !this.expanded;
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Toggles aria popup/controls attribute/state
|
|
117
|
+
*/
|
|
118
|
+
toggleHasPopup() {
|
|
119
|
+
if (!this.content) return;
|
|
120
|
+
|
|
121
|
+
this.hasPopup = !this.hasPopup;
|
|
122
|
+
|
|
123
|
+
if (!this.hasPopup) {
|
|
124
|
+
this.controls = null;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this.controls = this.content.id;
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* On click, do the following:
|
|
133
|
+
*
|
|
134
|
+
* 1. Toggle aria expanded attribute/state
|
|
135
|
+
* 2. Open the menu if it's closed
|
|
136
|
+
* 3. Close the menu if it's open
|
|
137
|
+
*/
|
|
138
|
+
onClick() {
|
|
139
|
+
if (!this.content) return;
|
|
140
|
+
|
|
141
|
+
this.toggleExpanded();
|
|
142
|
+
|
|
143
|
+
this.$nextTick(() => {
|
|
144
|
+
if (this.expanded) this.content.show();
|
|
145
|
+
else this.content.hide();
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* On key arrow down, do the following:
|
|
151
|
+
*
|
|
152
|
+
* 1. if the menu is not expanded, expand it and focus the first menu item
|
|
153
|
+
* 2. if the menu is expanded, focus the first menu item
|
|
154
|
+
*/
|
|
155
|
+
onKeyArrowDown() {
|
|
156
|
+
if (!this.content) return;
|
|
157
|
+
|
|
158
|
+
this.showContent();
|
|
159
|
+
|
|
160
|
+
this.$nextTick(() => {
|
|
161
|
+
this.firstMenuItem.focus();
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* On key arrow up, do the following:
|
|
167
|
+
*
|
|
168
|
+
* 1. if the menu is not expanded, expand it and focus the last menu item
|
|
169
|
+
* 2. if the menu is expanded, focus the last menu item
|
|
170
|
+
*/
|
|
171
|
+
onKeyArrowUp() {
|
|
172
|
+
if (!this.content) return;
|
|
173
|
+
|
|
174
|
+
this.showContent();
|
|
175
|
+
|
|
176
|
+
this.$nextTick(() => {
|
|
177
|
+
this.lastMenuItem.focus();
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
onKeyesc() {
|
|
182
|
+
if (!this.content) return;
|
|
183
|
+
|
|
184
|
+
if (this.expanded) {
|
|
185
|
+
this.toggleExpanded();
|
|
186
|
+
this.content.hide();
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
</script>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="form-feedback" :class="classes">
|
|
3
|
+
<component :is="icon" v-if="showIcon" />
|
|
4
|
+
<span class="text-gray-500"><slot></slot></span>
|
|
5
|
+
</div>
|
|
6
|
+
</template>
|
|
7
|
+
|
|
8
|
+
<script>
|
|
9
|
+
import { IconCheck, IconWarning } from '@veritree/icons';
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
name: 'VTFormFeedback',
|
|
13
|
+
|
|
14
|
+
components: {
|
|
15
|
+
IconWarning,
|
|
16
|
+
IconCheck,
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
props: {
|
|
20
|
+
variant: {
|
|
21
|
+
type: [String, Object],
|
|
22
|
+
default: '',
|
|
23
|
+
validator(value) {
|
|
24
|
+
if (value === '' || typeof value === 'object') {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return ['success', 'warning', 'error'].includes(value);
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
hideIcon: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: false,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
computed: {
|
|
38
|
+
classes() {
|
|
39
|
+
const classes = {};
|
|
40
|
+
|
|
41
|
+
if (this.variant) {
|
|
42
|
+
classes[`form-feedback--${this.variant}`] = true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return classes;
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
icon() {
|
|
49
|
+
if (this.variant === 'success') return IconCheck;
|
|
50
|
+
return IconWarning;
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
showIcon() {
|
|
54
|
+
return !this.hideIcon;
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
methods: {
|
|
59
|
+
onClick() {
|
|
60
|
+
this.$emit('click');
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
</script>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<component :is="as" :class="classes" class="form-group">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</component>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
export default {
|
|
9
|
+
props: {
|
|
10
|
+
as: {
|
|
11
|
+
type: String,
|
|
12
|
+
default: 'div',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
data() {
|
|
17
|
+
return {
|
|
18
|
+
classes: {},
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
</script>
|
|
@@ -1,150 +1,73 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="Listbox"
|
|
2
|
+
<div :class="{ Listbox: headless, relative: !headless, 'z-20': active }">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</div>
|
|
3
5
|
</template>
|
|
4
6
|
|
|
5
7
|
<script>
|
|
8
|
+
import { genId } from '~/utils/ids';
|
|
9
|
+
|
|
6
10
|
export default {
|
|
7
11
|
name: 'VTListbox',
|
|
8
12
|
|
|
9
13
|
provide() {
|
|
10
14
|
return {
|
|
11
15
|
api: () => {
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const getListboxValue = () => this.value;
|
|
15
|
-
const getListboxButton = () => this.listboxButton;
|
|
16
|
-
|
|
17
|
-
// Handle registering and unregistering
|
|
18
|
-
const registerListboxButton = (button) => {
|
|
19
|
-
if (!button) return;
|
|
20
|
-
this.listboxButton = button;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const registerListbox = (listbox) => {
|
|
24
|
-
if (!listbox) return;
|
|
25
|
-
this.listbox = listbox;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const registerOption = (option) => {
|
|
29
|
-
if (!option) return;
|
|
30
|
-
_register(this.listboxOptions, option);
|
|
31
|
-
};
|
|
16
|
+
const { dark: isDark, right: isRight } = this;
|
|
17
|
+
const { id, listbox, trigger, content, search, list, items } = this;
|
|
32
18
|
|
|
33
|
-
const
|
|
34
|
-
|
|
19
|
+
const registerTrigger = (trigger) => {
|
|
20
|
+
if (!trigger) return;
|
|
21
|
+
this.trigger = trigger;
|
|
35
22
|
};
|
|
36
23
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
const registerContent = (content) => {
|
|
25
|
+
if (!content) return;
|
|
26
|
+
this.content = content;
|
|
40
27
|
};
|
|
41
28
|
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
const registerSearch = (search) => {
|
|
30
|
+
if (!search) return;
|
|
31
|
+
this.search = search;
|
|
45
32
|
};
|
|
46
33
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.listboxOptions.forEach((option, i) => {
|
|
52
|
-
if (option.focused) index = i;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return index;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const focusOptionByFilter = (filter) => {
|
|
59
|
-
const optionIndex = this.listboxOptions.findIndex((option) => {
|
|
60
|
-
const text = option.$el.innerText;
|
|
61
|
-
return text.toLowerCase().indexOf(filter.toLowerCase()) === 0;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
if (optionIndex >= 0) _focusOption(optionIndex);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const focusFirstOption = () => {
|
|
68
|
-
_focusOption(0);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const focusLastOption = () => {
|
|
72
|
-
_focusOption(this.listboxOptions.length - 1);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const focusPreviousOption = () => {
|
|
76
|
-
const focusedIndex = getFocusedIndex();
|
|
77
|
-
const previousIndex = focusedIndex - 1;
|
|
78
|
-
|
|
79
|
-
if (previousIndex >= 0) _focusOption(previousIndex);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const focusNextOption = () => {
|
|
83
|
-
const focusedIndex = getFocusedIndex();
|
|
84
|
-
const nextIndex = focusedIndex + 1;
|
|
85
|
-
|
|
86
|
-
if (nextIndex < this.listboxOptions.length) _focusOption(nextIndex);
|
|
34
|
+
const registerList = (list) => {
|
|
35
|
+
if (!list) return;
|
|
36
|
+
this.list = list;
|
|
87
37
|
};
|
|
88
38
|
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
39
|
+
const registerItem = (item) => {
|
|
40
|
+
if (!item) return;
|
|
41
|
+
this.items.push(item);
|
|
93
42
|
};
|
|
94
43
|
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
this.
|
|
44
|
+
const unregisterItem = (id) => {
|
|
45
|
+
const index = this.items.findIndex((item) => item.id === id);
|
|
46
|
+
this.items.splice(index, 1);
|
|
98
47
|
};
|
|
99
48
|
|
|
100
|
-
const
|
|
101
|
-
return this.listboxOptions.filter((option) => option.focused)[0];
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// handle selecting and unselecting
|
|
105
|
-
const selectOption = () => {
|
|
106
|
-
const focusedOption = _getFocusedOption();
|
|
107
|
-
|
|
108
|
-
// do nothing if option is already selected
|
|
109
|
-
if (focusedOption.selected) return;
|
|
110
|
-
|
|
111
|
-
// unselect all options
|
|
112
|
-
this.listboxOptions.forEach((option) => option.unselect());
|
|
113
|
-
|
|
114
|
-
// select focused option
|
|
115
|
-
if (focusedOption) {
|
|
116
|
-
focusedOption.select();
|
|
117
|
-
_onSelectedOption(focusedOption.value);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const _onSelectedOption = (value) => {
|
|
122
|
-
this.listbox.hide();
|
|
49
|
+
const emit = (value) => {
|
|
123
50
|
this.$emit('input', value);
|
|
124
|
-
this.$emit('change');
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// Index helper functions
|
|
128
|
-
const _getIndex = (arr, id) => {
|
|
129
|
-
return arr.findIndex((item) => item.id === id);
|
|
51
|
+
this.$emit('change', value);
|
|
130
52
|
};
|
|
131
53
|
|
|
132
54
|
return {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
55
|
+
id,
|
|
56
|
+
isDark,
|
|
57
|
+
isRight,
|
|
58
|
+
listbox,
|
|
59
|
+
trigger,
|
|
60
|
+
search,
|
|
61
|
+
content,
|
|
62
|
+
list,
|
|
63
|
+
items,
|
|
64
|
+
registerTrigger,
|
|
65
|
+
registerContent,
|
|
66
|
+
registerSearch,
|
|
67
|
+
registerList,
|
|
68
|
+
registerItem,
|
|
69
|
+
unregisterItem,
|
|
70
|
+
emit,
|
|
148
71
|
};
|
|
149
72
|
},
|
|
150
73
|
};
|
|
@@ -155,14 +78,48 @@ export default {
|
|
|
155
78
|
type: [String, Number, Object],
|
|
156
79
|
default: null,
|
|
157
80
|
},
|
|
81
|
+
headless: {
|
|
82
|
+
type: Boolean,
|
|
83
|
+
default: false,
|
|
84
|
+
},
|
|
85
|
+
dark: {
|
|
86
|
+
type: Boolean,
|
|
87
|
+
default: false,
|
|
88
|
+
},
|
|
89
|
+
right: {
|
|
90
|
+
type: Boolean,
|
|
91
|
+
default: false,
|
|
92
|
+
},
|
|
158
93
|
},
|
|
159
94
|
|
|
160
95
|
data() {
|
|
161
96
|
return {
|
|
97
|
+
id: `listbox-${genId()}`,
|
|
162
98
|
listbox: null,
|
|
163
|
-
|
|
164
|
-
|
|
99
|
+
trigger: null,
|
|
100
|
+
content: null,
|
|
101
|
+
search: null,
|
|
102
|
+
list: null,
|
|
103
|
+
items: [],
|
|
104
|
+
active: false,
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
mounted() {
|
|
109
|
+
this.listbox = {
|
|
110
|
+
setActive: this.setActive,
|
|
111
|
+
clearActive: this.clearActive,
|
|
165
112
|
};
|
|
166
113
|
},
|
|
114
|
+
|
|
115
|
+
methods: {
|
|
116
|
+
setActive() {
|
|
117
|
+
this.active = true;
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
clearActive() {
|
|
121
|
+
this.active = null;
|
|
122
|
+
},
|
|
123
|
+
},
|
|
167
124
|
};
|
|
168
125
|
</script>
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<transition
|
|
3
|
+
enter-active-class="duration-200 ease-out"
|
|
4
|
+
enter-class="translate-y-[15px] opacity-0"
|
|
5
|
+
enter-to-class="translate-y-0 opacity-100"
|
|
6
|
+
leave-active-class="duration-200 ease-in"
|
|
7
|
+
leave-class="translate-y-0 opacity-100"
|
|
8
|
+
leave-to-class="translate-y-[15px] opacity-0"
|
|
9
|
+
@after-leave="hide"
|
|
10
|
+
>
|
|
11
|
+
<div
|
|
12
|
+
v-if="visible"
|
|
13
|
+
:id="id"
|
|
14
|
+
:aria-activedescendant="activeDescedant"
|
|
15
|
+
:class="{
|
|
16
|
+
MenuList: headless,
|
|
17
|
+
'absolute z-10 grid w-full min-w-[222px] overflow-hidden rounded-md py-2 px-3':
|
|
18
|
+
!headless,
|
|
19
|
+
'border-gray-100 bg-white shadow-300': !dark && !headless,
|
|
20
|
+
'bg-forest-default border border-solid border-gray-700 shadow-gray-700':
|
|
21
|
+
dark && !headless,
|
|
22
|
+
'left-0': !right && !headless,
|
|
23
|
+
'right-0': right && !headless,
|
|
24
|
+
'top-full mt-3': isTop && !headless,
|
|
25
|
+
'bottom-full mb-3': isBottom && !headless,
|
|
26
|
+
}"
|
|
27
|
+
role="listbox"
|
|
28
|
+
>
|
|
29
|
+
<slot></slot>
|
|
30
|
+
</div>
|
|
31
|
+
</transition>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<script>
|
|
35
|
+
import { genId } from '~/utils/ids';
|
|
36
|
+
|
|
37
|
+
export default {
|
|
38
|
+
name: 'VTListboxContent',
|
|
39
|
+
|
|
40
|
+
inject: ['api'],
|
|
41
|
+
|
|
42
|
+
props: {
|
|
43
|
+
headless: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: false,
|
|
46
|
+
},
|
|
47
|
+
bottom: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
default: false,
|
|
50
|
+
},
|
|
51
|
+
top: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: true,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
data() {
|
|
58
|
+
return {
|
|
59
|
+
id: `listboxcontent-${genId()}`,
|
|
60
|
+
activeDescedant: null,
|
|
61
|
+
visible: false,
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
computed: {
|
|
66
|
+
dark() {
|
|
67
|
+
return this.api().isDark;
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
right() {
|
|
71
|
+
return this.api().isRight;
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
listbox() {
|
|
75
|
+
return this.api().listbox;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
trigger() {
|
|
79
|
+
return this.api().trigger;
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
search() {
|
|
83
|
+
return this.api().search;
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
// directions
|
|
87
|
+
isTop() {
|
|
88
|
+
return this.top && !this.bottom;
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
isBottom() {
|
|
92
|
+
return this.bottom;
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
mounted() {
|
|
97
|
+
const content = {
|
|
98
|
+
id: this.id,
|
|
99
|
+
show: this.show,
|
|
100
|
+
hide: this.hide,
|
|
101
|
+
setActiveDescedant: this.setActiveDescedant,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
this.api().registerContent(content);
|
|
105
|
+
|
|
106
|
+
// TODO: Create a directive or mixin for this
|
|
107
|
+
document.addEventListener('click', (e) => {
|
|
108
|
+
e.stopPropagation();
|
|
109
|
+
if (this.visible && !this.$el.contains(e.target)) this.trigger.onClick();
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
destroyed() {
|
|
114
|
+
// TODO: Create a directive or mixin for this
|
|
115
|
+
document.removeEventListener('click', this.trigger.onClick());
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
methods: {
|
|
119
|
+
show() {
|
|
120
|
+
if (this.visible) return;
|
|
121
|
+
|
|
122
|
+
this.visible = true;
|
|
123
|
+
|
|
124
|
+
this.$nextTick(() => {
|
|
125
|
+
this.listbox.setActive();
|
|
126
|
+
|
|
127
|
+
if (this.search) this.search.el.focus();
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
hide() {
|
|
132
|
+
if (!this.visible) return;
|
|
133
|
+
|
|
134
|
+
this.visible = false;
|
|
135
|
+
|
|
136
|
+
this.$nextTick(() => {
|
|
137
|
+
this.trigger.focus();
|
|
138
|
+
|
|
139
|
+
setTimeout(() => {
|
|
140
|
+
this.listbox.clearActive();
|
|
141
|
+
this.trigger.contract();
|
|
142
|
+
}, 100);
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
setActiveDescedant(id) {
|
|
147
|
+
this.activeDescedant = id;
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
</script>
|