Skip to content

Instantly share code, notes, and snippets.

@jsmithdev
Last active August 25, 2020 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsmithdev/ebc729bb55a46126ba09dc922bcc8bd5 to your computer and use it in GitHub Desktop.
Save jsmithdev/ebc729bb55a46126ba09dc922bcc8bd5 to your computer and use it in GitHub Desktop.
Toast util JS file for LWC's
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