import { Injector } from '@angular/core' ; import { Content } from '@ngneat/overview' ; import { Observable } from 'rxjs' ; export class ToastConfig implements DefaultToastOptions { default reverseOrder = false ; ariaLive : ToastAriaLive = 'polite' ; role : ToastRole = 'status' ; position : ToastPosition = 'top-center' ; className : string ; closeStyle : any ; dismissible : boolean ; autoClose = true ; duration : number ; icon : Content ; iconTheme : IconTheme ; style : any ; theme : ToastTheme = 'toast' ; attributes : Record < string , string > = { } ; success : ToastOptions < unknown > & { content ? : Content ; } = { content : '' } ; error : ToastOptions < unknown > & { content ? : Content ; } = { content : '' } ; loading : ToastOptions < unknown > & { content ? : Content ; } = { content : '' } ; blank : ToastOptions < unknown > & { content ? : Content ; } = { content : '' } ; warning : ToastOptions < unknown > & { content ? : Content ; } = { content : '' } ; } export type ToastType = 'success' | 'error' | 'loading' | 'blank' | 'warning' | 'info' ; export type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' ; export type IconTheme = { primary : string ; secondary ? : string ; } ; export type ToastTheme = 'toast' | 'snackbar' ; export type ValueFunction < TValue , TArg > = ( arg : TArg ) => TValue ; export type ValueOrFunction < TValue , TArg > = TValue | ValueFunction < TValue , TArg > ; const isFunction = < TValue , TArg > ( valOrFunction ) : valOrFunction is ValueFunction < TValue , TArg > => typeof valOrFunction === 'function' ; export const resolveValueOrFunction = < TValue , TArg > ( valOrFunction , arg ) : TValue => isFunction ( valOrFunction ) ? valOrFunction ( arg ) : valOrFunction ; export type ToastRole = 'status' | 'alert' ; export type ToastAriaLive = 'assertive' | 'off' | 'polite' ; export interface Toast < DataType > { type : ToastType ; default id : string ; /** The message to show in the hot-toast. */ message : Content ; default role : ToastRole ; default ariaLive : ToastAriaLive ; /**Icon to show in the hot-toast */ icon ? : Content ; default duration ? : number ; default dismissible ? : boolean ; default autoClose ? : boolean ; /**Extra styles to apply for hot-toast */ style ? : any ; /**Extra CSS classes to be added to the hot toast container. */ className ? : string ; /**Extra attribute to be added to the hot toast container. */ attributes ? : Record < string , string > ; /**Use this to change icon color */ iconTheme ? : IconTheme ; default theme ? : ToastTheme ; default position ? : ToastPosition ; /**Extra styles to apply for close button */ closeStyle ? : any ; createdAt : number ; visible : boolean ; height ? : number ; observableMessages ? : ObservableMessages < unknown , DataType > ; example type { ToastPersistConfig } persist ? : ToastPersistConfig ; since type { Injector } memberof injector ? : Injector ; since type { DataType } memberof data ? : DataType ; } export type ToastOptions < DataType > = Partial < Pick < Toast < DataType > , 'id' | 'icon' | 'duration' | 'dismissible' | 'autoClose' | 'role' | 'ariaLive' | 'className' | 'style' | 'iconTheme' | 'theme' | 'position' | 'closeStyle' | 'persist' | 'injector' | 'data' | 'attributes' > > ; export type DefaultToastOptions = ToastOptions < unknown > & { [ key in ToastType ] ? : ToastOptions < unknown > & { content ? : Content ; } ; } ; export type ObservableLoading < DataType > = { content : Content ; } & ToastOptions < DataType > ; export type ObservableSuccessOrError < T , DataType > = { content : ValueOrFunction < Content , T > ; } & ToastOptions < DataType > ; export type ObservableMessages < T , DataType > = { loading ? : Content | ObservableLoading < DataType > ; success ? : ValueOrFunction < Content , T > | ObservableSuccessOrError < T , DataType > ; error ? : ValueOrFunction < Content , any > | ObservableSuccessOrError < any , DataType > ; } ; export interface HotToastServiceMethods { show < DataType > ( message ? , options ? ) : CreateHotToastRef < DataType | unknown > ; error < DataType > ( message ? , options ? ) : CreateHotToastRef < DataType | unknown > ; success < DataType > ( message ? , options ? ) : CreateHotToastRef < DataType | unknown > ; loading < DataType > ( message ? , options ? ) : CreateHotToastRef < DataType | unknown > ; warning < DataType > ( message ? , options ? ) : CreateHotToastRef < DataType | unknown > ; observe < T , DataType > ( messages ) : ( source : Observable < T > ) => Observable < T > ; close ( id ? ) : void ; } export type UpdateToastOptions < DataType > = Partial < Pick < Toast < DataType > , 'icon' | 'duration' | 'dismissible' | 'className' | 'style' | 'iconTheme' | 'type' | 'theme' | 'closeStyle' > > ; export interface HotToastRefProps < DataType > { /** Returns all the toast options */ getToast : ( ) => Toast < DataType > ; dispose : ( ) => void ; /**Updates only message */ updateMessage : ( message : Content ) => void ; /**Update updatable options of toast */ updateToast : ( options : UpdateToastOptions < DataType > ) => void ; /** Observable for notifying the user that the toast has been closed. */ afterClosed : Observable < HotToastClose > ; /**Closes the toast */ close : ( closeData ? : { dismissedByAction : boolean ; } ) => void ; since readonly data : DataType ; } /** Event that is emitted when a snack bar is dismissed. */ export interface HotToastClose { /** Whether the snack bar was dismissed using the action button. */ dismissedByAction : boolean ; id : string ; } export class ToastPersistConfig { type { ( 'local' | 'session' ) } memberof default storage ? : 'local' | 'session' = 'local' ; type { ( 'local' | 'session' ) } memberof default key ? : string = 'ngneat/hototast-${id}' ; memberof default count ? = 1 ; enabled = false ; } export type AddToastRef < DataType > = Pick < HotToastRefProps < DataType > , 'afterClosed' | 'dispose' | 'updateMessage' | 'updateToast' > ; export type CreateHotToastRef < DataType > = Omit < Omit < HotToastRefProps < DataType > , 'appendTo' > , 'dispose' > ; export type DefaultDataType = Record < string , any > ;