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

[docs] Improve Toolpad Core docs #43796

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

@bharatkashyap bharatkashyap added the docs Improvements or additions to the documentation label Sep 17, 2024
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}}
Copy link
Member

@Janpot Janpot Sep 18, 2024

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.

Copy link
Member Author

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

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 18, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 18, 2024
Copy link
Member

@Janpot Janpot left a 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

@bharatkashyap
Copy link
Member Author

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

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 20, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[docs] Refine Toolpad sections on Material UI docs
3 participants