-
Notifications
You must be signed in to change notification settings - Fork 17
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
Enhancement: Reusable ToastMessage #20
Comments
I'm interesting to understand more about this - if we had this reusable module we'd still need to import it into each component to be able to use it, so are there advantages to this over importing and using the built-in toast message directly? |
Yeah this makes sense, I can imagine there being some value in extending this out from core functionality at some point. Perhaps firing an event for logging or standardising how exceptions are parsed. Yes happy to support your suggestions around how this is designed |
Related to #19 I would like to suggest also a helper component created by me to make toastMessages reusable.
I've called the below component toastMessageHelper.js
With this approach you don't have the same import in different components. You only have one import in one component!
`import { ShowToastEvent } from 'lightning/platformShowToastEvent';
/**
* Toastmessage for user.
*
* @param {string} title -- The title of the toast, displayed as a heading.
* @param {string} message -- A string containing a message for the user.
* @param {string} variant -- The theme and icon displayed in the toast. Valid values are:
* info—(Default) A gray box with an info icon.
* success—A green box with a checkmark icon.
* warning—A yellow box with a warning icon.
* error—A red box with an error icon.
* @param {string} mode -- Determines how persistent the toast is. Valid values are:
* dismissable—(Default) Remains visible until the user clicks the close button or 3 seconds has elapsed, whichever comes first.
* pester—Remains visible for 3 seconds.
* sticky—Remains visible until the user clicks the close button.
*
* You can see the styling for each theme in the Lightning Design System (https://www.lightningdesignsystem.com/components/toast/) documentation.
*/
const notifyUser = (title, message, variant, mode) => {
const toastEvent = new ShowToastEvent({
title,
message,
variant,
mode
});
dispatchEvent(toastEvent);
}
The text was updated successfully, but these errors were encountered: