@datalayer/core
Version:
[](https://datalayer.io)
70 lines (69 loc) • 2.26 kB
TypeScript
import { JSXElementConstructor, PropsWithChildren } from 'react';
import { Dialog } from '@jupyterlab/apputils';
import { ReactWidget } from '@jupyterlab/ui-components';
import { DialogProps } from '@primer/react/experimental';
/**
* {@link JupyterDialog} options
*/
export interface IDialogWrapperOptions<T> {
/**
* Node to which the dialog will be attached
*/
host: HTMLElement;
/**
* React element factory for the dialog body.
*
* The body component is receiving two special props:
* - {@link willClose} A signal emitted when the dialog is closing;
* body is expected to call {@link setValue} in reaction.
* - {@link setValue} A callback to set the dialog body value.
*/
body: JSXElementConstructor<PropsWithChildren<DialogProps & {
setValue: (v: T | Error) => void;
}>>;
/**
* The checkbox to display in the footer. Default non checkbox.
*/
checkbox: Partial<Dialog.ICheckbox> | null;
/**
* The buttons to display.
*/
buttons: Dialog.IButton[];
/**
* The top level text for the dialog.
*/
title: string;
}
/**
* A primer dialog mimicking the JupyterLab dialog interface
*/
export declare class JupyterDialog<T> extends ReactWidget {
protected body: JSXElementConstructor<PropsWithChildren<DialogProps & {
setValue: (v: T | Error) => void;
}>>;
protected checkbox: Partial<Dialog.ICheckbox> | null;
protected buttons: Dialog.IButton[];
protected host: HTMLElement;
protected dialogTitle?: string;
private _closing;
private _result;
/**
* Create a dialog instance.
*/
constructor(options?: Partial<IDialogWrapperOptions<T>>);
private _renderBody;
private _renderFooter;
protected render(): JSX.Element | null;
/**
* Launch the dialog as a modal window.
*
* @returns a promise that resolves with the result of the dialog.
*/
launch(): Promise<Dialog.IResult<T>>;
protected handleButton: (idx: number) => void;
protected setButton: (button: Dialog.IButton) => void;
protected setChecked: (c: boolean) => void;
protected setValue: (v: T | Error) => void;
close: () => void;
}
export default JupyterDialog;