@fluid-topics/ft-floating-menu 1.1.3 → 1.1.5
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/build/ft-base-floating-menu.d.ts +1 -1
- package/build/ft-base-floating-menu.js +18 -36
- package/build/ft-floating-menu.light.js +164 -164
- package/build/ft-floating-menu.min.js +252 -247
- package/package.json +8 -7
|
@@ -38,5 +38,5 @@ export declare class FtBaseFloatingMenu extends FtLitElement implements FtBaseFl
|
|
|
38
38
|
disconnectedCallback(): void;
|
|
39
39
|
protected contentAvailableCallback(props: PropertyValues): void;
|
|
40
40
|
private positionMenuWrapper;
|
|
41
|
-
private
|
|
41
|
+
private convertPlacement;
|
|
42
42
|
}
|
|
@@ -10,6 +10,7 @@ import { eventPathContainsMatchingElement, FtLitElement, jsonProperty, } from "@
|
|
|
10
10
|
import { classMap } from "lit/directives/class-map.js";
|
|
11
11
|
import { FtFloatingMenuItem } from "./ft-floating-menu-item";
|
|
12
12
|
import { FtIconVariants } from "@fluid-topics/ft-icon/build/ft-icon.properties";
|
|
13
|
+
import { autoPlacement, computePosition, shift } from "@floating-ui/dom";
|
|
13
14
|
export class FloatingMenuCloseEvent extends CustomEvent {
|
|
14
15
|
constructor() {
|
|
15
16
|
super("close-ft-floating-menu");
|
|
@@ -115,47 +116,28 @@ class FtBaseFloatingMenu extends FtLitElement {
|
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
positionMenuWrapper() {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
this.menuWrapper.style.left = "";
|
|
120
|
+
this.menuWrapper.style.top = "";
|
|
121
|
+
computePosition(this.actionButton, this.menuWrapper, {
|
|
122
|
+
middleware: [
|
|
123
|
+
shift({ crossAxis: true }),
|
|
124
|
+
autoPlacement({ allowedPlacements: [this.convertPlacement()] }),
|
|
125
|
+
],
|
|
126
|
+
}).then(({ x, y }) => {
|
|
127
|
+
this.menuWrapper.style.left = `${x}px`;
|
|
128
|
+
this.menuWrapper.style.top = `${y}px`;
|
|
129
|
+
});
|
|
130
|
+
this.menuWrapper.classList.add("ft-floating-menu--wrapper-positioned");
|
|
131
|
+
}
|
|
132
|
+
convertPlacement() {
|
|
126
133
|
switch (this.horizontalAlignment) {
|
|
127
134
|
case "left":
|
|
128
|
-
|
|
129
|
-
break;
|
|
135
|
+
return this.verticalAlignment + "-start";
|
|
130
136
|
case "right":
|
|
131
|
-
|
|
132
|
-
break;
|
|
137
|
+
return this.verticalAlignment + "-end";
|
|
133
138
|
case "center":
|
|
134
|
-
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
switch (this.verticalAlignment) {
|
|
138
|
-
case "bottom":
|
|
139
|
-
top = this.actionButton.offsetTop + buttonHeight + 4 - this.menuWrapper.offsetTop;
|
|
140
|
-
break;
|
|
141
|
-
case "top":
|
|
142
|
-
top = this.actionButton.offsetTop - menuHeight - 4 - this.menuWrapper.offsetTop;
|
|
143
|
-
break;
|
|
139
|
+
return this.verticalAlignment + "-center";
|
|
144
140
|
}
|
|
145
|
-
const style = this.menuWrapper.style;
|
|
146
|
-
style.left = left + "px";
|
|
147
|
-
style.top = top + "px";
|
|
148
|
-
const boundingClientRect = this.menuWrapper.getBoundingClientRect();
|
|
149
|
-
let leftOutOfWindowPixels = -boundingClientRect.x;
|
|
150
|
-
let rightOutOfWindowPixels = (boundingClientRect.x + boundingClientRect.width) - window.innerWidth;
|
|
151
|
-
style.left = (left + Math.round(this.correctOutOfWindowPixels(leftOutOfWindowPixels, rightOutOfWindowPixels))) + "px";
|
|
152
|
-
let topOutOfWindowPixels = -boundingClientRect.y;
|
|
153
|
-
let bottomOutOfWindowPixels = (boundingClientRect.y + boundingClientRect.height) - window.innerHeight;
|
|
154
|
-
style.top = (top + Math.round(this.correctOutOfWindowPixels(topOutOfWindowPixels, bottomOutOfWindowPixels))) + "px";
|
|
155
|
-
this.menuWrapper.classList.add("ft-floating-menu--wrapper-positioned");
|
|
156
|
-
}
|
|
157
|
-
correctOutOfWindowPixels(leftOrTopOutOfWindowPixels, rightOrBottomOutOfWindowPixels) {
|
|
158
|
-
return Math.max(leftOrTopOutOfWindowPixels, Math.min(0, -rightOrBottomOutOfWindowPixels));
|
|
159
141
|
}
|
|
160
142
|
}
|
|
161
143
|
FtBaseFloatingMenu.elementDefinitions = {
|