UNPKG

7.23 kBTypeScriptView Raw
1import { ISignal } from '@lumino/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 get 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 get currentIndex(): number;
42 /**
43 * Set the index of the currently selected tab.
44 *
45 * #### Notes
46 * If the index is out of range, it will be set to `-1`.
47 */
48 set currentIndex(value: number);
49 /**
50 * Get the currently selected widget.
51 *
52 * #### Notes
53 * This will be `null` if there is no selected tab.
54 */
55 get currentWidget(): Widget | null;
56 /**
57 * Set the currently selected widget.
58 *
59 * #### Notes
60 * If the widget is not in the panel, it will be set to `null`.
61 */
62 set currentWidget(value: Widget | null);
63 /**
64 * Get the whether the tabs are movable by the user.
65 *
66 * #### Notes
67 * Tabs can always be moved programmatically.
68 */
69 get tabsMovable(): boolean;
70 /**
71 * Set the whether the tabs are movable by the user.
72 *
73 * #### Notes
74 * Tabs can always be moved programmatically.
75 */
76 set tabsMovable(value: boolean);
77 /**
78 * Get the whether the add button is enabled.
79 *
80 */
81 get addButtonEnabled(): boolean;
82 /**
83 * Set the whether the add button is enabled.
84 *
85 */
86 set addButtonEnabled(value: boolean);
87 /**
88 * Get the tab placement for the tab panel.
89 *
90 * #### Notes
91 * This controls the position of the tab bar relative to the content.
92 */
93 get tabPlacement(): TabPanel.TabPlacement;
94 /**
95 * Set the tab placement for the tab panel.
96 *
97 * #### Notes
98 * This controls the position of the tab bar relative to the content.
99 */
100 set tabPlacement(value: TabPanel.TabPlacement);
101 /**
102 * A signal emitted when the add button on a tab bar is clicked.
103 *
104 */
105 get addRequested(): ISignal<this, TabBar<Widget>>;
106 /**
107 * The tab bar used by the tab panel.
108 *
109 * #### Notes
110 * Modifying the tab bar directly can lead to undefined behavior.
111 */
112 readonly tabBar: TabBar<Widget>;
113 /**
114 * The stacked panel used by the tab panel.
115 *
116 * #### Notes
117 * Modifying the panel directly can lead to undefined behavior.
118 */
119 readonly stackedPanel: StackedPanel;
120 /**
121 * A read-only array of the widgets in the panel.
122 */
123 get widgets(): ReadonlyArray<Widget>;
124 /**
125 * Add a widget to the end of the tab panel.
126 *
127 * @param widget - The widget to add to the tab panel.
128 *
129 * #### Notes
130 * If the widget is already contained in the panel, it will be moved.
131 *
132 * The widget's `title` is used to populate the tab.
133 */
134 addWidget(widget: Widget): void;
135 /**
136 * Insert a widget into the tab panel at a specified index.
137 *
138 * @param index - The index at which to insert the widget.
139 *
140 * @param widget - The widget to insert into to the tab panel.
141 *
142 * #### Notes
143 * If the widget is already contained in the panel, it will be moved.
144 *
145 * The widget's `title` is used to populate the tab.
146 */
147 insertWidget(index: number, widget: Widget): void;
148 /**
149 * Handle the `currentChanged` signal from the tab bar.
150 */
151 private _onCurrentChanged;
152 /**
153 * Handle the `tabAddRequested` signal from the tab bar.
154 */
155 private _onTabAddRequested;
156 /**
157 * Handle the `tabActivateRequested` signal from the tab bar.
158 */
159 private _onTabActivateRequested;
160 /**
161 * Handle the `tabCloseRequested` signal from the tab bar.
162 */
163 private _onTabCloseRequested;
164 /**
165 * Handle the `tabMoved` signal from the tab bar.
166 */
167 private _onTabMoved;
168 /**
169 * Handle the `widgetRemoved` signal from the stacked panel.
170 */
171 private _onWidgetRemoved;
172 private _tabPlacement;
173 private _currentChanged;
174 private _addRequested;
175}
176/**
177 * The namespace for the `TabPanel` class statics.
178 */
179export declare namespace TabPanel {
180 /**
181 * A type alias for tab placement in a tab bar.
182 */
183 type TabPlacement = /**
184 * The tabs are placed as a row above the content.
185 */ 'top'
186 /**
187 * The tabs are placed as a column to the left of the content.
188 */
189 | 'left'
190 /**
191 * The tabs are placed as a column to the right of the content.
192 */
193 | 'right'
194 /**
195 * The tabs are placed as a row below the content.
196 */
197 | 'bottom';
198 /**
199 * An options object for initializing a tab panel.
200 */
201 interface IOptions {
202 /**
203 * The document to use with the tab panel.
204 *
205 * The default is the global `document` instance.
206 */
207 document?: Document | ShadowRoot;
208 /**
209 * Whether the tabs are movable by the user.
210 *
211 * The default is `false`.
212 */
213 tabsMovable?: boolean;
214 /**
215 * Whether the button to add new tabs is enabled.
216 *
217 * The default is `false`.
218 */
219 addButtonEnabled?: boolean;
220 /**
221 * The placement of the tab bar relative to the content.
222 *
223 * The default is `'top'`.
224 */
225 tabPlacement?: TabPlacement;
226 /**
227 * The renderer for the panel's tab bar.
228 *
229 * The default is a shared renderer instance.
230 */
231 renderer?: TabBar.IRenderer<Widget>;
232 }
233 /**
234 * The arguments object for the `currentChanged` signal.
235 */
236 interface ICurrentChangedArgs {
237 /**
238 * The previously selected index.
239 */
240 previousIndex: number;
241 /**
242 * The previously selected widget.
243 */
244 previousWidget: Widget | null;
245 /**
246 * The currently selected index.
247 */
248 currentIndex: number;
249 /**
250 * The currently selected widget.
251 */
252 currentWidget: Widget | null;
253 }
254}