Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | 2x 2x 2x 2x 2x 38x 2x 2x 2x 2x 12x 2x 2x 2x 166x 166x 166x 166x 166x 166x 166x 166x 166x 166x 166x 2x 334x 334x 334x 332x 178x 178x 176x 176x 176x 100x 176x 32x 8x 4x 4x 12x 12x 12x 10x 10x 10x 4x 2x 2x 2x 2x 378x 6x 378x 378x 12x 378x 38x 38x 38x 12x 6x 6x 6x 6x 166x 166x 166x 166x 166x 134x 166x 162x 166x 134x 166x 166x 166x 166x 166x 166x 166x 166x 30x 120x 90x 30x 30x 30x 136x 136x 136x 42x 34x 8x 42x 262x 42x 42x 94x 94x 26x 94x 94x 94x 136x 166x 166x 166x 166x 18x 18x 4x 18x 166x 166x 166x 10x 168x 168x 1300x 168x 166x 166x 168x 168x 1304x 166x 166x 166x 166x 188x 166x 166x 166x 46x 168x 168x 168x 168x 168x 12x 554x 378x 378x 378x 378x 378x 378x 340x 38x 38x 378x 378x 50x 50x 378x 166x 166x 50x 50x 378x 182x 196x 196x 24x 12x 12x 12x 172x 16x 20x 20x 20x 6x 6x 14x 840x 62x 62x 62x 42x 42x 40x 62x 62x 62x 32x 32x 32x 32x 30x 30x 4x 166x 166x 166x 166x 6x 24x 24x 24x 14x 24x 14x 14x 10x 6x 10x 36x 12x 15990x 40x | /**
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import {BaseComponent} from '../../../coral-base-component';
import {BaseOverlay} from '../../../coral-base-overlay';
import {DragAction} from '../../../coral-dragaction';
import {Icon} from '../../../coral-component-icon';
import '../../../coral-component-button';
import base from '../templates/base';
import {commons, transform, validate, i18n} from '../../../coral-utils';
import {Decorator} from '../../../coral-decorator';
/**
Enumeration for {@link Dialog} closable options.
@typedef {Object} DialogClosableEnum
@property {String} ON
Show a close button on the dialog and close the dialog when clicked.
@property {String} OFF
Do not show a close button. Elements with the <code>coral-close</code> attribute will still close the dialog.
*/
const closable = {
ON: 'on',
OFF: 'off'
};
/**
Enumeration for {@link Dialog} keyboard interaction options.
@typedef {Object} DialogInteractionEnum
@property {String} ON
Keyboard interaction is enabled.
@property {String} OFF
Keyboard interaction is disabled.
*/
const interaction = {
ON: 'on',
OFF: 'off'
};
/**
Enumeration for {@link Dialog} variants.
@typedef {Object} DialogVariantEnum
@property {String} DEFAULT
A default dialog without header icon.
@property {String} ERROR
A dialog with an error header and icon, indicating that an error has occurred.
@property {String} WARNING
A dialog with a warning header and icon, notifying the user of something important.
@property {String} SUCCESS
A dialog with a success header and icon, indicates to the user that an operation was successful.
@property {String} HELP
A dialog with a question header and icon, provides the user with help.
@property {String} INFO
A dialog with an info header and icon, informs the user of non-critical information.
*/
const variant = {
DEFAULT: 'default',
ERROR: 'error',
WARNING: 'warning',
SUCCESS: 'success',
HELP: 'help',
INFO: 'info'
};
/**
Enumeration for {@link Dialog} backdrops.
@typedef {Object} DialogBackdropEnum
@property {String} NONE
No backdrop.
@property {String} MODAL
A backdrop that hides the dialog when clicked.
@property {String} STATIC
A backdrop that does not hide the dialog when clicked.
*/
const backdrop = {
NONE: 'none',
MODAL: 'modal',
STATIC: 'static'
};
// Used to map icon with variant
const capitalize = s => s.charAt(0).toUpperCase() + s.slice(1);
// The dialog's base classname
const CLASSNAME = '_coral-Dialog';
// Modifier classnames
const FULLSCREEN_CLASSNAME = `${CLASSNAME}--fullscreenTakeover`;
// A string of all possible variant classnames
const ALL_VARIANT_CLASSES = [];
for (const variantValue in variant) {
ALL_VARIANT_CLASSES.push(`${CLASSNAME}--${variant[variantValue]}`);
}
/**
@class Coral.Dialog
@classdesc A Dialog component that supports various use cases with custom content. The Dialog can be given a size by
using the special attribute <code>[coral-dialog-size]</code> as selector.
@htmltag coral-dialog
@extends {HTMLElement}
@extends {BaseComponent}
@extends {BaseOverlay}
*/
const Dialog = Decorator(class extends BaseOverlay(BaseComponent(HTMLElement)) {
/** @ignore */
constructor() {
super();
// Prepare templates
this._elements = commons.extend(this._elements, {
// Fetch or create the content zone elements
header: this.querySelector('coral-dialog-header') || document.createElement('coral-dialog-header'),
content: this.querySelector('coral-dialog-content') || document.createElement('coral-dialog-content'),
footer: this.querySelector('coral-dialog-footer') || document.createElement('coral-dialog-footer')
});
base.call(this._elements, {i18n});
// Events
this._delegateEvents({
'coral-overlay:open': '_handleOpen',
'click [coral-close]': '_handleCloseClick',
// Since we cover the backdrop with ourself for positioning purposes, this is implemented as a click listener
// instead of using backdropClickedCallback
'click': '_handleClick',
// Handle resize events
'global:resize': 'center',
'global:key:escape': '_handleEscape'
});
// Override defaults from Overlay
this._trapFocus = this.constructor.trapFocus.ON;
this._returnFocus = this.constructor.returnFocus.ON;
this._overlayAnimationTime = this.constructor.FADETIME;
// Listen for mutations
this._headerObserver = new MutationObserver(this._hideHeaderIfEmpty.bind(this));
// Watch for changes to the header element's children
this._observeHeader();
}
/**
Whether keyboard interaction is enabled. See {@link DialogInteractionEnum}.
@type {DialogInteractionEnum}
@default DialogInteractionEnum.ON
*/
get interaction() {
return this._interaction || interaction.ON;
}
set interaction(value) {
value = transform.string(value).toLowerCase();
this._interaction = validate.enumeration(interaction)(value) && value || interaction.ON;
}
/**
The dialog header element.
@type {DialogHeader}
@contentzone
*/
get header() {
return this._getContentZone(this._elements.header);
}
set header(value) {
thEis._setContentZone('header', value, {
handle: 'header',
tagName: 'coral-dialog-header',
insert: function (header) {
header.classList.add(`${CLASSNAME}-title`);
// Position the header between the drag zone and the type icon
this._elements.headerWrapper.insertBefore(header, this._elements.dragZone.nextElementSibling);
},
set: function () {
// Stop observing the old header and observe the new one
this._observeHeader();
// Check if header needs to be hidden
this._hideHeaderIfEmpty();
}
});
}
/**
The dialog content element.
@type {DialogContent}
@contentzone
*/
get content() {
return this._getContentZone(this._elements.content);
}
set content(value) {
this._setContentZone('content', value, {
handle: 'content',
tagName: 'coral-dialog-content',
insert: function (content) {
content.classList.add(`${CLASSNAME}-content`);
const footer = this.footer;
// The content should always be before footer
this._elements.wrapper.insertBefore(content, this.contains(footer) && footer || null);
}
});
}
/**
The dialog footer element.
@type {DialogFooter}
@contentzone
*/
get footer() {
return this._getContentZone(this._elements.footer);
}
set footer(value) {
this._setContentZone('footer', value, {
handle: 'footer',
tagName: 'coral-dialog-footer',
insert: function (footer) {
footer.classList.add(`${CLASSNAME}-footer`);
// The footer should always be after content
this._elements.wrapper.appendChild(footer);
}
});
}
/**
The backdrop configuration for this dialog. See {@link DialogBackdropEnum}.
@type {String}
@default DialogBackdropEnum.MODAL
@htmlattribute backdrop
*/
get backdrop() {
return this._backdrop || backdrop.MODAL;
}
set backdrop(value) {
value = transform.string(value).toLowerCase();
this._backdrop = validate.enumeration(backdrop)(value) && value || backdrop.MODAL;
const showBackdrop = this._backdrop !== backdrop.NONE;
this._elements.wrapper.classList.toggle(`${CLASSNAME}--noBackdrop`, !showBackdrop);
// We're visible now, so hide or show the modal accordingly
if (this.open && showBackdrop) {
this._showBackdrop();
}
}
/**E
The dialog's variant. See {@link DialogVariantEnum}.
@type {String}
@default DialogVariantEnum.DEFAULT
@htmlattribute variant
@htmlattributereflected
*/
get variant() {
return this._variant || variant.DEFAULT;
}
set variant(value) {
value = transform.string(value).toLowerCase();
this._variant = validate.enumeration(variant)(value) && value || variant.DEFAULT;
this._reflectAttribute('variant', this._variant);
// Insert SVG icon
this._insertTypeIcon();
// Remove all variant classes
this._elements.wrapper.classList.remove(...ALL_VARIANT_CLASSES);
if (this._variant === variant.DEFAULT) {
// ARIA
this.setAttribute('role', 'dialog');
} else {
// Set new variant class
this._elements.wrapper.classList.add(`${CLASSNAME}--${this._variant}`);
// ARIA
this.setAttribute('role', 'alertdialog');
}
const hasHeader = this.header && this.header.textContent !== '';
// If the dialog has a header and is not otherwise labelled,
if (hasHeader && !(this.hasAttribute('aria-labelledby') || this.hasAttribute('aria-label'))) {
this.header.id = this.header.id || commons.getUID();
// label the dialog with a reference to the header
this.setAttribute('aria-labelledby', this.header.id);
}
// Provide the ARIA heading role to coral dialog header
// depending on whether the header contains focusable elements
if (hasHeader) {
if (this.header.querySelector(commons.FOCUSABLE_ELEMENT_SELECTOR) !== null) {
this.header.removeAttribute('role');
this.header.removeAttribute('aria-level');
} else if (!this.header.hasAttribute('role')) {
this.header.setAttribute('role', 'heading');
this.header.setAttribute('aria-level', '2');
}
}
// If the dialog has no content, or the content is empty, do nothing further.
if (!this.content || this.content.textContent === '') {
return;
}
// If the dialog has a content,
this.content.id = this.content.id || commons.getUID();
// In an alertdialog with a content region, if the alertdialog is not otherwise described.
if (this._variant !== variant.DEFAULT) {
// with no header,
if (!hasHeader) {
// label the alertdialog with a reference to the content
this.setAttribute('aria-labelledby', this.content.id);
}
// otherwise, if the alertdialog is not otherwise described,
else if (!this.hasAttribute('aria-describedby')) {
// ensure that the alertdialog is described by the content.
this.setAttribute('aria-describedby', this.content.id);
}
} else if (this.getAttribute('aria-labelledby') === this.content.id) {
this.removeAttribute('aria-labelledby');
}
}
E
/**
Whether the dialog should be displayed full screen (without borders or margin).
@type {Boolean}
@default false
@htmlattribute fullscreen
@htmlattributereflected
*/
get fullscreen() {
return this._fullscreen || false;
}
set fullscreen(value) {
this._fullscreen = transform.booleanAttr(value);
this._reflectAttribute('fullscreen', this._fullscreen);
if (this._fullscreen) {
// Full screen and movable are not compatible
this.movable = false;
this._elements.wrapper.classList.add(FULLSCREEN_CLASSNAME);
} else {
this._elements.wrapper.classList.remove(FULLSCREEN_CLASSNAME);
}
}
/**
Inherited from {@link BaseOverlay#open}.
*/
get open() {
return super.open;
}
set open(value) {
super.open = value;
// Ensure we're in the DOM
if (this.open) {
// If not child of document.body, we have to move it there
this._moveToDocumentBody();
// Show the backdrop, if necessary
if (this.backdrop !== backdrop.NONE) {
this._showBackdrop();
}
}
// SuppoErt animation
requestAnimationFrame(() => {
// Support wrapped dialog
this._elements.wrapper.classList.toggle('is-open', this.open);
// Handles what to focus based on focusOnShow
if (this.open) {
commons.transitionEnd(this._elements.wrapper, () => {
this._handleFocus();
this._elements.closeButton.tabIndex = 0;
this._elements.closeButton.removeAttribute('coral-tabcapture');
});
} else {
this._elements.closeButton.tabIndex = -1;
this._elements.closeButton.setAttribute('coral-tabcapture', '');
}
});
}
/**
The dialog's icon.
@type {String}
@default ""
@htmlattribute icon
*/
get icon() {
return this._elements.icon;
}
set icon(value) {
this._elements.icon = value;
}
/**
Whether the dialog should have a close button. See {@link DialogClosableEnum}.
@type {String}
@default DialogClosableEnum.OFF
@htmlattribute closable
@htmlattributereflected
*/
get closable() {
return this._closable || closable.OFF;
}
set closable(value) {
value = transform.string(value).toLowerCase();
this._closable = validate.enumeration(closable)(value) && value || closable.OFF;
this._reflectAttribute('closable', this._closable);
this._elements.wrapper.classList.toggle(`${CLASSNAME}--dismissible`, this._closable === closable.ON);
}
/**
Whether the dialog can moved around by dragging the title.
@type {Boolean}
@default false
@htmlattribute movable
@htmlattributereflected
*/
get movable() {
return this._movable || false;
}
set movable(value) {
this._movable = transform.booleanAttr(value);
this._reflectAttribute('movable', this._movable);
// Movable and fullscreen are not compatible
if (this._movable) {
this.fullscreen = false;
}
if (this._movable) {
const dragAction = new DragAction(this);
dragAction.handle = this._elements.headerWrapper;
} else {
// Disables any dragging interaction
if (this.dragAction) {
this.dragAction.destroy();
}
// Recenter the dialog once it's not movable anymore
this.center();
}
}
/**
Inherited from {@link BaseComponent#trackingElement}.
*/
get trackingElement() {
return typeof this._trackingElement === 'undefined' ?
(this.header && this.header.textContent && this.header.textContent.replace(/\s{2,}/g, ' ').trim() || '') :
this._trackingElement;
}
set trackingElement(value) {
super.trackingElement = value;
}
/** @ignore */
_observeHeader() {
if (this._headerObserver) {
this._headerObserver.disconnect();
if (this._elements.header) {
this._headerObserver.observe(this._elements.header, {
// Catch changes to childList
childList: true,
// Catch changes to textContent
characterData: true,
// Monitor any child node
subtree: true
});
}
}
}
/**
Hide the header wrapper if the header content zone is empty.
@ignore
*/
_hideHeaderIfEmpty() {
const header = this._elements.header;
if (header) {
const headerWrapper = this._elements.headerWrapper;
// If it's empty and has no non-textnode children, hide the header
const hiddenValue = header.children.length === 0 && header.textContent.replace(/\s*/g, '') === '';
// Only bother if the hidden status has changed
if (hiddenValue !== headerWrapper.hidden) {
headerWrapper.hidden = hiddenValue;
}
this.variant = this.variant;
}
}
_handleOpen(event) {
this._trackEvent('display', 'coral-dialog', event);
}
/** @ignore */
_handleEscape(event) {
// When escape is pressed, hide ourselves
if (this.interaction === interaction.ON && this.open && this._isTopOverlay()) {
event.stopPropagation();
this.open = false;
}
}
/**
@ignore
@todo maybe this should be base or something
*/
_handleCloseClick(event) {
const dismissTarget = event.matchedTarget;
const dismissValue = dismissTarget.getAttribute('coral-close');
if (!dismissValue || this.matches(dismissValue)) {
this.open = false;
event.stopPropagation();
this._trackEvent('close', 'coral-dialog', event);
}
}
_handleClick(event) {
// When we're modal, we close when our outer area (over the backdrop) is clicked
if (event.target === this && this.backdrop === backdrop.MODAL && this._isTopOverlay()) {
this.open = false;
this._trackEvent('close', 'coral-dialog', event);
}
}
/** @ignore */
_moveToDocumentBody() {
// Not in the DOM
if (!document.body.contains(this)) {
document.body.appendChild(this);
}
// In the DOM but not a direct child of body
else if (this.parentNode !== document.body) {
this._ignoreConnectedCallback = true;
this._repositioned = true;
document.body.appendChild(this);
this._ignoreConnectedCallback = false;
}
}
_insertTypeIcon() {
if (this._elements.icon) {
this._elements.icon.remove();
}
let variantValue = this.variant;
// Warning icon is same as ERROR icon
if (variantValue === variant.WARNING || variantValue === variant.ERROR) {
variantValue = 'alert';
}
// Inject the SVG icon
if (IvariantValue !== variant.DEFAULT) {
const iconName = capitalize(variantValue);
this._elements.headerWrapper.insertAdjacentHTML('beforeend', Icon._renderSVG(`spectrum-css-icon-${iconName}Medium`, ['_coral-Dialog-typeIcon', `_coral-UIIcon-${iconName}Medium`]));
this._elements.icon = this._elements.headerWrapper.querySelector('._coral-Dialog-typeIcon');
}
}
/** @ignore */
backdropClickedCallback() {
// When we're modal, we close when the backdrop is clicked
if (this.backdrop === backdrop.MODAL && this._isTopOverlay()) {
this.open = false;
}
}
/**
Centers the dialog in the middle of the screen.
@returns {Dialog} this, chainable.
*/
center() {
// We're already centered in fullscreen mode
if (this.fullscreen) {
return;E
}
// If moved we reset the position
this.stylIe.top = '';
this.style.left = '';
return this;
}
get _contentZones() {
return {
'coral-dialog-header': 'header',
'coral-dialog-content': 'content',
'coral-dialog-footer': 'footer'
};
}
/**
Returns {@link Dialog} variants.
@return {DialogVariantEnum}
*/
static get variant() {
return variant;
}
/**
Returns {@link Dialog} backdrops.
@return {DialogBackdropEnum}
*/
static get backdrop() {
return backdrop;
}
/**
Returns {@link Dialog} close options.
@return {DialogClosableEnum}
*/
static get closable() {
return closable;
}
/**
Returns {@link Dialog} interaction options.
@return {DialogInteractionEnum}
*/
static get interaction() {
return interaction;
}
/** @ignore */
static get observedAttributes() {
return super.observedAttributes.concat([
'interaction',
'backdrop',
'variant',
'fullscreen',
'icon',
'closable',
'movable'
]);
}
/** @ignore */
render() {
super.render();
this.classList.add(`${CLASSNAME}-wrapper`);
this.setAttribute("aria-modal", true);
// Default reflected attributes
if (!this._variant) {
this.variant = variant.DEFAULT;
}
if (!this._backdrop) {
this.backdrop = backdrop.MODAL;
}
if (!this._closable) {
this.closable = closable.OFF;
}
if (!this._interaction) {
this.interaction = interaction.ON;
}
// Fetch the content zones
const header = this._elements.header;
const content = this._elements.content;
const footer = this._elements.footer;
// Verify if a content zone is provided
const contentZoneProvided = this.contains(content) && content || this.contains(footer) && footer || this.contains(header) && header;
// Verify if the internal wrapper exists
let wrapper = this.querySelector(`.${CLASSNAME}`);
// Case where the dialog was rendered already - cloneNode support
if (wrapper) {
// Remove tab captures
Array.prototype.filter.call(this.children, (child) => child.hasAttribute('coral-tabcapture')).forEach((tabCapture) => {
this.removeChild(tabCapture);
});
// Assign internal elements
this._elements.headerWrapper = this.querySelector('._coral-Dialog-header');
this._elements.closeButton = this.querySelector('._coral-Dialog-closeButton');
this._elements.wrapper = wrapper;
}
// Case where the dialog needs to be rendered
else {
// Create default wrapper
wrapper = this._elements.wrapper;
// Create default header wrapper
const headerWrapper = this._elements.headerWrapper;
// Case where the dialog needs to be rendered and content zones are provided
if (contentZoneProvided) {
// Check if user wrapper is provided
if (contentZoneProvided.parentNode === this) {
// Content zone target defaults to default wrapper if no user wrapper element is provided
this._elements.wrapper = wrapper;
} else {
// Content zone target defaults to user wrapper element if provided
this._elements.wrapper = contentZoneProvided.parentNode;
}
// Move everything in the wrapper
while (this.firstChild) {
wrapper.appendChild(this.firstChild);
}
// Add the dialog header before the content
if(this._elements.wrapper.contains(content)) {
this._elements.wrapper.insertBefore(headerWrapper, content);
} else {
// try adding in next frame
// so that content is a child of dialog wrapper
commons.nextFrame(() => {
this._elements.wrapper.insertBefore(headerWrapper, content);
});
}
}
// Case where the dialog needs to be rendered and content zones need to be created
else {
// Default content zone target is wrapper
this._elements.wrapper = wrapper;
// Move everything in the "content" content zone
while (this.firstChild) {
content.appendChild(this.firstChild);
}
// Add the content zones in the wrapper
wrapper.appendChild(headerWrapper);
wrapper.appendChild(content);
wrapper.appendChild(footer);
}
// Add the wrapper to the dialog
this.appendChild(wrapper);
}
// Only the wrapper gets the dialog class
this._elements.wrapper.classList.add(CLASSNAME);
// Mark the dialog with a public attribute for sizing
this._elements.wrapper.setAttribute('coral-dialog-size', '');
// Close button should stay under the dialog
this._elements.wrapper.appendChild(this._elements.closeButton);
// Copy styles over to new wrapper
if (this._elements.wrapper.parentNode !== this) {
const contentWrapper = this.querySelector('[handle="wrapper"]');
Array.prototype.forEach.call(contentWrapper.classList, style => this._elements.wrapper.classList.add(style));
contentWrapper.removeAttribute('class');
}
// Assign content zones
this.header = header;
this.footer = footer;
this.content = content;
}
});
export default Dialog;
|