Alert Component

The toast notification system allows you to display temporary pop-up messages (toasts) with different styles (success, warning, info, error) in your application.

Component Visuals

To unlock early access to the component Get Access

Installation

To install the Quest react-sdk into your project, follow these steps:

  • Open your terminal/command prompt.

  • Navigate to your project's root directory using the cd command if you're not already there.

  • Run the following command to install the quest-sdk package using npm:

npm install @questlabs/react-sdk

This command will download and install the package and its dependencies into your project.

Make sure your project has npm and Node.js installed, and that you have the necessary permissions to install packages in your project directory.

Usage

To display a toast notification, you can use the following methods:

showToast.success({ text, duration })

Displays a success toast message.

  • text (optional): The text message to display in the toast (default: 'This is a success message').

  • duration (optional): The duration (in milliseconds) for which the toast is displayed (default: 2000ms).

Example:

import {showToast} from "@questlabs/react-sdk"
import '@questlabs/react-sdk/dist/style.css'
showToast.success({
  text: 'Success! Your operation was completed.',
  duration: 3000,
});

// also you can just pass the string 
showToast.success("Submitted successfully");

Similarly we have showToast.warn, showToast.error, showToast.info as well

Or you can pass a custom element to showToast example:

showToast(<div>This is a toast element<div/>)

Example Usage

Here's an example of how to use the showToast service within your React application:

import showToast from '@questlabs/react-sdk'; // Import the toast module.

function MyComponent() {
  const handleSuccessClick = () => {
    showToast.success({
      text: 'Operation successful!',
      duration: 3000,
    });
  };

  const handleErrorClick = () => {
    showToast.error({
      text: 'An error occurred.',
      duration: 4000,
    });
    //or
    showToast.error("An error occurred");
  };

  return (
    <div>
      <button onClick={handleSuccessClick}>Show Success Toast</button>
      <button onClick={handleErrorClick}>Show Error Toast</button>
    </div>
  );
}

This documentation provides an overview of the showToast service, installation instructions (not required), usage examples, and customization options. You can adapt it to your specific needs and provide more details if necessary.

Demo

Last updated