Toast

General

Please look at the your screen 👀


Show Code
import React from "react";
import Toast from 'funda-ui/Toast';
 
// component styles
import 'funda-ui/Toast/index.css';
 
export default () => {
 
    return (
        <>
          
        <Toast 
            direction="bottom-right" 
            autoCloseTime={3000} 
            data={[
                { title: "Toast one", message: "First..." },
                { title: "Toast two", message: "Source of radiant heat." },
                { title: "Toast three", message: "ok!" },
                { title: "Toast four", message: "Last item here..." }
            ]} 
            onClose={(e, currentIndex, displayedElements) => {
                console.log(e, currentIndex, displayedElements);
            }}
        />
 
          
        <Toast
            cascading={false}
            direction="top-center"
            schemeBody="align-items-center text-white border-0 p-2"
            closeBtnColor="#fff"
            autoCloseTime={5000}
            data={[
                { theme: 'dark', title: false, note: false, message: "First..." },
                { theme: 'success', title: false, note: false, message: "Source of radiant heat." },
                { theme: 'danger', title: false, note: false, message: "ok!" },
                { theme: 'warning', title: false, note: false, message: "Last item here..." }
            ]}
        />
    
                
        <Toast 
            direction="bottom-center" 
            autoCloseTime={false} data={[
                { title: false, note: "11 mins ago", message: <><div style={{fontSize:"14px"}}>This is <span style={{color:"orange"}}>orange</span> text <p>...</p></div></> }
            ]} 
        />	
 
 
        <Toast 
            direction="vertical-center" 
            schemeHeader="text-white bg-dark" 
            closeBtnColor="#fff"  
            data={[
                { title: false, note: "11 mins ago", message: <><div>Text here</div></> }
            ]} 
        />	
 
 
       <Toast 
            direction="bottom-center" 
            schemeBody="align-items-center text-white bg-dark border-0" 
            closeBtnColor="#fff" 
            data={[
                { title: false, note: false, message: <><div>Text Here</div></> }
            ]} 
        />
 
 
          
        </>
    );
}

Asynchronous Usage

Use asynchronous toast information to dynamically display notifications.

If you delete the autoHideMultiple attribute, all records will stay on the page.


Click here to display Toast information dynamically
Show Code
import React, { useState, useRef } from "react";
import Toast from 'funda-ui/Toast';
 
// component styles
import 'funda-ui/Toast/index.css';
 
 
export default () => {
 
    const counter = useRef<any>({ num: 0 });
    const [toastData, setToastData] = useState<any[]>([]);
    
    function handleClick(e) {
        e.preventDefault();
        counter.current.num++;
        //
        setToastData((prevState) => [
            ...prevState,
            { title: false, note: false, message: <><div dangerouslySetInnerHTML={{__html: `No.${counter.current.num}: ${Date.now()}`}}></div></> }
        ]);
 
    }
 
    return (
        <>
 
            <a href="#" onClick={handleClick}>Click here to display Toast information dynamically</a>
            <Toast 
                cascading={false}
                autoCloseTime={3000} 
                direction="bottom-center" 
                schemeBody="align-items-center text-white bg-dark border-0" 
                closeBtnColor="#fff" 
                data={toastData} 
                async
                onClose={(e, currentIndex, displayedElements) => {
                    setToastData((prevState: any) => {
                        prevState.splice(displayedElements.length - 1, 1);
                        return prevState;
 
                    });
                    console.log(e, currentIndex, displayedElements);
 
                }}
                autoHideMultiple
            />
 
        </>
    )
}

API

Toast

import Toast from 'funda-ui/Toast';
PropertyTypeDefaultDescriptionRequired
wrapperClassNamestring-The class name of the toast wrapper.-
dataarray-Specify data of toasts as a JSON string format. Such as:
[{"title":"Title 1","note":"","message":"description..."},{"title":"Title 2","note":"","message":"description..."}].
If its value is an empty array [], the Toast will not be displayed.
Note: If the data is asynchronous, the attribute async needs to be set to true
asyncbooleanfalseUse asynchronous triggering.-
autoHideMultiplebooleanfalseAutomatically hide multiple items. It creates a transition animation effect with multiple records and only one displayed.-
lockbooleanfalseYou can not close pop-win when it is enabled.-
cascadingbooleantrueWhether to use cascading styles.-
schemeBodystring-Self-defined class name for body, such as: align-items-center text-white bg-primary border-0-
schemeHeaderstring-Self-defined class name for header, such as: text-white bg-dark-
closeBtnColorstring-Set the color of the close button.-
closeDisabledbooleanfalseDisable the close button.-
directionbottom-left | bottom-center | bottom-right | top-left | top-center | top-right | vertical-centerbottom-centerThe direction of the toast-
autoCloseTimeboolean | numberfalseSet an automatic closing time, multiple items will be accumulated in order. Amount of time measured in milliseconds. If false or without this attribute, Auto-Close will be disabled.-
onClosefunction-Call a function when the modal is opened. It returns three callback values.
  1. The first is the current element (HTMLDivElement)
  2. The second is the current index of removed item (Number)
  3. The third is the all displayed elements (HTMLDivElement[])
-

Array configuration properties of the data:

PropertyTypeDefaultDescriptionRequired
titlestring | ReactNode | boolean-Specifies an alternate and title for the toast-
notestring | ReactNode | boolean-A light-colored comment next to the title, which can be information such as time.-
messagestring | ReactNode-Specifies the content, or HTML elements to the toast-
themeprimary | secondary | success | info | warning | danger | light | dark | undefinedundefinedSpecifies a theme to .toast. All these colors are available as a Sass map of Bootstrap.-