-
Notifications
You must be signed in to change notification settings - Fork 841
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
[EuiToast & Co.] Convert to function component, Emotion styling #6068
Conversation
// Toast dismissal side effect | ||
// Ensure the callback has correct state by not enclosing it in `setTimeout` | ||
useEffect(() => { | ||
const toast = toastToDismiss; | ||
// Because this is triggered by a setTimeout, and because React does not guarantee when | ||
// state updates happen, it is possible to double-dismiss a toast | ||
// including by double-clicking the "x" button on the toast | ||
// so, first check to make sure we haven't already dismissed this toast | ||
if (toast && toastIdToTimerMap.current.hasOwnProperty(toast.id)) { | ||
dismissToastProp(toast); |
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.
Only important change in the conversion to using hooks.
Previsouly props.dismissToast
was called directly from within the setTimeout
function and that was fine. With hooks, the closure inside useCallback
would "lock" the state at time of instantiation and state would be outdated by the time the callback occurred.
This could be solved by requiring consumers to use the previous state param in their state management (setToastList((prevToasts) => prevToasts.filter(() => {}));
but we can avoid the requirement with this side effect.
${logicalCSS('padding-left', euiTheme.size.base)}; | ||
${logicalCSS('padding-right', euiTheme.size.base)}; | ||
${logicalCSS('padding-vertical', euiTheme.size.base)}; |
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.
Using -left
and -right
instead of -horizontal
because these values are potentially overridden by :not(:empty)
logic and -left
/-right
will not cancel -horizontal
(different generated CSS properties).
Preview documentation changes for this PR: https://eui.elastic.co/pr_6068/ |
Preview documentation changes for this PR: https://eui.elastic.co/pr_6068/ |
Preview documentation changes for this PR: https://eui.elastic.co/pr_6068/ |
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 @thompsongl! 🎉
I tested in Chrome, Firefox and Safari. Works well! 🚀
I just have two suggestions. Let me know what you think.
Preview documentation changes for this PR: https://eui.elastic.co/pr_6068/ |
Summary
Converts
EuiGlobalToastList
to a function component. Pretty straightforward, but see line comments for a more involved explanation.Converts
EuiToast
,EuiGlobalToastListItem
andEuiGlobalToastList
to styling with@emotion
.View by commit for the easiest review path!
Checklist