-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
[docs] Improve Toolpad Core docs #43796
base: master
Are you sure you want to change the base?
Conversation
You can create and manipulate dialogs imperatively with the [`useDialog`](https://mui.com/toolpad/core/react-use-dialogs/) API in `@toolpad/core`. This API provides state management for opening and closing dialogs and for passing data to the dialog and back. It allows for stacking multiple dialogs. It also provides themed alternatives for `window.alert`, `window.confirm` and `window.prompt`. | ||
You can create and manipulate dialogs imperatively with the [`useDialogs`](https://mui.com/toolpad/core/react-use-dialogs/) API in `@toolpad/core`. This API provides state management for opening and closing dialogs and for passing data to the dialog and back. It allows for stacking multiple dialogs. It also provides themed alternatives for `window.alert`, `window.confirm` and `window.prompt`. | ||
|
||
{{"demo": "ToolpadDialogs.js", "defaultCodeOpen": false}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me, an issue with this demo is that it doesn't capture the imperative nature of the APIs. I find it hard to see what information a user gets out of it by clicking these buttons. IMO it would make more sense to share just a code snippet, e.g. something like:
const handleDelete = async (id: string) => {
const deleteConfirmed = await dialogs.confirm(`Are you sure you want to delete "${id}"?`);
if (!deleteConfirmed) return;
try {
await api.delete(id)
} catch (error) {
await dialogs.open(CustomErrorDialog, { id, error })
}
}
This shows the benefits of imperative APIs as they mix well with the async flows you'd often use them in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I've updated the demo (and added a code snippet) to reflect the actual utility much better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. We can add a notifications demo in a separate PR. I propose we just copy https://mui.com/toolpad/core/react-use-notifications/#close-notifications
I can update the current notifications demo in this PR itself, should be a small change |
Closes [docs] Refine Toolpad sections on Material UI docs toolpad#4007
https://deploy-preview-43796--material-ui.netlify.app/material-ui/react-dialog/#toolpad
https://deploy-preview-43796--material-ui.netlify.app/material-ui/react-drawer/#toolpad
https://deploy-preview-43796--material-ui.netlify.app/material-ui/react-app-bar/#toolpad
https://deploy-preview-43796--material-ui.netlify.app/material-ui/react-snackbar/#toolpad
https://deploy-preview-43796--material-ui.netlify.app/material-ui/react-breadcrumbs/#toolpad
https://deploy-preview-43796--material-ui.netlify.app/material-ui/react-drawer/#toolpad