File

src/helpers/toast.helper.ts

Deprecated

Use SqToastService instead for better testability and Angular integration. SqToastService provides Observable-based lifecycle, data-test attributes, and proper mocking support.

Description

A service for displaying toast messages in Angular applications.

Toast messages are often used to provide feedback to users in a non-intrusive way. This service provides methods to display different types of toast messages with various configurations.

Look the link about the component in original framework and the appearance

See https://css.squidit.com.br/components/toast

SqToastService provides Observable-based lifecycle, data-test attributes, and proper mocking support.

Example :
// OLD (deprecated):
this.toastHelper.toast.success('Message');

// NEW (recommended): this.toastService.success('Message');

Index

Properties
Methods

Constructor

constructor()

Creates an instance of the ToastHelper service.

Methods

toastLogSrr
toastLogSrr(message: string, config?: ToastConfig)

Logs and returns a toast message with the provided message and configuration.

Parameters :
Name Type Optional Description
message string No
  • The message content of the toast.
config ToastConfig Yes
  • The configuration options for the toast.
Returns : ToastResponse
  • The response containing the message and configuration.

Properties

Public toast
Type : Toast
Default value : { success: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config), error: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config), inverted: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config), info: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config), warning: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config), grayscale: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config), custom: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config), default: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config), show: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config), theme: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config), }

An object containing methods for displaying different types of toast messages.

import { Injectable } from '@angular/core';
import { Toast, ToastConfig, ToastResponse } from '../interfaces/toast.interface';

/**
 * Global declare to get from window
 */
declare const Toast: Toast;

/**
 * A service for displaying toast messages in Angular applications.
 *
 * Toast messages are often used to provide feedback to users in a non-intrusive way. This service
 * provides methods to display different types of toast messages with various configurations.
 *
 * Look the link about the component in original framework and the appearance
 *
 * @see {@link https://css.squidit.com.br/components/toast}
 *
 * @deprecated Use SqToastService instead for better testability and Angular integration.
 * SqToastService provides Observable-based lifecycle, data-test attributes, and proper mocking support.
 *
 * @example
 * // OLD (deprecated):
 * this.toastHelper.toast.success('Message');
 *
 * // NEW (recommended):
 * this.toastService.success('Message');
 */
@Injectable({
  providedIn: 'root',
})
export class ToastHelper {
  /**
   * An object containing methods for displaying different types of toast messages.
   */
  public toast: Toast = {
    success: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config),
    error: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config),
    inverted: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config),
    info: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config),
    warning: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config),
    grayscale: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config),
    custom: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config),
    default: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config),
    show: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config),
    theme: (message: string, config?: ToastConfig) => this.toastLogSrr(message, config),
  };

  /**
   * Creates an instance of the ToastHelper service.
   */
  constructor() {
    // Check if Toast is available globally (from @squidit/css)
    if (typeof window !== 'undefined' && window['Toast' as any]) {
      this.toast = window['Toast' as any] as unknown as Toast;
    }
    // Otherwise, use the fallback implementation (toastLogSrr)
  }

  /**
   * Logs and returns a toast message with the provided message and configuration.
   * @param {string} message - The message content of the toast.
   * @param {ToastConfig} config - The configuration options for the toast.
   * @returns {ToastResponse} - The response containing the message and configuration.
   */
  toastLogSrr(message: string, config?: ToastConfig): ToastResponse {
    return {
      message,
      config,
    };
  }
}

results matching ""

    No results matching ""