@fluid-topics/ft-floating-menu 2.0.38 → 2.1.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.
@@ -1,10 +1,8 @@
1
1
  import { FtFloatingMenu } from "./ft-floating-menu";
2
2
  import { FtFloatingMenuItem } from "./ft-floating-menu-item";
3
- import { FtdsFloatingMenu } from "./ftds-floating-menu";
4
3
  import { FtFloatingMenuLabel } from "./ft-floating-menu-label";
5
4
  declare const _default: {
6
5
  "ft-floating-menu": typeof FtFloatingMenu;
7
- "ftds-floating-menu": typeof FtdsFloatingMenu;
8
6
  "ft-floating-menu-item": typeof FtFloatingMenuItem;
9
7
  "ft-floating-menu-label": typeof FtFloatingMenuLabel;
10
8
  };
@@ -1,10 +1,8 @@
1
1
  import { FtFloatingMenu } from "./ft-floating-menu";
2
2
  import { FtFloatingMenuItem } from "./ft-floating-menu-item";
3
- import { FtdsFloatingMenu } from "./ftds-floating-menu";
4
3
  import { FtFloatingMenuLabel } from "./ft-floating-menu-label";
5
4
  export default {
6
5
  "ft-floating-menu": FtFloatingMenu,
7
- "ftds-floating-menu": FtdsFloatingMenu,
8
6
  "ft-floating-menu-item": FtFloatingMenuItem,
9
7
  "ft-floating-menu-label": FtFloatingMenuLabel,
10
8
  };
@@ -10,7 +10,7 @@ import { FtLitElement, ignoreComposingEvents, } from "@fluid-topics/ft-wc-utils"
10
10
  import { itemStyles } from "./ft-floating-menu-item.styles";
11
11
  import { FtIcon, } from "@fluid-topics/ft-icon";
12
12
  import { FtRipple } from "@fluid-topics/ft-ripple";
13
- import { FtTypography } from "@fluid-topics/ft-typography";
13
+ import { FtTypography, FtTypographyVariants, } from "@fluid-topics/ft-typography";
14
14
  import { classMap, } from "lit/directives/class-map.js";
