ezfw-core 1.0.8 → 1.0.10
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/components/dialog/EzDialog.ts +168 -0
- package/modules.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import styles from './EzDialog.module.scss';
|
|
2
|
+
import { cx } from '../../utils/cssModules.js';
|
|
3
|
+
import { EzBaseComponent } from '../EzBaseComponent.js';
|
|
4
|
+
|
|
5
|
+
const css = cx(styles);
|
|
6
|
+
|
|
7
|
+
declare const ez: {
|
|
8
|
+
_createElement(config: unknown): Promise<HTMLElement>;
|
|
9
|
+
_createChildElements(items: unknown[], controller: unknown, parent: unknown): Promise<Node[]>;
|
|
10
|
+
define(name: string, component: unknown): void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
interface DialogButton {
|
|
14
|
+
text: string;
|
|
15
|
+
variant?: string;
|
|
16
|
+
value?: unknown;
|
|
17
|
+
onClick?: (instance: DialogInstance) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface DialogInstance {
|
|
21
|
+
close: (result?: unknown) => void;
|
|
22
|
+
toggleMaximize: () => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface EzDialogConfig {
|
|
26
|
+
props?: {
|
|
27
|
+
title?: string;
|
|
28
|
+
message?: string;
|
|
29
|
+
icon?: string;
|
|
30
|
+
iconVariant?: 'info' | 'success' | 'warning' | 'danger';
|
|
31
|
+
size?: 'sm' | 'md' | 'lg' | 'xl' | 'full' | 'auto';
|
|
32
|
+
closable?: boolean;
|
|
33
|
+
maximizable?: boolean;
|
|
34
|
+
items?: unknown[];
|
|
35
|
+
buttons?: DialogButton[];
|
|
36
|
+
_dialogInstance?: DialogInstance;
|
|
37
|
+
};
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class EzDialog extends EzBaseComponent {
|
|
42
|
+
static eztype = 'EzDialog';
|
|
43
|
+
declare config: EzDialogConfig;
|
|
44
|
+
|
|
45
|
+
async render(): Promise<HTMLDivElement> {
|
|
46
|
+
const props = this.config.props || this.config;
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
title,
|
|
50
|
+
message,
|
|
51
|
+
icon,
|
|
52
|
+
iconVariant = 'info',
|
|
53
|
+
size = 'md',
|
|
54
|
+
closable = true,
|
|
55
|
+
maximizable = false,
|
|
56
|
+
items,
|
|
57
|
+
buttons,
|
|
58
|
+
_dialogInstance
|
|
59
|
+
} = props as EzDialogConfig['props'] & { [key: string]: unknown };
|
|
60
|
+
|
|
61
|
+
// Create overlay
|
|
62
|
+
const overlay = document.createElement('div');
|
|
63
|
+
overlay.className = css('overlay');
|
|
64
|
+
|
|
65
|
+
// Create dialog
|
|
66
|
+
const dialog = document.createElement('div');
|
|
67
|
+
dialog.className = css('dialog', size);
|
|
68
|
+
|
|
69
|
+
// Header
|
|
70
|
+
if (title || icon || closable || maximizable) {
|
|
71
|
+
const header = document.createElement('div');
|
|
72
|
+
header.className = css('header');
|
|
73
|
+
|
|
74
|
+
if (icon) {
|
|
75
|
+
const iconEl = document.createElement('div');
|
|
76
|
+
iconEl.className = css('headerIcon', iconVariant);
|
|
77
|
+
iconEl.innerHTML = `<i class="${icon}"></i>`;
|
|
78
|
+
header.appendChild(iconEl);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (title) {
|
|
82
|
+
const titleEl = document.createElement('h3');
|
|
83
|
+
titleEl.className = css('title');
|
|
84
|
+
titleEl.textContent = title;
|
|
85
|
+
header.appendChild(titleEl);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Spacer
|
|
89
|
+
const spacer = document.createElement('div');
|
|
90
|
+
spacer.style.flex = '1';
|
|
91
|
+
header.appendChild(spacer);
|
|
92
|
+
|
|
93
|
+
if (maximizable) {
|
|
94
|
+
const maxBtn = document.createElement('button');
|
|
95
|
+
maxBtn.className = css('headerBtn');
|
|
96
|
+
maxBtn.innerHTML = '<i class="fa-solid fa-expand"></i>';
|
|
97
|
+
maxBtn.onclick = () => _dialogInstance?.toggleMaximize();
|
|
98
|
+
header.appendChild(maxBtn);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (closable) {
|
|
102
|
+
const closeBtn = document.createElement('button');
|
|
103
|
+
closeBtn.className = css('headerBtn');
|
|
104
|
+
closeBtn.innerHTML = '<i class="fa-solid fa-xmark"></i>';
|
|
105
|
+
closeBtn.onclick = () => _dialogInstance?.close();
|
|
106
|
+
header.appendChild(closeBtn);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
dialog.appendChild(header);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Body
|
|
113
|
+
const body = document.createElement('div');
|
|
114
|
+
body.className = css('body');
|
|
115
|
+
|
|
116
|
+
if (message) {
|
|
117
|
+
const messageEl = document.createElement('p');
|
|
118
|
+
messageEl.className = css('message');
|
|
119
|
+
messageEl.textContent = message;
|
|
120
|
+
body.appendChild(messageEl);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (items && items.length > 0) {
|
|
124
|
+
const children = await ez._createChildElements(items, null, null);
|
|
125
|
+
for (const child of children) {
|
|
126
|
+
if (child instanceof Node) {
|
|
127
|
+
body.appendChild(child);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
dialog.appendChild(body);
|
|
133
|
+
|
|
134
|
+
// Footer with buttons
|
|
135
|
+
if (buttons && buttons.length > 0) {
|
|
136
|
+
const footer = document.createElement('div');
|
|
137
|
+
footer.className = css('footer');
|
|
138
|
+
|
|
139
|
+
for (const btn of buttons) {
|
|
140
|
+
const buttonConfig = {
|
|
141
|
+
eztype: 'EzButton',
|
|
142
|
+
text: btn.text,
|
|
143
|
+
variant: btn.variant || 'secondary',
|
|
144
|
+
onClick: () => {
|
|
145
|
+
if (btn.onClick) {
|
|
146
|
+
btn.onClick(_dialogInstance!);
|
|
147
|
+
}
|
|
148
|
+
if (btn.value !== undefined) {
|
|
149
|
+
_dialogInstance?.close(btn.value);
|
|
150
|
+
} else if (!btn.onClick) {
|
|
151
|
+
_dialogInstance?.close();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const buttonEl = await ez._createElement(buttonConfig);
|
|
157
|
+
footer.appendChild(buttonEl);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
dialog.appendChild(footer);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
overlay.appendChild(dialog);
|
|
164
|
+
return overlay;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
ez.define('EzDialog', EzDialog);
|
package/modules.ts
CHANGED
|
@@ -38,6 +38,7 @@ export const frameworkModules: Record<string, () => Promise<unknown>> = {
|
|
|
38
38
|
'./components/panel/EzPanel.ts': () => import('./components/panel/EzPanel.js'),
|
|
39
39
|
'./components/skeleton/EzSkeleton.ts': () => import('./components/skeleton/EzSkeleton.js'),
|
|
40
40
|
'./components/tooltip/EzTooltip.ts': () => import('./components/tooltip/EzTooltip.js'),
|
|
41
|
+
'./components/dialog/EzDialog.ts': () => import('./components/dialog/EzDialog.js'),
|
|
41
42
|
|
|
42
43
|
// Feed
|
|
43
44
|
'./components/feed/EzActivityFeed.ts': () => import('./components/feed/EzActivityFeed.js'),
|