webcimes-modal 2.0.2 → 2.2.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.
@@ -29,14 +29,22 @@ export interface Options {
29
29
  width: string;
30
30
  /** height (specify unit), default "auto" */
31
31
  height: string;
32
+ /** html for header (overrides titleHtml), default "null" */
33
+ headerHtml: string | HTMLElement | (() => HTMLElement) | null;
32
34
  /** html for title, default "null" */
33
- titleHtml: string | null;
35
+ titleHtml: string | HTMLElement | (() => HTMLElement) | null;
34
36
  /** html for body, default "null" */
35
- bodyHtml: string | null;
37
+ bodyHtml: string | HTMLElement | (() => HTMLElement) | null;
38
+ /** html for footer (overrides buttonCancelHtml and buttonConfirmHtml), default "null" */
39
+ footerHtml: string | HTMLElement | (() => HTMLElement) | null;
36
40
  /** html for cancel button, default "null" */
37
- buttonCancelHtml: string | null;
41
+ buttonCancelHtml: string | HTMLElement | (() => HTMLElement) | null;
38
42
  /** html for confirm button, default "null" */
39
- buttonConfirmHtml: string | null;
43
+ buttonConfirmHtml: string | HTMLElement | (() => HTMLElement) | null;
44
+ /** add extra css classes to cancel button, default "[]" */
45
+ buttonCancelClass: string[];
46
+ /** add extra css classes to confirm button, default "[]" */
47
+ buttonConfirmClass: string[];
40
48
  /** close modal after trigger cancel button, default "true" */
41
49
  closeOnCancelButton: boolean;
42
50
  /** close modal after trigger confirm button, default "true" */
@@ -53,10 +61,6 @@ export interface Options {
53
61
  moveFromBody: boolean;
54
62
  /** if allowMovement is set to "true", ability to move modal from footer, default "true" */
55
63
  moveFromFooter: boolean;
56
- /** keep header sticky (visible) when scrolling, default "true" */
57
- stickyHeader: boolean;
58
- /** keep footer sticky (visible) when scrolling, default "true" */
59
- stickyFooter: boolean;
60
64
  /** add extra css style to modal, default null */
61
65
  style: string | null;
62
66
  /** "animDropDown" or "animFadeIn" for show animation, default "animDropDown" */
@@ -1 +1 @@
1
- {"version":3,"file":"webcimes-modal.d.ts","sourceRoot":"","sources":["web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AO,CAAC;IACtB,2FAA2F;IAC3F,cAAc,EAAE,OAAO,CAAC;IACxB,iDAAiD;IACjD,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,gFAAgF;IAChF,eAAe,EAAE,cAAc,GAAG,YAAY,CAAC;IAC/C,gFAAgF;IAChF,kBAAkB,EAAE,YAAY,GAAG,aAAa,CAAC;IACjD,8CAA8C;IAC9C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iCAAiC;IACjC,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,gCAAgC;IAChC,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,oCAAoC;IACpC,aAAa,EAAE,MAAM,IAAI,CAAC;IAC1B,mCAAmC;IACnC,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,8CAA8C;IAC9C,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,+CAA+C;IAC/C,eAAe,EAAE,MAAM,IAAI,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC1B,gDAAgD;IAChD,MAAM,EAAE,WAAW,CAAC;IACpB,+CAA+C;IAC/C,KAAK,EAAE,WAAW,CAAC;IACnB,gCAAgC;IAChC,OAAO,IAAI,IAAI,CAAC;CACnB;AAimBD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,aAAa,CAE5E"}
@@ -33,14 +33,22 @@ export interface Options {
33
33
  width: string;
34
34
  /** height (specify unit), default "auto" */
35
35
  height: string;
36
+ /** html for header (overrides titleHtml), default "null" */
37
+ headerHtml: string | HTMLElement | (() => HTMLElement) | null;
36
38
  /** html for title, default "null" */
37
- titleHtml: string | null;
39
+ titleHtml: string | HTMLElement | (() => HTMLElement) | null;
38
40
  /** html for body, default "null" */
39
- bodyHtml: string | null;
41
+ bodyHtml: string | HTMLElement | (() => HTMLElement) | null;
42
+ /** html for footer (overrides buttonCancelHtml and buttonConfirmHtml), default "null" */
43
+ footerHtml: string | HTMLElement | (() => HTMLElement) | null;
40
44
  /** html for cancel button, default "null" */
41
- buttonCancelHtml: string | null;
45
+ buttonCancelHtml: string | HTMLElement | (() => HTMLElement) | null;
42
46
  /** html for confirm button, default "null" */
43
- buttonConfirmHtml: string | null;
47
+ buttonConfirmHtml: string | HTMLElement | (() => HTMLElement) | null;
48
+ /** add extra css classes to cancel button, default "[]" */
49
+ buttonCancelClass: string[];
50
+ /** add extra css classes to confirm button, default "[]" */
51
+ buttonConfirmClass: string[];
44
52
  /** close modal after trigger cancel button, default "true" */
45
53
  closeOnCancelButton: boolean;
46
54
  /** close modal after trigger confirm button, default "true" */
@@ -57,10 +65,6 @@ export interface Options {
57
65
  moveFromBody: boolean;
58
66
  /** if allowMovement is set to "true", ability to move modal from footer, default "true" */
59
67
  moveFromFooter: boolean;
60
- /** keep header sticky (visible) when scrolling, default "true" */
61
- stickyHeader: boolean;
62
- /** keep footer sticky (visible) when scrolling, default "true" */
63
- stickyFooter: boolean;
64
68
  /** add extra css style to modal, default null */
65
69
  style: string | null;
66
70
  /** "animDropDown" or "animFadeIn" for show animation, default "animDropDown" */
@@ -228,6 +232,194 @@ class WebcimesModalImpl implements WebcimesModal {
228
232
  this.modal.style.removeProperty('top');
229
233
  };
230
234
 
235
+ /**
236
+ * Helper method to set content on an element (string, HTMLElement, or function)
237
+ */
238
+ private setElementContent(
239
+ element: HTMLElement,
240
+ content: string | HTMLElement | (() => HTMLElement),
241
+ ): void {
242
+ if (typeof content === 'string') {
243
+ element.innerHTML = content;
244
+ } else if (typeof content === 'function') {
245
+ element.appendChild(content());
246
+ } else {
247
+ element.appendChild(content);
248
+ }
249
+ }
250
+
251
+ /**
252
+ * Build modal header with content
253
+ */
254
+ private buildHeader(): HTMLElement | null {
255
+ // Check if header should be created
256
+ if (!this.options.headerHtml && !this.options.titleHtml) {
257
+ return null;
258
+ }
259
+
260
+ // Create header element with common classes
261
+ const header = document.createElement('div');
262
+ header.className = 'webcimes-modal__header';
263
+
264
+ if (this.options.moveFromHeader) {
265
+ header.classList.add('webcimes-modal__header--is-movable');
266
+ }
267
+
268
+ // If headerHtml is provided, use it directly (full control)
269
+ if (this.options.headerHtml) {
270
+ this.setElementContent(header, this.options.headerHtml);
271
+ return header;
272
+ }
273
+
274
+ // Otherwise, create title and/or close button
275
+ if (this.options.titleHtml) {
276
+ const title = document.createElement('div');
277
+ title.className = 'webcimes-modal__title';
278
+ this.setElementContent(title, this.options.titleHtml);
279
+ header.appendChild(title);
280
+ }
281
+
282
+ return header;
283
+ }
284
+
285
+ /**
286
+ * Build modal body with content
287
+ */
288
+ private buildBody(): HTMLElement | null {
289
+ if (!this.options.bodyHtml) {
290
+ return null;
291
+ }
292
+
293
+ const body = document.createElement('div');
294
+ body.className = 'webcimes-modal__body';
295
+
296
+ if (this.options.moveFromBody) {
297
+ body.classList.add('webcimes-modal__body--is-movable');
298
+ }
299
+
300
+ this.setElementContent(body, this.options.bodyHtml);
301
+
302
+ return body;
303
+ }
304
+
305
+ /**
306
+ * Build modal footer with content
307
+ */
308
+ private buildFooter(): HTMLElement | null {
309
+ // Check if footer should be created
310
+ if (
311
+ !this.options.footerHtml &&
312
+ !this.options.buttonCancelHtml &&
313
+ !this.options.buttonConfirmHtml
314
+ ) {
315
+ return null;
316
+ }
317
+
318
+ // Create footer element with common classes
319
+ const footer = document.createElement('div');
320
+ footer.className = 'webcimes-modal__footer';
321
+
322
+ if (this.options.moveFromFooter) {
323
+ footer.classList.add('webcimes-modal__footer--is-movable');
324
+ }
325
+
326
+ // If footerHtml is provided, use it directly (full control)
327
+ if (this.options.footerHtml) {
328
+ this.setElementContent(footer, this.options.footerHtml);
329
+ return footer;
330
+ }
331
+
332
+ // Otherwise, create buttons wrapper
333
+ const buttonsWrapper = document.createElement('div');
334
+ buttonsWrapper.className = 'webcimes-modal__footer-buttons';
335
+
336
+ if (this.options.buttonCancelHtml) {
337
+ const cancelButton = document.createElement('button');
338
+ cancelButton.className =
339
+ 'webcimes-modal__button webcimes-modal__footer-button webcimes-modal__footer-button--cancel';
340
+ if (this.options.buttonCancelClass.length > 0) {
341
+ cancelButton.classList.add(...this.options.buttonCancelClass);
342
+ }
343
+ if (this.options.closeOnCancelButton) {
344
+ cancelButton.classList.add('webcimes-modal__close');
345
+ }
346
+ this.setElementContent(cancelButton, this.options.buttonCancelHtml);
347
+ buttonsWrapper.appendChild(cancelButton);
348
+ }
349
+
350
+ if (this.options.buttonConfirmHtml) {
351
+ const confirmButton = document.createElement('button');
352
+ confirmButton.className =
353
+ 'webcimes-modal__button webcimes-modal__footer-button webcimes-modal__footer-button--confirm';
354
+ if (this.options.buttonConfirmClass.length > 0) {
355
+ confirmButton.classList.add(...this.options.buttonConfirmClass);
356
+ }
357
+ if (this.options.closeOnConfirmButton) {
358
+ confirmButton.classList.add('webcimes-modal__close');
359
+ }
360
+ this.setElementContent(confirmButton, this.options.buttonConfirmHtml);
361
+ buttonsWrapper.appendChild(confirmButton);
362
+ }
363
+
364
+ footer.appendChild(buttonsWrapper);
365
+
366
+ return footer;
367
+ }
368
+
369
+ /**
370
+ * Build close button
371
+ */
372
+ private buildCloseButton(): HTMLElement {
373
+ const closeButton = document.createElement('button');
374
+ closeButton.className =
375
+ 'webcimes-modal__button webcimes-modal__close-button webcimes-modal__close';
376
+ closeButton.setAttribute('aria-label', 'Close modal');
377
+ closeButton.innerHTML =
378
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M193.94 256L296.5 153.44l21.15-21.15c3.12-3.12 3.12-8.19 0-11.31l-22.63-22.63c-3.12-3.12-8.19-3.12-11.31 0L160 222.06 36.29 98.34c-3.12-3.12-8.19-3.12-11.31 0L2.34 120.97c-3.12 3.12-3.12 8.19 0 11.31L126.06 256 2.34 379.71c-3.12 3.12-3.12 8.19 0 11.31l22.63 22.63c3.12 3.12 8.19 3.12 11.31 0L160 289.94 262.56 392.5l21.15 21.15c3.12 3.12 8.19 3.12 11.31 0l22.63-22.63c3.12-3.12 3.12-8.19 0-11.31L193.94 256z"/></svg>';
379
+ return closeButton;
380
+ }
381
+
382
+ /**
383
+ * Build complete modal with content
384
+ */
385
+ private buildModal(): HTMLElement {
386
+ const modal = document.createElement('div');
387
+ modal.className = `webcimes-modal ${this.options.animationOnShow}`;
388
+
389
+ // ARIA attributes for accessibility
390
+ modal.setAttribute('role', 'dialog');
391
+ modal.setAttribute('aria-modal', 'true');
392
+
393
+ if (this.options.setClass) {
394
+ modal.classList.add(this.options.setClass);
395
+ }
396
+ if (this.options.setId) {
397
+ modal.id = this.options.setId;
398
+ }
399
+
400
+ const header = this.buildHeader();
401
+ if (header) {
402
+ modal.appendChild(header);
403
+ }
404
+
405
+ const body = this.buildBody();
406
+ if (body) {
407
+ modal.appendChild(body);
408
+ }
409
+
410
+ const footer = this.buildFooter();
411
+ if (footer) {
412
+ modal.appendChild(footer);
413
+ }
414
+
415
+ // Add close button at modal level (always present and independent)
416
+ if (this.options.showCloseButton) {
417
+ modal.appendChild(this.buildCloseButton());
418
+ }
419
+
420
+ return modal;
421
+ }
422
+
231
423
  /**
232
424
  * Create modal
233
425
  */
@@ -238,10 +430,14 @@ class WebcimesModalImpl implements WebcimesModal {
238
430
  setClass: null,
239
431
  width: 'auto',
240
432
  height: 'auto',
433
+ headerHtml: null,
241
434
  titleHtml: null,
242
435
  bodyHtml: null,
436
+ footerHtml: null,
243
437
  buttonCancelHtml: null,
244
438
  buttonConfirmHtml: null,
439
+ buttonCancelClass: [],
440
+ buttonConfirmClass: [],
245
441
  closeOnCancelButton: true,
246
442
  closeOnConfirmButton: true,
247
443
  showCloseButton: true,
@@ -250,8 +446,6 @@ class WebcimesModalImpl implements WebcimesModal {
250
446
  moveFromHeader: true,
251
447
  moveFromBody: false,
252
448
  moveFromFooter: true,
253
- stickyHeader: true,
254
- stickyFooter: true,
255
449
  style: null,
256
450
  animationOnShow: 'animDropDown',
257
451
  animationOnDestroy: 'animDropUp',
@@ -273,14 +467,10 @@ class WebcimesModalImpl implements WebcimesModal {
273
467
  * Initialization of the current modal
274
468
  */
275
469
  private init() {
276
- // Create modals
470
+ // Create modals container
277
471
  if (!document.querySelector('.webcimes-modals')) {
278
- // Create modals
279
- document.body.insertAdjacentHTML(
280
- 'beforeend',
281
- '<div class="webcimes-modals animFadeIn"></div>',
282
- );
283
- this.modals = <HTMLElement>document.querySelector('.webcimes-modals');
472
+ this.modals = document.createElement('div');
473
+ this.modals.className = 'webcimes-modals animFadeIn';
284
474
 
285
475
  // Set animation duration for modals
286
476
  this.modals.style.setProperty(
@@ -288,6 +478,8 @@ class WebcimesModalImpl implements WebcimesModal {
288
478
  this.options.animationDuration + 'ms',
289
479
  );
290
480
 
481
+ document.body.appendChild(this.modals);
482
+
291
483
  // Delete enter animation after animation delay
292
484
  setTimeout(() => {
293
485
  this.modals.classList.remove('animFadeIn');
@@ -300,80 +492,9 @@ class WebcimesModalImpl implements WebcimesModal {
300
492
  this.modals.classList.remove('animFadeOut');
301
493
  }
302
494
 
303
- // Create modal
304
- this.modals.insertAdjacentHTML(
305
- 'beforeend',
306
- `<div class="webcimes-modal ` +
307
- (this.options.setClass ? this.options.setClass : '') +
308
- ` ` +
309
- this.options.animationOnShow +
310
- `" ` +
311
- (this.options.setId ? 'id="' + this.options.setId + '"' : '') +
312
- `>
313
- ` +
314
- (this.options.titleHtml || this.options.showCloseButton
315
- ? `<div class="webcimes-modal__header ` +
316
- (this.options.stickyHeader ? 'webcimes-modal__header--is-sticky' : '') +
317
- ` ` +
318
- (this.options.moveFromHeader ? 'webcimes-modal__header--is-movable' : '') +
319
- `">
320
- ` +
321
- (this.options.titleHtml
322
- ? '<div class="webcimes-modal__title">' +
323
- this.options.titleHtml +
324
- '</div>'
325
- : '') +
326
- `
327
- ` +
328
- (this.options.showCloseButton
329
- ? '<button class="webcimes-modal__button webcimes-modal__header-close webcimes-modal__close"></button>'
330
- : '') +
331
- `
332
- </div>`
333
- : '') +
334
- `
335
- ` +
336
- (this.options.bodyHtml
337
- ? `<div class="webcimes-modal__body ` +
338
- (this.options.moveFromBody ? '.webcimes-modal__body--is-movable' : '') +
339
- `">
340
- ` +
341
- this.options.bodyHtml +
342
- `
343
- </div>`
344
- : '') +
345
- `
346
- ` +
347
- (this.options.buttonCancelHtml || this.options.buttonConfirmHtml
348
- ? `<div class="webcimes-modal__footer ` +
349
- (this.options.stickyFooter ? '.webcimes-modal__footer--is-sticky' : '') +
350
- ` ` +
351
- (this.options.moveFromFooter ? 'webcimes-modal__footer--is-movable' : '') +
352
- `">
353
- ` +
354
- (this.options.buttonCancelHtml
355
- ? '<button class="webcimes-modal__button webcimes-modal__footer-button webcimes-modal__footer-button--cancel ' +
356
- (this.options.closeOnCancelButton ? 'webcimes-modal__close' : '') +
357
- '">' +
358
- this.options.buttonCancelHtml +
359
- '</button>'
360
- : '') +
361
- `
362
- ` +
363
- (this.options.buttonConfirmHtml
364
- ? '<button class="webcimes-modal__button webcimes-modal__footer-button webcimes-modal__footer-button--confirm ' +
365
- (this.options.closeOnConfirmButton ? 'webcimes-modal__close' : '') +
366
- '">' +
367
- this.options.buttonConfirmHtml +
368
- '</button>'
369
- : '') +
370
- `
371
- </div>`
372
- : '') +
373
- `
374
- </div>`,
375
- );
376
- this.modal = <HTMLElement>this.modals.lastElementChild;
495
+ // Create modal with content
496
+ this.modal = this.buildModal();
497
+ this.modals.appendChild(this.modal);
377
498
 
378
499
  // Callback before show modal (set a timeout of zero, to wait for some dom to load)
379
500
  setTimeout(() => {
@@ -398,7 +519,6 @@ class WebcimesModalImpl implements WebcimesModal {
398
519
  }, this.options.animationDuration);
399
520
 
400
521
  // Width of modal
401
- this.modal.style.setProperty('max-width', '90%');
402
522
  if (this.options.width != 'auto' && this.options.width) {
403
523
  this.modal.style.setProperty('width', this.options.width);
404
524
  } else {
@@ -407,7 +527,6 @@ class WebcimesModalImpl implements WebcimesModal {
407
527
  }
408
528
 
409
529
  // Height of modal
410
- this.modal.style.setProperty('max-height', '90%');
411
530
  if (this.options.height != 'auto' && this.options.height) {
412
531
  this.modal.style.setProperty('height', this.options.height);
413
532
  } else {
package/test/script.js CHANGED
@@ -3,9 +3,10 @@ import { createWebcimesModal } from '../dist/js/webcimes-modal.esm.js';
3
3
 
4
4
  // Wait for dom content loaded
5
5
  document.addEventListener('DOMContentLoaded', function () {
6
+ // Example 1: Simple modal with string content
6
7
  let modal1 = createWebcimesModal({
7
8
  titleHtml: 'My title',
8
- bodyHtml: 'My Body',
9
+ bodyHtml: 'My Body - Click on body to open modal 2',
9
10
  afterDestroy: () => {
10
11
  console.log('destroy modal 1');
11
12
  },
@@ -16,12 +17,40 @@ document.addEventListener('DOMContentLoaded', function () {
16
17
  console.log('event');
17
18
  });
18
19
 
20
+ // Example 2: Modal with HTMLElement
21
+ const bodyElement = document.createElement('div');
22
+ bodyElement.innerHTML = '<strong>My Body 2</strong><br>This uses an HTMLElement';
23
+
19
24
  createWebcimesModal({
20
25
  titleHtml: 'My title 2',
21
- bodyHtml: 'My Body 2',
26
+ bodyHtml: bodyElement,
27
+ buttonCancelHtml: 'Cancel',
28
+ buttonConfirmHtml: 'Confirm',
22
29
  afterDestroy: () => {
23
30
  console.log('after destroy modal 2');
24
31
  },
25
32
  });
26
33
  });
34
+
35
+ // Example 3: Modal with custom header and footer
36
+ createWebcimesModal({
37
+ headerHtml: () => {
38
+ const header = document.createElement('div');
39
+ header.innerHTML =
40
+ '<h2>Custom Header</h2><p style="font-size: 12px;">With subtitle</p>';
41
+ return header;
42
+ },
43
+ bodyHtml: 'Body with custom header and footer',
44
+ footerHtml: () => {
45
+ const footer = document.createElement('div');
46
+ footer.style.textAlign = 'center';
47
+ footer.innerHTML =
48
+ '<button class="webcimes-modal__close" style="padding: 10px 20px;">Close Me</button>';
49
+ return footer;
50
+ },
51
+ showCloseButton: true, // Close button still appears
52
+ });
53
+ createWebcimesModal({
54
+ bodyHtml: 'This modal has no header and footer, only body content.',
55
+ });
27
56
  });