@fluid-topics/ft-drawer 1.3.56
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/README.md +19 -0
- package/build/FtDrawerMessages.d.ts +6 -0
- package/build/FtDrawerMessages.js +5 -0
- package/build/ft-drawer.d.ts +23 -0
- package/build/ft-drawer.js +131 -0
- package/build/ft-drawer.light.js +1274 -0
- package/build/ft-drawer.min.js +1509 -0
- package/build/ft-drawer.properties.d.ts +7 -0
- package/build/ft-drawer.properties.js +2 -0
- package/build/ft-drawer.styles.d.ts +24 -0
- package/build/ft-drawer.styles.js +141 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +6 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
A drawer component
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npm install @fluid-topics/ft-drawer
|
|
7
|
+
yarn add @fluid-topics/ft-drawer
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { html } from "lit"
|
|
14
|
+
import "@fluid-topics/ft-drawer"
|
|
15
|
+
|
|
16
|
+
function render() {
|
|
17
|
+
return html` <ft-drawer foo="bar"></ft-drawer> `
|
|
18
|
+
}
|
|
19
|
+
```
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DefaultI18nMessages, I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n";
|
|
2
|
+
export interface FtDrawerMessages extends I18nMessages {
|
|
3
|
+
closeDrawer(): string;
|
|
4
|
+
}
|
|
5
|
+
export declare const ftDrawerContext: I18nMessageContext<FtDrawerMessages>;
|
|
6
|
+
export declare const defaultFtDrawerMessages: DefaultI18nMessages<FtDrawerMessages>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ElementDefinitionsMap, FtdsBase } from "@fluid-topics/ft-wc-utils";
|
|
2
|
+
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;
|
|
6
|
+
static styles: import("lit").CSSResult;
|
|
7
|
+
buttonLabel: string;
|
|
8
|
+
buttonIcon?: string;
|
|
9
|
+
heading: string;
|
|
10
|
+
dialog?: HTMLDialogElement;
|
|
11
|
+
constructor();
|
|
12
|
+
protected render(): import("lit-html").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
|
+
disconnectedCallback(): void;
|
|
20
|
+
private onClose;
|
|
21
|
+
private onOverlayClick;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
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 { FtdsBase, } from "@fluid-topics/ft-wc-utils";
|
|
10
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
11
|
+
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
|
+
import { ftDrawerStyles } from "./ft-drawer.styles";
|
|
18
|
+
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
|
+
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
|
+
});
|
|
39
|
+
this.addI18nContext(ftDrawerContext, defaultFtDrawerMessages);
|
|
40
|
+
}
|
|
41
|
+
render() {
|
|
42
|
+
const classes = {
|
|
43
|
+
"ft-drawer": true,
|
|
44
|
+
};
|
|
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" aria-labelledby="heading" @close=${this.onClose}>
|
|
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
|
+
}
|
|
75
|
+
renderCloseButton() {
|
|
76
|
+
return html `
|
|
77
|
+
<ft-button part="closing-button"
|
|
78
|
+
icon="${FtIcons.CLOSE}"
|
|
79
|
+
tertiary
|
|
80
|
+
label="${ftDrawerContext.messages.closeDrawer()}"
|
|
81
|
+
tooltipPosition="right"
|
|
82
|
+
@click=${this.close}></ft-button>`;
|
|
83
|
+
}
|
|
84
|
+
onTriggerClick(e) {
|
|
85
|
+
this.open(e.target);
|
|
86
|
+
}
|
|
87
|
+
open(elementToFocusOnClose) {
|
|
88
|
+
this.elementToFocusOnClose = elementToFocusOnClose;
|
|
89
|
+
if (this.dialog) {
|
|
90
|
+
this.dialog.showModal();
|
|
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.close();
|
|
98
|
+
this.onClose();
|
|
99
|
+
}
|
|
100
|
+
disconnectedCallback() {
|
|
101
|
+
super.disconnectedCallback();
|
|
102
|
+
this.close();
|
|
103
|
+
}
|
|
104
|
+
onClose() {
|
|
105
|
+
var _a;
|
|
106
|
+
this.intersectionObserver.disconnect();
|
|
107
|
+
(_a = this.elementToFocusOnClose) === null || _a === void 0 ? void 0 : _a.focus();
|
|
108
|
+
this.dispatchEvent(new FtDrawerCloseEvent());
|
|
109
|
+
}
|
|
110
|
+
onOverlayClick() {
|
|
111
|
+
this.close();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
FtDrawer.elementDefinitions = {
|
|
115
|
+
"ft-button": FtButton,
|
|
116
|
+
"ft-typography": FtTypography,
|
|
117
|
+
};
|
|
118
|
+
FtDrawer.styles = ftDrawerStyles;
|
|
119
|
+
__decorate([
|
|
120
|
+
property()
|
|
121
|
+
], FtDrawer.prototype, "buttonLabel", void 0);
|
|
122
|
+
__decorate([
|
|
123
|
+
property()
|
|
124
|
+
], FtDrawer.prototype, "buttonIcon", void 0);
|
|
125
|
+
__decorate([
|
|
126
|
+
property()
|
|
127
|
+
], FtDrawer.prototype, "heading", void 0);
|
|
128
|
+
__decorate([
|
|
129
|
+
query("dialog")
|
|
130
|
+
], FtDrawer.prototype, "dialog", void 0);
|
|
131
|
+
export { FtDrawer };
|