15
15
  export class FtFloatingMenuItemSelectEvent extends CustomEvent {
16
16
  constructor(value) {
@@ -43,7 +43,7 @@ export class FtFloatingMenuItem extends FtLitElement {
43
43
  ${this.icon ? html `
44
44
  <ft-icon .variant=${this.iconVariant} .value=${this.icon}></ft-icon>
45
45
  ` : nothing}
46
- <ft-typography variant="body2">
46
+ <ft-typography variant="${FtTypographyVariants.body2}">
47
47
  <slot></slot>
48
48
  </ft-typography>
49
49
  </div>
@@ -1,6 +1,2 @@
1
- import { FtIconVariants } from "@fluid-topics/ft-icon/build/ft-icon.properties";
2
1
  export interface FtFloatingMenuItemProperties {
3
- iconVariant?: FtIconVariants;
4
- icon?: string;
5
- value: string;
6
2
  }
@@ -1,4 +1,4 @@
1
1
  export declare const FtFloatingMenuItemCssVariables: {
2
- iconColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
2
+ iconColor: import("@fluid-topics/design-system-variables").FtCssVariable;
3
3
  };
4
4
  export declare const itemStyles: import("lit").CSSResult;
@@ -1,12 +1,12 @@
1
1
  import { html } from "lit";
2
- import { FtLitElement } from "@fluid-topics/ft-wc-utils";
3
- import { FtTypography } from "@fluid-topics/ft-typography";
2
+ import { FtLitElement, } from "@fluid-topics/ft-wc-utils";
3
+ import { FtTypography, FtTypographyVariants, } from "@fluid-topics/ft-typography";
4
4
  import { labelStyles } from "./ft-floating-menu-label.styles";
5
5
  export class FtFloatingMenuLabel extends FtLitElement {
6
6
  render() {
7
7
  return html `
8
8
  <div class="ft-floating-menu-label">
9
- <ft-typography variant="caption">
9
+ <ft-typography variant="${FtTypographyVariants.caption}">
10
10
  <slot></slot>
11
11
  </ft-typography>
12
12
  </div>
@@ -1,4 +1,4 @@
1
1
  export declare const FtFloatingMenuLabelCssVariables: {
2
- color: import("@fluid-topics/ft-wc-utils").FtCssVariable;
2
+ color: import("@fluid-topics/design-system-variables").FtCssVariable;
3
3
  };
4
4
  export declare const labelStyles: import("lit").CSSResult;
@@ -1,5 +1,5 @@
1
1
  import { css } from "lit";
2
- import { designSystemVariables, FtCssVariableFactory } from "@fluid-topics/ft-wc-utils";
2
+ import { designSystemVariables, FtCssVariableFactory, } from "@fluid-topics/ft-wc-utils";
3
3
  export const FtFloatingMenuLabelCssVariables = {
4
4
  color: FtCssVariableFactory.extend("--ft-floating-menu-label-color", "", designSystemVariables.colorOnSurfaceMedium),
5
5
  };
@@ -1,7 +1,50 @@
1
- import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
2
- import { FtFloatingMenuProperties } from "./ft-floating-menu.properties";
3
- import { FtBaseFloatingMenu } from "./ft-base-floating-menu";
4
- export declare class FtFloatingMenu extends FtBaseFloatingMenu implements FtFloatingMenuProperties {
1
+ import { PropertyValues } from "lit";
2
+ import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
3
+ import { FtIconVariants } from "@fluid-topics/ft-icon/build/ft-icon.properties";
4
+ import { Position } from "@fluid-topics/ft-tooltip/build/ft-tooltip.properties";
5
+ import { FtFloatingMenuProperties, FtHorizontalAlignment, FtVerticalAlignment } from "./ft-floating-menu.properties";
6
+ export declare class FtFloatingMenuStatusChangeEvent extends CustomEvent<{
7
+ open: boolean;
8
+ }> {
9
+ constructor(open: boolean);
10
+ }
11
+ export declare class FloatingMenuCloseEvent extends CustomEvent<void> {
12
+ constructor();
13
+ }
14
+ export declare class FtFloatingMenuSelectEvent extends CustomEvent<string> {
15
+ constructor(detail: string);
16
+ }
17
+ export declare class FtFloatingMenu extends FtLitElement implements FtFloatingMenuProperties {
5
18
  static elementDefinitions: ElementDefinitionsMap;
6
19
  static styles: import("lit").CSSResult;
20
+ horizontalAlignment: FtHorizontalAlignment;
21
+ verticalAlignment: FtVerticalAlignment;
22
+ closeMenuMatchers: string[];
23
+ primary: boolean;
24
+ label?: string;
25
+ tooltipPosition?: Position;
26
+ icon: string;
27
+ iconVariant: FtIconVariants;
28
+ text?: string;
29
+ disabled: boolean;
30
+ private menuOpen;
31
+ forceMenuOpen: boolean;
32
+ private container;
33
+ private menuWrapper;
34
+ private actionButton?;
35
+ private customToggle;
36
+ protected updated(props: PropertyValues): void;
37
+ protected render(): import("lit-html").TemplateResult<1>;
38
+ toggleMenu(): void;
39
+ openMenu(): void;
40
+ closeMenu(): void;
41
+ private hideOptionsOnClickOutside;
42
+ private onCloseEvent;
43
+ private onItemSelect;
44
+ private onContentClick;
45
+ disconnectedCallback(): void;
46
+ protected contentAvailableCallback(props: PropertyValues): void;
47
+ private positionMenuWrapper;
48
+ private convertPlacement;
49
+ private onKeyDown;
7
50
  }
@@ -1,9 +1,212 @@
1
- import { styles } from "./ft-floating-menu.styles";
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, } from "lit";
8
+ import { property, query, queryAssignedElements, state, } from "lit/decorators.js";
9
+ import { eventPathContainsMatchingElement, FtLitElement, jsonProperty, } from "@fluid-topics/ft-wc-utils";
2
10
  import { FtButton } from "@fluid-topics/ft-button";
3
- import { FtBaseFloatingMenu } from "./ft-base-floating-menu";
4
- export class FtFloatingMenu extends FtBaseFloatingMenu {
11
+ import { classMap } from "lit/directives/class-map.js";
12
+ import { FtFloatingMenuItem, } from "./ft-floating-menu-item";
13
+ import { FtIconVariants } from "@fluid-topics/ft-icon/build/ft-icon.properties";
14
+ import { computeOffsetPosition } from "@fluid-topics/ft-wc-utils/build/floating";
15
+ import { floatingMenuStyles } from "./ft-floating-menu.styles";
16
+ export class FtFloatingMenuStatusChangeEvent extends CustomEvent {
17
+ constructor(open) {
18
+ super("change", { detail: { open } });
19
+ }
20
+ }
21
+ export class FloatingMenuCloseEvent extends CustomEvent {
22
+ constructor() {
23
+ super("close-ft-floating-menu");
24
+ }
25
+ }
26
+ export class FtFloatingMenuSelectEvent extends CustomEvent {
27
+ constructor(detail) {
28
+ super("select", { detail });
29
+ }
30
+ }
31
+ export class FtFloatingMenu extends FtLitElement {
32
+ constructor() {
33
+ super(...arguments);
34
+ this.horizontalAlignment = "left";
35
+ this.verticalAlignment = "bottom";
36
+ this.closeMenuMatchers = [];
37
+ // Button properties
38
+ this.primary = false;
39
+ this.icon = "SHORTCUT_MENU";
40
+ this.iconVariant = FtIconVariants.fluid_topics;
41
+ this.disabled = false;
42
+ this.menuOpen = false;
43
+ this.forceMenuOpen = false;
44
+ this.hideOptionsOnClickOutside = (e) => {
45
+ this.menuOpen = this.menuOpen && e.composedPath().includes(this.container);
46
+ };
47
+ }
48
+ updated(props) {
49
+ super.updated(props);
50
+ if (props.has("menuOpen")) {
51
+ this.dispatchEvent(new FtFloatingMenuStatusChangeEvent(this.menuOpen));
52
+ }
53
+ }
54
+ render() {
55
+ const classes = {
56
+ "ft-floating-menu": true,
57
+ "ft-floating-menu--open": this.forceMenuOpen || this.menuOpen,
58
+ ["ft-floating-menu--" + this.horizontalAlignment.toLowerCase()]: true,
59
+ ["ft-floating-menu--" + this.verticalAlignment.toLowerCase()]: true,
60
+ };
61
+ return html `
62
+ <div part="container" class="${classMap(classes)}" @keydown=${this.onKeyDown}>
63
+ <slot name="toggle"
64
+ part="toggle"
65
+ @click=${this.toggleMenu}
66
+ aria-controls="ft-floating-menu-options"
67
+ aria-expanded="${this.forceMenuOpen || this.menuOpen}">
68
+ <ft-button id="actions-button"
69
+ part="button"
70
+ ?primary=${this.primary}
71
+ dense round
72
+ icon="${this.icon}"
73
+ .iconVariant=${this.iconVariant}
74
+ .label=${this.label}
75
+ .tooltipPosition=${this.tooltipPosition}
76
+ ?disabled=${this.disabled}>
77
+ ${this.text}
78
+ </ft-button>
79
+ </slot>
80
+ <div part="options-wrapper" class="ft-floating-menu--wrapper">
81
+ <div id="ft-floating-menu-options"
82
+ class="ft-floating-menu--options"
83
+ part="options"
84
+ @ft-floating-menu-item-select=${this.onItemSelect}>
85
+ <slot id="ft-floating-menu-content"
86
+ @click=${this.onContentClick}
87
+ @close-ft-floating-menu=${this.onCloseEvent}
88
+ ></slot>
89
+ </div>
90
+ </div>
91
+ </div>
92
+ `;
93
+ }
94
+ toggleMenu() {
95
+ this.menuOpen = !this.menuOpen;
96
+ }
97
+ openMenu() {
98
+ this.menuOpen = true;
99
+ }
100
+ closeMenu() {
101
+ this.menuOpen = false;
102
+ }
103
+ onCloseEvent(e) {
104
+ e.stopPropagation();
105
+ this.closeMenu();
106
+ }
107
+ onItemSelect(e) {
108
+ e.stopPropagation();
109
+ this.dispatchEvent(new FtFloatingMenuSelectEvent(e.detail));
110
+ this.closeMenu();
111
+ }
112
+ onContentClick(e) {
113
+ if (eventPathContainsMatchingElement(e, this.closeMenuMatchers, this)) {
114
+ this.closeMenu();
115
+ }
116
+ }
117
+ disconnectedCallback() {
118
+ super.disconnectedCallback();
119
+ document.removeEventListener("click", this.hideOptionsOnClickOutside);
120
+ }
121
+ contentAvailableCallback(props) {
122
+ super.contentAvailableCallback(props);
123
+ if (props.has("menuOpen")) {
124
+ if (this.menuOpen) {
125
+ this.menuWrapper.classList.remove("ft-floating-menu--wrapper-positioned");
126
+ this.positionMenuWrapper();
127
+ document.addEventListener("click", this.hideOptionsOnClickOutside);
128
+ }
129
+ else {
130
+ document.removeEventListener("click", this.hideOptionsOnClickOutside);
131
+ }
132
+ }
133
+ }
134
+ async positionMenuWrapper() {
135
+ this.menuWrapper.style.left = "";
136
+ this.menuWrapper.style.top = "";
137
+ const reference = this.customToggle.length > 0 ? this.customToggle[0] : this.actionButton;
138
+ const { x, y } = await computeOffsetPosition(reference, this.menuWrapper, this.convertPlacement());
139
+ this.menuWrapper.style.left = `${x}px`;
140
+ this.menuWrapper.style.top = `${y}px`;
141
+ this.menuWrapper.classList.add("ft-floating-menu--wrapper-positioned");
142
+ }
143
+ convertPlacement() {
144
+ switch (this.horizontalAlignment) {
145
+ case "left":
146
+ return this.verticalAlignment + "-start";
147
+ case "right":
148
+ return this.verticalAlignment + "-end";
149
+ case "center":
150
+ return this.verticalAlignment + "-center";
151
+ }
152
+ }
153
+ onKeyDown(e) {
154
+ if (e.code == "Escape") {
155
+ this.closeMenu();
156
+ e.stopPropagation();
157
+ }
158
+ }
5
159
  }
6
160
  FtFloatingMenu.elementDefinitions = {
7
- "ft-or-ftds-button": FtButton,
161
+ "ft-floating-menu-item": FtFloatingMenuItem,
162
+ "ft-button": FtButton,
8
163
  };
9
- FtFloatingMenu.styles = styles;
164
+ FtFloatingMenu.styles = floatingMenuStyles;
165
+ __decorate([
166
+ property()
167
+ ], FtFloatingMenu.prototype, "horizontalAlignment", void 0);
168
+ __decorate([
169
+ property()
170
+ ], FtFloatingMenu.prototype, "verticalAlignment", void 0);
171
+ __decorate([
172
+ jsonProperty([])
173
+ ], FtFloatingMenu.prototype, "closeMenuMatchers", void 0);
174
+ __decorate([
175
+ property({ type: Boolean })
176
+ ], FtFloatingMenu.prototype, "primary", void 0);
177
+ __decorate([
178
+ property()
179
+ ], FtFloatingMenu.prototype, "label", void 0);
180
+ __decorate([
181
+ property()
182
+ ], FtFloatingMenu.prototype, "tooltipPosition", void 0);
183
+ __decorate([
184
+ property()
185
+ ], FtFloatingMenu.prototype, "icon", void 0);
186
+ __decorate([
187
+ property()
188
+ ], FtFloatingMenu.prototype, "iconVariant", void 0);
189
+ __decorate([
190
+ property()
191
+ ], FtFloatingMenu.prototype, "text", void 0);
192
+ __decorate([
193
+ property({ type: Boolean })
194
+ ], FtFloatingMenu.prototype, "disabled", void 0);
195
+ __decorate([
196
+ state()
197
+ ], FtFloatingMenu.prototype, "menuOpen", void 0);
198
+ __decorate([
199
+ state()
200
+ ], FtFloatingMenu.prototype, "forceMenuOpen", void 0);
201
+ __decorate([
202
+ query(".ft-floating-menu")
203
+ ], FtFloatingMenu.prototype, "container", void 0);
204
+ __decorate([
205
+ query(".ft-floating-menu--wrapper")
206
+ ], FtFloatingMenu.prototype, "menuWrapper", void 0);
207
+ __decorate([
208
+ query("#actions-button")
209
+ ], FtFloatingMenu.prototype, "actionButton", void 0);
210
+ __decorate([
211
+ queryAssignedElements({ slot: "toggle" })
212
+ ], FtFloatingMenu.prototype, "customToggle", void 0);