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

Pass toast message through props #9

Merged
merged 3 commits into from
Oct 5, 2022
Merged

Pass toast message through props #9

merged 3 commits into from
Oct 5, 2022

Conversation

hasparus
Copy link
Contributor

@hasparus hasparus commented Oct 4, 2022

We're now expecting the user to handle displaying messages with a Toast component compatible with @edgeandnode/components.

Previous GraphiQL Playground we've used had its own snackbar implementation, but @cmwhited convinced me this is a responsibility of the host application. Same toast component should be displayed to communicate network errors.

To support this, we can notice that @radix-ui/react-toast exports a context provider to wrap the whole application:

@netlify
Copy link

netlify bot commented Oct 4, 2022

Deploy Preview for enn-graphiql ready!

Name Link
🔨 Latest commit 5370c91
🔍 Latest deploy log https://app.netlify.com/sites/enn-graphiql/deploys/633ce39b2c7d650009b0ab24
😎 Deploy Preview https://deploy-preview-9--enn-graphiql.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Comment on lines +93 to +105
{/* TODO: I'm not quite sure if this is the best public API. */}
<Toast
open={!!toast}
severity={toast?.severity || 'error'}
title={toast?.title || ''}
action={toast?.action}
description={toast?.description}
onClose={() => {
toast?.onClose?.()
setToast(undefined)
}}
/>
</>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to go back to the Toast after shipping the Playground anyway, so... this might change and look better in the future.

Copy link
Contributor

@cmwhited cmwhited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure I understand, does @edgeandnode/component use the ToastProvider from radix-ui? Like is that wrapped in the <ThemeProvider> we expose? So any app could use the toast message? cc @benface

src/SavedQueriesToolbar/SavedQueriesActionButtons.tsx Outdated Show resolved Hide resolved
@benface
Copy link
Contributor

benface commented Oct 4, 2022

To make sure I understand, does @edgeandnode/component use the ToastProvider from radix-ui? Like is that wrapped in the we expose? So any app could use the toast message?

I just checked and no. Reading the Radix docs, you're right that it seems like we should add that. @hasparus – It works without it? Maybe it's needed for accessibility?

@hasparus
Copy link
Contributor Author

hasparus commented Oct 5, 2022

@benface @cmwhited Currently @edgeandnode/components has the simplest usage of the ToastProvider. (Same as Hosted Service.) We only ever render one Toast.Root, so putting it right above it was correct. I didn't extract it out, because I wasn't sure yet why it was needed and Radix docs aren't so clear on this, so I think I'm gonna have to read the source.

image

@hasparus hasparus merged commit 6b3901d into main Oct 5, 2022
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

Successfully merging this pull request may close these issues.

None yet

3 participants