This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
modal-container.ts
97 lines (82 loc) · 2.6 KB
/
modal-container.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { CSSResultGroup, LitElement, html } from 'lit';
import { customElement } from 'lit/decorators.js';
import { WebComponentsBase } from '../base';
import { modalStyle } from './styles/index.style';
import { ModalOptions } from './types';
const WebComponentsBaseElement = WebComponentsBase(LitElement);
const styles: CSSResultGroup[] = [WebComponentsBaseElement.styles, modalStyle];
@customElement('superviz-modal-container')
export class ModalContainer extends WebComponentsBaseElement {
static styles = styles;
private options: ModalOptions;
setOptions(options: ModalOptions) {
this.options = options;
}
private closeModal = () => {
window.document.body.dispatchEvent(
new CustomEvent('superviz-modal--close', {
bubbles: true,
composed: true,
}),
);
};
private confirmModal = () => {
window.document.body.dispatchEvent(
new CustomEvent('superviz-modal--confirm', {
bubbles: true,
composed: true,
}),
);
};
protected render() {
const header = () => {
return html`
<div class="modal--header">
<span class="text text-bold sv-gray-600">${this.options.title}</span>
<div class="close" @click=${this.closeModal}>
<superviz-icon name="close" size="md"></superviz-icon>
</div>
</div>
`;
};
const body = () => {
return html`
<div class="modal--body">
<div class="modal--body-content">${this.options.body}</div>
</div>
`;
};
const footer = () => {
if (this.options.footer) {
return html` <div class="modal--footer">${this.options.footer}</div> `;
}
const confirmLabel = this.options.confirmLabel || 'OK';
const cancelLabel = this.options.cancelLabel || 'Cancel';
if (this.options.confirm && this.options.cancel) {
return html`
<div class="modal--footer">
<button class="text text-bold btn btn--cancel" @click=${this.closeModal}>
${cancelLabel}
</button>
<button class="text text-bold btn btn--confirm" @click=${this.confirmModal}>
${confirmLabel}
</button>
</div>
`;
}
return html`
<div class="modal--footer">
<button class="text text-bold btn btn--confirm" @click=${this.confirmModal}>
${confirmLabel}
</button>
</div>
`;
};
return html`
<div class="modal--overlay"></div>
<div class="modal--container">
<div class="modal">${header()} ${body()} ${footer()}</div>
</div>
`;
}
}