Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example about dialogs #252

Open
jtpio opened this issue Oct 17, 2023 · 2 comments
Open

Add an example about dialogs #252

jtpio opened this issue Oct 17, 2023 · 2 comments

Comments

@jtpio
Copy link
Member

jtpio commented Oct 17, 2023

It would be nice to have an example showing how to use dialogs and / or all the different types of dialogs available.

Some examples already use dialogs, for example:

showDialog({
title: file.name,
body: 'Path: ' + file.path,
buttons: [Dialog.okButton()]
}).catch(e => console.log(e));

But it could be useful to have a dedicated example so it's easier to find and reference elsewhere.

@jtpio
Copy link
Member Author

jtpio commented Oct 17, 2023

Another question that is sometimes asked is how to dismiss a dialog automatically.

For JupyterLab 3 the following snippet seems to be doing the trick (for dismissing the first dialog only):

const hideFirstDialog = async (_: unknown, w: Dialog<unknown>) => {
  Dialog.tracker.widgetAdded.disconnect(hideFirstDialog);
  requestAnimationFrame(() => w.dispose());
};
Dialog.tracker.widgetAdded.connect(hideFirstDialog);

In JupyterLab 4 there is now a ready promise, which could likely be used instead of the requestAnimationFrame above:

https://github.com/jupyterlab/jupyterlab/blob/0f178d3094f07f4474dc171a9493effbf0b38e90/packages/apputils/src/dialog.tsx#L147-L152

@krassowski
Copy link
Member

Alternatively, we could improve the documentation which already has a few examples:
https://jupyterlab.readthedocs.io/en/latest/extension/ui_helpers.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants