UNPKG

14.2 kBTypeScriptView Raw
1/// <reference types="react" />
2import { ITranslator } from '@jupyterlab/translation';
3import { LabIcon } from '@jupyterlab/ui-components';
4import { IIterator } from '@lumino/algorithm';
5import { CommandRegistry } from '@lumino/commands';
6import { ReadonlyJSONObject } from '@lumino/coreutils';
7import { Message } from '@lumino/messaging';
8import { Layout, Widget } from '@lumino/widgets';
9import { ISessionContext } from '../sessioncontext';
10import { ReactWidget } from '../vdom';
11/**
12 * A class which provides a toolbar widget.
13 */
14export declare class Toolbar<T extends Widget = Widget> extends Widget {
15 /**
16 * Construct a new toolbar widget.
17 */
18 constructor(options?: Toolbar.IOptions);
19 /**
20 * Get an iterator over the ordered toolbar item names.
21 *
22 * @returns An iterator over the toolbar item names.
23 */
24 names(): IIterator<string>;
25 /**
26 * Add an item to the end of the toolbar.
27 *
28 * @param name - The name of the widget to add to the toolbar.
29 *
30 * @param widget - The widget to add to the toolbar.
31 *
32 * @param index - The optional name of the item to insert after.
33 *
34 * @returns Whether the item was added to toolbar. Returns false if
35 * an item of the same name is already in the toolbar.
36 *
37 * #### Notes
38 * The item can be removed from the toolbar by setting its parent to `null`.
39 */
40 addItem(name: string, widget: T): boolean;
41 /**
42 * Insert an item into the toolbar at the specified index.
43 *
44 * @param index - The index at which to insert the item.
45 *
46 * @param name - The name of the item.
47 *
48 * @param widget - The widget to add.
49 *
50 * @returns Whether the item was added to the toolbar. Returns false if
51 * an item of the same name is already in the toolbar.
52 *
53 * #### Notes
54 * The index will be clamped to the bounds of the items.
55 * The item can be removed from the toolbar by setting its parent to `null`.
56 */
57 insertItem(index: number, name: string, widget: T): boolean;
58 /**
59 * Insert an item into the toolbar at the after a target item.
60 *
61 * @param at - The target item to insert after.
62 *
63 * @param name - The name of the item.
64 *
65 * @param widget - The widget to add.
66 *
67 * @returns Whether the item was added to the toolbar. Returns false if
68 * an item of the same name is already in the toolbar.
69 *
70 * #### Notes
71 * The index will be clamped to the bounds of the items.
72 * The item can be removed from the toolbar by setting its parent to `null`.
73 */
74 insertAfter(at: string, name: string, widget: T): boolean;
75 /**
76 * Insert an item into the toolbar at the before a target item.
77 *
78 * @param at - The target item to insert before.
79 *
80 * @param name - The name of the item.
81 *
82 * @param widget - The widget to add.
83 *
84 * @returns Whether the item was added to the toolbar. Returns false if
85 * an item of the same name is already in the toolbar.
86 *
87 * #### Notes
88 * The index will be clamped to the bounds of the items.
89 * The item can be removed from the toolbar by setting its parent to `null`.
90 */
91 insertBefore(at: string, name: string, widget: T): boolean;
92 private _insertRelative;
93 /**
94 * Handle the DOM events for the widget.
95 *
96 * @param event - The DOM event sent to the widget.
97 *
98 * #### Notes
99 * This method implements the DOM `EventListener` interface and is
100 * called in response to events on the dock panel's node. It should
101 * not be called directly by user code.
102 */
103 handleEvent(event: Event): void;
104 /**
105 * Handle a DOM click event.
106 */
107 protected handleClick(event: Event): void;
108 /**
109 * Handle `after-attach` messages for the widget.
110 */
111 protected onAfterAttach(msg: Message): void;
112 /**
113 * Handle `before-detach` messages for the widget.
114 */
115 protected onBeforeDetach(msg: Message): void;
116}
117/**
118 * A class which provides a toolbar widget.
119 */
120export declare class ReactiveToolbar extends Toolbar<Widget> {
121 /**
122 * Construct a new toolbar widget.
123 */
124 constructor();
125 /**
126 * Dispose of the widget and its descendant widgets.
127 */
128 dispose(): void;
129 /**
130 * Insert an item into the toolbar at the after a target item.
131 *
132 * @param at - The target item to insert after.
133 *
134 * @param name - The name of the item.
135 *
136 * @param widget - The widget to add.
137 *
138 * @returns Whether the item was added to the toolbar. Returns false if
139 * an item of the same name is already in the toolbar or if the target
140 * is the toolbar pop-up opener.
141 *
142 * #### Notes
143 * The index will be clamped to the bounds of the items.
144 * The item can be removed from the toolbar by setting its parent to `null`.
145 */
146 insertAfter(at: string, name: string, widget: Widget): boolean;
147 /**
148 * Insert an item into the toolbar at the specified index.
149 *
150 * @param index - The index at which to insert the item.
151 *
152 * @param name - The name of the item.
153 *
154 * @param widget - The widget to add.
155 *
156 * @returns Whether the item was added to the toolbar. Returns false if
157 * an item of the same name is already in the toolbar.
158 *
159 * #### Notes
160 * The index will be clamped to the bounds of the items.
161 * The item can be removed from the toolbar by setting its parent to `null`.
162 */
163 insertItem(index: number, name: string, widget: Widget): boolean;
164 /**
165 * A message handler invoked on a `'before-hide'` message.
166 *
167 * It will hide the pop-up panel
168 */
169 onBeforeHide(msg: Message): void;
170 protected onResize(msg: Widget.ResizeMessage): void;
171 private _onResize;
172 private _saveWidgetWidth;
173 private _getWidgetWidth;
174 protected readonly popupOpener: ToolbarPopupOpener;
175 private readonly _widgetWidths;
176 private readonly _resizer;
177}
178/**
179 * The namespace for Toolbar class statics.
180 */
181export declare namespace Toolbar {
182 /**
183 * The options used to create a toolbar.
184 */
185 interface IOptions {
186 /**
187 * Toolbar widget layout.
188 */
189 layout?: Layout;
190 }
191 /**
192 * Widget with associated toolbar
193 */
194 interface IWidgetToolbar extends Widget {
195 /**
196 * Toolbar of actions on the widget
197 */
198 toolbar?: Toolbar;
199 }
200 /**
201 * Create an interrupt toolbar item.
202 *
203 * @deprecated since version v3.2
204 * This is dead code now.
205 */
206 function createInterruptButton(sessionContext: ISessionContext, translator?: ITranslator): Widget;
207 /**
208 * Create a restart toolbar item.
209 *
210 * @deprecated since v3.2
211 * This is dead code now.
212 */
213 function createRestartButton(sessionContext: ISessionContext, dialogs?: ISessionContext.IDialogs, translator?: ITranslator): Widget;
214 /**
215 * Create a toolbar spacer item.
216 *
217 * #### Notes
218 * It is a flex spacer that separates the left toolbar items
219 * from the right toolbar items.
220 */
221 function createSpacerItem(): Widget;
222 /**
223 * Create a kernel name indicator item.
224 *
225 * #### Notes
226 * It will display the `'display_name`' of the session context. It can
227 * handle a change in context or kernel.
228 */
229 function createKernelNameItem(sessionContext: ISessionContext, dialogs?: ISessionContext.IDialogs, translator?: ITranslator): Widget;
230 /**
231 * Create a kernel status indicator item.
232 *
233 * #### Notes
234 * It will show a busy status if the kernel status is busy.
235 * It will show the current status in the node title.
236 * It can handle a change to the context or the kernel.
237 */
238 function createKernelStatusItem(sessionContext: ISessionContext, translator?: ITranslator): Widget;
239}
240/**
241 * Namespace for ToolbarButtonComponent.
242 */
243export declare namespace ToolbarButtonComponent {
244 /**
245 * Interface for ToolbarButtonComponent props.
246 */
247 interface IProps {
248 className?: string;
249 /**
250 * Data set of the button
251 */
252 dataset?: DOMStringMap;
253 label?: string;
254 icon?: LabIcon.IMaybeResolvable;
255 iconClass?: string;
256 iconLabel?: string;
257 tooltip?: string;
258 onClick?: () => void;
259 enabled?: boolean;
260 pressed?: boolean;
261 pressedIcon?: LabIcon.IMaybeResolvable;
262 pressedTooltip?: string;
263 disabledTooltip?: string;
264 /**
265 * Trigger the button on the actual onClick event rather than onMouseDown.
266 *
267 * See note in ToolbarButtonComponent below as to why the default is to
268 * trigger on onMouseDown.
269 */
270 actualOnClick?: boolean;
271 /**
272 * The application language translator.
273 */
274 translator?: ITranslator;
275 }
276}
277/**
278 * React component for a toolbar button.
279 *
280 * @param props - The props for ToolbarButtonComponent.
281 */
282export declare function ToolbarButtonComponent(props: ToolbarButtonComponent.IProps): JSX.Element;
283/**
284 * Adds the toolbar button class to the toolbar widget.
285 * @param w Toolbar button widget.
286 */
287export declare function addToolbarButtonClass(w: Widget): Widget;
288/**
289 * Phosphor Widget version of static ToolbarButtonComponent.
290 */
291export declare class ToolbarButton extends ReactWidget {
292 private props;
293 /**
294 * Creates a toolbar button
295 * @param props props for underlying `ToolbarButton` component
296 */
297 constructor(props?: ToolbarButtonComponent.IProps);
298 /**
299 * Sets the pressed state for the button
300 * @param value true if button is pressed, false otherwise
301 */
302 set pressed(value: boolean);
303 /**
304 * Returns true if button is pressed, false otherwise
305 */
306 get pressed(): boolean;
307 /**
308 * Sets the enabled state for the button
309 * @param value true to enable the button, false otherwise
310 */
311 set enabled(value: boolean);
312 /**
313 * Returns true if button is enabled, false otherwise
314 */
315 get enabled(): boolean;
316 /**
317 * Sets the click handler for the button
318 * @param value click handler
319 */
320 set onClick(value: () => void);
321 /**
322 * Returns the click handler for the button
323 */
324 get onClick(): () => void;
325 render(): JSX.Element;
326 private _pressed;
327 private _enabled;
328 private _onClick;
329}
330/**
331 * Namespace for CommandToolbarButtonComponent.
332 */
333export declare namespace CommandToolbarButtonComponent {
334 /**
335 * Interface for CommandToolbarButtonComponent props.
336 */
337 interface IProps {
338 /**
339 * Application commands registry
340 */
341 commands: CommandRegistry;
342 /**
343 * Command unique id
344 */
345 id: string;
346 /**
347 * Command arguments
348 */
349 args?: ReadonlyJSONObject;
350 /**
351 * Overrides command icon
352 */
353 icon?: LabIcon;
354 /**
355 * Overrides command label
356 */
357 label?: string;
358 }
359}
360/**
361 * React component for a toolbar button that wraps a command.
362 *
363 * This wraps the ToolbarButtonComponent and watches the command registry
364 * for changes to the command.
365 */
366export declare function CommandToolbarButtonComponent(props: CommandToolbarButtonComponent.IProps): JSX.Element;
367export declare function addCommandToolbarButtonClass(w: Widget): Widget;
368/**
369 * Phosphor Widget version of CommandToolbarButtonComponent.
370 */
371export declare class CommandToolbarButton extends ReactWidget {
372 private props;
373 /**
374 * Creates a command toolbar button
375 * @param props props for underlying `CommandToolbarButtonComponent` component
376 */
377 constructor(props: CommandToolbarButtonComponent.IProps);
378 render(): JSX.Element;
379}
380/**
381 * A class which provides a toolbar popup
382 * used to store widgets that don't fit
383 * in the toolbar when it is resized
384 */
385declare class ToolbarPopup extends Widget {
386 width: number;
387 /**
388 * Construct a new ToolbarPopup
389 */
390 constructor();
391 /**
392 * Updates the width of the popup, this
393 * should match with the toolbar width
394 *
395 * @param width - The width to resize to
396 * @protected
397 */
398 updateWidth(width: number): void;
399 /**
400 * Aligns the popup to left bottom of widget
401 *
402 * @param widget the widget to align to
403 * @private
404 */
405 alignTo(widget: Widget): void;
406 /**
407 * Inserts the widget at specified index
408 * @param index the index
409 * @param widget widget to add
410 */
411 insertWidget(index: number, widget: Widget): void;
412 /**
413 * Total number of widgets in the popup
414 */
415 widgetCount(): number;
416 /**
417 * Returns the widget at index
418 * @param index the index
419 */
420 widgetAt(index: number): Widget;
421}
422/**
423 * A class that provides a ToolbarPopupOpener,
424 * which is a button added to toolbar when
425 * the toolbar items overflow toolbar width
426 */
427declare class ToolbarPopupOpener extends ToolbarButton {
428 /**
429 * Create a new popup opener
430 */
431 constructor();
432 /**
433 * Add widget to the popup, prepends widgets
434 * @param widget the widget to add
435 */
436 addWidget(widget: Widget): void;
437 /**
438 * Dispose of the widget and its descendant widgets.
439 *
440 * #### Notes
441 * It is unsafe to use the widget after it has been disposed.
442 *
443 * All calls made to this method after the first are a no-op.
444 */
445 dispose(): void;
446 /**
447 * Hides the opener and the popup
448 */
449 hide(): void;
450 /**
451 * Hides the popup
452 */
453 hidePopup(): void;
454 /**
455 * Updates width and position of the popup
456 * to align with the toolbar
457 */
458 updatePopup(): void;
459 /**
460 * Returns widget at index in the popup
461 * @param index
462 */
463 widgetAt(index: number): Widget;
464 /**
465 * Returns total number of widgets in the popup
466 *
467 * @returns Number of widgets
468 */
469 widgetCount(): number;
470 protected handleClick(): void;
471 protected popup: ToolbarPopup;
472}
473export {};