0.3.0 • Published 10 months ago

@choi-ui/react-toast v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@choi-ui/react-toast

This package provides easy access to toast messages in React applications.

Installation

// npm
$ npm insatll @choi-ui/react-toast

// pnpm
$ pnpm add @choi-ui/react-toast

Usage

import Toast, { onToast } from '@choi-ui/react-toast';

cosnt App = () => {
  const handleClick = () => {
    onToast({
      message: 'hello toast!',
    });
  };

  return (
    <div>
        <button onClick={onToast}>toast</button>
        <Toast />
    </div>
  );
}

Storybook Documentation

It will be helpful to refer to the storybook when using it.

Description

It is recommended to declare the <Toast /> component in the top-level component. ex. App.tsx

If you declare it in the top-level component, you don't need to add it to each component where toast is used.

Props

The props of the onToast function, which is the event used when generating a toast, are as follows.

propstypedefaultdescription
messagestringdisplayed message
typesuccess | warn | error | defaultdefaultColors by toast type
durationnumber3000Toast Duration (ms)
positiontop | top-right | top-left | bottom | bottom-right | bottom-leftbottombottomToast display position
isClosablebooleantrueWhether to display the close button
variantsfilled | outlinedfilledfilled has a solid background, outlined has a border
customReact.ReactNodeCustomize toast content

Note

In onToast's props, custom values ​​are designed to have priority over message values.

import Toast, { onToast } from '@choi-ui/react-toast';

cosnt App = () => {
  const handleClick = () => {
    onToast({
      message: 'simple message', // Skip
      custom: () => <div>
        <h1>Hello</h1>
        <p>this is custom toast message</p>
      </div>
    });
  };

  return (
    <div>
        <button onClick={onToast}>toast</button>
        <Toast />
    </div>
  );
}

It is effective for displaying a toast in the form of a component rather than a simple text message.

0.3.0

10 months ago

0.2.9

10 months ago

0.2.8

10 months ago

0.2.7

10 months ago

0.2.6

10 months ago

0.2.5

10 months ago

0.2.4

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago