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

@scrumble-nl/react-quick-toaster

v2.0.1

Published

A quick and easy wrapper around react-bootstrap toasters, you can toast from anywhere in your application with a few simple steps.

Downloads

1,682

Readme

Quick-Toaster

A quick and easy wrapper around react-bootstrap toasters, you can toast from anywhere in your application with a few simple steps.

Quick

alt text

Installation

npm install @scrumble-nl/react-quick-toaster

or

yarn add @scrumble-nl/react-quick-toaster

Usage

Provider

Add the provider as top level as possible:

import React from 'react';
import App from './src/app';
import {ToastProvider} from '@scrumble-nl/quick-toaster'; // Don't forget to import this

export default class ToastApp extends React.Component<{}, {}> {
    render = (): JSX.Element => {
        return (
            <ToastProvider>
                <App/>
            </ToastProvider>
        )       
    }       
}

The ToastProvider has multiple optional props so you can customize it to your needs:

| Name | Type | Required | Description | Default| |--------------|:----------------------------------------------------------------------------------------:|:----------:|:-------------------------------------|------| | position | 'top-left', 'top-right', 'bottom-left', 'bottom-right' | false | The position of the toast container | top-right | maxItems | number | false | The maximum amount of toasts rendered at a given time | 8 | defaultTimer | number | false | The default amount of ms before the toast is removed | 4000

Adding toasts hooks

  1. Import useToaster in the component where you want to create a toast
  2. Finally, you can create a toast with the desired configuration from your component:
import React from 'react';
import {useToaster} from '@scrumble-nl/quick-toaster'; // Step 1

const MyComponent = (): JSX.Element => {
    const add = useToaster();
    
    showToast = (): void => {
        add({content: 'Damn, this is an easy package!'}); // Step 2
    }

    return (
        <button onClick={this.showToast}>Show my awesome toast</button>            
    )
}

Adding toasts class components

  1. Import withToaster in the component where you want to create a toast
  2. If you are using TypeScript, import ToasterProps and use for props typing
  3. Add export default withToaster(MyComponent) to the file
  4. Finally, you can create a toast with the desired configuration from your component:
import React from 'react';
import {withToaster, ToasterProps} from '@scrumble-nl/quick-toaster'; // Step 1 (& 2)

class MyComponent extends React.Component<ToasterProps, {}> {

    showToast = (): void => {
        this.props.toaster.add({content: 'Damn, this is an easy package!'}); // Step 4
    }

    render = (): JSX.Element => {
        return (
            <button onClick={this.showToast}>Show my awesome toast</button>            
        )
    }
}

export default withToaster(MyComponent); // Step 3

The following options can be used for customization:

| Name | Type | Required | Description | Default | |--------------|:----------------------------------------------------------------------------------------:|:----------:|:-------------------------------------| -------- | | content | string | true | The content for the toast | undefined | | header | string | false | The header for the toast | '' | variant | 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light' | false | The toast type | success | dismissTimer | number | false | Auto dismiss amount in milliseconds | dismissTimer of ToastProvider | dismissible | boolean | false | If you can dismiss the toast | true

Next to that you can override the bootstrap class .alert to change the look of the toasts.

Roadmap

  • [x] Packagize component
  • [ ] Improve styling customizability
  • [ ] Automated testing implementation
  • [ ] Switch from interfaces to types
  • [ ] Improve scss usage

Contributing

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

Scrumble

This product has been originally developed by Scrumble for internal use. As we have been using lots of open source packages we wanted to give back to the community. We hope this helps you getting forward as much as other people helped us!