UNPKG

13 kBTypeScriptView Raw
1import { Message } from '@lumino/messaging';
2import { Widget } from '@lumino/widgets';
3import * as React from 'react';
4import { WidgetTracker } from './widgettracker';
5/**
6 * Create and show a dialog.
7 *
8 * @param options - The dialog setup options.
9 *
10 * @returns A promise that resolves with whether the dialog was accepted.
11 */
12export declare function showDialog<T>(options?: Partial<Dialog.IOptions<T>>): Promise<Dialog.IResult<T>>;
13/**
14 * Show an error message dialog.
15 *
16 * @param title - The title of the dialog box.
17 *
18 * @param error - the error to show in the dialog body (either a string
19 * or an object with a string `message` property).
20 */
21export declare function showErrorMessage(title: string, error: any, buttons?: ReadonlyArray<Dialog.IButton>): Promise<void>;
22/**
23 * A modal dialog widget.
24 */
25export declare class Dialog<T> extends Widget {
26 /**
27 * Create a dialog panel instance.
28 *
29 * @param options - The dialog setup options.
30 */
31 constructor(options?: Partial<Dialog.IOptions<T>>);
32 /**
33 * Dispose of the resources used by the dialog.
34 */
35 dispose(): void;
36 /**
37 * Launch the dialog as a modal window.
38 *
39 * @returns a promise that resolves with the result of the dialog.
40 */
41 launch(): Promise<Dialog.IResult<T>>;
42 /**
43 * Resolve the current dialog.
44 *
45 * @param index - An optional index to the button to resolve.
46 *
47 * #### Notes
48 * Will default to the defaultIndex.
49 * Will resolve the current `show()` with the button value.
50 * Will be a no-op if the dialog is not shown.
51 */
52 resolve(index?: number): void;
53 /**
54 * Reject the current dialog with a default reject value.
55 *
56 * #### Notes
57 * Will be a no-op if the dialog is not shown.
58 */
59 reject(): void;
60 /**
61 * Handle the DOM events for the directory listing.
62 *
63 * @param event - The DOM event sent to the widget.
64 *
65 * #### Notes
66 * This method implements the DOM `EventListener` interface and is
67 * called in response to events on the panel's DOM node. It should
68 * not be called directly by user code.
69 */
70 handleEvent(event: Event): void;
71 /**
72 * A message handler invoked on an `'after-attach'` message.
73 */
74 protected onAfterAttach(msg: Message): void;
75 /**
76 * A message handler invoked on an `'after-detach'` message.
77 */
78 protected onAfterDetach(msg: Message): void;
79 /**
80 * A message handler invoked on a `'close-request'` message.
81 */
82 protected onCloseRequest(msg: Message): void;
83 /**
84 * Handle the `'click'` event for a dialog button.
85 *
86 * @param event - The DOM event sent to the widget
87 */
88 protected _evtClick(event: MouseEvent): void;
89 /**
90 * Handle the `'keydown'` event for the widget.
91 *
92 * @param event - The DOM event sent to the widget
93 */
94 protected _evtKeydown(event: KeyboardEvent): void;
95 /**
96 * Handle the `'focus'` event for the widget.
97 *
98 * @param event - The DOM event sent to the widget
99 */
100 protected _evtFocus(event: FocusEvent): void;
101 /**
102 * Handle the `'mousedown'` event for the widget.
103 *
104 * @param event - The DOM event sent to the widget
105 */
106 protected _evtMouseDown(event: MouseEvent): void;
107 /**
108 * Resolve a button item.
109 */
110 private _resolve;
111 private _buttonNodes;
112 private _buttons;
113 private _checkboxNode;
114 private _original;
115 private _first;
116 private _primary;
117 private _promise;
118 private _defaultButton;
119 private _host;
120 private _hasClose;
121 private _body;
122 private _lastMouseDownInDialog;
123 private _focusNodeSelector;
124}
125/**
126 * The namespace for Dialog class statics.
127 */
128export declare namespace Dialog {
129 /**
130 * The body input types.
131 */
132 type Body<T> = IBodyWidget<T> | React.ReactElement<any> | string;
133 /**
134 * The header input types.
135 */
136 type Header = React.ReactElement<any> | string;
137 /**
138 * A widget used as a dialog body.
139 */
140 interface IBodyWidget<T = string> extends Widget {
141 /**
142 * Get the serialized value of the widget.
143 */
144 getValue?(): T;
145 }
146 /**
147 * The options used to make a button item.
148 */
149 interface IButton {
150 /**
151 * The label for the button.
152 */
153 label: string;
154 /**
155 * The icon class for the button.
156 */
157 iconClass: string;
158 /**
159 * The icon label for the button.
160 */
161 iconLabel: string;
162 /**
163 * The caption for the button.
164 */
165 caption: string;
166 /**
167 * The extra class name for the button.
168 */
169 className: string;
170 /**
171 * The dialog action to perform when the button is clicked.
172 */
173 accept: boolean;
174 /**
175 * The additional dialog actions to perform when the button is clicked.
176 */
177 actions: Array<string>;
178 /**
179 * The button display type.
180 */
181 displayType: 'default' | 'warn';
182 }
183 /**
184 * The options used to make a checkbox item.
185 */
186 interface ICheckbox {
187 /**
188 * The label for the checkbox.
189 */
190 label: string;
191 /**
192 * The caption for the checkbox.
193 */
194 caption: string;
195 /**
196 * The initial checkbox state.
197 */
198 checked: boolean;
199 /**
200 * The extra class name for the checkbox.
201 */
202 className: string;
203 }
204 /**
205 * The options used to create a dialog.
206 */
207 interface IOptions<T> {
208 /**
209 * The top level text for the dialog. Defaults to an empty string.
210 */
211 title: Header;
212 /**
213 * The main body element for the dialog or a message to display.
214 * Defaults to an empty string.
215 *
216 * #### Notes
217 * If a widget is given as the body, it will be disposed after the
218 * dialog is resolved. If the widget has a `getValue()` method,
219 * the method will be called prior to disposal and the value
220 * will be provided as part of the dialog result.
221 * A string argument will be used as raw `textContent`.
222 * All `input` and `select` nodes will be wrapped and styled.
223 */
224 body: Body<T>;
225 /**
226 * The host element for the dialog. Defaults to `document.body`.
227 */
228 host: HTMLElement;
229 /**
230 * The buttons to display. Defaults to cancel and accept buttons.
231 */
232 buttons: ReadonlyArray<IButton>;
233 /**
234 * The checkbox to display in the footer. Defaults no checkbox.
235 */
236 checkbox: Partial<ICheckbox> | null;
237 /**
238 * The index of the default button. Defaults to the last button.
239 */
240 defaultButton: number;
241 /**
242 * A selector for the primary element that should take focus in the dialog.
243 * Defaults to an empty string, causing the [[defaultButton]] to take
244 * focus.
245 */
246 focusNodeSelector: string;
247 /**
248 * When "false", disallows user from dismissing the dialog by clicking outside it
249 * or pressing escape. Defaults to "true", which renders a close button.
250 */
251 hasClose: boolean;
252 /**
253 * An optional renderer for dialog items. Defaults to a shared
254 * default renderer.
255 */
256 renderer: IRenderer;
257 }
258 /**
259 * A dialog renderer.
260 */
261 interface IRenderer {
262 /**
263 * Create the header of the dialog.
264 *
265 * @param title - The title of the dialog.
266 *
267 * @returns A widget for the dialog header.
268 */
269 createHeader<T>(title: Header, reject: () => void, options: Partial<Dialog.IOptions<T>>): Widget;
270 /**
271 * Create the body of the dialog.
272 *
273 * @param body - The input value for the body.
274 *
275 * @returns A widget for the body.
276 */
277 createBody(body: Body<any>): Widget;
278 /**
279 * Create the footer of the dialog.
280 *
281 * @param buttons - The button nodes to add to the footer.
282 * @param checkbox - The checkbox node to add to the footer.
283 *
284 * @returns A widget for the footer.
285 */
286 createFooter(buttons: ReadonlyArray<HTMLElement>, checkbox: HTMLElement | null): Widget;
287 /**
288 * Create a button node for the dialog.
289 *
290 * @param button - The button data.
291 *
292 * @returns A node for the button.
293 */
294 createButtonNode(button: IButton): HTMLElement;
295 /**
296 * Create a checkbox node for the dialog.
297 *
298 * @param checkbox - The checkbox data.
299 *
300 * @returns A node for the checkbox.
301 */
302 createCheckboxNode(checkbox: ICheckbox): HTMLElement;
303 }
304 /**
305 * The result of a dialog.
306 */
307 interface IResult<T> {
308 /**
309 * The button that was pressed.
310 */
311 button: IButton;
312 /**
313 * State of the dialog checkbox.
314 *
315 * #### Notes
316 * It will be null if no checkbox is defined for the dialog.
317 */
318 isChecked: boolean | null;
319 /**
320 * The value retrieved from `.getValue()` if given on the widget.
321 */
322 value: T | null;
323 }
324 /**
325 * Create a button item.
326 */
327 function createButton(value: Partial<IButton>): Readonly<IButton>;
328 /**
329 * Create a reject button.
330 */
331 function cancelButton(options?: Partial<IButton>): Readonly<IButton>;
332 /**
333 * Create an accept button.
334 */
335 function okButton(options?: Partial<IButton>): Readonly<IButton>;
336 /**
337 * Create a warn button.
338 */
339 function warnButton(options?: Partial<IButton>): Readonly<IButton>;
340 /**
341 * Disposes all dialog instances.
342 *
343 * #### Notes
344 * This function should only be used in tests or cases where application state
345 * may be discarded.
346 */
347 function flush(): void;
348 /**
349 * The default implementation of a dialog renderer.
350 */
351 class Renderer {
352 /**
353 * Create the header of the dialog.
354 *
355 * @param title - The title of the dialog.
356 *
357 * @returns A widget for the dialog header.
358 */
359 createHeader<T>(title: Header, reject?: () => void, options?: Partial<Dialog.IOptions<T>>): Widget;
360 /**
361 * Create the body of the dialog.
362 *
363 * @param value - The input value for the body.
364 *
365 * @returns A widget for the body.
366 */
367 createBody(value: Body<any>): Widget;
368 /**
369 * Create the footer of the dialog.
370 *
371 * @param buttons - The buttons nodes to add to the footer.
372 * @param checkbox - The checkbox node to add to the footer.
373 *
374 * @returns A widget for the footer.
375 */
376 createFooter(buttons: ReadonlyArray<HTMLElement>, checkbox: HTMLElement | null): Widget;
377 /**
378 * Create a button node for the dialog.
379 *
380 * @param button - The button data.
381 *
382 * @returns A node for the button.
383 */
384 createButtonNode(button: IButton): HTMLElement;
385 /**
386 * Create a checkbox node for the dialog.
387 *
388 * @param checkbox - The checkbox data.
389 *
390 * @returns A node for the checkbox.
391 */
392 createCheckboxNode(checkbox: ICheckbox): HTMLElement;
393 /**
394 * Create the class name for the button.
395 *
396 * @param data - The data to use for the class name.
397 *
398 * @returns The full class name for the button.
399 */
400 createItemClass(data: IButton): string;
401 /**
402 * Render an icon element for a dialog item.
403 *
404 * @param data - The data to use for rendering the icon.
405 *
406 * @returns An HTML element representing the icon.
407 */
408 renderIcon(data: IButton): HTMLElement;
409 /**
410 * Create the class name for the button icon.
411 *
412 * @param data - The data to use for the class name.
413 *
414 * @returns The full class name for the item icon.
415 */
416 createIconClass(data: IButton): string;
417 /**
418 * Render the label element for a button.
419 *
420 * @param data - The data to use for rendering the label.
421 *
422 * @returns An HTML element representing the item label.
423 */
424 renderLabel(data: IButton): HTMLElement;
425 }
426 /**
427 * The default renderer instance.
428 */
429 const defaultRenderer: Renderer;
430 /**
431 * The dialog widget tracker.
432 */
433 const tracker: WidgetTracker<Dialog<any>>;
434}
435
\No newline at end of file