1.0.39 • Published 2 years ago

react-toast-me v1.0.39

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

React-Toast-Me allows you to show notification toasts in your page easily!

Get started

Install with yarn

$ yarn add react-toast-me

Install with npm

$ npm install --save react-toast-me

Try it yourself

JSX:

import React from 'react';

import ToastProvider, { useToast } from 'react-toast-me';

function MyToasterButton() {
  const { showToast } = useToast();

  return (
    <button
      onClick={() =>
        showToast({
          type: 'success',
          message: 'You are toasted!',
          enableClose: true,
        })
      }
    >
      Click me to be toasted!
    </button>
  );
}

function App() {
  return (
    <ToastProvider 
      expiresIn={7500} 
      horizontalPosition="left" 
      verticalPosition="bottom"
    >
      <MyToasterButton />
    </ToastProvider>
  );
}

TSX:

import React from 'react';

import ToastProvider, { useToast, ToastProps } from 'react-toast-me';

const MyToasterButton: React.FC = () => {
  const { showToast } = useToast();

  const myToast: ToastProps = {
    type: 'success',
    message: 'You are toasted!',
    enableClose: true,
  };

  return (
    <button onClick={() => showToast(myToast)}>
      Click me to be toasted!
    </button>;
  )
};

const App: React.FC = () => {
  return (
    <ToastProvider
      expiresIn={7500}
      horizontalPosition="left"
      verticalPosition="bottom"
    >
      <MyToasterButton />
    </ToastProvider>
  );
};

Docs

ToastProvider

To use react-toast-me you should wrap your component or application with the ToastProvider.

All the ToastProvider props are optional:

PropsTypeDescriptionDefault
expiresIn (ms)numberDefault life time of all toasts.5000
horizontalPositionleft | center | rightHorizontal position of toasts.left
verticalPositiontop | bottomVertical position of toasts.bottom

useToast

React Hook responsible for managing all the toasts actions and data.

toasts

List of enabled toasts. All the toasts visible in the page will be within this array.

showToast

Function that fires a new toast in the page.

Returns the new toast id.

Sintax:

showToast(toastProps, id)
ParamRequiredTypeDescription
toastPropstrueToastPropsToast props to the new toast.
idfalsestringCustom id for the new toast.

hideToast

Function that remove an existing toast from the page.

Sintax:

hideToast(id)
ParamRequiredTypeDescription
idtruestringId of the toast to be removed.

Typings

These types can be imported and used in a Typescript project.

ToastProps

Can be use to type an object to be used in showToast.

RequiredRequiredTypeDescriptionDefault
typetruesuccess | info | warning | errorType of toast.-
messagetruestringMessage to be shown in the toast.''
expiresIn (ms)falsenumberToast's life time. If it's not define it will assume the ToastProvider life time.5000
fadeTimeout (ms)falsenumberToast's fade in and fade out timeout.300
enableClosefalsebooleanEnable or disable the close button for a toast.false

ToastType

Defines the values that can be passed to type property of a toast.

The values are success, info, warning and error.

1.0.39

2 years ago

1.0.38

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.3

2 years ago

1.0.25

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago