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

use-toast-notification

v0.1.3

Published

Customizable react notification toast hook

Downloads

42

Readme

📦 use-toast-notification

React hooks library to display notification toast.

NPM npm

Install

npm install use-toast-notification

# or

yarn add use-toast-notification

Usage

Simple Usage

import React from 'react'
import NotificationProvider, { useNotification } from 'use-toast-notification'

const App = () => {
  const notification = useNotification()

  const handleSubmit = async (e) => {
    try {
        notification.show({
            message: 'Your delivery is on its way', 
            title: 'Delivery Status',
            variant: 'success'
        })
    } catch(e){
        notification.show({
            message: 'Your delivery could not be processed', 
            title: 'Delivery Status',
            variant: 'error'
        })
    }
  }

  return (
    <div>
        <form onSubmit={handleSubmit}>
            <input name='address'/>
            <button type='submit'>Submit</button>
        </form>
    </div>
  )
}


const Main = () =>{
    return (
        <NotificationProvider
			config={{
				position: 'top-right',
				isCloseable: false,
				showTitle: true,
				showIcon: true,
				duration: 5,
			}}
		>
            <App/>
        </NotificationProvider>
    )
}


export default Main

| Name | Type | Default | Description | | ------------- | --------- | ------------------ | ------------------------------------------------------------ | | title | String | notify | Title of the notification | | message | ReactNode | | The body of the notification required | | duration | Number | config.duration | The duration in seconds |

⚙️ Config

You can customize your notification toast

all configurations are optional

import React from 'react'
import NotificationProvider from 'use-toast-notification'

const App = () => {
  ...
}

const Main = () =>{
    return (
        <NotificationProvider
			config={{
				position: 'center',
				showClose: true,
				showIcon: false,
				showTitle: true,
				duration: 30, 
			}}
            overrideStyles={{
				cardContainer: {
                    ...
                },
                ...
			}}
		>
            <App/>
        </NotificationProvider>
    )
}

export default Main

Available Config Properties

| Name | Type | Default | Description | | --------------------- | ------------- | ------------| -------------------------------------------------------------| | position | String | 'top-right' | The position of the card | | duration | Number | 5 | The duration in seconds | | animationDuration | Number | 300 | The animation duration in milliseconds | | isCloseable | Boolean | false | Toggle close button | | showIcon | Boolean | true | Toggle card heading icon | | showTitle | Boolean | true | Toggle card heading (icon and title) button | | closeIcon | ReactNode | | Custom close icon | | successIcon | ReactNode | | Custom success icon | | errorIcon | ReactNode | | Custom error icon | | infoIcon | ReactNode | | Custom info icon | | errorColor | string | 'red' | color for the error variant if no custom Icon | | successColor | string | 'green' | color for the success variant if no custom Icon | | infoColor | string | 'blue' | color for the info variant if no custom Icon |

position is one of 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'top-center' | 'bottom-center' | 'center';

Available overrideStyles Properties

| Name | Type | Description | | --------------------- | -----------------| -----------------------------------------------------------------| | container | CSSProperties | The style for the wrapper for all notification boxes | | cardContainer | CSSProperties | The style for the container for a single notification box | | cardContent | CSSProperties | The style for the content for a single notification | | icon | CSSProperties | The icon sizes | | closeButton | CSSProperties | The close button style | | cardMessage | CSSProperties | The style for the message of the notification | | cardIcon | CSSProperties | The style for the icons container | | cardTitle | CSSProperties | The style for the title of the notification | | animateIn | CSSProperties | The animation properties for displaying the notification | | animateOut | CSSProperties | The animation properties for removing the notification |

License

MIT © thelamina