@fluid-topics/ftds-modal 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.
- package/README.md +34 -0
- package/build/FtDsModalMessages.d.ts +6 -0
- package/build/FtDsModalMessages.js +5 -0
- package/build/define.d.ts +1 -0
- package/build/define.js +3 -0
- package/build/definitions.d.ts +7 -0
- package/build/definitions.js +6 -0
- package/build/ftds-modal-confirm.d.ts +20 -0
- package/build/ftds-modal-confirm.js +107 -0
- package/build/ftds-modal.d.ts +25 -0
- package/build/ftds-modal.js +122 -0
- package/build/ftds-modal.light.js +1670 -0
- package/build/ftds-modal.min.js +1786 -0
- package/build/ftds-modal.properties.d.ts +9 -0
- package/build/ftds-modal.properties.js +2 -0
- package/build/ftds-modal.styles.d.ts +3 -0
- package/build/ftds-modal.styles.js +95 -0
- package/build/index.d.ts +8 -0
- package/build/index.js +8 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
The design system modal component
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npm install @fluid-topics/ftds-modal
|
|
7
|
+
yarn add @fluid-topics/ftds-modal
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import {html} from "lit"
|
|
14
|
+
import "@fluid-topics/ft-modal"
|
|
15
|
+
|
|
16
|
+
function render() {
|
|
17
|
+
return html`
|
|
18
|
+
<ftds-button @click="${() => document.querySelector<FtdsModal>("#example-modal")?.open()}">
|
|
19
|
+
Small example
|
|
20
|
+
</ftds-button>
|
|
21
|
+
<ftds-modal heading="Modal title" id="example-modal">
|
|
22
|
+
<ft-typography variant="${FtDsModalBodyTypography}">
|
|
23
|
+
Modal content text
|
|
24
|
+
</ft-typography>
|
|
25
|
+
<ftds-button slot="actions">
|
|
26
|
+
Button 1
|
|
27
|
+
</ftds-button>
|
|
28
|
+
<ftds-button slot="actions">
|
|
29
|
+
Button 2
|
|
30
|
+
</ftds-button>
|
|
31
|
+
</ftds-modal>
|
|
32
|
+
`
|
|
33
|
+
}
|
|
34
|
+
```
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DefaultI18nMessages, I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n";
|
|
2
|
+
export interface FtDsModalMessages extends I18nMessages {
|
|
3
|
+
closeModal(): string;
|
|
4
|
+
}
|
|
5
|
+
export declare const modal: I18nMessageContext<FtDsModalMessages>;
|
|
6
|
+
export declare const defaultModalMessages: DefaultI18nMessages<FtDsModalMessages>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/build/define.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ElementDefinitionsMap, FtLitElement } from "@fluid-topics/ft-wc-utils";
|
|
2
|
+
import { FtdsModal } from "./ftds-modal";
|
|
3
|
+
import { FtdsIcons } from "@fluid-topics/ftds-icon";
|
|
4
|
+
export declare class FtdsModalConfirm extends FtLitElement {
|
|
5
|
+
static elementDefinitions: ElementDefinitionsMap;
|
|
6
|
+
heading: string;
|
|
7
|
+
text: string;
|
|
8
|
+
confirmText: string;
|
|
9
|
+
cancelText: string;
|
|
10
|
+
confirmIcon: FtdsIcons;
|
|
11
|
+
confirmIconVariant: string;
|
|
12
|
+
cancelIcon: FtdsIcons;
|
|
13
|
+
cancelIconVariant: string;
|
|
14
|
+
modal: FtdsModal;
|
|
15
|
+
promiseResolve?: (value: boolean) => void;
|
|
16
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
17
|
+
askConfirmation(): Promise<boolean>;
|
|
18
|
+
onConfirm(): void;
|
|
19
|
+
onCancel(): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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 { DesignSystemFamily, FtLitElement, } from "@fluid-topics/ft-wc-utils";
|
|
8
|
+
import { html } from "lit";
|
|
9
|
+
import { FtdsModal } from "./ftds-modal";
|
|
10
|
+
import { DesignSystemSize } from "@fluid-topics/design-system-variables";
|
|
11
|
+
import { FtDsModalBodyTypography } from "./ftds-modal.properties";
|
|
12
|
+
import { FtdsIcons, FtdsIconVariants, } from "@fluid-topics/ftds-icon";
|
|
13
|
+
import { property, query, } from "lit/decorators.js";
|
|
14
|
+
import { FtdsTypography } from "@fluid-topics/ftds-typography";
|
|
15
|
+
import { FtdsButton } from "@fluid-topics/ftds-button";
|
|
16
|
+
export class FtdsModalConfirm extends FtLitElement {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.confirmText = "Confirm";
|
|
20
|
+
this.cancelText = "Cancel";
|
|
21
|
+
this.confirmIcon = FtdsIcons.CHECK;
|
|
22
|
+
this.confirmIconVariant = FtdsIconVariants.regular;
|
|
23
|
+
this.cancelIcon = FtdsIcons.XMARK;
|
|
24
|
+
this.cancelIconVariant = FtdsIconVariants.regular;
|
|
25
|
+
}
|
|
26
|
+
render() {
|
|
27
|
+
return html `
|
|
28
|
+
<ftds-modal
|
|
29
|
+
heading="${this.heading}"
|
|
30
|
+
size="${DesignSystemSize.small}"
|
|
31
|
+
@close=${this.onCancel}
|
|
32
|
+
>
|
|
33
|
+
<ftds-typography variant="${FtDsModalBodyTypography}">
|
|
34
|
+
${this.text}
|
|
35
|
+
</ftds-typography>
|
|
36
|
+
<ftds-button slot="actions"
|
|
37
|
+
tertiary
|
|
38
|
+
autofocus
|
|
39
|
+
family="${DesignSystemFamily.neutral}"
|
|
40
|
+
size="${DesignSystemSize.large}"
|
|
41
|
+
icon="${this.cancelIcon}"
|
|
42
|
+
iconVariant="${this.cancelIconVariant}"
|
|
43
|
+
@click=${this.onCancel}>
|
|
44
|
+
${this.cancelText}
|
|
45
|
+
</ftds-button>
|
|
46
|
+
<ftds-button slot="actions"
|
|
47
|
+
primary
|
|
48
|
+
size="${DesignSystemSize.large}"
|
|
49
|
+
@click=${this.onConfirm}
|
|
50
|
+
icon="${this.confirmIcon}"
|
|
51
|
+
iconVariant="${this.confirmIconVariant}">
|
|
52
|
+
${this.confirmText}
|
|
53
|
+
</ftds-button>
|
|
54
|
+
</ftds-modal>
|
|
55
|
+
`;
|
|
56
|
+
}
|
|
57
|
+
async askConfirmation() {
|
|
58
|
+
this.modal.open();
|
|
59
|
+
const result = await new Promise((resolve) => {
|
|
60
|
+
this.promiseResolve = resolve;
|
|
61
|
+
});
|
|
62
|
+
this.modal.close();
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
onConfirm() {
|
|
66
|
+
var _a;
|
|
67
|
+
(_a = this.promiseResolve) === null || _a === void 0 ? void 0 : _a.call(this, true);
|
|
68
|
+
this.promiseResolve = undefined;
|
|
69
|
+
}
|
|
70
|
+
onCancel() {
|
|
71
|
+
var _a;
|
|
72
|
+
(_a = this.promiseResolve) === null || _a === void 0 ? void 0 : _a.call(this, false);
|
|
73
|
+
this.promiseResolve = undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
FtdsModalConfirm.elementDefinitions = {
|
|
77
|
+
"ftds-modal": FtdsModal,
|
|
78
|
+
"ftds-typography": FtdsTypography,
|
|
79
|
+
"ftds-button": FtdsButton,
|
|
80
|
+
};
|
|
81
|
+
__decorate([
|
|
82
|
+
property({ type: String })
|
|
83
|
+
], FtdsModalConfirm.prototype, "heading", void 0);
|
|
84
|
+
__decorate([
|
|
85
|
+
property({ type: String })
|
|
86
|
+
], FtdsModalConfirm.prototype, "text", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
property({ type: String })
|
|
89
|
+
], FtdsModalConfirm.prototype, "confirmText", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
property({ type: String })
|
|
92
|
+
], FtdsModalConfirm.prototype, "cancelText", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
property({ type: String })
|
|
95
|
+
], FtdsModalConfirm.prototype, "confirmIcon", void 0);
|
|
96
|
+
__decorate([
|
|
97
|
+
property({ type: String })
|
|
98
|
+
], FtdsModalConfirm.prototype, "confirmIconVariant", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
property({ type: String })
|
|
101
|
+
], FtdsModalConfirm.prototype, "cancelIcon", void 0);
|
|
102
|
+
__decorate([
|
|
103
|
+
property({ type: String })
|
|
104
|
+
], FtdsModalConfirm.prototype, "cancelIconVariant", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
query("ftds-modal")
|
|
107
|
+
], FtdsModalConfirm.prototype, "modal", void 0);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PropertyValues } from "lit";
|
|
2
|
+
import { ElementDefinitionsMap, FtdsBase } from "@fluid-topics/ft-wc-utils";
|
|
3
|
+
import { FtdsModalProperties } from "./ftds-modal.properties";
|
|
4
|
+
import { DesignSystemSize } from "@fluid-topics/design-system-variables";
|
|
5
|
+
import { FtdsIcons, FtdsIconVariants } from "@fluid-topics/ftds-icon";
|
|
6
|
+
declare const FtdsModal_base: typeof FtdsBase & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
|
|
7
|
+
export declare class FtdsModal extends FtdsModal_base implements FtdsModalProperties {
|
|
8
|
+
static elementDefinitions: ElementDefinitionsMap;
|
|
9
|
+
static styles: import("lit").CSSResult[];
|
|
10
|
+
heading: string;
|
|
11
|
+
icon?: FtdsIcons;
|
|
12
|
+
iconVariant?: FtdsIconVariants;
|
|
13
|
+
dialogOpen?: boolean;
|
|
14
|
+
private dialog;
|
|
15
|
+
size: DesignSystemSize;
|
|
16
|
+
constructor();
|
|
17
|
+
protected render(): import("lit-html").TemplateResult<1>;
|
|
18
|
+
protected contentAvailableCallback(props: PropertyValues): void;
|
|
19
|
+
open(): void;
|
|
20
|
+
close(): void;
|
|
21
|
+
disconnectedCallback(): void;
|
|
22
|
+
private onOverlayClick;
|
|
23
|
+
private onClose;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
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 { DesignSystemFamily, FtdsBase, } from "@fluid-topics/ft-wc-utils";
|
|
10
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
11
|
+
import { designSystemStyle } from "./ftds-modal.styles";
|
|
12
|
+
import { FtdsButton } from "@fluid-topics/ftds-button";
|
|
13
|
+
import { DesignSystemSize } from "@fluid-topics/design-system-variables";
|
|
14
|
+
import { FtdsIcon, FtdsIcons, } from "@fluid-topics/ftds-icon";
|
|
15
|
+
import { FtdsTypography, FtdsTypographyVariants, } from "@fluid-topics/ftds-typography";
|
|
16
|
+
import { withI18n } from "@fluid-topics/ft-i18n";
|
|
17
|
+
import { defaultModalMessages, modal, } from "./FtDsModalMessages";
|
|
18
|
+
class FtdsModalCloseEvent extends Event {
|
|
19
|
+
constructor() {
|
|
20
|
+
super("close");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class FtdsModal extends withI18n(FtdsBase) {
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.heading = "";
|
|
27
|
+
this.size = DesignSystemSize.small;
|
|
28
|
+
this.addI18nContext(modal, defaultModalMessages);
|
|
29
|
+
}
|
|
30
|
+
render() {
|
|
31
|
+
const classes = {
|
|
32
|
+
"ftds-modal": true,
|
|
33
|
+
...this.getDesignSystemBaseClasses(),
|
|
34
|
+
};
|
|
35
|
+
return html `
|
|
36
|
+
<div class="${classMap(classes)}" part="container">
|
|
37
|
+
<dialog part="dialog"
|
|
38
|
+
@close=${this.onClose}>
|
|
39
|
+
<div part="overlay" @click=${this.onOverlayClick}></div>
|
|
40
|
+
<div part="inner-container">
|
|
41
|
+
<div part="header">
|
|
42
|
+
${this.icon ? html `
|
|
43
|
+
<ftds-icon part="icon" icon="${this.icon}" variant="${this.iconVariant}"></ftds-icon>
|
|
44
|
+
` : nothing}
|
|
45
|
+
<ftds-typography part="heading" variant="${FtdsTypographyVariants.body1semibold}">
|
|
46
|
+
${this.heading}
|
|
47
|
+
</ftds-typography>
|
|
48
|
+
<ftds-button part="closing-button"
|
|
49
|
+
size="${DesignSystemSize.large}"
|
|
50
|
+
icon="${FtdsIcons.XMARK}"
|
|
51
|
+
tertiary
|
|
52
|
+
family="${DesignSystemFamily.neutral}"
|
|
53
|
+
label="${modal.messages.closeModal()}"
|
|
54
|
+
@click=${this.close}>
|
|
55
|
+
</ftds-button>
|
|
56
|
+
</div>
|
|
57
|
+
<div part="body">
|
|
58
|
+
<div part="content">
|
|
59
|
+
<slot></slot>
|
|
60
|
+
</div>
|
|
61
|
+
<div part="actions">
|
|
62
|
+
<slot name="actions"></slot>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
</dialog>
|
|
67
|
+
</div>
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
contentAvailableCallback(props) {
|
|
71
|
+
super.contentAvailableCallback(props);
|
|
72
|
+
if (props.has("dialogOpen")) {
|
|
73
|
+
if (this.dialogOpen) {
|
|
74
|
+
this.dialog.showModal();
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.dialog.close();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
open() {
|
|
82
|
+
this.dialogOpen = true;
|
|
83
|
+
}
|
|
84
|
+
close() {
|
|
85
|
+
this.dialogOpen = false;
|
|
86
|
+
}
|
|
87
|
+
disconnectedCallback() {
|
|
88
|
+
super.disconnectedCallback();
|
|
89
|
+
this.close();
|
|
90
|
+
}
|
|
91
|
+
onOverlayClick() {
|
|
92
|
+
this.close();
|
|
93
|
+
}
|
|
94
|
+
onClose() {
|
|
95
|
+
this.dispatchEvent(new FtdsModalCloseEvent());
|
|
96
|
+
this.close();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
FtdsModal.elementDefinitions = {
|
|
100
|
+
"ftds-button": FtdsButton,
|
|
101
|
+
"ftds-typography": FtdsTypography,
|
|
102
|
+
"ftds-icon": FtdsIcon,
|
|
103
|
+
};
|
|
104
|
+
FtdsModal.styles = designSystemStyle;
|
|
105
|
+
__decorate([
|
|
106
|
+
property()
|
|
107
|
+
], FtdsModal.prototype, "heading", void 0);
|
|
108
|
+
__decorate([
|
|
109
|
+
property()
|
|
110
|
+
], FtdsModal.prototype, "icon", void 0);
|
|
111
|
+
__decorate([
|
|
112
|
+
property()
|
|
113
|
+
], FtdsModal.prototype, "iconVariant", void 0);
|
|
114
|
+
__decorate([
|
|
115
|
+
property({ type: Boolean, reflect: true })
|
|
116
|
+
], FtdsModal.prototype, "dialogOpen", void 0);
|
|
117
|
+
__decorate([
|
|
118
|
+
query("dialog")
|
|
119
|
+
], FtdsModal.prototype, "dialog", void 0);
|
|
120
|
+
__decorate([
|
|
121
|
+
property()
|
|
122
|
+
], FtdsModal.prototype, "size", void 0);
|