Giter Club home page Giter Club logo

toast's Introduction

toast ๐Ÿž

Version Top language Stars Contributors License

A lightweight easy-to-use toast library

Installation

yarn add @gino/toast
npm install @gino/toast

Basic usage

  1. You must wrap your App component with our ToastProvider to access the required context.
import { ToastProvider } from "@gino/toast"

<ToastProvider>
  <Component {...pageProps} />
</ToastProvider>
  1. To create a toast, simply use the toast function exported from the useToast hook.
const { toast } = useToast();

<button
  onClick={() => {
    toast("This is my toast");
  }}
>
  Add toast
</button>

Rendering toasts

We have made this library as flexibile as possible. In order to render toasts, you can simply map over the toasts array that is exported by the useToasts hook.

const { toasts, removeToast } = useToast();

return (
  <ul>
    {toasts.map((toast) => (
      <li key={toast.id}>
        <div>{toast.message}</div>
        <button onClick={() => removeToast(toast.id)}>Close toast</button>
      </li>
    ))}
  </ul>
)

Making toasts disappear after a certain time

To make toasts disappear after a certain amount of time, we have created a useToastTimer hook that easily handles all this functionality for you. To see this feature in action, please refer to our example project.

import { useToastTimer } from "@gino/toast"

const ref = useToastTimer<HTMLDivElement>(toast.id, {
  duration: 3,
  pauseOnHover: true,
});

return (
  <div ref={ref}>
    <div>This toast will disappear after 3 seconds unless I'm being hovered</div>
  </div>
)

This library is a headless toast library that does not include any styling or animations. You are free to add those yourself or copy an example of how it could be used.

toast's People

Contributors

gino avatar

Watchers

 avatar

toast's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.