@fluid-topics/ft-drawer 2.2.36 → 2.2.38

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,25 +1,8 @@
1
- import { ElementDefinitionsMap, FtdsBase } from "@fluid-topics/ft-wc-utils";
2
1
  import { FtDrawerProperties } from "./ft-drawer.properties";
3
- declare const FtDrawer_base: typeof FtdsBase & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
4
- export declare class FtDrawer extends FtDrawer_base implements FtDrawerProperties {
5
- static elementDefinitions: ElementDefinitionsMap;
2
+ import { FtModal } from "@fluid-topics/ft-modal";
3
+ export declare class FtDrawer extends FtModal implements FtDrawerProperties {
6
4
  static styles: import("lit").CSSResult;
7
- buttonLabel: string;
8
- buttonIcon?: string;
9
- heading: string;
10
- dialog?: HTMLDialogElement;
11
- constructor();
12
- protected render(): import("lit").TemplateResult<1>;
13
- private renderCloseButton;
14
- protected onTriggerClick(e: MouseEvent): void;
15
- protected elementToFocusOnClose?: HTMLElement;
16
- private intersectionObserver;
17
- open(elementToFocusOnClose?: HTMLElement): void;
18
- close(): void;
19
- connectedCallback(): void;
20
- disconnectedCallback(): void;
21
- private onClose;
22
- private onOverlayClick;
23
- private onEscapePressed;
5
+ protected setupI18nContext(): void;
6
+ protected getContainerClasses(): Record<string, boolean>;
7
+ protected renderCloseButton(): import("lit").TemplateResult<1>;
24
8
  }
25
- export {};
@@ -1,76 +1,16 @@
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 { focusTrap, FtdsBase, } from "@fluid-topics/ft-wc-utils";
10
- import { classMap } from "lit/directives/class-map.js";
1
+ import { html } from "lit";
11
2
  import { FtIcons } from "@fluid-topics/ft-icon";
12
- import { FtTypography, FtTypographyVariants, } from "@fluid-topics/ft-typography";
13
- import { withI18n } from "@fluid-topics/ft-i18n";
14
- import { when } from "lit/directives/when.js";
15
- import { ifDefined } from "lit/directives/if-defined.js";
16
- import { FtButton } from "@fluid-topics/ft-button";
17
3
  import { ftDrawerStyles } from "./ft-drawer.styles";
18
4
  import { defaultFtDrawerMessages, ftDrawerContext, } from "./FtDrawerMessages";
19
- class FtDrawerCloseEvent extends Event {
20
- constructor() {
21
- super("close");
22
- }
23
- }
24
- class FtDrawerOpenEvent extends Event {
25
- constructor() {
26
- super("open");
27
- }
28
- }
29
- export class FtDrawer extends withI18n(FtdsBase) {
30
- constructor() {
31
- super();
32
- this.buttonLabel = "";
33
- this.heading = "";
34
- this.intersectionObserver = new IntersectionObserver(() => {
35
- if (this.dialog && !this.dialog.checkVisibility()) {
36
- this.close();
37
- }
38
- });
5
+ import { FtModal } from "@fluid-topics/ft-modal";
6
+ export class FtDrawer extends FtModal {
7
+ setupI18nContext() {
39
8
  this.addI18nContext(ftDrawerContext, defaultFtDrawerMessages);
40
9
  }
41
- render() {
42
- const classes = {
10
+ getContainerClasses() {
11
+ return {
43
12
  "ft-drawer": true,
44
13
  };
45
- return html `
46
- <div class="${classMap(classes)}" part="container">
47
- <slot @click=${this.onTriggerClick} name="trigger">
48
- <ft-button part="button" icon="${ifDefined(this.buttonIcon)}" label="${this.buttonLabel}" ariaHasPopup="dialog">
49
- ${when(this.buttonIcon, () => nothing, () => this.buttonLabel)}
50
- </ft-button>
51
- </slot>
52
- <dialog part="dialog" popover="manual" aria-labelledby="heading" @close=${this.onClose} ${focusTrap()}>
53
- <div part="overlay" @click=${this.onOverlayClick}></div>
54
- <div part="inner-container">
55
- <div part="header">
56
- ${this.renderCloseButton()}
57
- <ft-typography id="heading" part="heading" role="heading" variant="${FtTypographyVariants.title}">
58
- ${this.heading}
59
- </ft-typography>
60
- <slot name="header-actions"></slot>
61
- </div>
62
- <div part="body">
63
- <div part="content">
64
- <slot></slot>
65
- </div>
66
- </div>
67
- <div part="actions">
68
- <slot name="actions"></slot>
69
- </div>
70
- </div>
71
- </dialog>
72
- </div>
73
- `;
74
14
  }
75
15
  renderCloseButton() {
76
16
  return html `
@@ -81,60 +21,5 @@ export class FtDrawer extends withI18n(FtdsBase) {
81
21
  tooltipPosition="right"
82
22
  @click=${this.close}></ft-button>`;
83
23
  }
84
- onTriggerClick(e) {
85
- this.open(e.target);
86
- }
87
- open(elementToFocusOnClose) {
88
- this.elementToFocusOnClose = elementToFocusOnClose;
89
- if (this.dialog) {
90
- this.dialog.showPopover();
91
- this.intersectionObserver.observe(this.dialog);
92
- this.dispatchEvent(new FtDrawerOpenEvent());
93
- }
94
- }
95
- close() {
96
- var _a;
97
- (_a = this.dialog) === null || _a === void 0 ? void 0 : _a.hidePopover();
98
- this.onClose();
99
- }
100
- connectedCallback() {
101
- super.connectedCallback();
102
- this.addEventListener("keydown", this.onEscapePressed);
103
- }
104
- disconnectedCallback() {
105
- super.disconnectedCallback();
106
- this.removeEventListener("keydown", this.onEscapePressed);
107
- this.close();
108
- }
109
- onClose() {
110
- var _a;
111
- this.intersectionObserver.disconnect();
112
- (_a = this.elementToFocusOnClose) === null || _a === void 0 ? void 0 : _a.focus();
113
- this.dispatchEvent(new FtDrawerCloseEvent());
114
- }
115
- onOverlayClick() {
116
- this.close();
117
- }
118
- onEscapePressed(e) {
119
- if (e.key === "Escape") {
120
- this.close();
121
- }
122
- }
123
24
  }
124
- FtDrawer.elementDefinitions = {
125
- "ft-button": FtButton,
126
- "ft-typography": FtTypography,
127
- };
128
25
  FtDrawer.styles = ftDrawerStyles;
129
- __decorate([
130
- property()
131
- ], FtDrawer.prototype, "buttonLabel", void 0);
132
- __decorate([
133
- property()
134
- ], FtDrawer.prototype, "buttonIcon", void 0);
135
- __decorate([
136
- property()
137
- ], FtDrawer.prototype, "heading", void 0);
138
- __decorate([
139
- query("dialog")
140
- ], FtDrawer.prototype, "dialog", void 0);