@daracl/dialog 0.0.1
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/LICENSE +21 -0
- package/README.md +78 -0
- package/dist/dara.dialog.css +1 -0
- package/dist/dara.dialog.css.map +1 -0
- package/dist/dara.dialog.js +5787 -0
- package/dist/dara.dialog.js.map +1 -0
- package/dist/dara.dialog.min.css +1 -0
- package/dist/dara.dialog.min.css.map +1 -0
- package/dist/dara.dialog.min.js +7 -0
- package/dist/dara.dialog.min.js.LICENSE.txt +5 -0
- package/dist/dara.dialog.min.js.map +1 -0
- package/dist/index.cjs +438 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +138 -0
- package/dist/index.html +101 -0
- package/dist/index.js +418 -0
- package/dist/index.js.map +7 -0
- package/package.json +125 -0
- package/src/index.html +101 -0
- package/src/index.js +540 -0
- package/style/_icon.scss +24 -0
- package/style/dara.dialog copy.scss1 +307 -0
- package/style/dara.dialog.scss +337 -0
- package/style/svg/cancel.svg +1 -0
- package/style/svg/danger.svg +1 -0
- package/style/svg/help.svg +1 -0
- package/style/svg/info.svg +1 -0
- package/style/svg/success.svg +1 -0
- package/style/svg/warning.svg +1 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
let DIALOG_IDX = 0;
|
|
2
|
+
|
|
3
|
+
const iconStyleMap = {
|
|
4
|
+
primary: "primary",
|
|
5
|
+
secondary: "secondary",
|
|
6
|
+
info: "info",
|
|
7
|
+
success: "success",
|
|
8
|
+
warning: "warning",
|
|
9
|
+
danger: "danger",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 다이얼로그 옵션
|
|
14
|
+
* @typedef {Object} defaultOptions
|
|
15
|
+
* @property {string, number} [width = 400] - 넓이
|
|
16
|
+
* @property {string, number} [height= 300] - 높이
|
|
17
|
+
* @property {string} styleClass - css class
|
|
18
|
+
* @property {boolean} [isModal= false] - 모달 사용여부
|
|
19
|
+
* @property {string} [icon= ""] - icon primary, secondary, info, success, warning, danger
|
|
20
|
+
* @property {boolean} [autoOpen= true] - 자동 열기 여부
|
|
21
|
+
* @property {boolean} [draggable= true] - drag 가능여부
|
|
22
|
+
* @property {boolean} [resizable= false] - 창 리사이즈 여부
|
|
23
|
+
* @property {boolean} [enableHeader= true] - 헤더 영역 보일지 여부
|
|
24
|
+
* @property {boolean} [enableFooter= true] - 하단 버튼 영역 보일지 여부
|
|
25
|
+
* @property {boolean} [enableMaxButton= true] - 최대화 버튼
|
|
26
|
+
* @property {boolean} [enableCloseButton= true] - 닫기 버튼 활성화 여부
|
|
27
|
+
* @property {number} [minHeight= 130] - 최소 높이
|
|
28
|
+
* @property {number} [minWidth= 230] - 최소 넓이
|
|
29
|
+
* @property {number} [zIndex= 10000] - css z-index
|
|
30
|
+
* @property {string} [dragOverflow= true] - darg 창 넘어서 drag 할지 여부
|
|
31
|
+
* @property {Array} buttons= [] - dialog 하단 버튼
|
|
32
|
+
* @property {number} moveDelay= 15 - drag delay time
|
|
33
|
+
* @property {function} afterOpen - 오픈후
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/** @type {defaultOptions} */
|
|
37
|
+
let defaultOptions = {
|
|
38
|
+
width: 400,
|
|
39
|
+
height: 300,
|
|
40
|
+
styleClass: "",
|
|
41
|
+
isModal: false,
|
|
42
|
+
icon: "", // info,
|
|
43
|
+
// 자동 열기 여부
|
|
44
|
+
autoOpen: true,
|
|
45
|
+
// drag 가능여부
|
|
46
|
+
draggable: true,
|
|
47
|
+
// 창 리사이즈 여부
|
|
48
|
+
resizable: false,
|
|
49
|
+
// 헤더 영역 보일지 여부
|
|
50
|
+
enableHeader: true,
|
|
51
|
+
// 하단 버튼 영역 보일지 여부
|
|
52
|
+
enableFooter: true,
|
|
53
|
+
// 최대화 버튼
|
|
54
|
+
enableMaxButton: true,
|
|
55
|
+
// 닫기 버튼 활성화 여부
|
|
56
|
+
enableCloseButton: true,
|
|
57
|
+
// 최소 높이
|
|
58
|
+
minHeight: 130,
|
|
59
|
+
// 최소 넓이
|
|
60
|
+
minWidth: 230,
|
|
61
|
+
// css z-index
|
|
62
|
+
zIndex: 10000,
|
|
63
|
+
dragOverflow: true,
|
|
64
|
+
buttons: [],
|
|
65
|
+
moveDelay: 15,
|
|
66
|
+
afterOpen: false, // open 후 호출 메소드
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function dialogHiddenElement() {
|
|
70
|
+
if (document.getElementById("daraDialogHidden") == null) {
|
|
71
|
+
document.querySelector("body")?.insertAdjacentHTML("beforeend", `<div id="daraDialogHidden" class="dara-dialog-hidden"></div>`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return document.getElementById("daraDialogHidden");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* dialog 모듈
|
|
79
|
+
*
|
|
80
|
+
* @export
|
|
81
|
+
* @class Dialog
|
|
82
|
+
* @typedef {Dialog}
|
|
83
|
+
*/
|
|
84
|
+
export class Dialog {
|
|
85
|
+
static VERSION = APP_VERSION;
|
|
86
|
+
constructor(options) {
|
|
87
|
+
if (typeof options === "string") {
|
|
88
|
+
options = { items: options };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.options = Object.assign({}, defaultOptions, options);
|
|
92
|
+
this.idx = DIALOG_IDX += 1;
|
|
93
|
+
|
|
94
|
+
const dialogWrapperElement = document.createElement("div");
|
|
95
|
+
dialogWrapperElement.className = `dara-dialog-wrapper hide dd-${DIALOG_IDX}`;
|
|
96
|
+
const style = dialogWrapperElement.style;
|
|
97
|
+
style.zIndex = this.options.zIndex + DIALOG_IDX;
|
|
98
|
+
style.width = this.options.width == "auto" ? "auto" : this.options.width + "px";
|
|
99
|
+
style.height = this.options.height == "auto" ? "auto" : this.options.height + "px";
|
|
100
|
+
style.minHeight = this.options.minHeight + "px";
|
|
101
|
+
style.minWidth = this.options.minWidth + "px";
|
|
102
|
+
|
|
103
|
+
dialogHiddenElement().appendChild(dialogWrapperElement);
|
|
104
|
+
this.dialogWrapperElement = dialogWrapperElement;
|
|
105
|
+
|
|
106
|
+
this.dialogTemplate();
|
|
107
|
+
|
|
108
|
+
if (this.options.draggable !== false) {
|
|
109
|
+
this.initDrag();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (this.options.resizable === true) {
|
|
113
|
+
dialogWrapperElement.classList.add("resizable");
|
|
114
|
+
this.initResize();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (this.options.autoOpen !== false) {
|
|
118
|
+
this.show();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* default options 셋팅
|
|
124
|
+
*
|
|
125
|
+
* @static
|
|
126
|
+
* @typedef {Object} defaultOptions
|
|
127
|
+
*/
|
|
128
|
+
static setOptions(options) {
|
|
129
|
+
defaultOptions = Object.assign({}, defaultOptions, options);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 사이즈 조절 초기화 */
|
|
133
|
+
initResize() {
|
|
134
|
+
const dialogElement = this.dialogWrapperElement;
|
|
135
|
+
const reslzeElement = this.dialogWrapperElement.querySelectorAll(".resizer");
|
|
136
|
+
|
|
137
|
+
let dialogWidth, dialogHeight;
|
|
138
|
+
let startX, startY;
|
|
139
|
+
let moveMode = "";
|
|
140
|
+
let offsetX = -1,
|
|
141
|
+
offsetY = -1;
|
|
142
|
+
|
|
143
|
+
let isResizeTop, isResizeLeft;
|
|
144
|
+
|
|
145
|
+
this.addEvent(reslzeElement, "mousedown touchdown", (e) => {
|
|
146
|
+
if (this.isMaximise()) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
moveMode = e.target.getAttribute("data-mode");
|
|
151
|
+
|
|
152
|
+
isResizeTop = moveMode.indexOf("t") > -1;
|
|
153
|
+
isResizeLeft = moveMode.indexOf("l") > -1;
|
|
154
|
+
|
|
155
|
+
offsetX = isResizeLeft ? dialogElement.getBoundingClientRect().left : -1;
|
|
156
|
+
offsetY = isResizeTop ? dialogElement.getBoundingClientRect().top : -1;
|
|
157
|
+
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
|
|
160
|
+
const oe = e.touches;
|
|
161
|
+
|
|
162
|
+
startX = oe && oe[0] ? oe[0].pageX : e.pageX;
|
|
163
|
+
startY = oe && oe[0] ? oe[0].pageY : e.pageY;
|
|
164
|
+
|
|
165
|
+
dialogWidth = dialogElement.clientWidth;
|
|
166
|
+
dialogHeight = dialogElement.clientHeight;
|
|
167
|
+
|
|
168
|
+
if (!dialogElement.classList.contains("transform-disable")) {
|
|
169
|
+
const offsetX = e.clientX - dialogElement.getBoundingClientRect().left;
|
|
170
|
+
const offsetY = e.clientY - dialogElement.getBoundingClientRect().top;
|
|
171
|
+
|
|
172
|
+
this.setPosition(e, offsetX, offsetY, dialogWidth, dialogHeight);
|
|
173
|
+
|
|
174
|
+
dialogElement.classList.add("transform-disable");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
this.addEvent(document, "mousemove touchmove", onResizeMouseMove);
|
|
178
|
+
|
|
179
|
+
this.addEvent(document, "mouseup touchup", onResizeMouseUp);
|
|
180
|
+
});
|
|
181
|
+
let startTime = -1;
|
|
182
|
+
let moveTimer;
|
|
183
|
+
const moveDelay = this.options.moveDelay;
|
|
184
|
+
const onResizeMouseMove = (e) => {
|
|
185
|
+
if (startTime == -1) {
|
|
186
|
+
startTime = new Date().getTime();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (new Date().getTime() - moveDelay <= startTime) {
|
|
190
|
+
clearTimeout(moveTimer);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const oe1 = e.touches;
|
|
194
|
+
|
|
195
|
+
moveTimer = setTimeout(() => {
|
|
196
|
+
startTime = -1;
|
|
197
|
+
let moveX = (oe1 && oe1[0] ? oe1[0].pageX : e.pageX) - startX,
|
|
198
|
+
moveY = (oe1 && oe1[0] ? oe1[0].pageY : e.pageY) - startY;
|
|
199
|
+
|
|
200
|
+
moveY = isResizeTop ? moveY * -1 : moveY;
|
|
201
|
+
moveX = isResizeLeft ? moveX * -1 : moveX;
|
|
202
|
+
|
|
203
|
+
let resizeHeight = dialogHeight + moveY,
|
|
204
|
+
resizeWidth = dialogWidth + moveX;
|
|
205
|
+
|
|
206
|
+
if (this.options.minHeight >= resizeHeight) {
|
|
207
|
+
resizeHeight = this.options.minHeight;
|
|
208
|
+
moveY = (dialogHeight - resizeHeight) * -1;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (this.options.minWidth >= resizeWidth) {
|
|
212
|
+
resizeWidth = this.options.minWidth;
|
|
213
|
+
moveX = (dialogWidth - resizeWidth) * -1;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let topVal = -1;
|
|
217
|
+
if (isResizeTop) {
|
|
218
|
+
topVal = offsetY - moveY;
|
|
219
|
+
if (topVal <= 0) {
|
|
220
|
+
topVal = 0;
|
|
221
|
+
resizeHeight = dialogHeight + offsetY;
|
|
222
|
+
}
|
|
223
|
+
dialogElement.style.top = topVal + "px";
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
let leftVal = -1;
|
|
227
|
+
if (isResizeLeft) {
|
|
228
|
+
leftVal = offsetX - moveX;
|
|
229
|
+
if (leftVal <= 0) {
|
|
230
|
+
leftVal = 0;
|
|
231
|
+
resizeWidth = dialogWidth + offsetX;
|
|
232
|
+
}
|
|
233
|
+
dialogElement.style.left = leftVal + "px";
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (moveMode != "b" && moveMode != "t") {
|
|
237
|
+
dialogElement.style.width = resizeWidth + "px";
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (moveMode != "r" && moveMode != "l") {
|
|
241
|
+
dialogElement.style.height = resizeHeight + "px";
|
|
242
|
+
}
|
|
243
|
+
}, moveDelay);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const onResizeMouseUp = () => {
|
|
247
|
+
clearTimeout(moveTimer);
|
|
248
|
+
this.removeEvent(document, "mousemove touchmove", onResizeMouseMove);
|
|
249
|
+
this.removeEvent(document, "mouseup touchup", onResizeMouseUp);
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* init drag
|
|
255
|
+
*/
|
|
256
|
+
initDrag() {
|
|
257
|
+
const dialogElement = this.dialogWrapperElement;
|
|
258
|
+
const dragElement = this.dialogWrapperElement.querySelector(".dialog-header");
|
|
259
|
+
|
|
260
|
+
let isDragging = false;
|
|
261
|
+
|
|
262
|
+
let offsetX, offsetY, dialogWidth, dialogHeight;
|
|
263
|
+
|
|
264
|
+
let isDrag = false;
|
|
265
|
+
|
|
266
|
+
this.addEvent(dragElement, "mousedown touchdown", (e) => {
|
|
267
|
+
const tagName = e.target.tagName;
|
|
268
|
+
|
|
269
|
+
if (tagName.search(/(input|textarea|select|button)/gi) > -1) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (this.isMaximise()) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
e.preventDefault();
|
|
278
|
+
|
|
279
|
+
dialogWidth = dialogElement.clientWidth;
|
|
280
|
+
dialogHeight = dialogElement.clientHeight;
|
|
281
|
+
|
|
282
|
+
isDragging = true;
|
|
283
|
+
offsetX = e.clientX - dialogElement.getBoundingClientRect().left;
|
|
284
|
+
offsetY = e.clientY - dialogElement.getBoundingClientRect().top;
|
|
285
|
+
|
|
286
|
+
if (!isDrag) {
|
|
287
|
+
this.setPosition(e, offsetX, offsetY, dialogWidth, dialogHeight);
|
|
288
|
+
|
|
289
|
+
isDrag = true;
|
|
290
|
+
dialogElement.classList.add("transform-disable");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
dialogElement.classList.add("move-on");
|
|
294
|
+
|
|
295
|
+
this.addEvent(document, "mousemove touchmove", onMouseMove);
|
|
296
|
+
|
|
297
|
+
this.addEvent(document, "mouseup touchup", onMouseUp);
|
|
298
|
+
});
|
|
299
|
+
let startTime = -1;
|
|
300
|
+
let moveTimer;
|
|
301
|
+
const moveDelay = this.options.moveDelay;
|
|
302
|
+
const onMouseMove = (e) => {
|
|
303
|
+
if (isDragging) {
|
|
304
|
+
if (startTime == -1) {
|
|
305
|
+
startTime = new Date().getTime();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
if (new Date().getTime() - moveDelay <= startTime) {
|
|
309
|
+
clearTimeout(moveTimer);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
moveTimer = setTimeout(() => {
|
|
313
|
+
startTime = -1;
|
|
314
|
+
this.setPosition(e, offsetX, offsetY, dialogWidth, dialogHeight);
|
|
315
|
+
}, moveDelay);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const onMouseUp = () => {
|
|
320
|
+
isDragging = false;
|
|
321
|
+
clearTimeout(moveTimer);
|
|
322
|
+
|
|
323
|
+
dialogElement.classList.remove("move-on");
|
|
324
|
+
this.removeEvent(document, "mousemove touchmove", onMouseMove);
|
|
325
|
+
this.removeEvent(document, "mouseup touchup", onMouseUp);
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* dialog position
|
|
331
|
+
*
|
|
332
|
+
* @param {Event} e event
|
|
333
|
+
* @param {Number} offsetX offset x
|
|
334
|
+
* @param {Number} offsetY offset y
|
|
335
|
+
* @param {Number} dialogWidth dialog width
|
|
336
|
+
* @param {Number} dialogHeight dialog height
|
|
337
|
+
*/
|
|
338
|
+
setPosition(e, offsetX, offsetY, dialogWidth, dialogHeight) {
|
|
339
|
+
let minX, minY;
|
|
340
|
+
if (this.options.dragOverflow === false) {
|
|
341
|
+
minX = Math.min(Math.max(e.clientX - offsetX, 0), window.innerWidth - dialogWidth);
|
|
342
|
+
minY = Math.min(Math.max(e.clientY - offsetY, 0), window.innerHeight - dialogHeight);
|
|
343
|
+
} else {
|
|
344
|
+
minX = Math.min(Math.max(e.clientX - offsetX, (dialogWidth - 80) * -1), window.innerWidth - 80);
|
|
345
|
+
|
|
346
|
+
minY = Math.min(Math.max(e.clientY - offsetY, 0), window.innerHeight - 30);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
this.dialogWrapperElement.style.left = minX + "px";
|
|
350
|
+
this.dialogWrapperElement.style.top = minY + "px";
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
dialogTemplate() {
|
|
354
|
+
const enableHeader = this.options.enableHeader !== false;
|
|
355
|
+
const dialog = document.createElement("div");
|
|
356
|
+
const styleClass = this.options.styleClass ?? "";
|
|
357
|
+
|
|
358
|
+
dialog.className = `dara-dialog ${styleClass}`;
|
|
359
|
+
|
|
360
|
+
let dialogHtml = [];
|
|
361
|
+
|
|
362
|
+
if (enableHeader) {
|
|
363
|
+
dialogHtml.push(
|
|
364
|
+
`<div class="dialog-header" >
|
|
365
|
+
${this.options.title ?? ""}
|
|
366
|
+
<div class="btn-area">
|
|
367
|
+
${this.options.enableMaxButton ? `<span class="dialog-maximise"></span>` : ""}
|
|
368
|
+
${this.options.enableCloseButton ? `<span class="dialog-close"></span>` : ""}
|
|
369
|
+
</div>
|
|
370
|
+
</div>`
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
dialogHtml.push(
|
|
375
|
+
`<div class="dialog-body ${iconStyleMap[this.options.icon] ?? ""}" style="height: calc(100% ${enableHeader ? " - 40px" : ""}${this.options.enableFooter ? " - 45px" : ""})"><div class="dialog-move-overay"></div><div class="dialog-content">`
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
if (this.options.url) {
|
|
379
|
+
dialogHtml.push(`<iframe src="${this.options.url}" class="dialog-frame"></iframe>`);
|
|
380
|
+
} else {
|
|
381
|
+
if (typeof this.options.template === "string") {
|
|
382
|
+
dialogHtml.push(this.options.template);
|
|
383
|
+
} else {
|
|
384
|
+
dialogHtml.push(this.options.template());
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
dialogHtml.push("</div></div>");
|
|
389
|
+
|
|
390
|
+
// footer
|
|
391
|
+
const buttons = this.options.buttons ?? [];
|
|
392
|
+
|
|
393
|
+
if (this.options.enableFooter !== false) {
|
|
394
|
+
dialogHtml.push('<div class="dialog-footer"><div class="btn-area">');
|
|
395
|
+
|
|
396
|
+
for (let i = 0; i < buttons.length; i++) {
|
|
397
|
+
const button = buttons[i];
|
|
398
|
+
const styleClass = button.styleClass ?? "success";
|
|
399
|
+
dialogHtml.push(`<span class="dialog-btn dialog-btn-${i} ${styleClass}">${button.label}</span>`);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
dialogHtml.push("</div></div>");
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (this.options.resizable === true) {
|
|
406
|
+
dialogHtml.push(`
|
|
407
|
+
<div class="resizer top" data-mode="t"></div>
|
|
408
|
+
<div class="resizer left" data-mode="l"></div>
|
|
409
|
+
<div class="resizer right" data-mode="r"></div>
|
|
410
|
+
<div class="resizer bottom" data-mode="b"></div>
|
|
411
|
+
|
|
412
|
+
<div class="resizer top-left" data-mode="tl"></div>
|
|
413
|
+
<div class="resizer top-right" data-mode="tr"></div>
|
|
414
|
+
<div class="resizer bottom-left" data-mode="bl"></div>
|
|
415
|
+
<div class="resizer bottom-right" data-mode="br"></div>
|
|
416
|
+
`);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
dialog.innerHTML = dialogHtml.join("");
|
|
420
|
+
|
|
421
|
+
this.dialogWrapperElement.appendChild(dialog); // Append the dialog element
|
|
422
|
+
|
|
423
|
+
if (this.options.enableMaxButton) {
|
|
424
|
+
dialog.querySelector(".dialog-maximise").addEventListener("click", () => {
|
|
425
|
+
this.maximise(dialog);
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (this.options.enableCloseButton) {
|
|
430
|
+
dialog.querySelector(".dialog-close").addEventListener("click", () => {
|
|
431
|
+
this.hide(dialog);
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (this.options.enableFooter !== false) {
|
|
436
|
+
for (let i = 0; i < buttons.length; i++) {
|
|
437
|
+
const button = buttons[i];
|
|
438
|
+
const btnElement = this.dialogWrapperElement.querySelector(`.dialog-footer .dialog-btn-${i}`);
|
|
439
|
+
btnElement.addEventListener("mousedown", (e) => {
|
|
440
|
+
if (button.callback) {
|
|
441
|
+
button.callback(e);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* show dialog message
|
|
450
|
+
* @param {*} viewItems
|
|
451
|
+
* @returns
|
|
452
|
+
*/
|
|
453
|
+
show = () => {
|
|
454
|
+
this.dialogWrapperElement.classList.remove("hide");
|
|
455
|
+
if (this.options.isModal === true) {
|
|
456
|
+
const dialogOverrayElement = document.createElement("div");
|
|
457
|
+
dialogOverrayElement.className = "dara-dialog-overlay";
|
|
458
|
+
dialogOverrayElement.style.zIndex = this.options.zIndex + this.idx;
|
|
459
|
+
|
|
460
|
+
const hiddenElement = dialogHiddenElement();
|
|
461
|
+
const firstChild = hiddenElement.firstChild;
|
|
462
|
+
|
|
463
|
+
if (firstChild) {
|
|
464
|
+
hiddenElement.insertBefore(dialogOverrayElement, firstChild);
|
|
465
|
+
} else {
|
|
466
|
+
hiddenElement.appendChild(dialogOverrayElement);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
this.dialogOverrayElement = dialogOverrayElement;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
if (typeof this.options.afterOpen === "function") {
|
|
473
|
+
this.options.afterOpen.call(this, this.dialogWrapperElement);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return this;
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* dialog hide
|
|
481
|
+
*/
|
|
482
|
+
hide = () => {
|
|
483
|
+
this.dialogWrapperElement.classList.add("hide");
|
|
484
|
+
|
|
485
|
+
if (this.options.isModal === true) {
|
|
486
|
+
dialogHiddenElement().removeChild(this.dialogOverrayElement);
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* maximise hide
|
|
492
|
+
*
|
|
493
|
+
*/
|
|
494
|
+
maximise = () => {
|
|
495
|
+
const classList = this.dialogWrapperElement.classList;
|
|
496
|
+
if (classList.contains("maximise")) {
|
|
497
|
+
classList.remove("maximise");
|
|
498
|
+
} else {
|
|
499
|
+
classList.add("maximise");
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
isMaximise() {
|
|
504
|
+
return this.dialogWrapperElement.classList.contains("maximise");
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
addEvent(elements, events, fnHandler) {
|
|
508
|
+
events.split(" ").forEach(function (e) {
|
|
509
|
+
if (elements instanceof NodeList) {
|
|
510
|
+
for (let element of elements) {
|
|
511
|
+
element.addEventListener(e, fnHandler, false);
|
|
512
|
+
}
|
|
513
|
+
} else {
|
|
514
|
+
elements.addEventListener(e, fnHandler, false);
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
removeEvent(elements, events, fnHandler) {
|
|
520
|
+
events.split(" ").forEach(function (e) {
|
|
521
|
+
if (elements instanceof NodeList) {
|
|
522
|
+
for (let element of elements) {
|
|
523
|
+
element.removeEventListener(e, fnHandler);
|
|
524
|
+
}
|
|
525
|
+
} else {
|
|
526
|
+
elements.removeEventListener(e, fnHandler);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* dialog destroy
|
|
533
|
+
*/
|
|
534
|
+
destroy = () => {
|
|
535
|
+
dialogHiddenElement().removeChild(this.dialogWrapperElement);
|
|
536
|
+
this.dialogWrapperElement = null;
|
|
537
|
+
this.options = null;
|
|
538
|
+
this.idx = -1;
|
|
539
|
+
};
|
|
540
|
+
}
|
package/style/_icon.scss
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
@function icon($iconName, $color: 000000) {
|
|
2
|
+
$iconMap: (
|
|
3
|
+
primary:
|
|
4
|
+
"%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23#{$color}' height='24' viewBox='0 -960 960 960' width='24'%3E%3Cpath d='M480-271.521q20.603 0 34.541-13.938 13.938-13.938 13.938-34.541v-151.521q0-20.604-13.938-34.541Q500.603-520 480-520q-20.603 0-34.541 13.938-13.938 13.937-13.938 34.541V-320q0 20.603 13.938 34.541 13.938 13.938 34.541 13.938Zm0-317.174q21.805 0 36.555-14.75T531.305-640q0-21.805-14.75-36.555T480-691.305q-21.805 0-36.555 14.75T428.695-640q0 21.805 14.75 36.555T480-588.695Zm0 527.913q-87.522 0-163.906-32.96-76.385-32.96-132.888-89.464-56.504-56.503-89.464-132.888Q60.782-392.478 60.782-480t32.96-163.906q32.96-76.385 89.464-132.888 56.503-56.504 132.888-89.464 76.384-32.96 163.906-32.96t163.906 32.96q76.385 32.96 132.888 89.464 56.504 56.503 89.464 132.888 32.96 76.384 32.96 163.906t-32.96 163.906q-32.96 76.385-89.464 132.888-56.503 56.504-132.888 89.464Q567.522-60.782 480-60.782Zm0-106.001q131.739 0 222.478-90.739T793.217-480q0-131.739-90.739-222.478T480-793.217q-131.739 0-222.478 90.739T166.783-480q0 131.739 90.739 222.478T480-166.783ZM480-480Z'/%3E%3C/svg%3E",
|
|
5
|
+
secondary:
|
|
6
|
+
"%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23#{$color}' height='24' viewBox='0 -960 960 960' width='24'%3E%3Cpath d='M480-271.521q20.603 0 34.541-13.938 13.938-13.938 13.938-34.541v-151.521q0-20.604-13.938-34.541Q500.603-520 480-520q-20.603 0-34.541 13.938-13.938 13.937-13.938 34.541V-320q0 20.603 13.938 34.541 13.938 13.938 34.541 13.938Zm0-317.174q21.805 0 36.555-14.75T531.305-640q0-21.805-14.75-36.555T480-691.305q-21.805 0-36.555 14.75T428.695-640q0 21.805 14.75 36.555T480-588.695Zm0 527.913q-87.522 0-163.906-32.96-76.385-32.96-132.888-89.464-56.504-56.503-89.464-132.888Q60.782-392.478 60.782-480t32.96-163.906q32.96-76.385 89.464-132.888 56.503-56.504 132.888-89.464 76.384-32.96 163.906-32.96t163.906 32.96q76.385 32.96 132.888 89.464 56.504 56.503 89.464 132.888 32.96 76.384 32.96 163.906t-32.96 163.906q-32.96 76.385-89.464 132.888-56.503 56.504-132.888 89.464Q567.522-60.782 480-60.782Zm0-106.001q131.739 0 222.478-90.739T793.217-480q0-131.739-90.739-222.478T480-793.217q-131.739 0-222.478 90.739T166.783-480q0 131.739 90.739 222.478T480-166.783ZM480-480Z'/%3E%3C/svg%3E",
|
|
7
|
+
info:
|
|
8
|
+
"%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23#{$color}' height='24' viewBox='0 -960 960 960' width='24'%3E%3Cpath d='M480-271.521q20.603 0 34.541-13.938 13.938-13.938 13.938-34.541v-151.521q0-20.604-13.938-34.541Q500.603-520 480-520q-20.603 0-34.541 13.938-13.938 13.937-13.938 34.541V-320q0 20.603 13.938 34.541 13.938 13.938 34.541 13.938Zm0-317.174q21.805 0 36.555-14.75T531.305-640q0-21.805-14.75-36.555T480-691.305q-21.805 0-36.555 14.75T428.695-640q0 21.805 14.75 36.555T480-588.695Zm0 527.913q-87.522 0-163.906-32.96-76.385-32.96-132.888-89.464-56.504-56.503-89.464-132.888Q60.782-392.478 60.782-480t32.96-163.906q32.96-76.385 89.464-132.888 56.503-56.504 132.888-89.464 76.384-32.96 163.906-32.96t163.906 32.96q76.385 32.96 132.888 89.464 56.504 56.503 89.464 132.888 32.96 76.384 32.96 163.906t-32.96 163.906q-32.96 76.385-89.464 132.888-56.503 56.504-132.888 89.464Q567.522-60.782 480-60.782Zm0-106.001q131.739 0 222.478-90.739T793.217-480q0-131.739-90.739-222.478T480-793.217q-131.739 0-222.478 90.739T166.783-480q0 131.739 90.739 222.478T480-166.783ZM480-480Z'/%3E%3C/svg%3E",
|
|
9
|
+
success:
|
|
10
|
+
"%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23#{$color}' height='24' viewBox='0 -960 960 960' width='24'%3E%3Cpath d='m422.304-427.784-71.303-71.303q-14.392-14.392-35.914-14.392-21.522 0-35.913 14.392-14.392 14.391-14.109 35.913.283 21.522 14.674 35.914l104.956 104.956q16.162 15.956 37.712 15.956 21.55 0 37.506-15.956l217.522-217.522q14.391-14.391 14.391-35.63 0-21.24-14.391-35.631-14.392-14.392-35.914-14.392-21.522 0-35.913 14.392L422.304-427.784ZM480-60.782q-87.522 0-163.906-32.96-76.385-32.96-132.888-89.464-56.504-56.503-89.464-132.888Q60.782-392.478 60.782-480t32.96-163.906q32.96-76.385 89.464-132.888 56.503-56.504 132.888-89.464 76.384-32.96 163.906-32.96t163.906 32.96q76.385 32.96 132.888 89.464 56.504 56.503 89.464 132.888 32.96 76.384 32.96 163.906t-32.96 163.906q-32.96 76.385-89.464 132.888-56.503 56.504-132.888 89.464Q567.522-60.782 480-60.782Zm0-106.001q131.739 0 222.478-90.739T793.217-480q0-131.739-90.739-222.478T480-793.217q-131.739 0-222.478 90.739T166.783-480q0 131.739 90.739 222.478T480-166.783ZM480-480Z'/%3E%3C/svg%3E",
|
|
11
|
+
warning:
|
|
12
|
+
"%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23#{$color}' height='24' viewBox='0 -960 960 960' width='24'%3E%3Cpath d='M115.218-110.391q-14.957 0-26.832-7.365-11.876-7.365-18.473-19.418-6.696-11.826-7.196-25.772-.5-13.946 7.196-27.228L433.695-820q7.696-13.391 20.363-19.805 12.666-6.413 26-6.413 13.333 0 25.942 6.413 12.609 6.414 20.305 19.805l363.782 629.826q7.696 13.282 7.196 27.228-.5 13.946-7.196 25.772-6.696 11.826-18.522 19.305-11.826 7.478-26.783 7.478H115.218Zm76.913-97.522h575.738L480-704.173l-287.869 496.26ZM480-241.696q17.565 0 30.196-12.63 12.63-12.631 12.63-30.196t-12.63-29.913Q497.565-326.783 480-326.783t-30.196 12.348q-12.63 12.348-12.63 29.913 0 17.565 12.63 30.196 12.631 12.63 30.196 12.63ZM480-360q17 0 28.5-11.5T520-400v-113.782q0-17-11.5-28.5t-28.5-11.5q-17 0-28.5 11.5t-11.5 28.5V-400q0 17 11.5 28.5T480-360Zm0-96.043Z'/%3E%3C/svg%3E",
|
|
13
|
+
danger:
|
|
14
|
+
"%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23#{$color}' height='24' viewBox='0 -960 960 960' width='24'%3E%3Cpath d='M479.871-260.782q23.912 0 40.217-16.175 16.304-16.176 16.304-40.088 0-23.912-16.176-40.499-16.175-16.587-40.087-16.587-23.912 0-40.217 16.587-16.304 16.587-16.304 40.499 0 23.912 16.176 40.088 16.175 16.175 40.087 16.175ZM480-438.87q22.087 0 37.544-15.456 15.457-15.457 15.457-37.544v-147q0-22.087-15.457-37.543Q502.087-691.87 480-691.87q-22.087 0-37.544 15.457-15.457 15.456-15.457 37.543v147q0 22.087 15.457 37.544Q457.913-438.87 480-438.87Zm0 378.088q-87.522 0-163.906-32.96-76.385-32.96-132.888-89.464-56.504-56.503-89.464-132.888Q60.782-392.478 60.782-480t32.96-163.906q32.96-76.385 89.464-132.888 56.503-56.504 132.888-89.464 76.384-32.96 163.906-32.96t163.906 32.96q76.385 32.96 132.888 89.464 56.504 56.503 89.464 132.888 32.96 76.384 32.96 163.906t-32.96 163.906q-32.96 76.385-89.464 132.888-56.503 56.504-132.888 89.464Q567.522-60.782 480-60.782Zm0-106.001q131.739 0 222.478-90.739T793.217-480q0-131.739-90.739-222.478T480-793.217q-131.739 0-222.478 90.739T166.783-480q0 131.739 90.739 222.478T480-166.783ZM480-480Z'/%3E%3C/svg%3E",
|
|
15
|
+
|
|
16
|
+
maximise:
|
|
17
|
+
"%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23#{$color}' width='16px' height='16px' viewBox='0 0 16 16' %3E%3Cpath d='M4.5 3C3.67157 3 3 3.67157 3 4.5V11.5C3 12.3284 3.67157 13 4.5 13H11.5C12.3284 13 13 12.3284 13 11.5V4.5C13 3.67157 12.3284 3 11.5 3H4.5ZM4.5 4H11.5C11.7761 4 12 4.22386 12 4.5V11.5C12 11.7761 11.7761 12 11.5 12H4.5C4.22386 12 4 11.7761 4 11.5V4.5C4 4.22386 4.22386 4 4.5 4Z' /%3E%3C/svg%3E",
|
|
18
|
+
|
|
19
|
+
close:
|
|
20
|
+
"%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23#{$color}' width='16px' height='16px' viewBox='0 0 1024 1024'%3E%3Cpath d='M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z'/%3E%3C/svg%3E",
|
|
21
|
+
);
|
|
22
|
+
$icon: map-get($iconMap, $iconName);
|
|
23
|
+
@return url("data:image/svg+xml;charset=utf8,#{$icon}");
|
|
24
|
+
}
|