/
panel.ts
97 lines (90 loc) · 2.54 KB
/
panel.ts
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
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2017, PhosphorJS Contributors
|
| Distributed under the terms of the BSD 3-Clause License.
|
| The full license is in the file LICENSE, distributed with this software.
|----------------------------------------------------------------------------*/
import { PanelLayout } from './panellayout';
import { Widget } from './widget';
/**
* A simple and convenient panel widget class.
*
* #### Notes
* This class is suitable as a base class for implementing a variety of
* convenience panel widgets, but can also be used directly with CSS to
* arrange a collection of widgets.
*
* This class provides a convenience wrapper around a {@link PanelLayout}.
*/
export class Panel extends Widget {
/**
* Construct a new panel.
*
* @param options - The options for initializing the panel.
*/
constructor(options: Panel.IOptions = {}) {
super();
this.addClass('lm-Panel');
this.layout = Private.createLayout(options);
}
/**
* A read-only array of the widgets in the panel.
*/
get widgets(): ReadonlyArray<Widget> {
return (this.layout as PanelLayout).widgets;
}
/**
* Add a widget to the end of the panel.
*
* @param widget - The widget to add to the panel.
*
* #### Notes
* If the widget is already contained in the panel, it will be moved.
*/
addWidget(widget: Widget): void {
(this.layout as PanelLayout).addWidget(widget);
}
/**
* Insert a widget at the specified index.
*
* @param index - The index at which to insert the widget.
*
* @param widget - The widget to insert into to the panel.
*
* #### Notes
* If the widget is already contained in the panel, it will be moved.
*/
insertWidget(index: number, widget: Widget): void {
(this.layout as PanelLayout).insertWidget(index, widget);
}
}
/**
* The namespace for the `Panel` class statics.
*/
export namespace Panel {
/**
* An options object for creating a panel.
*/
export interface IOptions {
/**
* The panel layout to use for the panel.
*
* The default is a new `PanelLayout`.
*/
layout?: PanelLayout;
}
}
/**
* The namespace for the module implementation details.
*/
namespace Private {
/**
* Create a panel layout for the given panel options.
*/
export function createLayout(options: Panel.IOptions): PanelLayout {
return options.layout || new PanelLayout();
}
}