UNPKG

6.17 kBTypeScriptView Raw
1import { ISignal } from '@phosphor/signaling';
2import { StackedPanel } from './stackedpanel';
3import { TabBar } from './tabbar';
4import { Widget } from './widget';
5/**
6 * A widget which combines a `TabBar` and a `StackedPanel`.
7 *
8 * #### Notes
9 * This is a simple panel which handles the common case of a tab bar
10 * placed next to a content area. The selected tab controls the widget
11 * which is shown in the content area.
12 *
13 * For use cases which require more control than is provided by this
14 * panel, the `TabBar` widget may be used independently.
15 */
16export declare class TabPanel extends Widget {
17 /**
18 * Construct a new tab panel.
19 *
20 * @param options - The options for initializing the tab panel.
21 */
22 constructor(options?: TabPanel.IOptions);
23 /**
24 * A signal emitted when the current tab is changed.
25 *
26 * #### Notes
27 * This signal is emitted when the currently selected tab is changed
28 * either through user or programmatic interaction.
29 *
30 * Notably, this signal is not emitted when the index of the current
31 * tab changes due to tabs being inserted, removed, or moved. It is
32 * only emitted when the actual current tab node is changed.
33 */
34 readonly currentChanged: ISignal<this, TabPanel.ICurrentChangedArgs>;
35 /**
36 * Get the index of the currently selected tab.
37 *
38 * #### Notes
39 * This will be `-1` if no tab is selected.
40 */
41 /**
42 * Set the index of the currently selected tab.
43 *
44 * #### Notes
45 * If the index is out of range, it will be set to `-1`.
46 */
47 currentIndex: number;
48 /**
49 * Get the currently selected widget.
50 *
51 * #### Notes
52 * This will be `null` if there is no selected tab.
53 */
54 /**
55 * Set the currently selected widget.
56 *
57 * #### Notes
58 * If the widget is not in the panel, it will be set to `null`.
59 */
60 currentWidget: Widget | null;
61 /**
62 * Get the whether the tabs are movable by the user.
63 *
64 * #### Notes
65 * Tabs can always be moved programmatically.
66 */
67 /**
68 * Set the whether the tabs are movable by the user.
69 *
70 * #### Notes
71 * Tabs can always be moved programmatically.
72 */
73 tabsMovable: boolean;
74 /**
75 * Get the tab placement for the tab panel.
76 *
77 * #### Notes
78 * This controls the position of the tab bar relative to the content.
79 */
80 /**
81 * Set the tab placement for the tab panel.
82 *
83 * #### Notes
84 * This controls the position of the tab bar relative to the content.
85 */
86 tabPlacement: TabPanel.TabPlacement;
87 /**
88 * The tab bar used by the tab panel.
89 *
90 * #### Notes
91 * Modifying the tab bar directly can lead to undefined behavior.
92 */
93 readonly tabBar: TabBar<Widget>;
94 /**
95 * The stacked panel used by the tab panel.
96 *
97 * #### Notes
98 * Modifying the panel directly can lead to undefined behavior.
99 */
100 readonly stackedPanel: StackedPanel;
101 /**
102 * A read-only array of the widgets in the panel.
103 */
104 readonly widgets: ReadonlyArray<Widget>;
105 /**
106 * Add a widget to the end of the tab panel.
107 *
108 * @param widget - The widget to add to the tab panel.
109 *
110 * #### Notes
111 * If the widget is already contained in the panel, it will be moved.
112 *
113 * The widget's `title` is used to populate the tab.
114 */
115 addWidget(widget: Widget): void;
116 /**
117 * Insert a widget into the tab panel at a specified index.
118 *
119 * @param index - The index at which to insert the widget.
120 *
121 * @param widget - The widget to insert into to the tab panel.
122 *
123 * #### Notes
124 * If the widget is already contained in the panel, it will be moved.
125 *
126 * The widget's `title` is used to populate the tab.
127 */
128 insertWidget(index: number, widget: Widget): void;
129 /**
130 * Handle the `currentChanged` signal from the tab bar.
131 */
132 private _onCurrentChanged;
133 /**
134 * Handle the `tabActivateRequested` signal from the tab bar.
135 */
136 private _onTabActivateRequested;
137 /**
138 * Handle the `tabCloseRequested` signal from the tab bar.
139 */
140 private _onTabCloseRequested;
141 /**
142 * Handle the `tabMoved` signal from the tab bar.
143 */
144 private _onTabMoved;
145 /**
146 * Handle the `widgetRemoved` signal from the stacked panel.
147 */
148 private _onWidgetRemoved;
149 private _tabPlacement;
150 private _currentChanged;
151}
152/**
153 * The namespace for the `TabPanel` class statics.
154 */
155export declare namespace TabPanel {
156 /**
157 * A type alias for tab placement in a tab bar.
158 */
159 type TabPlacement = (
160 /**
161 * The tabs are placed as a row above the content.
162 */
163 'top' |
164 /**
165 * The tabs are placed as a column to the left of the content.
166 */
167 'left' |
168 /**
169 * The tabs are placed as a column to the right of the content.
170 */
171 'right' |
172 /**
173 * The tabs are placed as a row below the content.
174 */
175 'bottom');
176 /**
177 * An options object for initializing a tab panel.
178 */
179 interface IOptions {
180 /**
181 * Whether the tabs are movable by the user.
182 *
183 * The default is `false`.
184 */
185 tabsMovable?: boolean;
186 /**
187 * The placement of the tab bar relative to the content.
188 *
189 * The default is `'top'`.
190 */
191 tabPlacement?: TabPlacement;
192 /**
193 * The renderer for the panel's tab bar.
194 *
195 * The default is a shared renderer instance.
196 */
197 renderer?: TabBar.IRenderer<Widget>;
198 }
199 /**
200 * The arguments object for the `currentChanged` signal.
201 */
202 interface ICurrentChangedArgs {
203 /**
204 * The previously selected index.
205 */
206 previousIndex: number;
207 /**
208 * The previously selected widget.
209 */
210 previousWidget: Widget | null;
211 /**
212 * The currently selected index.
213 */
214 currentIndex: number;
215 /**
216 * The currently selected widget.
217 */
218 currentWidget: Widget | null;
219 }
220}