0.0.4 • Published 2 years ago

tailwind-react-alert v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Simple, beautiful and customizable alerts

tailwind-react-alert provides alerts out of the box with react. this library uses animate css and font awesome, so you can customize your alerts super easy

Content List

  • Installation
  • Configurations
  • Usage

Installation

npm i tailwind-react-alert

Configurations

  • First we import the AlertProvider and add it to the index.js;
import { AlertProvider } from "tailwind-react-alert";
  • This is a context so it should surround your application.
ReactDOM.render(
  <React.StrictMode>
    <AlertProvider>
      <App />
    </AlertProvider>
  </React.StrictMode>,
  document.getElementById("root")
);

Usage

  • Import the hook called useAlert
import { useAlert } from "tailwind-react-alert";
  • Let's store the hook methods in a constant
const TWRA = useAlert();
  • if you prefer you can destruct the available methods
const { aBorder, aContent, aSimple } = useAlert();

Using Simple Alert

  • The simple alert can receive the following properties
  • Available colors and icons are at the end of the documentation.

    PropertyTypeDefault
    textstringInfo! Change a few things
    colorstringblue
    autoClosenumber0
    animatestringanimate__fadeInRight
    animateOutstringanimate__fadeOut
    iconstringinfo
    showIconbooleantrue
    showBtnDismissbooleantrue

Example

  • In this example I will fill all the properties but all are optional since it will take the default values.
const onClickButton = () => {
  aSimple({
    text: "This is a test with CRA!!",
    icon: "success",
    color: "green",
    autoClose: 4000,
    animate: "animate__flipInX",
    animateOut: "animate__fadeOut",
    showIcon: true,
    showBtnDismiss: false,
  });
};

Using Border Alert

  • The border alert can receive the following properties
  • Available colors and icons are at the end of the documentation.
PropertyTypeDefault
textstringInfo! Change a few things
colorstringblue
autoClosenumber4000
animatestringanimate__fadeInRight
animateOutstringanimate__fadeOut
iconstringinfo

Example

  • In this example I will fill all the properties but all are optional since it will take the default values.
const onClickButton = () => {
  aBorder({
    text: "This is a test with CRA!!",
    icon: "warning",
    color: "yellow",
    autoClose: 4000,
    animate: "animate__flipInX",
    animateOut: "animate__fadeOut",
  });
};

Using Content Alert

  • The border alert can receive the following properties
  • Available colors and icons are at the end of the documentation.
PropertyTypeDefault
titlestringThis is a default title of alert
textstringThis is a default text of alert :)
colorstringblue
autoClosenumber0
animatestringanimate__flipInX
animateOutstringanimate__fadeOut
iconstringinfo
textBtnstringView more
textBtnDismissstringDismiss
iconBtnstringfa-solid fa-eye
onClickBtnfunction()=> console.log('clicked')

Example

  • In this example I will fill all the properties but all are optional since it will take the default values.
const onClickButton = () => {
  aContent({
    title: "Save your contacts!",
    text: "This is a test with CRA!!",
    icon: "info",
    color: "sky",
    autoClose: 5000,
    animate: "animate__flipInX",
    animateOut: "animate__flipOutX",
    textBtn: "Contacts",
    textBtnDismiss: "Close",
    iconBtn: "fa-solid fa-address-book",
    onClickBtn: () => {
      alert("Hi alert!");
    },
  });
};

Colors avalibles

  • blue
  • red
  • green
  • yellow
  • dark
  • indigo
  • sky
  • purple

Icons avalibles

  • info
  • exclamation
  • error
  • warning
  • question
  • success