1 | // Copyright (c) Jupyter Development Team.
|
2 | // Distributed under the terms of the Modified BSD License.
|
3 | /*-----------------------------------------------------------------------------
|
4 | | Copyright (c) 2014-2017, PhosphorJS Contributors
|
5 | |
|
6 | | Distributed under the terms of the BSD 3-Clause License.
|
7 | |
|
8 | | The full license is in the file LICENSE, distributed with this software.
|
9 | |----------------------------------------------------------------------------*/
|
10 | import { ISignal, Signal } from '@lumino/signaling';
|
11 |
|
12 | import { Panel } from './panel';
|
13 |
|
14 | import { StackedLayout } from './stackedlayout';
|
15 |
|
16 | import { Widget } from './widget';
|
17 |
|
18 | /**
|
19 | * A panel where visible widgets are stacked atop one another.
|
20 | *
|
21 | * #### Notes
|
22 | * This class provides a convenience wrapper around a [[StackedLayout]].
|
23 | */
|
24 | export class StackedPanel extends Panel {
|
25 | /**
|
26 | * Construct a new stacked panel.
|
27 | *
|
28 | * @param options - The options for initializing the panel.
|
29 | */
|
30 | constructor(options: StackedPanel.IOptions = {}) {
|
31 | super({ layout: Private.createLayout(options) });
|
32 | this.addClass('lm-StackedPanel');
|
33 | /* <DEPRECATED> */
|
34 | this.addClass('p-StackedPanel');
|
35 | /* </DEPRECATED> */
|
36 | }
|
37 |
|
38 | /**
|
39 | * The method for hiding widgets.
|
40 | *
|
41 | * #### Notes
|
42 | * If there is only one child widget, `Display` hiding mode will be used
|
43 | * regardless of this setting.
|
44 | */
|
45 | get hiddenMode(): Widget.HiddenMode {
|
46 | return (this.layout as StackedLayout).hiddenMode;
|
47 | }
|
48 |
|
49 | /**
|
50 | * Set the method for hiding widgets.
|
51 | *
|
52 | * #### Notes
|
53 | * If there is only one child widget, `Display` hiding mode will be used
|
54 | * regardless of this setting.
|
55 | */
|
56 | set hiddenMode(v: Widget.HiddenMode) {
|
57 | (this.layout as StackedLayout).hiddenMode = v;
|
58 | }
|
59 |
|
60 | /**
|
61 | * A signal emitted when a widget is removed from a stacked panel.
|
62 | */
|
63 | get widgetRemoved(): ISignal<this, Widget> {
|
64 | return this._widgetRemoved;
|
65 | }
|
66 |
|
67 | /**
|
68 | * A message handler invoked on a `'child-added'` message.
|
69 | */
|
70 | protected onChildAdded(msg: Widget.ChildMessage): void {
|
71 | msg.child.addClass('lm-StackedPanel-child');
|
72 | /* <DEPRECATED> */
|
73 | msg.child.addClass('p-StackedPanel-child');
|
74 | /* </DEPRECATED> */
|
75 | }
|
76 |
|
77 | /**
|
78 | * A message handler invoked on a `'child-removed'` message.
|
79 | */
|
80 | protected onChildRemoved(msg: Widget.ChildMessage): void {
|
81 | msg.child.removeClass('lm-StackedPanel-child');
|
82 | /* <DEPRECATED> */
|
83 | msg.child.removeClass('p-StackedPanel-child');
|
84 | /* </DEPRECATED> */
|
85 | this._widgetRemoved.emit(msg.child);
|
86 | }
|
87 |
|
88 | private _widgetRemoved = new Signal<this, Widget>(this);
|
89 | }
|
90 |
|
91 | /**
|
92 | * The namespace for the `StackedPanel` class statics.
|
93 | */
|
94 | export namespace StackedPanel {
|
95 | /**
|
96 | * An options object for creating a stacked panel.
|
97 | */
|
98 | export interface IOptions {
|
99 | /**
|
100 | * The stacked layout to use for the stacked panel.
|
101 | *
|
102 | * The default is a new `StackedLayout`.
|
103 | */
|
104 | layout?: StackedLayout;
|
105 | }
|
106 | }
|
107 |
|
108 | /**
|
109 | * The namespace for the module implementation details.
|
110 | */
|
111 | namespace Private {
|
112 | /**
|
113 | * Create a stacked layout for the given panel options.
|
114 | */
|
115 | export function createLayout(options: StackedPanel.IOptions): StackedLayout {
|
116 | return options.layout || new StackedLayout();
|
117 | }
|
118 | }
|