@veritree/ui 0.76.1-9 → 0.77.0-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.
@@ -3,7 +3,7 @@ import { computePosition, flip, shift, offset, size } from '@floating-ui/dom';
3
3
  export const floatingUiMixin = {
4
4
  props: {
5
5
  offset: {
6
- type: [Number, String],
6
+ type: [Number, String, Object],
7
7
  default: 5,
8
8
  },
9
9
  },
@@ -39,11 +39,90 @@ export const floatingUiMixin = {
39
39
  this.active = null;
40
40
  },
41
41
 
42
+ positionContentToTriggerByTopAndLeft(trigger, content, minWidthLimit) {
43
+ /*
44
+ TODO: Try to replace this with the offset object from floating-ui, using mainAxis, crossAxis, and alignmentAxis.
45
+ The problem is that the floating-ui offset values are px values, not percentages, which is the use case I am trying to solve.
46
+ I tried to calculate the percentage based off of the width and height of the trigger element,
47
+ but depending on the placement prop, mainAxis could be x OR y and crossAxis could be x OR y,
48
+ so to calculate the offset based on the width/height of the trigger element
49
+ we would have to calculate it differently for each individual placement preset.
50
+ */
51
+ const contentRect = content.getBoundingClientRect();
52
+ const contentWidth = contentRect.width;
53
+ const contentHeight = contentRect.height;
54
+ const triggerWidth = trigger.getBoundingClientRect().width;
55
+
56
+ let leftObject = this.leftPosition || {};
57
+ let topObject = this.topPosition || {};
58
+
59
+ let left = leftObject.value || 0;
60
+ let top = topObject.value || 0;
61
+
62
+ if (leftObject.unit === '%') {
63
+ left = (triggerWidth * left) / 100;
64
+ }
65
+ if (topObject.unit === '%') {
66
+ top = (triggerWidth * top) / 100;
67
+ }
68
+ if (leftObject.positionBy === 'center') {
69
+ left = left - contentWidth / 2;
70
+ }
71
+ if (leftObject.positionBy === 'end') {
72
+ left = left - contentWidth;
73
+ }
74
+ if (topObject.positionBy === 'top') {
75
+ top = top + contentHeight;
76
+ }
77
+ if (topObject.positionBy === 'center') {
78
+ top = top + contentHeight / 2;
79
+ }
80
+
81
+ computePosition(trigger, content, {
82
+ placement: 'top-start',
83
+ middleware: [
84
+ flip(),
85
+ shift({ padding: 5 }),
86
+ size({
87
+ apply({ rects }) {
88
+ if (!minWidthLimit) return;
89
+
90
+ const width = rects.reference.width;
91
+ const minWidth = width < minWidthLimit ? minWidthLimit : width;
92
+
93
+ Object.assign(content.style, {
94
+ minWidth: `${minWidth}px`,
95
+ });
96
+ },
97
+ }),
98
+ ],
99
+ }).then(({ x, y }) => {
100
+ Object.assign(content.style, {
101
+ left: `${x + left}px`,
102
+ top: `${y + top}px`,
103
+ });
104
+ });
105
+ },
106
+
42
107
  positionContentToTrigger() {
43
108
  const trigger = document.getElementById(this.componentTrigger.id);
44
109
  const content = document.getElementById(this.componentContent.id);
45
110
  const minWidthLimit = Number(this.floatingUiMinWidth);
46
111
 
112
+ if (
113
+ this.top !== null ||
114
+ this.top !== undefined ||
115
+ this.left !== null ||
116
+ this.left !== undefined
117
+ ) {
118
+ this.positionContentToTriggerByTopAndLeft(
119
+ trigger,
120
+ content,
121
+ minWidthLimit,
122
+ );
123
+ return;
124
+ }
125
+
47
126
  computePosition(trigger, content, {
48
127
  placement: this.placement,
49
128
  middleware: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veritree/ui",
3
- "version": "0.76.1-9",
3
+ "version": "0.77.0-0",
4
4
  "description": "veritree ui library",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -7,7 +7,7 @@
7
7
  <span
8
8
  v-if="!iconless"
9
9
  class="pointer-events-none absolute right-3 top-1/2 -translate-y-1/2"
10
- :class="[disabled ? 'bg-gray-100' : 'bg-white']"
10
+ :class="[disabled ? 'bg-gray-200' : 'bg-white']"
11
11
  >
12
12
  <IconCalendar class="-z-0 h-5 w-5 scale-90 text-gray-600" />
13
13
  </span>
@@ -31,8 +31,34 @@ export default {
31
31
  default: false,
32
32
  },
33
33
  /**
34
- * The placement of the component relative to its trigger element.
35
- * @type {string}
34
+ * The position of the tooltip from the top of the trigger. This overrides the placement prop.
35
+ *
36
+ * @type {Object}
37
+ * @property {string} unit - The unit of the top position (% or px).
38
+ * @property {string} positionBy - Whether to position the top, center, or bottom of the tooltip at it's top value. Defaults to bottom.
39
+ * @property {number} value - The value of the top position.
40
+ * @default null
41
+ */
42
+ topPosition: {
43
+ type: Object,
44
+ default: null,
45
+ },
46
+ /**
47
+ * The position of the tooltip from the start (left) of the trigger. This overrides the placement prop.
48
+ *
49
+ * @type {Object}
50
+ * @property {string} unit - The unit of the top position (& or px).
51
+ * @property {string} positionBy - Whether to position the start, center, or end of the tooltip at it's left value. Defaults to start.
52
+ * @property {number} value - The value of the top position.
53
+ * @default null
54
+ */
55
+ leftPosition: {
56
+ type: Object,
57
+ default: null,
58
+ },
59
+ /**
60
+ * The placement of the component relative to its trigger element. If top or bottom are supplied, this value will be ignored.
61
+ * @type {string|number}
36
62
  * @values 'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end'
37
63
  * @default 'bottom-start'
38
64
  */