1.1.10 • Published 10 months ago

react-flare-toast v1.1.10

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

React Flare Toast

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

./src/assets/react-flare-toast-demo.gif

Installation

You can install React Flare Toast via npm:

npm i react-flare-toast

Usage

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

Import the useToast hook and necessary styles in your component:

import useToast from "react-flare-toast";

Initialize the useToast hook with your preferred position:

const { Toast, triggerToast } = useToast("top-right");

Positions

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

Use Toast in your JSX to display toasts:

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

Trigger toasts using the triggerToast function:

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

Animations

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

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

API

useToast(position: PositionType)

This hook returns an object with the following properties:

  • Toast: React element representing the toast container.
  • triggerToast(toastProps: toastProps): Function to trigger a toast with the specified properties.

toastProps The triggerToast function accepts an object of type toastProps, which includes:

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

Example

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

import React from "react";
import useToast from "react-flare-toast";

function App() {
  const { Toast, triggerToast } = useToast("top-right");

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

  return (
    <div className="App">
      {Toast}
      <h1>Toast Component</h1>
      <button onClick={handleButtonClick}>Show Success</button>
    </div>
  );
}

export default App;

License

This project is licensed under the MIT License

1.1.10

10 months ago

1.1.9

10 months ago

1.1.8

10 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

1.1.3

11 months ago

1.1.2

11 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago