@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.
Files changed (29) hide show
  1. package/mixins/floating-ui-content.js +102 -0
  2. package/mixins/floating-ui-item.js +216 -0
  3. package/mixins/floating-ui.js +14 -6
  4. package/mixins/form-control.js +72 -0
  5. package/package.json +2 -2
  6. package/src/components/Avatar/VTAvatar.vue +32 -29
  7. package/src/components/DropdownMenu/VTDropdownMenu.vue +5 -16
  8. package/src/components/DropdownMenu/VTDropdownMenuContent.vue +17 -65
  9. package/src/components/DropdownMenu/VTDropdownMenuDivider.vue +8 -5
  10. package/src/components/DropdownMenu/VTDropdownMenuItem.vue +9 -143
  11. package/src/components/DropdownMenu/VTDropdownMenuLabel.vue +3 -3
  12. package/src/components/DropdownMenu/VTDropdownMenuTrigger.vue +67 -103
  13. package/src/components/Form/VTInput.vue +28 -40
  14. package/src/components/Form/VTInputQty.vue +165 -0
  15. package/src/components/Form/VTTextarea.vue +22 -0
  16. package/src/components/Listbox/VTListbox.vue +6 -11
  17. package/src/components/Listbox/VTListboxContent.vue +11 -76
  18. package/src/components/Listbox/VTListboxItem.vue +9 -181
  19. package/src/components/Listbox/VTListboxLabel.vue +0 -10
  20. package/src/components/Listbox/VTListboxList.vue +24 -33
  21. package/src/components/Listbox/VTListboxSearch.vue +21 -18
  22. package/src/components/Listbox/VTListboxTrigger.vue +58 -97
  23. package/src/components/Popover/VTPopover.vue +1 -14
  24. package/src/components/Popover/VTPopoverContent.vue +14 -65
  25. package/src/components/Popover/VTPopoverDivider.vue +4 -11
  26. package/src/components/Popover/VTPopoverItem.vue +16 -13
  27. package/src/components/Popover/VTPopoverTrigger.vue +118 -21
  28. package/src/components/Utils/FloatingUi.vue +6 -1
  29. package/src/utils/components.js +0 -18
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div :id="id" @keydown.esc.prevent="onEsc">
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: ['api'],
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.api().id}`;
24
+ return `popover-trigger-${this.apiPopover().id}`;
16
25
  },
17
26
 
18
27
  componentContent() {
19
- return this.api().componentContent;
28
+ return this.apiPopover().componentContent;
20
29
  },
21
30
  },
22
31
 
23
32
  mounted() {
24
- this.api().registerTrigger(this);
25
- this.handleSlotTrigger();
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
- handleSlotTrigger() {
30
- const slot = this.$slots.default;
31
- const trigger = slot[0].elm;
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
- if (slot.length > 1) {
34
- console.error('VTPopoverButton only accepts one item in its slot');
71
+ init(e) {
72
+ if (!this.componentContent) {
35
73
  return;
36
74
  }
37
75
 
38
- trigger.addEventListener('click', (e) => {
39
- this.onClick();
40
- e.stopPropagation();
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.$el.focus();
101
+ if (this.trigger) this.trigger.focus();
46
102
  },
47
103
 
48
- onClick() {
49
- if (this.componentContent.visible) this.componentContent.hide();
50
- else this.componentContent.show();
104
+ showComponentContent() {
105
+ this.componentContent.show();
51
106
  },
52
107
 
53
- onEsc() {
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 min-w-[222px] overflow-hidden rounded-md py-2 px-3 border-gray-100 bg-white shadow-300',
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: {
@@ -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
- };