Last active
August 25, 2020 19:16
-
-
Save jsmithdev/ebc729bb55a46126ba09dc922bcc8bd5 to your computer and use it in GitHub Desktop.
Toast util JS file for LWC's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ShowToastEvent } from 'lightning/platformShowToastEvent' | |
/** | |
* | |
* @param {String} str - String to capitalize the first character | |
* @returns {String} String with first character capitalized | |
*/ | |
export function capitalize(str){ | |
return str.charAt(0).toUpperCase() + str.slice(1) | |
} | |
/** | |
* @param {String} msg message to display to user | |
* @param {String} type variant to use; Acceptables are: success, error, info or warning (Defaults to info) | |
* @returns {ShowToastEvent} Event ready to dispatch using this.dispatchEvent(event) | |
*/ | |
export function toast(msg, type = 'info'){ | |
const event = new ShowToastEvent({ | |
title: capitalize(type), | |
message: msg, | |
variant: type, | |
}); | |
return event | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment