Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions lib/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,38 @@ export interface ToastOptions {
/**
* Defines the timeout after which the toast is closed. Set to -1 to have a persistent toast.
*/
timeout?: number;
timeout?: number

/**
* Set to true to allow HTML content inside of the toast text
* @default false
*/
isHTML?: Boolean;
isHTML?: Boolean

/**
* Set a type of {ToastType} to style the modal
*/
type?: ToastType|undefined;
type?: ToastType

/**
* Provide a function that is called after the toast is removed
*/
onRemove?: Function,
onRemove?: Function

/**
* Provide a function that is called when the toast is clicked
*/
onClick?: Function,
onClick?: Function

/**
* Make the toast closable
*/
close?: Boolean;
close?: Boolean

/**
* Specify the element to attach the toast element to (for testing)
*/
selector?: string
}

/**
Expand All @@ -47,8 +57,9 @@ export function showMessage(text: string, options?: ToastOptions): Toast {
timeout: 7,
isHTML: false,
type: undefined,
onRemove: () => {},
onClick: () => {},
selector: 'body-user',
onRemove: () => { },
onClick: () => { },
close: true
}, options)
if (!options.isHTML) {
Expand All @@ -67,7 +78,7 @@ export function showMessage(text: string, options?: ToastOptions): Toast {
onClick: options.onClick,
close: options.close,
gravity: 'top',
selector: 'body-user',
selector: options.selector,
position: 'right',
backgroundColor: '',
className: 'toast ' + classes,
Expand All @@ -83,7 +94,7 @@ export function showMessage(text: string, options?: ToastOptions): Toast {
* @param options
*/
export function showError(text: string, options?: ToastOptions): Toast {
return showMessage(text, {...options, type: ToastType.ERROR})
return showMessage(text, { ...options, type: ToastType.ERROR })
}

/**
Expand All @@ -93,7 +104,7 @@ export function showError(text: string, options?: ToastOptions): Toast {
* @param options
*/
export function showWarning(text: string, options?: ToastOptions): Toast {
return showMessage(text, {...options, type: ToastType.WARNING})
return showMessage(text, { ...options, type: ToastType.WARNING })
}

/**
Expand All @@ -103,7 +114,7 @@ export function showWarning(text: string, options?: ToastOptions): Toast {
* @param options
*/
export function showInfo(text: string, options?: ToastOptions): Toast {
return showMessage(text, {...options, type: ToastType.INFO})
return showMessage(text, { ...options, type: ToastType.INFO })
}

/**
Expand All @@ -113,5 +124,5 @@ export function showInfo(text: string, options?: ToastOptions): Toast {
* @param options
*/
export function showSuccess(text: string, options?: ToastOptions): Toast {
return showMessage(text, {...options, type: ToastType.SUCCESS})
return showMessage(text, { ...options, type: ToastType.SUCCESS })
}