@veritree/ui 0.67.1 → 0.68.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/ui",
3
- "version": "0.67.1",
3
+ "version": "0.68.0",
4
4
  "description": "veritree ui library",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <span
3
3
  :id="id"
4
- :class="[headless ? 'dialog-header' : 'text-2xl font-semibold']"
4
+ :class="[headless ? 'dialog-header' : 'text-xl font-semibold']"
5
5
  >
6
6
  <slot></slot
7
7
  ></span>
@@ -1,34 +1,47 @@
1
1
  <template>
2
- <div
3
- :class="[
4
- headless ? 'listbox-highlight' : 'relative',
5
- headless
6
- ? isActive
7
- ? 'listbox-highlight--active'
8
- : null
9
- : isActive
10
- ? '[&>*]:border-gray-700'
11
- : null,
12
- ]"
13
- >
14
- <span
15
- v-show="isBadgeVisible"
2
+ <div>
3
+ <div
4
+ :id="highlightId"
16
5
  :class="[
6
+ headless ? 'listbox-highlight' : 'relative',
17
7
  headless
18
- ? 'listbox-highlight__badge'
19
- : 'absolute -right-2 -top-2 z-10 grid h-5 min-w-[20px] place-content-center rounded-full bg-gray-800 text-xs font-medium text-white',
8
+ ? isActive
9
+ ? 'listbox-highlight--active'
10
+ : null
11
+ : isActive
12
+ ? '[&>*]:border-gray-700'
13
+ : null,
20
14
  ]"
21
15
  >
22
- {{ valueLength }}
23
- </span>
24
- <slot />
16
+ <slot />
17
+ </div>
18
+ <Portal>
19
+ <span
20
+ :id="counterId"
21
+ v-show="isBadgeVisible"
22
+ :class="[
23
+ headless
24
+ ? 'listbox-highlight__badge'
25
+ : 'absolute z-40 grid h-5 min-w-[20px] place-content-center rounded-full bg-gray-800 text-xs font-medium text-white',
26
+ ]"
27
+ >
28
+ {{ computedValueLength }}
29
+ </span>
30
+ </Portal>
25
31
  </div>
26
32
  </template>
27
33
 
28
34
  <script>
