Skip to content

Conversation

mcasimir
Copy link
Collaborator

@mcasimir mcasimir commented Feb 7, 2022

Replace state-based toasts with a global provider + hooks

Feb-07-2022.21-19-28.mp4

@mcasimir mcasimir added wip and removed wip labels Feb 7, 2022
@mcasimir mcasimir changed the title feat(compass-components): add useToast feat(compass-components): add useToast COMPASS-5473 Feb 7, 2022
Copy link
Collaborator

@gribnoysup gribnoysup left a comment

Choose a reason for hiding this comment

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

Overall I think it looks good, but there are a few issues that I spotted that I think we should address before this can be merged

Comment on lines 52 to 61
<Toast
className={toastStyles}
key={id}
title={title}
body={body}
variant={variant}
progress={progress}
open={true}
close={() => closeToast(id)}
/>
Copy link
Collaborator

@gribnoysup gribnoysup Feb 8, 2022

Choose a reason for hiding this comment

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

Seems like by default toast component renders itself with position fixed which means that multiple toasts are just stacked on top of each other and you can't see them:

This is how three toasts look in UI:

image

And this is the DOM (just to prove that there are multiple of them):

image

I think we either need to ask leafygreen team to implement toast stack or work around that by having our own fixed container here + adding some styles to the toast to override its position (we probably would need to do both because I don't see leafygreen implementing this change any time soon)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed container here + adding some styles

That's probably easy enough and probably we could rely on the fact that position: fixed should always be on the Toast element itself.

We decided not to make this change here, but worth a try

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok tried this out and is actually not possible to get a handle of the container for the toasts. All gets rendered by LG in a child of body, so not much we can do.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah yeah, I see now that they render them in a portal (on top of having fixed position, why?) and in this case don't allow to override the portal node (or disable the portal similar to other components). I will ask them how are we even supposed to handle this. If you want to merge this as-is that's fine, but basically with how leafygreen works right now we can't make multiple toasts work on the same screen and so maybe we shouldn't even "allow" this on the hook level, because we are basically allowing broken behavior that way

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At hook level is partially handled, I think is best if LG fixes it, but since you have to pass an id, creating multiple toasts has to be intentional. Ie. the copy-connection-string will not create multiple toasts, but the next one will replace the previous one if is there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, we definitely handle it on our side! What I mean is what happens when I need to add a toast with another id somewhere else in the app? It will result in a broken UI with overlapping toasts, do we just agree that this is okay for now and wait for leafygreen team to provide the solution in the future?

@mcasimir mcasimir removed the wip label Feb 9, 2022
@mcasimir mcasimir requested a review from gribnoysup February 9, 2022 10:56
Copy link
Collaborator

@gribnoysup gribnoysup 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! I'm concerned about this #2765 (comment) and would prefer to decide how we should handle this before this PR lands, but also don't want to block it on this

@mcasimir mcasimir merged commit 1835f28 into main Feb 10, 2022
@mcasimir mcasimir deleted the COMPASS-5473 branch February 10, 2022 09:09
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.

2 participants