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

@kano/kbc-toast

v2.0.61

Published

Toast manager.

Downloads

25

Readme

kbc-toast

A manager and a set of toast configurations.

Setup

This package provides a context with a global toastManager that you can use to trigger toasts. To set it up, add the following provider:

import { ToastManagerProvider } from '@kano/kbc-toast';

ReactDOM.render(
    <ToastManagerProvider config={{}} >
        {/* A component that will trigger a toast. */}
        <Component prop="Hello" />
    </ToastManagerProvider>
);

How to trigger a toast

You can trigger a toast like so

import { withToastManager, IToastManagerAPI } from '@kano/kbc-toast';

interface ComponentProps extends IToastManagerAPI {
    prop: string;
}

const Component = withToastManager(({ prop, toastManager }: ComponentProps) => {
    const handleClick = () => {
        toastManager.queueToast(
            'notice',
            'consent-needed', /* Toast id */
            {
                icon: 'Info',
                title: 'Can\'t do this',
                message: 'You need permission to click this button'
            }
        );
    };

    return <button className="component" onClick={handleClick}>{prop}</button>;
});

The first parameter selects which toast component to use (in this case notice). The second parameter is custom toast id that you can use to refer to the toast later. The last parameter will be passed as props to the toast component.

toastManager.current has the currently displayed toast.

toastManager.current.id has the id that you provided as a second parameter.

You can dismiss it by calling current.dismiss(). The toast manager will show the next toast in the queue. You can also cancel the entire queue by calling current.cancel().

## Toast types

Here are the toast types currently available. To add a new one, create a new file in the toasts/ directory.

Notice

A notice with a customisable icon, title and message.

Example:

toastManager.queueToast(
    'notice',
    'consent-needed',
    {
        icon: 'Info',
        title: 'Can\'t do this',
        message: 'You need permission to click this button'
    }
);

Cookie Consent

A cookie consent with Allow, Deny and close dismiss buttons.

Example:

toastManager.queueToast(
    'cookie-consent',
    'rich-teas',
    {
        onAllow() {
            console.log('COOL');
        },
        onDeny() {
            console.log('NOT COOL');
        },
    }
);