@veritree/ui 0.21.1-0 → 0.21.1-10
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/mixins/floating-ui-content.js +102 -0
- package/mixins/floating-ui-item.js +216 -0
- package/mixins/floating-ui.js +14 -6
- package/mixins/form-control.js +72 -0
- package/package.json +2 -2
- package/src/components/Avatar/VTAvatar.vue +32 -29
- package/src/components/DropdownMenu/VTDropdownMenu.vue +5 -16
- package/src/components/DropdownMenu/VTDropdownMenuContent.vue +17 -65
- package/src/components/DropdownMenu/VTDropdownMenuDivider.vue +8 -5
- package/src/components/DropdownMenu/VTDropdownMenuItem.vue +9 -143
- package/src/components/DropdownMenu/VTDropdownMenuLabel.vue +3 -3
- package/src/components/DropdownMenu/VTDropdownMenuTrigger.vue +67 -103
- package/src/components/Form/VTInput.vue +28 -40
- package/src/components/Form/VTInputQty.vue +165 -0
- package/src/components/Form/VTTextarea.vue +22 -0
- package/src/components/Listbox/VTListbox.vue +6 -11
- package/src/components/Listbox/VTListboxContent.vue +11 -76
- package/src/components/Listbox/VTListboxItem.vue +9 -181
- package/src/components/Listbox/VTListboxLabel.vue +0 -10
- package/src/components/Listbox/VTListboxList.vue +24 -33
- package/src/components/Listbox/VTListboxSearch.vue +21 -18
- package/src/components/Listbox/VTListboxTrigger.vue +58 -97
- package/src/components/Popover/VTPopover.vue +1 -14
- package/src/components/Popover/VTPopoverContent.vue +14 -65
- package/src/components/Popover/VTPopoverDivider.vue +4 -11
- package/src/components/Popover/VTPopoverItem.vue +16 -13
- package/src/components/Popover/VTPopoverTrigger.vue +118 -21
- package/src/components/Utils/FloatingUi.vue +6 -1
- package/src/utils/components.js +0 -18
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div :id="id" @keydown.esc.prevent="
|
|
2
|
+
<div :id="id" @keydown.esc.prevent="onKeyEsc">
|
|
3
3
|
<slot></slot>
|
|
4
4
|
</div>
|
|
5
5
|
</template>
|
|
@@ -8,52 +8,149 @@
|
|
|
8
8
|
export default {
|
|
9
9
|
name: 'VTPopoverTrigger',
|
|
10
10
|
|
|
11
|
-
inject: ['
|
|
11
|
+
inject: ['apiPopover'],
|
|
12
|
+
|
|
13
|
+
data() {
|
|
14
|
+
return {
|
|
15
|
+
expanded: false,
|
|
16
|
+
hasPopup: false,
|
|
17
|
+
controls: null,
|
|
18
|
+
trigger: null,
|
|
19
|
+
};
|
|
20
|
+
},
|
|
12
21
|
|
|
13
22
|
computed: {
|
|
14
23
|
id() {
|
|
15
|
-
return `popover-trigger-${this.
|
|
24
|
+
return `popover-trigger-${this.apiPopover().id}`;
|
|
16
25
|
},
|
|
17
26
|
|
|
18
27
|
componentContent() {
|
|
19
|
-
return this.
|
|
28
|
+
return this.apiPopover().componentContent;
|
|
20
29
|
},
|
|
21
30
|
},
|
|
22
31
|
|
|
23
32
|
mounted() {
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
const trigger = {
|
|
34
|
+
id: this.id,
|
|
35
|
+
el: this.$el,
|
|
36
|
+
cancel: this.cancel,
|
|
37
|
+
focus: this.focus,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
this.apiPopover().registerTrigger(trigger);
|
|
41
|
+
|
|
42
|
+
this.setTrigger();
|
|
43
|
+
this.addTriggerEvents();
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
destroyed() {
|
|
47
|
+
this.trigger.removeEventListener('click', this.onClick);
|
|
26
48
|
},
|
|
27
49
|
|
|
28
50
|
methods: {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
51
|
+
setTrigger() {
|
|
52
|
+
this.trigger = this.$el.querySelector(':first-child');
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Add event listener to slot element
|
|
57
|
+
*
|
|
58
|
+
* The click event has to be added to the slot child element
|
|
59
|
+
* since we are not setting the onclick on the component
|
|
60
|
+
* itself.
|
|
61
|
+
*
|
|
62
|
+
* Slot must have only one child element. It avoids
|
|
63
|
+
* errors related to adding the event listener.
|
|
64
|
+
*/
|
|
65
|
+
addTriggerEvents() {
|
|
66
|
+
this.trigger.addEventListener('click', (e) => {
|
|
67
|
+
this.onClick(e);
|
|
68
|
+
});
|
|
69
|
+
},
|
|
32
70
|
|
|
33
|
-
|
|
34
|
-
|
|
71
|
+
init(e) {
|
|
72
|
+
if (!this.componentContent) {
|
|
35
73
|
return;
|
|
36
74
|
}
|
|
37
75
|
|
|
38
|
-
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
}
|
|
76
|
+
if (this.expanded) {
|
|
77
|
+
this.cancel();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.expanded = true;
|
|
82
|
+
|
|
83
|
+
// delay stop propagation to close other visible
|
|
84
|
+
// dropdowns and delay click event to control
|
|
85
|
+
// this dropdown visibility
|
|
86
|
+
setTimeout(() => e.stopImmediatePropagation(), 50);
|
|
87
|
+
setTimeout(() => this.showComponentContent(), 100);
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
cancel() {
|
|
91
|
+
if (!this.componentContent) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.expanded = false;
|
|
96
|
+
|
|
97
|
+
this.hideComponentContent();
|
|
42
98
|
},
|
|
43
99
|
|
|
44
100
|
focus() {
|
|
45
|
-
this
|
|
101
|
+
if (this.trigger) this.trigger.focus();
|
|
46
102
|
},
|
|
47
103
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
else this.componentContent.show();
|
|
104
|
+
showComponentContent() {
|
|
105
|
+
this.componentContent.show();
|
|
51
106
|
},
|
|
52
107
|
|
|
53
|
-
|
|
54
|
-
if (!this.componentContent) return;
|
|
108
|
+
hideComponentContent() {
|
|
55
109
|
this.componentContent.hide();
|
|
56
110
|
},
|
|
111
|
+
|
|
112
|
+
toggleAriaHasPopup() {
|
|
113
|
+
if (this.expanded) {
|
|
114
|
+
this.hasPopup = this.componentContent !== null;
|
|
115
|
+
this.controls = this.hasPopup ? this.componentContent.id : null;
|
|
116
|
+
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
this.hasPopup = null;
|
|
121
|
+
this.controls = null;
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
onClick(e) {
|
|
125
|
+
this.init(e);
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
onKeyDownOrUp(e) {
|
|
129
|
+
if (!this.expanded) {
|
|
130
|
+
this.$el.click(e);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const keyCode = e.code;
|
|
134
|
+
const listItemPosition =
|
|
135
|
+
keyCode === 'ArrowDown'
|
|
136
|
+
? 'firstMenuItem'
|
|
137
|
+
: keyCode === 'ArrowUp'
|
|
138
|
+
? 'lastMenuItem'
|
|
139
|
+
: null;
|
|
140
|
+
|
|
141
|
+
// settimeout here is delaying the focusing the element
|
|
142
|
+
// since it is not rendered yet. All items will only
|
|
143
|
+
// be available when the content is fully visible.
|
|
144
|
+
this.$nextTick(() => {
|
|
145
|
+
setTimeout(() => this[listItemPosition].focus(), 100);
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
// change it to a better name or move the methods inside to another function
|
|
150
|
+
onKeyEsc() {
|
|
151
|
+
this.cancel();
|
|
152
|
+
this.focus();
|
|
153
|
+
},
|
|
57
154
|
},
|
|
58
155
|
};
|
|
59
156
|
</script>
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
:class="[
|
|
16
16
|
headless
|
|
17
17
|
? null
|
|
18
|
-
: 'absolute z-50 grid
|
|
18
|
+
: 'absolute z-50 grid overflow-x-hidden rounded-md py-2 px-3 border-gray-100 bg-white shadow-300',
|
|
19
|
+
floatingUiClass ? floatingUiClass : null,
|
|
19
20
|
]"
|
|
20
21
|
>
|
|
21
22
|
<slot></slot>
|
|
@@ -45,6 +46,10 @@ export default {
|
|
|
45
46
|
type: Boolean,
|
|
46
47
|
default: false,
|
|
47
48
|
},
|
|
49
|
+
floatingUiClass: {
|
|
50
|
+
type: [String, Function],
|
|
51
|
+
default: null,
|
|
52
|
+
},
|
|
48
53
|
},
|
|
49
54
|
|
|
50
55
|
methods: {
|
package/src/utils/components.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param {HTMLElement} el
|
|
4
|
-
* @param {HTMLElement} parent
|
|
5
|
-
*/
|
|
6
|
-
export const scrollElementIntoView = (el, parent) => {
|
|
7
|
-
// this works better than scrollIntoView
|
|
8
|
-
if (parent.scrollHeight <= parent.clientHeight) return;
|
|
9
|
-
|
|
10
|
-
const scrollBottom = parent.clientHeight + parent.scrollTop;
|
|
11
|
-
const elBottom = el.offsetTop + el.offsetHeight;
|
|
12
|
-
|
|
13
|
-
if (elBottom > scrollBottom) {
|
|
14
|
-
parent.scrollTop = elBottom - parent.clientHeight;
|
|
15
|
-
} else if (el.offsetTop < parent.scrollTop) {
|
|
16
|
-
parent.scrollTop = el.offsetTop;
|
|
17
|
-
}
|
|
18
|
-
};
|