@fluid-topics/ft-popover 2.0.6 → 2.0.7

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.
@@ -0,0 +1,3 @@
1
+ import { FtBasePopoverProperties } from "./ft-base-popover";
2
+ export interface FtPopoverProperties extends FtBasePopoverProperties {
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const ftPopoverStyles: import("lit").CSSResult;
@@ -0,0 +1,65 @@
1
+ import { css } from "lit";
2
+ // language=css
3
+ export const ftPopoverStyles = css `
4
+ :host {
5
+ position: relative;
6
+ display: inline-block;
7
+ }
8
+
9
+ [part="root-container"] {
10
+ position: relative;
11
+ }
12
+
13
+ [part="popover-container"] {
14
+ position: absolute;
15
+ z-index: 100;
16
+ display: block;
17
+ margin: auto;
18
+ }
19
+
20
+ [part="closing-button-container"] {
21
+ position: absolute;
22
+ top: 8px;
23
+ right: 8px;
24
+
25
+ ft-button {
26
+ --ft-button-icon-size: 12px;
27
+ --ft-button-background-color: #fff;
28
+ }
29
+ }
30
+
31
+ [part="overlay"] {
32
+ position: fixed;
33
+ top: 0;
34
+ right: 0;
35
+ bottom: 0;
36
+ left: 0;
37
+ height: 100%;
38
+ width: 100%;
39
+ opacity: 0;
40
+ }
41
+
42
+ [part="wrapper"] {
43
+ visibility: hidden;
44
+ position: fixed;
45
+ display: flex;
46
+ flex-direction: column;
47
+
48
+ max-width: 464px;
49
+ width: max-content;
50
+
51
+ padding: 24px;
52
+
53
+ background-color: #fff;
54
+ border-radius: 8px;
55
+ box-shadow: 0 0 1px 0 #0000000F, 0 2px 5px 0 #00000024, 0 4px 10px 0 #0000000F;;
56
+
57
+ &.positioned {
58
+ visibility: visible;
59
+ }
60
+ }
61
+
62
+ .hidden {
63
+ display: none;
64
+ }
65
+ `;
@@ -1,39 +1,27 @@
1
- import { nothing, PropertyValues } from "lit";
2
- import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
1
+ import { TemplateResult } from "lit";
2
+ import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
3
+ import { FtdsButton } from "@fluid-topics/ft-button";
3
4
  import { FtdsPopoverProperties } from "./ftds-popover.properties";
4
- import { DesignSystemFamily, DesignSystemSize } from "@fluid-topics/design-system-variables";
5
- import { Position } from "@fluid-topics/ft-tooltip";
6
- import { FtIcons } from "@fluid-topics/ft-icon";
7
- export declare class FtdsPopover extends FtLitElement implements FtdsPopoverProperties {
8
- static elementDefinitions: ElementDefinitionsMap;
5
+ import { FtBasePopover } from "./ft-base-popover";
6
+ export declare class FtdsPopover extends FtBasePopover implements FtdsPopoverProperties {
9
7
  static styles: import("lit").CSSResult;
8
+ static elementDefinitions: ElementDefinitionsMap;
10
9
  heading: string;
11
- closeButtonLabel: string;
12
- openButtonIcon: FtIcons;
13
- openButtonLabel: string;
14
- openButtonTooltipPosition: Position;
15
- opened: boolean;
16
- hidden: boolean;
17
- openButtonSize: DesignSystemSize;
18
- openButtonFamily: DesignSystemFamily;
19
- private openingButton?;
20
- private closingButton?;
21
- private popoverWrapper?;
10
+ protected openingButton?: FtdsButton;
11
+ protected closingButton?: FtdsButton;
22
12
  private popoverContentDiv?;
23
13
  private popoverContentSlot?;
24
14
  private slottedLinkContent?;
25
15
  private popoverLinkTypography?;
26
16
  private popoverSectionsDiv?;
27
17
  private popoverSectionsSlot?;
28
- protected render(): typeof nothing | import("lit-html").TemplateResult<1>;
29
- renderPopover(): typeof nothing | import("lit-html").TemplateResult<1>;
30
- updated(properties: PropertyValues<FtdsPopover>): void;
31
- close(): void;
32
- open(): void;
33
- hasEmptySlot(slot?: HTMLSlotElement): boolean;
34
- private watchFocusIn;
35
- private watchEscapeKey;
36
- private closeAndFocusOpeningButton;
37
- private positionWrapper;
38
- private hideUnusedSlots;
18
+ protected wrapperId: string;
19
+ protected headingId: string;
20
+ protected contentId: string;
21
+ maxWidth: import("@fluid-topics/ft-wc-utils").FtCssVariable;
22
+ protected renderOpeningButton(): TemplateResult;
23
+ protected renderClosingButton(): TemplateResult;
24
+ protected renderFullContent(): TemplateResult;
25
+ protected hideUnusedSlots(): void;
26
+ private hasEmptySlot;
39
27
  }
@@ -5,156 +5,73 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { html, nothing } from "lit";
8
- import { property, query } from "lit/decorators.js";
9
- import { ifDefined } from "lit/directives/if-defined.js";
10
- import { computeOffsetAutoPosition, FtLitElement, unslotText } from "@fluid-topics/ft-wc-utils";
8
+ import { query } from "lit/decorators.js";
9
+ import { unslotText } from "@fluid-topics/ft-wc-utils";
11
10
  import { FtdsTypography, FtdsTypographyVariants } from "@fluid-topics/ft-typography";
12
11
  import { FtdsButton } from "@fluid-topics/ft-button";
13
- import { styles } from "./ftds-popover.styles";
14
- import { classMap } from "lit/directives/class-map.js";
15
12
  import { DesignSystemFamily, DesignSystemSize, popover } from "@fluid-topics/design-system-variables";
16
13
  import { FtIcons } from "@fluid-topics/ft-icon";
17
- class FtdsPopover extends FtLitElement {
14
+ import { FtBasePopover } from "./ft-base-popover";
15
+ import { property } from "lit/decorators.js";
16
+ import { styles } from "./ftds-popover.styles";
17
+ class FtdsPopover extends FtBasePopover {
18
18
  constructor() {
19
19
  super(...arguments);
20
20
  this.heading = "";
21
- this.closeButtonLabel = "close info";
22
- this.openButtonIcon = FtIcons.CIRCLE_QUESTION;
23
- this.openButtonLabel = "more info";
24
- this.openButtonTooltipPosition = "bottom";
25
- this.opened = false;
26
- this.hidden = false;
27
- this.openButtonSize = DesignSystemSize.medium;
28
- this.openButtonFamily = DesignSystemFamily.info;
29
- this.watchFocusIn = (event) => {
30
- if (this.popoverWrapper && !event.composedPath().includes(this.popoverWrapper)) {
31
- this.close();
32
- }
33
- };
34
- this.watchEscapeKey = (event) => {
35
- var _a;
36
- if (event.key === "Escape") {
37
- this.close();
38
- (_a = this.openingButton) === null || _a === void 0 ? void 0 : _a.focus();
39
- }
40
- };
21
+ this.wrapperId = "ftds-popover-wrapper";
22
+ this.headingId = "ftds-popover-heading";
23
+ this.contentId = "ftds-popover-content";
24
+ this.maxWidth = popover.maxWidth;
41
25
  }
42
- render() {
43
- const classes = {
44
- opened: this.opened,
45
- };
46
- return this.hidden ? nothing : html `
47
- <div part="root-container" class="${classMap(classes)}">
48
- <ftds-button @focusin=${this.close}
49
- part="opening-button"
50
- icon="${this.openButtonIcon}"
51
- size="${this.openButtonSize}" family="${this.openButtonFamily}"
52
- label="${this.openButtonLabel}" tooltipposition="${this.openButtonTooltipPosition}"
53
- aria-haspopup="true" aria-expanded="${this.opened}" aria-controls="ftds-popover-wrapper"
54
- @click=${this.open}>
55
- </ftds-button>
56
- ${this.renderPopover()}
57
- </div>
26
+ renderOpeningButton() {
27
+ return html `
28
+ <ftds-button @focusin=${this.close}
29
+ part="opening-button"
30
+ icon="${this.openButtonIcon}"
31
+ size="${this.openButtonSize}" family="${this.openButtonFamily}"
32
+ label="${this.openButtonLabel}" tooltipposition="${this.openButtonTooltipPosition}"
33
+ aria-haspopup="true" aria-expanded="${this.opened}" aria-controls="${this.wrapperId}"
34
+ @click=${this.open}>
35
+ </ftds-button>
58
36
  `;
59
37
  }
60
- renderPopover() {
61
- return this.opened ? html `
62
- <div part="popover-container">
63
- <div part="overlay" @click=${this.close}></div>
64
- <div id="ftds-popover-wrapper" part="wrapper" role="dialog"
65
- aria-labelledby="${ifDefined(this.heading ? "ftds-popover-heading" : undefined)}"
66
- aria-describedby="ftds-popover-content">
67
- <div part="closing-button-container">
68
- <ftds-button part="closing-button"
69
- icon="${FtIcons.CLOSE}"
70
- size="${DesignSystemSize.small}"
71
- family="${DesignSystemFamily.neutral}"
72
- label="${this.closeButtonLabel}"
73
- @click=${this.closeAndFocusOpeningButton}></ftds-button>
74
- </div>
75
- <slot name="heading">
76
- ${this.heading ? html `
77
- <div id="ftds-popover-heading" part="heading">
78
- <ftds-typography element="span" variant="${FtdsTypographyVariants.body2semibold}">
79
- ${this.heading}
80
- </ftds-typography>
81
- </div>
82
- ` : nothing}
83
- </slot>
84
- <div id="ftds-popover-content" part="content">
85
- <ftds-typography variant="${FtdsTypographyVariants.body2medium}">
86
- <slot part="popover-content-slot"></slot>
87
- </ftds-typography>
88
- </div>
89
- <ftds-typography variant="${FtdsTypographyVariants.body2medium}" part="popover-link-typography">
90
- <slot name="link"
91
- part="popover-link"
92
- @slotchange=${() => this.requestUpdate()}
93
- ></slot>
94
- </ftds-typography>
95
- <div part="popover-sections">
96
- <slot name="sections" part="popover-sections-slot"></slot>
97
- </div>
98
- </div>
99
- </div>
100
- ` : nothing;
101
- }
102
- updated(properties) {
103
- super.updated(properties);
104
- if (properties.has("opened")) {
105
- if (this.opened) {
106
- setTimeout(() => {
107
- this.positionWrapper();
108
- document.addEventListener("keydown", this.watchEscapeKey);
109
- document.addEventListener("focusin", this.watchFocusIn);
110
- }, 0);
111
- }
112
- else {
113
- document.removeEventListener("keydown", this.watchEscapeKey);
114
- document.removeEventListener("focusin", this.watchFocusIn);
115
- }
116
- }
117
- }
118
- close() {
119
- this.opened = false;
120
- this.dispatchEvent(new CustomEvent("opened-changed", { detail: { opened: false } }));
121
- }
122
- open() {
123
- this.opened = true;
124
- this.dispatchEvent(new CustomEvent("opened-changed", { detail: { opened: true } }));
125
- }
126
- hasEmptySlot(slot) {
127
- return unslotText(slot).trim().length === 0;
128
- }
129
- closeAndFocusOpeningButton() {
130
- var _a, _b;
131
- this.close();
132
- (_a = this.openingButton) === null || _a === void 0 ? void 0 : _a.focus();
133
- if (window.FluidTopicsA11yHints.isKeyboardNavigation) {
134
- (_b = this.openingButton) === null || _b === void 0 ? void 0 : _b.showTooltip();
135
- }
38
+ renderClosingButton() {
39
+ return html `
40
+ <ftds-button part="closing-button"
41
+ icon="${FtIcons.CLOSE}"
42
+ size="${DesignSystemSize.small}"
43
+ family="${DesignSystemFamily.neutral}"
44
+ label="${this.closeButtonLabel}"
45
+ @click=${this.closeAndFocusOpeningButton}>
46
+ </ftds-button>
47
+ `;
136
48
  }
137
- async positionWrapper() {
138
- var _a, _b;
139
- if (this.popoverWrapper) {
140
- this.popoverWrapper.classList.remove("positioned");
141
- this.popoverWrapper.style.left = "";
142
- this.popoverWrapper.style.top = "";
143
- if (this.openingButton) {
144
- const allowedPlacements = ["bottom-start", "right-start", "bottom-end", "right-end", "left-start", "left-end", "top-start", "top-end"];
145
- const defaultPlacement = "bottom-start";
146
- const options = { placement: defaultPlacement, allowedPlacements: allowedPlacements, maxWidthCssVariable: popover.maxWidth };
147
- const { x, y } = await computeOffsetAutoPosition(this.openingButton, this.popoverWrapper, options);
148
- this.popoverWrapper.style.left = `${x}px`;
149
- this.popoverWrapper.style.top = `${y}px`;
150
- }
151
- this.popoverWrapper.classList.add("positioned");
152
- }
153
- this.hideUnusedSlots();
154
- (_a = this.closingButton) === null || _a === void 0 ? void 0 : _a.focus();
155
- if (window.FluidTopicsA11yHints.isKeyboardNavigation) {
156
- (_b = this.closingButton) === null || _b === void 0 ? void 0 : _b.showTooltip();
157
- }
49
+ renderFullContent() {
50
+ return html `
51
+ <slot name="heading">
52
+ ${this.heading ? html `
53
+ <div id="ftds-popover-heading" part="heading">
54
+ <ftds-typography element="span" variant="${FtdsTypographyVariants.body2semibold}">
55
+ ${this.heading}
56
+ </ftds-typography>
57
+ </div>
58
+ ` : nothing}
59
+ </slot>
60
+ <div id="ftds-popover-content" part="content">
61
+ <ftds-typography variant="${FtdsTypographyVariants.body2medium}">
62
+ <slot part="popover-content-slot"></slot>
63
+ </ftds-typography>
64
+ </div>
65
+ <ftds-typography variant="${FtdsTypographyVariants.body2medium}" part="popover-link-typography">
66
+ <slot name="link"
67
+ part="popover-link"
68
+ @slotchange=${() => this.requestUpdate()}
69
+ ></slot>
70
+ </ftds-typography>
71
+ <div part="popover-sections">
72
+ <slot name="sections" part="popover-sections-slot"></slot>
73
+ </div>
74
+ `;
158
75
  }
159
76
  hideUnusedSlots() {
160
77
  var _a, _b, _c;
@@ -162,48 +79,24 @@ class FtdsPopover extends FtLitElement {
162
79
  (_b = this.popoverContentDiv) === null || _b === void 0 ? void 0 : _b.classList.toggle("hidden", this.hasEmptySlot(this.popoverContentSlot));
163
80
  (_c = this.popoverSectionsDiv) === null || _c === void 0 ? void 0 : _c.classList.toggle("hidden", this.hasEmptySlot(this.popoverSectionsSlot));
164
81
  }
82
+ hasEmptySlot(slot) {
83
+ return unslotText(slot).trim().length === 0;
84
+ }
165
85
  }
86
+ FtdsPopover.styles = styles;
166
87
  FtdsPopover.elementDefinitions = {
167
88
  "ftds-typography": FtdsTypography,
168
89
  "ftds-button": FtdsButton,
169
90
  };
170
- FtdsPopover.styles = styles;
171
91
  __decorate([
172
92
  property()
173
93
  ], FtdsPopover.prototype, "heading", void 0);
174
- __decorate([
175
- property()
176
- ], FtdsPopover.prototype, "closeButtonLabel", void 0);
177
- __decorate([
178
- property()
179
- ], FtdsPopover.prototype, "openButtonIcon", void 0);
180
- __decorate([
181
- property()
182
- ], FtdsPopover.prototype, "openButtonLabel", void 0);
183
- __decorate([
184
- property()
185
- ], FtdsPopover.prototype, "openButtonTooltipPosition", void 0);
186
- __decorate([
187
- property({ type: Boolean })
188
- ], FtdsPopover.prototype, "opened", void 0);
189
- __decorate([
190
- property({ type: Boolean })
191
- ], FtdsPopover.prototype, "hidden", void 0);
192
- __decorate([
193
- property({ type: DesignSystemSize })
194
- ], FtdsPopover.prototype, "openButtonSize", void 0);
195
- __decorate([
196
- property({ type: DesignSystemFamily })
197
- ], FtdsPopover.prototype, "openButtonFamily", void 0);
198
94
  __decorate([
199
95
  query(`[part="opening-button"]`)
200
96
  ], FtdsPopover.prototype, "openingButton", void 0);
201
97
  __decorate([
202
98
  query(`[part="closing-button"]`)
203
99
  ], FtdsPopover.prototype, "closingButton", void 0);
204
- __decorate([
205
- query(`[part="wrapper"]`)
206
- ], FtdsPopover.prototype, "popoverWrapper", void 0);
207
100
  __decorate([
208
101
  query(`[part="content"]`)
209
102
  ], FtdsPopover.prototype, "popoverContentDiv", void 0);
@@ -1,9 +1,4 @@
1
- import { Position } from "@fluid-topics/ft-tooltip";
2
- export interface FtdsPopoverProperties {
3
- opened?: boolean;
4
- hidden?: boolean;
1
+ import { FtBasePopoverProperties } from "./ft-base-popover";
2
+ export interface FtdsPopoverProperties extends FtBasePopoverProperties {
5
3
  heading?: string;
6
- closeButtonLabel?: string;
7
- openButtonLabel?: string;
8
- openButtonTooltipPosition?: Position;
9
4
  }
package/build/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ export * from "./ft-popover.styles";
2
+ export * from "./ft-popover";
3
+ export * from "./ft-popover.properties";
1
4
  export * from "./ftds-popover";
2
5
  export * from "./ftds-popover.styles";
3
6
  export * from "./ftds-popover.properties";
package/build/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ export * from "./ft-popover.styles";
2
+ export * from "./ft-popover";
3
+ export * from "./ft-popover.properties";
1
4
  export * from "./ftds-popover";
2
5
  export * from "./ftds-popover.styles";
3
6
  export * from "./ftds-popover.properties";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-popover",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "A simple popover component",
5
5
  "keywords": [
6
6
  "Lit"
@@ -20,12 +20,12 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@fluid-topics/design-system-variables": "3.1.0",
23
- "@fluid-topics/ft-button": "2.0.6",
24
- "@fluid-topics/ft-icon": "2.0.6",
25
- "@fluid-topics/ft-link": "2.0.6",
26
- "@fluid-topics/ft-typography": "2.0.6",
27
- "@fluid-topics/ft-wc-utils": "2.0.6",
23
+ "@fluid-topics/ft-button": "2.0.7",
24
+ "@fluid-topics/ft-icon": "2.0.7",
25
+ "@fluid-topics/ft-link": "2.0.7",
26
+ "@fluid-topics/ft-typography": "2.0.7",
27
+ "@fluid-topics/ft-wc-utils": "2.0.7",
28
28
  "lit": "3.1.0"
29
29
  },
30
- "gitHead": "5ac509a512d721285a979c031a69f29cad891ce8"
30
+ "gitHead": "8555f88ae4858c380daee8311a887142043c46a9"
31
31
  }