UNPKG

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