3 * Copyright Google Inc. All Rights Reserved.
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
8 /* tslint:disable:array-type member-access variable-name typedef
9 only-arrow-functions directive-class-suffix component-class-suffix
11 import {Injectable, Optional, SkipSelf} from '@angular/core';
15 * The OverlayContainer is the container in which all overlays will load.
16 * It should be provided in the root component to ensure it is properly shared.
19 export class OverlayContainer {
20 protected _containerElement: HTMLElement;
22 private _themeClass: string;
25 * Base theme to be applied to all overlay-based components.
27 get themeClass(): string {
28 return this._themeClass;
30 set themeClass(value: string) {
31 if (this._containerElement) {
32 this._containerElement.classList.remove(this._themeClass);
35 this._containerElement.classList.add(value);
39 this._themeClass = value;
43 * This method returns the overlay container element. It will lazily
44 * create the element the first time it is called to facilitate using
45 * the container in non-browser environments.
46 * @returns the container element
48 getContainerElement(): HTMLElement {
49 if (!this._containerElement) {
50 this._createContainer();
52 return this._containerElement;
56 * Create the overlay container element, which is simply a div
57 * with the 'cdk-overlay-container' class on the document body.
59 protected _createContainer(): void {
60 const container = document.createElement('div');
61 container.classList.add('nz-overlay-container');
63 if (this._themeClass) {
64 container.classList.add(this._themeClass);
67 document.body.appendChild(container);
68 this._containerElement = container;
72 export function OVERLAY_CONTAINER_PROVIDER_FACTORY(
73 parentContainer: OverlayContainer) {
74 return parentContainer || new OverlayContainer();
77 export const OVERLAY_CONTAINER_PROVIDER = {
78 // If there is already an OverlayContainer available, use that. Otherwise,
80 provide: OverlayContainer,
81 deps: [[new Optional(), new SkipSelf(), OverlayContainer]],
82 useFactory: OVERLAY_CONTAINER_PROVIDER_FACTORY