35
+ import { Portal } from '@linusborg/vue-simple-portal';
36
+ import { computePosition, offset, autoUpdate } from '@floating-ui/dom';
37
+
29
38
  export default {
30
39
  name: 'VTListboxHighlight',
31
40
 
41
+ components: {
42
+ Portal,
43
+ },
44
+
32
45
  inject: ['apiListbox'],
33
46
 
34
47
  props: {
@@ -56,32 +69,156 @@ export default {
56
69
  },
57
70
 
58
71
  computed: {
59
- // Computes the current value of the listbox item.
60
- value() {
72
+ /**
73
+ * Computed property that generates an identifier for the counter element associated with the listbox.
74
+ *
75
+ * @property
76
+ * @name counterId
77
+ * @memberof VTListboxTriggerHighlight
78
+ * @description Returns an ID for the listbox counter element.
79
+ * @returns {string} The generated counter ID.
80
+ */
81
+ counterId() {
82
+ return `listbox-counter-${this.apiListbox().id}`;
83
+ },
84
+
85
+ /**
86
+ * Computed property that generates an identifier for the highlight element associated with the listbox.
87
+ *
88
+ * @property
89
+ * @name highlightId
90
+ * @memberof VTListboxTriggerHighlight
91
+ * @description Returns an ID for the listbox highlight element.
92
+ * @returns {string} The generated highlight ID.
93
+ */
94
+ highlightId() {
95
+ return `listbox-highlight-${this.apiListbox().id}`;
96
+ },
97
+
98
+ /**
99
+ * Computes the current value of the listbox item.
100
+ *
101
+ * @property
102
+ * @name computedValue
103
+ * @memberof VTListboxTriggerHighlight
104
+ * @description Returns the computed value of the listbox item.
105
+ * @returns {*} The computed value.
106
+ */
107
+ computedValue() {
61
108
  return this.apiListbox().valueComputed;
62
109
  },
63
110
 
64
- // Checks if the computed value is an array.
111
+ /**
112
+ * Checks if the computed value is an array.
113
+ *
114
+ * @property
115
+ * @name isValueAnArray
116
+ * @memberof VTListboxTriggerHighlight
117
+ * @description Checks if the computed value is an array.
118
+ * @returns {boolean} True if the value is an array, false otherwise.
119
+ */
65
120
  isValueAnArray() {
66
- return Array.isArray(this.value);
121
+ return Array.isArray(this.computedValue);
67
122
  },
68
123
 
69
- // Computes the length of the value, considering whether it's an array or a single value.
70
- valueLength() {
71
- return this.isValueAnArray ? this.value.length : this.value ? 1 : 0;
124
+ /**
125
+ * Computes the length of the value, considering whether it's an array or a single value.
126
+ *
127
+ * @property
128
+ * @name computedValueLength
129
+ * @memberof VTListboxTriggerHighlight
130
+ * @description Returns the length of the computed value.
131
+ * @returns {number} The length of the computed value.
132
+ */
133
+ computedValueLength() {
134
+ if (this.isValueAnArray) {
135
+ return this.computedValue.length;
136
+ } else {
137
+ return this.computedValue ? 1 : 0;
138
+ }
72
139
  },
73
140
 
74
- // Determines if the listbox item is active based on its value and default value.
141
+ /**
142
+ * Determines if the listbox item is active based on its value and default value.
143
+ *
144
+ * @property
145
+ * @name isActive
146
+ * @memberof VTListboxTriggerHighlight
147
+ * @description Checks if the listbox item is considered active.
148
+ * @returns {boolean} True if the listbox item is active, false otherwise.
149
+ */
75
150
  isActive() {
76
151
  return this.isValueAnArray
77
- ? this.valueLength > 0
78
- : this.defaultValue !== this.value;
152
+ ? this.computedValueLength > 0
153
+ : this.defaultValue !== this.computedValue;
79
154
  },
80
155
 
81
- // Checks if the badge should be visible for the listbox item.
156
+ /**
157
+ * Checks if the badge should be visible for the listbox item.
158
+ *
159
+ * @property
160
+ * @name isBadgeVisible
161
+ * @memberof VTListboxTriggerHighlight
162
+ * @description Checks if the badge should be visible for the listbox item.
163
+ * @returns {boolean} True if the badge should be visible, false otherwise.
164
+ */
82
165
  isBadgeVisible() {
83
166
  return this.isValueAnArray && this.isActive;
84
167
  },
85
168
  },
169
+
170
+ mounted() {
171
+ this.$nextTick(() => this.positionFloatingContent());
172
+ },
173
+
174
+ methods: {
175
+ /**
176
+ * Positions the floating content relative to a specified trigger element.
177
+ *
178
+ * @function
179
+ * @name positionFloatingContent
180
+ * @description Calculates and updates the position of the floating content
181
+ * based on the position of the reference element.
182
+ * @returns {void}
183
+ */
184
+ positionFloatingContent() {
185
+ /**
186
+ * The reference element that triggers the positioning of the floating content.
187
+ * @type {HTMLElement}
188
+ */
189
+ const referenceElement = document.getElementById(this.highlightId);
190
+
191
+ /**
192
+ * The floating element whose position needs to be updated.
193
+ * @type {HTMLElement}
194
+ */
195
+ const floatingElement = document.getElementById(this.counterId);
196
+
197
+ /**
198
+ * Callback function to update the position of the floating element
199
+ * using the autoUpdate and computePosition utilities.
200
+ * @type {Function}
201
+ */
202
+ const updatePositionCallback = () => {
203
+ computePosition(referenceElement, floatingElement, {
204
+ placement: 'top-end',
205
+ middleware: [
206
+ offset({
207
+ alignmentAxis: -10,
208
+ mainAxis: -10,
209
+ }),
210
+ ],
211
+ }).then(({ x, y }) => {
212
+ Object.assign(floatingElement.style, {
213
+ left: `${x}px`,
214
+ top: `${y}px`,
215
+ });
216
+ });
217
+ };
218
+
219
+ // Call the autoUpdate function with the specified elements and callback.
220
+ autoUpdate(referenceElement, floatingElement, updatePositionCallback);
221
+ },
222
+ },
86
223
  };
87
224
  </script>