@superleapai/flow-ui 2.5.8 → 2.5.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/components/tooltip.js +42 -0
- package/core/flow.js +16 -34
- package/dist/superleap-flow.min.js +2 -2
- package/package.json +1 -1
package/components/tooltip.js
CHANGED
|
@@ -17,12 +17,18 @@
|
|
|
17
17
|
return Array.prototype.filter.call(arguments, Boolean).join(" ");
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
var VIEWPORT_PADDING = 8;
|
|
21
|
+
|
|
20
22
|
function positionTooltip(triggerRect, tooltipEl, placement) {
|
|
21
23
|
var style = tooltipEl.style;
|
|
22
24
|
style.position = "fixed";
|
|
23
25
|
var cx = triggerRect.left + triggerRect.width / 2;
|
|
24
26
|
var cy = triggerRect.top + triggerRect.height / 2;
|
|
25
27
|
var gap = 4;
|
|
28
|
+
var vw = window.innerWidth;
|
|
29
|
+
var vh = window.innerHeight;
|
|
30
|
+
var pad = VIEWPORT_PADDING;
|
|
31
|
+
|
|
26
32
|
if (placement === "top") {
|
|
27
33
|
style.left = cx + "px";
|
|
28
34
|
style.top = triggerRect.top + "px";
|
|
@@ -40,6 +46,42 @@
|
|
|
40
46
|
style.top = cy + "px";
|
|
41
47
|
style.transform = "translate(" + gap + "px, -50%)";
|
|
42
48
|
}
|
|
49
|
+
|
|
50
|
+
// Force layout so we can read tooltip dimensions
|
|
51
|
+
void tooltipEl.offsetHeight;
|
|
52
|
+
var tr = tooltipEl.getBoundingClientRect();
|
|
53
|
+
var adjustX = 0;
|
|
54
|
+
var adjustY = 0;
|
|
55
|
+
|
|
56
|
+
if (placement === "top" || placement === "bottom") {
|
|
57
|
+
if (tr.left < pad) adjustX = pad - tr.left;
|
|
58
|
+
else if (tr.right > vw - pad) adjustX = (vw - pad) - tr.right;
|
|
59
|
+
if (adjustX !== 0) {
|
|
60
|
+
var base = placement === "top"
|
|
61
|
+
? "translate(-50%, -100%) translateY(-" + gap + "px)"
|
|
62
|
+
: "translate(-50%, " + gap + "px)";
|
|
63
|
+
style.transform = base + " translateX(" + adjustX + "px)";
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
if (tr.top < pad) adjustY = pad - tr.top;
|
|
67
|
+
else if (tr.bottom > vh - pad) adjustY = (vh - pad) - tr.bottom;
|
|
68
|
+
if (adjustY !== 0) {
|
|
69
|
+
var base = placement === "left"
|
|
70
|
+
? "translate(-100%, -50%) translateX(-" + gap + "px)"
|
|
71
|
+
: "translate(" + gap + "px, -50%)";
|
|
72
|
+
style.transform = base + " translateY(" + adjustY + "px)";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Keep arrow pointing at trigger when tooltip was shifted for viewport
|
|
77
|
+
var arrowEl = tooltipEl.querySelector("[data-tooltip-arrow]");
|
|
78
|
+
if (arrowEl) {
|
|
79
|
+
if (placement === "top" || placement === "bottom") {
|
|
80
|
+
arrowEl.style.transform = adjustX !== 0 ? "translateX(" + -adjustX + "px)" : "";
|
|
81
|
+
} else {
|
|
82
|
+
arrowEl.style.transform = adjustY !== 0 ? "translateY(" + -adjustY + "px)" : "";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
43
85
|
}
|
|
44
86
|
|
|
45
87
|
/**
|
package/core/flow.js
CHANGED
|
@@ -123,42 +123,24 @@
|
|
|
123
123
|
const field = document.createElement("div");
|
|
124
124
|
field.className = "field";
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
labelEl.className = "field-label";
|
|
141
|
-
const labelContentWrapper = document.createElement("span");
|
|
142
|
-
labelContentWrapper.style.display = "inline-flex";
|
|
143
|
-
labelContentWrapper.style.alignItems = "center";
|
|
144
|
-
labelContentWrapper.style.gap = "0.25rem";
|
|
145
|
-
if (required) {
|
|
146
|
-
labelContentWrapper.appendChild(document.createTextNode(label + " "));
|
|
147
|
-
const asterisk = document.createElement("span");
|
|
148
|
-
asterisk.className = "required-asterisk";
|
|
149
|
-
asterisk.textContent = "*";
|
|
150
|
-
labelContentWrapper.appendChild(asterisk);
|
|
151
|
-
} else {
|
|
152
|
-
labelContentWrapper.appendChild(document.createTextNode(label));
|
|
153
|
-
}
|
|
154
|
-
if (helpText && getComponent("Tooltip")) {
|
|
155
|
-
const tooltip = getComponent("Tooltip").create({ content: helpText, label: "?" });
|
|
156
|
-
if (tooltip) labelContentWrapper.appendChild(tooltip);
|
|
126
|
+
const hasLabel = label != null && String(label).trim() !== "";
|
|
127
|
+
let labelEl = null;
|
|
128
|
+
|
|
129
|
+
if (hasLabel) {
|
|
130
|
+
const LabelComponent = getComponent("Label");
|
|
131
|
+
if (LabelComponent && typeof LabelComponent.create === "function") {
|
|
132
|
+
labelEl = LabelComponent.create({
|
|
133
|
+
label: label,
|
|
134
|
+
required: required,
|
|
135
|
+
requiredPosition: "right",
|
|
136
|
+
optional: false,
|
|
137
|
+
size: "default",
|
|
138
|
+
helpText: helpText || undefined,
|
|
139
|
+
});
|
|
157
140
|
}
|
|
158
|
-
labelEl.appendChild(labelContentWrapper);
|
|
159
141
|
}
|
|
160
142
|
|
|
161
|
-
field.appendChild(labelEl);
|
|
143
|
+
if (labelEl) field.appendChild(labelEl);
|
|
162
144
|
return field;
|
|
163
145
|
}
|
|
164
146
|
|
|
@@ -1256,7 +1238,7 @@
|
|
|
1256
1238
|
onChange,
|
|
1257
1239
|
} = config;
|
|
1258
1240
|
|
|
1259
|
-
const field = createFieldWrapper(label
|
|
1241
|
+
const field = createFieldWrapper(label, required, helpText);
|
|
1260
1242
|
field.setAttribute("data-field-id", fieldId);
|
|
1261
1243
|
|
|
1262
1244
|
if (getComponent("CurrencyComponent") && getComponent("CurrencyComponent").create) {
|