Add slot name to `amplify-toast`
See original GitHub issueIs your feature request related to a problem? Please describe. I’d like to add custom style to toast notification. I’ve seen other issue about this, like #5604 #6167 #2834
Describe the solution you’d like
Fully customize toast notification via slot
as other ui components do.
I think it’s matter of few lines in this file: https://github.com/aws-amplify/amplify-js/blob/3642e6af455ee1848c1cc743a7a503e96baefa41/packages/amplify-ui-components/src/components/amplify-toast/amplify-toast.tsx
render() {
return (
<slot name="toast-notification">
<div class="toast">
<amplify-icon class="toast-icon" name="warning" />
{this.message ? <span>{this.message}</span> : null}
<slot />
<button class="toast-close" onClick={this.handleClose} />
</div>
</slot name="toast-notification">
);
}
Could you consider a PR?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:19
- Comments:16 (5 by maintainers)
Top Results From Across the Web
Developers - Add slot name to `amplify-toast` - - Bountysource
Add slot name to `amplify -toast` ... I'd like to add custom style to toast notification. I've seen other issue about this, like...
Read more >Figma-to-Code (React) - Component slots - AWS Amplify Docs
Add component slots to Amplify-generated Figma-to-code components. Use this to support nested components or collections in React code. - AWS Amplify Docs.
Read more >amplify-js
AWS Amplify provides a declarative and easy-to-use interface across different categories of cloud operations. AWS Amplify goes well with any JavaScript based ...
Read more >Change auth state from custom component while using @aws ...
I am trying to integrate Amplify Auth with a React application. ... slot={props.slot}> <h4>Login</h4> <p>Need an account?
Read more >Introducing Component Slots for Figma-to-React code in ...
Add a Slot · By default, your slot will inherit the name of the Frame you selected · You'll be prompted to confirm...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can now prevent the default
toast
from showing using thehideToast
prop onAmplifyAuthenticator
.See this simple example from #7129 for how to implement your own notification/alert component in react (typescript):
You can just replace
<div>{alertMessage}</div>
with your own component, using your own styles etc (for example a modal).For anyone wondering why this ended up as a
prop
instead of aslot
as suggested at the top of this issue; a slot approach was investigated (#7601) but the implementation would have required making trade-offs that theprop
approach simply avoids.I have solved the problem.
It should listen to
UI Auth
instead ofauth
channel, then check whether theres.payload.event
isToastAuthError
. It would literally captured all events related to authorization including case that no actual auth request is sent.Here is the code :
On hiding the default Toast, I’ve changed to use interval to loop on it instead of just once, so that it is still safe to set a shorter waiting time (Not sure whether it has significant improvement though).