1.1.53 • Published 11 months ago

react-chat-package v1.1.53

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

React Toast Popup

React Toast Popup is a simple and customizable toast notification component for React applications.

Frontend_System_Design_Questions__Toast_Component___HLD_LLD

Installation

You can install React Toast Popup via npm:

npm install react-toast-popup

Usage

To use React Toast Popup in your React application, follow these steps:

Import the useNotification hook and necessary styles in your component:

import useNotification from "react-toast-popup";

Initialize the useNotification hook with your preferred position:

const { NotificationComponent, triggerNotification } =
  useNotification("top-left");

Postions

  • "bottom-left"
  • "bottom-right"
  • "top-left"
  • "top-right"

Use NotificationComponent in your JSX to display notifications:

return (
  <div className="App">
    {NotificationComponent}
    {/* Your other JSX content */}
  </div>
);

Trigger notifications using the triggerNotification function:

triggerNotification({
  type: "success",
  message: "This is a success message!",
  duration: 3000,
});

Animations

You can specify an animation type for the notifications. The available animations are:

  • "fade"
  • "pop"
  • "slide"
triggerNotification({
  type: "success",
  message: "This is a success message with a pop animation!",
  duration: 3000,
  animation: "pop",
});

API

useNotification(position: PositionType)

This hook returns an object with the following properties:

  • NotificationComponent: React element representing the notification container.
  • triggerNotification(notificationProps: NotificationProps): Function to trigger a notification with the specified properties.

NotificationProps The triggerNotification function accepts an object of type NotificationProps, which includes:

  • type: Type of the notification (success, info, warning, error).
  • message: Message to display in the notification.
  • duration: Duration in milliseconds for which the notification should be displayed.
  • animation (optional): Animation type for the notification (fade, pop, slide).

Example

Here's a basic example of how to use React Toast Popup:

import React from "react";
import useNotification from "react-toast-popup";

function App() {
  const { NotificationComponent, triggerNotification } =
    useNotification("top-left");

  const handleButtonClick = () => {
    triggerNotification({
      type: "success",
      message: "This is a success message!",
      duration: 3000,
    });
  };

  return (
    <div className="App">
      {NotificationComponent}
      <h1>Toast Component</h1>
      <img
        onClick={handleButtonClick}
        src="https://exei-bkt-important-object.s3.ap-south-1.amazonaws.com/Frame+2.png"
        alt="avatar"
      />
      <button onClick={handleButtonClick}>Show Success</button>
    </div>
  );
}

export default App;

License

This project is licensed under the MIT License - see the LICENSE file for details.

1.1.53

11 months ago

1.1.52

11 months ago

1.1.51

11 months ago

1.1.50

11 months ago

1.1.49

11 months ago

1.1.47

11 months ago

1.1.46

11 months ago

1.1.45

11 months ago

1.1.44

11 months ago

1.1.43

11 months ago

1.1.42

11 months ago

1.1.40

11 months ago

1.1.38

11 months ago

1.1.37

11 months ago

1.1.34

11 months ago

1.1.33

11 months ago

1.1.32

11 months ago

1.1.31

11 months ago

1.1.30

11 months ago

1.1.29

11 months ago

1.1.28

11 months ago

1.1.26

11 months ago

1.1.25

11 months ago

1.1.24

11 months ago

1.1.23

11 months ago

1.1.18

11 months ago

1.1.17

11 months ago

1.1.16

11 months ago

1.1.15

11 months ago

1.1.14

11 months ago

1.1.13

11 months ago

1.1.12

11 months ago

1.1.11

11 months ago

1.1.10

11 months ago

1.1.8

11 months ago

1.1.7

11 months ago

1.1.6

11 months ago

1.1.5

11 months ago

1.1.4

11 months ago

0.1.0

11 months ago