@fluid-topics/ft-popover 1.1.115

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,29 @@
1
+ import { nothing, PropertyValues } from "lit";
2
+ import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
3
+ 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
+ export declare class FtdsPopover extends FtLitElement implements FtdsPopoverProperties {
7
+ static elementDefinitions: ElementDefinitionsMap;
8
+ heading: string;
9
+ closeButtonLabel: string;
10
+ openButtonLabel: string;
11
+ openButtonTooltipPosition: Position;
12
+ opened: boolean;
13
+ openButtonSize: DesignSystemSize;
14
+ openButtonFamily: DesignSystemFamily;
15
+ private openingButton;
16
+ private closingButton;
17
+ private popoverWrapper;
18
+ static styles: import("lit").CSSResult;
19
+ protected render(): import("lit").TemplateResult<1>;
20
+ renderPopover(): import("lit").TemplateResult<1> | typeof nothing;
21
+ renderClosingButton(): import("lit").TemplateResult<1>;
22
+ renderHeading(): import("lit").TemplateResult<1> | typeof nothing;
23
+ updated(properties: PropertyValues<FtdsPopover>): void;
24
+ close(): void;
25
+ open(): void;
26
+ private watchFocusIn;
27
+ private watchEscapeKey;
28
+ private positionWrapper;
29
+ }
@@ -0,0 +1,169 @@
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, nothing } from "lit";
8
+ import { property, query, } from "lit/decorators.js";
9
+ import { computeFlipOffsetPosition, FtLitElement } from "@fluid-topics/ft-wc-utils";
10
+ import { FtTypography } from "@fluid-topics/ft-typography";
11
+ import { FtdsButton } from "@fluid-topics/ft-button";
12
+ import { styles } from "./ftds-popover.styles";
13
+ import { classMap } from "lit/directives/class-map.js";
14
+ import { DesignSystemFamily, DesignSystemSize } from "@fluid-topics/design-system-variables";
15
+ import { FtIcons } from "@fluid-topics/ft-icon";
16
+ class FtdsPopover extends FtLitElement {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.heading = "";
20
+ this.closeButtonLabel = "close info";
21
+ this.openButtonLabel = "more info";
22
+ this.openButtonTooltipPosition = "bottom";
23
+ this.opened = false;
24
+ this.openButtonSize = DesignSystemSize.medium;
25
+ this.openButtonFamily = DesignSystemFamily.brand;
26
+ this.watchFocusIn = (event) => {
27
+ if (!event.composedPath().includes(this.popoverWrapper)) {
28
+ this.close();
29
+ }
30
+ };
31
+ this.watchEscapeKey = (event) => {
32
+ if (event.key === "Escape") {
33
+ this.close();
34
+ this.openingButton.focus();
35
+ }
36
+ };
37
+ }
38
+ render() {
39
+ const classes = {
40
+ "ftds-popover": true,
41
+ "ftds-popover--opened": this.opened
42
+ };
43
+ return html `
44
+ <div part="container" class="${classMap(classes)}">
45
+ <ftds-button @focusin="${this.close}"
46
+ part="opening-button"
47
+ size="${this.openButtonSize}" family="${this.openButtonFamily}" label="${this.openButtonLabel}"
48
+ tooltipposition="${this.openButtonTooltipPosition}" icon="${FtIcons.CIRCLE_QUESTION}"
49
+ aria-haspopup="true" aria-expanded="${this.opened}" aria-controls="ftds-popover-dialog"
50
+ @click=${this.open}>
51
+ </ftds-button>
52
+ ${this.renderPopover()}
53
+ </div>
54
+ `;
55
+ }
56
+ renderPopover() {
57
+ return this.opened ? html `
58
+ <div class="ftds-popover--container">
59
+ <div class="ftds-popover--overlay" part="overlay" @click="${this.close}"></div>
60
+ <div class="ftds-popover--wrapper" part="wrapper" role="dialog" id="ftds-popover-dialog"
61
+ aria-labelledby="ftds-popover-heading" aria-describedby="ftds-popover-content">
62
+ ${this.renderClosingButton()}
63
+ <slot name="heading">
64
+ ${this.renderHeading()}
65
+ </slot>
66
+ <div class="ftds-popover--content" part="content" id="ftds-popover-content">
67
+ <ft-typography variant="body-2-medium">
68
+ <slot></slot>
69
+ </ft-typography>
70
+ </div>
71
+ <ft-typography variant="body-2-medium">
72
+ <slot name="link"
73
+ part="popover-link"
74
+ class="ftds-popover--link"
75
+ @slotchange=${this.requestUpdate}
76
+ ></slot>
77
+ </ft-typography>
78
+ </div>
79
+ </div>
80
+ ` : nothing;
81
+ }
82
+ renderClosingButton() {
83
+ return html `
84
+ <div class="ftds-popover--closing-button">
85
+ <ftds-button icon="${FtIcons.CLOSE}" size="${DesignSystemSize.small}" family="${DesignSystemFamily.neutral}"
86
+ part="closing-button" label="${this.closeButtonLabel}" @click=${this.close}></ftds-button>
87
+ </div>
88
+ `;
89
+ }
90
+ renderHeading() {
91
+ return this.heading ? html `
92
+ <div class="ftds-popover--heading" part="heading" id="ftds-popover-heading">
93
+ <ft-typography element="span" variant="body-2-semibold">${this.heading}</ft-typography>
94
+ </div>
95
+ ` : nothing;
96
+ }
97
+ updated(properties) {
98
+ super.updated(properties);
99
+ if (properties.has("opened")) {
100
+ if (this.opened) {
101
+ setTimeout(() => {
102
+ this.positionWrapper();
103
+ document.addEventListener("keydown", this.watchEscapeKey);
104
+ document.addEventListener("focusin", this.watchFocusIn);
105
+ }, 0);
106
+ }
107
+ else {
108
+ document.removeEventListener("keydown", this.watchEscapeKey);
109
+ document.removeEventListener("focusin", this.watchFocusIn);
110
+ }
111
+ }
112
+ }
113
+ close() {
114
+ this.opened = false;
115
+ this.dispatchEvent(new CustomEvent("opened-changed", { detail: { opened: false } }));
116
+ }
117
+ open() {
118
+ this.opened = true;
119
+ this.dispatchEvent(new CustomEvent("opened-changed", { detail: { opened: true } }));
120
+ }
121
+ async positionWrapper() {
122
+ this.popoverWrapper.classList.remove("ftds-popover--wrapper-positioned");
123
+ this.popoverWrapper.style.left = "";
124
+ this.popoverWrapper.style.top = "";
125
+ const reference = this.openingButton;
126
+ const fallbackPlacements = ["right-start", "bottom-end", "right-end", "left-start", "left-end", "top-start", "top-end"];
127
+ const { x, y } = await computeFlipOffsetPosition(reference, this.popoverWrapper, "bottom-start", fallbackPlacements, "fixed");
128
+ this.popoverWrapper.style.left = `${x}px`;
129
+ this.popoverWrapper.style.top = `${y}px`;
130
+ this.popoverWrapper.classList.add("ftds-popover--wrapper-positioned");
131
+ this.closingButton.focus();
132
+ }
133
+ }
134
+ FtdsPopover.elementDefinitions = {
135
+ "ft-typography": FtTypography,
136
+ "ftds-button": FtdsButton,
137
+ };
138
+ FtdsPopover.styles = styles;
139
+ __decorate([
140
+ property({ type: String })
141
+ ], FtdsPopover.prototype, "heading", void 0);
142
+ __decorate([
143
+ property({ type: String })
144
+ ], FtdsPopover.prototype, "closeButtonLabel", void 0);
145
+ __decorate([
146
+ property({ type: String })
147
+ ], FtdsPopover.prototype, "openButtonLabel", void 0);
148
+ __decorate([
149
+ property({ type: String })
150
+ ], FtdsPopover.prototype, "openButtonTooltipPosition", void 0);
151
+ __decorate([
152
+ property({ type: Boolean })
153
+ ], FtdsPopover.prototype, "opened", void 0);
154
+ __decorate([
155
+ property({ type: DesignSystemSize })
156
+ ], FtdsPopover.prototype, "openButtonSize", void 0);
157
+ __decorate([
158
+ property({ type: DesignSystemFamily })
159
+ ], FtdsPopover.prototype, "openButtonFamily", void 0);
160
+ __decorate([
161
+ query("[part=opening-button]")
162
+ ], FtdsPopover.prototype, "openingButton", void 0);
163
+ __decorate([
164
+ query("[part=closing-button]")
165
+ ], FtdsPopover.prototype, "closingButton", void 0);
166
+ __decorate([
167
+ query("[part=wrapper]")
168
+ ], FtdsPopover.prototype, "popoverWrapper", void 0);
169
+ export { FtdsPopover };
@@ -0,0 +1,8 @@
1
+ import { Position } from "@fluid-topics/ft-tooltip";
2
+ export interface FtdsPopoverProperties {
3
+ opened?: boolean;
4
+ heading?: string;
5
+ closeButtonLabel?: string;
6
+ openButtonLabel?: string;
7
+ openButtonTooltipPosition?: Position;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const styles: import("lit").CSSResult;
@@ -0,0 +1,83 @@
1
+ import { css } from "lit";
2
+ import { popover } from "@fluid-topics/design-system-variables";
3
+ //language=css
4
+ export const styles = css `
5
+ :host {
6
+ position: relative;
7
+ display: inline-block;
8
+ }
9
+
10
+ .ftds-popover {
11
+ position: relative;
12
+ }
13
+
14
+ .ftds-popover--container {
15
+ position: absolute;
16
+ z-index: 2;
17
+ display: block;
18
+ margin: auto;
19
+ }
20
+
21
+ .ftds-popover--closing-button {
22
+ position: absolute;
23
+ top: 8px;
24
+ right: 8px;
25
+ }
26
+
27
+ .ftds-popover--overlay {
28
+ position: fixed;
29
+ top: 0;
30
+ right: 0;
31
+ bottom: 0;
32
+ left: 0;
33
+ height: 100%;
34
+ width: 100%;
35
+ opacity: 0;
36
+ }
37
+
38
+ .ftds-popover--wrapper {
39
+ visibility: hidden;
40
+ position: fixed;
41
+ display: flex;
42
+ flex-direction: column;
43
+
44
+ max-width: 464px;
45
+ width: max-content;
46
+
47
+ padding-left: ${popover.horizontalPadding};
48
+ padding-right: ${popover.horizontalPadding};
49
+ padding-top: ${popover.verticalPadding};
50
+ padding-bottom: ${popover.verticalPadding};
51
+ gap: ${popover.gap};
52
+
53
+ background-color: ${popover.backgroundColor};
54
+ border-radius: ${popover.borderRadius};
55
+ box-shadow: ${popover.shadow};
56
+ }
57
+
58
+ .ftds-popover--heading {
59
+ flex-shrink: 0;
60
+
61
+ display: flex;
62
+ align-items: center;
63
+ gap: ${popover.gap};
64
+
65
+ color: ${popover.titleColor};
66
+ }
67
+
68
+ .ftds-popover--heading ft-typography {
69
+ flex-grow: 1;
70
+ flex-shrink: 1;
71
+ text-overflow: ellipsis;
72
+ overflow: hidden;
73
+ white-space: nowrap;
74
+ }
75
+
76
+ .ftds-popover--content {
77
+ color: ${popover.bodyColor};
78
+ }
79
+
80
+ .ftds-popover--wrapper-positioned {
81
+ visibility: visible;
82
+ }
83
+ `;
@@ -0,0 +1,3 @@
1
+ export * from "./ftds-popover";
2
+ export * from "./ftds-popover.styles";
3
+ export * from "./ftds-popover.properties";
package/build/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { customElement } from "@fluid-topics/ft-wc-utils";
2
+ import { FtdsPopover } from "./ftds-popover";
3
+ export * from "./ftds-popover";
4
+ export * from "./ftds-popover.styles";
5
+ export * from "./ftds-popover.properties";
6
+ customElement("ftds-popover")(FtdsPopover);
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@fluid-topics/ft-popover",
3
+ "version": "1.1.115",
4
+ "description": "A simple popover component",
5
+ "keywords": [
6
+ "Lit"
7
+ ],
8
+ "author": "Fluid Topics <devtopics@antidot.net>",
9
+ "license": "ISC",
10
+ "main": "build/index.js",
11
+ "web": "build/ft-popover.min.js",
12
+ "typings": "build/index",
13
+ "files": [
14
+ "build/**/*.ts",
15
+ "build/**/*.js"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
20
+ },
21
+ "dependencies": {
22
+ "@fluid-topics/design-system-variables": "0.0.29",
23
+ "@fluid-topics/ft-button": "1.1.115",
24
+ "@fluid-topics/ft-icon": "1.1.115",
25
+ "@fluid-topics/ft-link": "1.1.115",
26
+ "@fluid-topics/ft-typography": "1.1.115",
27
+ "@fluid-topics/ft-wc-utils": "1.1.115",
28
+ "lit": "3.1.0"
29
+ },
30
+ "gitHead": "7a0d8f324bb95d068d787990f2d1f1325399467f"
31
+ }