Skip to content

fjmg84/fj-toast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fj-toast

fj-toast is for creating toast in an easy way, without other dependencies. You import the library, call the component and pass it a reference.

Example

import { useRef } from "react";
import { ToastPortal } from "./components/ToastPortal";
 const App = () => {
  const toastRef = useRef<ToastRefProps>();
  const messageRef = useRef<HTMLInputElement>(null)

  const addToast = (event: React.FormEvent<HTMLFormElement>): void => {
    event.preventDefault();

    if (messageRef.current) {
      toastRef.current?.addMessage({
        message: messageRef.current.value
      });
    }
  };

  return (
    <div className="App">
      <h1>Hello</h1>

      <form onSubmit={addToast}>

        <input ref={messageRef} type="text" name="message" />
        <button>Show Toast</button>

      </form>


      <ToastPortal position={"bottom-left"} ref={toastRef} />
    </div>
  );
};

Props of ToastPortal

autoClose = boolean

autoCloseTime = number

position = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'

myStyles = object


Description

autoClose: so that the toasts, after the time defined in autoCloseTime, close by themselves (true value default)

autoCloseTime: the time to close the toast (5000 milliseconds default)

position: is position of the toast

myStyles: object by personal styles

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published