1.0.4 • Published 2 years ago

react-custom-alert v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-custom-alert

  • Easy to set up and call alert function like calling a hook.
  • light weight. (gzipped : 1.3KB)
  • customize alert component.
  • support to next.js(server-side-rendering).

toast-image

toast-sample

Installation

npm

$ npm install react-custom-alert

yarn

$ yarn add react-custom-alert

Example

import React from 'react';
import { ToastContainer, toast } from 'react-custom-alert';
import 'react-custom-alert/dist/index.css'; // import css file from root.

function RootComponent() {
  return (
    <>
      <App />
      {/* Add ToastContainer from your root component. */}
      {/* If you use next.js, add it to app.js */}
      {/* If no floatingTime, the default is 3000ms. */}
      <ToastContainer floatingTime={5000} />
    </>
  );
}

function App() {
  // toast methods : info | success | warning | error
  const alertInfo = () => toast.info('info');
  const alertSuccess = () => toast.success('success');
  const alertWarning = () => toast.warning('warning');
  const alertError = () => toast.error('error');

  return (
    <div>
      <button onClick={alertInfo}>Info</button>
      <button onClick={alertSuccess}>Success</button>
      <button onClick={alertWarning}>Warning</button>
      <button onClick={alertError}>Error</button>
    </div>
  );
}

Guide

ToastContainer

Prop nameDescriptiontypedefault value
containerStyleUpper element style that contains toast listundefined | React.CSSPropertiesundefined
floatingTimeTime to expose default toast(ms)undefined | number3000
toastStyleDefault toast style to overrideundefined | React.CSSPropertiesundefined

toast

Toast has four methods(info, success, warning, error).

Each method has the same type as the table below.

type ToastMethods = (message: string, options?: ToastOptions) => void;
Toast optionsDescriptiontypedefault value
floatingTimeTime to expose specific toast(ms)undefined | numberundefined
toastStyleSpecific toast style to overrideundefined | React.CSSPropertiesundefined
1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.0

2 years ago