npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-toast-react-bootstrap

v1.0.9

Published

An easy and flexible wrapper for Toast React Bootstrap, enabling you to create toasts from any part of your application with just a few easy steps.

Downloads

5

Readme

Easy-Toast-React-Bootstrap

An easy and flexible wrapper for Toast React Bootstrap, enabling you to create toasts from any part of your application with just a few easy steps.

Installation

npm install easy-toast-react-bootstrap

or

yarn add easy-toast-react-bootstrap

Usage

just 2 steps!

Step 1: EasyToastContainer

Add <EasyToastContainer> component as top level as possible.

Example:

import {EasyToastContainer} from "easy-toast-react-bootstrap"; // Don't forget to import this

export function App() {
    return (
        <EasyToastContainer position="top-start" className="p-3">
            <App/>
        </EasyToastContainer>
    )
}

Optional props of <EasyToastContainer> exactly like <ToastContainer> in React Bootstrap.

Step 2: useEasyToast

useEasyToast hook returns an array with exactly two values:

  1. showToast(<Toast>...</Toast>) function: Call it Anywhere you need to show a toast. Give <Toast>...</Toast> component as the first argument.

  2. closeToast(event) function: Call it for close the toast in onClick prop of <CloseButton/> or any button. Don't forget to give event of onClick as the first argument.

Example:

import {useEasyToast} from "easy-toast-react-bootstrap";
import {Toast, Stack, CloseButton} from "react-bootstrap";

export function MyComponent() {
    const [showToast, closeToast] = useEasyToast();
    const handleOnClick = () => {
        showToast(
            <Toast
                bg="success"
                autohide
                className="text-white"
            >
                <Stack direction="horizontal" gap={2}>
                    <Toast.Body>My Toast Message!</Toast.Body>
                    <CloseButton className="me-2 m-auto" variant="white" onClick={closeToast}/>
                </Stack>
            </Toast>
        );
    }
    
}

Example image:

Easy Toast React Bootstrap

Additional Options

  • showToast() function has second argument for when multiple toasts exists: default is "addTop". If you want the new toast added from bottom of other toasts set it "addBottom".
  • You can wrap <Toast>...</Toast> component inside your custom component and then give it to showToast() function. Example:

MyComponent.js

import {useEasyToast} from "easy-toast-react-bootstrap";

export function MyComponent() {
    const [showToast, closeToast] = useEasyToast();
    const handleOnClick = () => {
        showToast(
            <MyCustomToast
                message="My Toast Message!"
                bg="success"
                onClose={closeToast}
            />
        );
    }
    
}

MyCustomToast.js

import {CloseButton, Stack, Toast} from "react-bootstrap";

const MyCustomToast = ({message, bg, onClose}) => {
    return (
        <Toast
            bg={bg}
            autohide
            className="text-white"
        >
            <Stack direction="horizontal" gap={2}>
                <Toast.Body>
                    {message}
                </Toast.Body>
                <CloseButton className="me-2 m-auto" variant="white" onClick={onClose}/>
            </Stack>
        </Toast>
    );
};

export default MyCustomToast;

Contributing

If you would like to see additions/changes to this package you are always welcome to add some code or improve it.