1.0.2 • Published 1 year ago

edlesstoast v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

EdlessToast 🍞

A customizable toast for react.

This was mostly used as a project for me to learn from and is not heavily maintained.

Install

Installable through:

npm

npm i edlesstoast

yarn

yarn add edlesstoast

Usage

App should be wrapped in a ToastProvider, child components will then have access to the useToast hook. There is a default toast element included.

import { ToastProvider, useToast } from 'edlesstoast';

const SomeComponent = () => {
    const { openToast, closeToast } = useToast();

    const openHandler = () => openToast({ 
        color: '#5cb85c', // Green Color
        text: 'This is a toast!' 
    });

    const closeHandler = () => clostToast();

    return (
        <button onClick={openHandler}>
            Open Toast
        </button>
        <button onClick={clostHandler}>
            Close Toast
        </button>
    );
}

const App = () => {
    <ToastProvider>
        <SomeComponent />
    </ToastProvider>
}

ToastProvider

Props:

PropDescription
children ReactNodeChildren of the ToastProvider.
toastElement JSX ElementYour custom toast element.
toastVisableTime numberThe time in ms that your toast is visable.
toastFadeTime numberThe time of the fade animation for your toast.

useToast

The useToast hook is used like:

const { openToast, closeToast } = useToast();

The openToast method will open a toast, and takes one argument options which are the props that should be passed to your toast element.

The closeToast method will close an open toast.