@veritree/ui 0.77.1 → 0.77.2
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.js
CHANGED
|
@@ -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],
|
|
7
7
|
default: 5,
|
|
8
8
|
},
|
|
9
9
|
},
|
|
@@ -39,82 +39,11 @@ 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.left || {};
|
|
57
|
-
let topObject = this.top || {};
|
|
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
|
-
|
|
107
42
|
positionContentToTrigger() {
|
|
108
43
|
const trigger = document.getElementById(this.componentTrigger.id);
|
|
109
44
|
const content = document.getElementById(this.componentContent.id);
|
|
110
45
|
const minWidthLimit = Number(this.floatingUiMinWidth);
|
|
111
46
|
|
|
112
|
-
if (this.top !== null || this.top !== undefined || this.left !== null || this.left !== undefined) {
|
|
113
|
-
this.positionContentToTriggerByTopAndLeft(trigger, content, minWidthLimit);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
47
|
computePosition(trigger, content, {
|
|
119
48
|
placement: this.placement,
|
|
120
49
|
middleware: [
|
package/package.json
CHANGED
|
@@ -31,34 +31,8 @@ export default {
|
|
|
31
31
|
default: false,
|
|
32
32
|
},
|
|
33
33
|
/**
|
|
34
|
-
* The
|
|
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
|
-
top: {
|
|
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
|
-
left: {
|
|
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}
|
|
34
|
+
* The placement of the component relative to its trigger element.
|
|
35
|
+
* @type {string}
|
|
62
36
|
* @values 'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end', 'right', 'right-start', 'right-end'
|
|
63
37
|
* @default 'bottom-start'
|
|
64
38
|
*/
|