UNPKG

14.3 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 * @deprecated since v3.5
234 * The kernel status indicator is now replaced by the execution status indicator.
235 *
236 * #### Notes
237 * It will show a busy status if the kernel status is busy.
238 * It will show the current status in the node title.
239 * It can handle a change to the context or the kernel.
240 */
241 function createKernelStatusItem(sessionContext: ISessionContext, translator?: ITranslator): Widget;
242}
243/**
244 * Namespace for ToolbarButtonComponent.
245 */
246export declare namespace ToolbarButtonComponent {
247 /**
248 * Interface for ToolbarButtonComponent props.
249 */
250 interface IProps {
251 className?: string;
252 /**
253 * Data set of the button
254 */
255 dataset?: DOMStringMap;
256 label?: string;
257 icon?: LabIcon.IMaybeResolvable;
258 iconClass?: string;
259 iconLabel?: string;
260 tooltip?: string;
261 onClick?: () => void;
262 enabled?: boolean;
263 pressed?: boolean;
264 pressedIcon?: LabIcon.IMaybeResolvable;
265 pressedTooltip?: string;
266 disabledTooltip?: string;
267 /**
268 * Trigger the button on the actual onClick event rather than onMouseDown.
269 *
270 * See note in ToolbarButtonComponent below as to why the default is to
271 * trigger on onMouseDown.
272 */
273 actualOnClick?: boolean;
274 /**
275 * The application language translator.
276 */
277 translator?: ITranslator;
278 }
279}
280/**
281 * React component for a toolbar button.
282 *
283 * @param props - The props for ToolbarButtonComponent.
284 */
285export declare function ToolbarButtonComponent(props: ToolbarButtonComponent.IProps): JSX.Element;
286/**
287 * Adds the toolbar button class to the toolbar widget.
288 * @param w Toolbar button widget.
289 */
290export declare function addToolbarButtonClass(w: Widget): Widget;
291/**
292 * Phosphor Widget version of static ToolbarButtonComponent.
293 */
294export declare class ToolbarButton extends ReactWidget {
295 private props;
296 /**
297 * Creates a toolbar button
298 * @param props props for underlying `ToolbarButton` component
299 */
300 constructor(props?: ToolbarButtonComponent.IProps);
301 /**
302 * Sets the pressed state for the button
303 * @param value true if button is pressed, false otherwise
304 */
305 set pressed(value: boolean);
306 /**
307 * Returns true if button is pressed, false otherwise
308 */
309 get pressed(): boolean;
310 /**
311 * Sets the enabled state for the button
312 * @param value true to enable the button, false otherwise
313 */
314 set enabled(value: boolean);
315 /**
316 * Returns true if button is enabled, false otherwise
317 */
318 get enabled(): boolean;
319 /**
320 * Sets the click handler for the button
321 * @param value click handler
322 */
323 set onClick(value: () => void);
324 /**
325 * Returns the click handler for the button
326 */
327 get onClick(): () => void;
328 render(): JSX.Element;
329 private _pressed;
330 private _enabled;
331 private _onClick;
332}
333/**
334 * Namespace for CommandToolbarButtonComponent.
335 */
336export declare namespace CommandToolbarButtonComponent {
337 /**
338 * Interface for CommandToolbarButtonComponent props.
339 */
340 interface IProps {
341 /**
342 * Application commands registry
343 */
344 commands: CommandRegistry;
345 /**
346 * Command unique id
347 */
348 id: string;
349 /**
350 * Command arguments
351 */
352 args?: ReadonlyJSONObject;
353 /**
354 * Overrides command icon
355 */
356 icon?: LabIcon;
357 /**
358 * Overrides command label
359 */
360 label?: string;
361 }
362}
363/**
364 * React component for a toolbar button that wraps a command.
365 *
366 * This wraps the ToolbarButtonComponent and watches the command registry
367 * for changes to the command.
368 */
369export declare function CommandToolbarButtonComponent(props: CommandToolbarButtonComponent.IProps): JSX.Element;
370export declare function addCommandToolbarButtonClass(w: Widget): Widget;
371/**
372 * Phosphor Widget version of CommandToolbarButtonComponent.
373 */
374export declare class CommandToolbarButton extends ReactWidget {
375 private props;
376 /**
377 * Creates a command toolbar button
378 * @param props props for underlying `CommandToolbarButtonComponent` component
379 */
380 constructor(props: CommandToolbarButtonComponent.IProps);
381 render(): JSX.Element;
382}
383/**
384 * A class which provides a toolbar popup
385 * used to store widgets that don't fit
386 * in the toolbar when it is resized
387 */
388declare class ToolbarPopup extends Widget {
389 width: number;
390 /**
391 * Construct a new ToolbarPopup
392 */
393 constructor();
394 /**
395 * Updates the width of the popup, this
396 * should match with the toolbar width
397 *
398 * @param width - The width to resize to
399 * @protected
400 */
401 updateWidth(width: number): void;
402 /**
403 * Aligns the popup to left bottom of widget
404 *
405 * @param widget the widget to align to
406 * @private
407 */
408 alignTo(widget: Widget): void;
409 /**
410 * Inserts the widget at specified index
411 * @param index the index
412 * @param widget widget to add
413 */
414 insertWidget(index: number, widget: Widget): void;
415 /**
416 * Total number of widgets in the popup
417 */
418 widgetCount(): number;
419 /**
420 * Returns the widget at index
421 * @param index the index
422 */
423 widgetAt(index: number): Widget;
424}
425/**
426 * A class that provides a ToolbarPopupOpener,
427 * which is a button added to toolbar when
428 * the toolbar items overflow toolbar width
429 */
430declare class ToolbarPopupOpener extends ToolbarButton {
431 /**
432 * Create a new popup opener
433 */
434 constructor();
435 /**
436 * Add widget to the popup, prepends widgets
437 * @param widget the widget to add
438 */
439 addWidget(widget: Widget): void;
440 /**
441 * Dispose of the widget and its descendant widgets.
442 *
443 * #### Notes
444 * It is unsafe to use the widget after it has been disposed.
445 *
446 * All calls made to this method after the first are a no-op.
447 */
448 dispose(): void;
449 /**
450 * Hides the opener and the popup
451 */
452 hide(): void;
453 /**
454 * Hides the popup
455 */
456 hidePopup(): void;
457 /**
458 * Updates width and position of the popup
459 * to align with the toolbar
460 */
461 updatePopup(): void;
462 /**
463 * Returns widget at index in the popup
464 * @param index
465 */
466 widgetAt(index: number): Widget;
467 /**
468 * Returns total number of widgets in the popup
469 *
470 * @returns Number of widgets
471 */
472 widgetCount(): number;
473 protected handleClick(): void;
474 protected popup: ToolbarPopup;
475}
476export {};