aboutsummaryrefslogtreecommitdiffstats
path: root/deprecated-workflow-designer/sdc-workflow-designer-ui/src/app/paletx/plx-modal/modal.ts
blob: 5935eee6a72f6c359754eb5bc14c9233ccc810af (plain)
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
import {Injectable, Injector, ComponentFactoryResolver} from '@angular/core';
import {PlxModalStack} from './modal-stack';
import {PlxModalRef} from './modal-ref';

/**
 * Represent options available when opening new modal windows.
 */
export interface PlxModalOptions {
    /**
     * Whether a backdrop element should be created for a given modal (true by default).
     * Alternatively, specify 'static' for a backdrop which doesn't close the modal on click.
     */
    backdrop?: boolean | 'static';

    /**
     * An element to which to attach newly opened modal windows.
     */
    container?: string;

    /**
     * Whether to close the modal when escape key is pressed (true by default).
     */
    keyboard?: boolean;

    /**
     * Size of a new modal window.
     */
    size?: 'sm' | 'lg';

    /**
     * Custom class to append to the modal window
     */
    windowClass?: string;
}

/**
 * A service to open modal windows. Creating a modal is straightforward: create a template and pass it as an argument to
 * the "open" method!
 */
@Injectable()
export class PlxModal {
    constructor(private _moduleCFR: ComponentFactoryResolver, private _injector: Injector, private _modalStack: PlxModalStack) {
    }

    /**
     * Opens a new modal window with the specified content and using supplied options. Content can be provided
     * as a TemplateRef or a component type. If you pass a component type as content than instances of those
     * components can be injected with an instance of the PlxActiveModal class. You can use methods on the
     * PlxActiveModal class to close / dismiss modals from "inside" of a component.
     */
    public open(content: any, options: PlxModalOptions = {}): PlxModalRef {
        return this._modalStack.open(this._moduleCFR, this._injector, content, options);
    }
}