import React, { useState } from 'react' import { CCard, CCardHeader, CCardBody, CForm, CFormControl, CFormCheck, CFormSelect, CButton, CContainer, CRow, CCol, CFormLabel, CToast, CToaster, } from '@coreui/react' import { DocsLink } from 'src/reusable' const Toaster = () => { const placements = [ 'top-start', 'top-center', 'top-end', 'middle-start', 'middle-center', 'middle-end', 'bottom-start', 'bottom-center', 'bottom-end', ] const [toasts, setToasts] = useState([ { placement: 'static' }, { placement: 'static' }, { placement: 'top-end', autohide: 3000 }, ]) const [placement, setPlacement] = useState('top-end') const [autohide, setAutohide] = useState(true) const [autohideValue, setAutohideValue] = useState(5000) const [closeButton, setCloseButton] = useState(true) const [fade, setFade] = useState(true) const addToast = () => { setToasts([...toasts, { placement, autohide: autohide && autohideValue, closeButton, fade }]) } const toasters = (() => { return toasts.reduce((toasters, toast) => { toasters[toast.placement] = toasters[toast.placement] || [] toasters[toast.placement].push(toast) return toasters }, {}) })() return ( Toasts.
Add toast with following props:
{ setAutohide(e.target.checked) }} custom /> Autohide of the toast
{autohide && (
Time to autohide { setAutohideValue(Number(e.target.value)) }} />
)}
Placement { setPlacement(e.target.value) }} > {placements.map((placement, i) => ( ))}
{ setFade(e.target.checked) }} custom /> fade
{ setCloseButton(e.target.checked) }} /> closeButton
Add toast
{Object.keys(toasters).map((toasterKey) => ( {toasters[toasterKey].map((toast, key) => { return ( } title="CoreUI for React.js" time="7 min ago" autohide={toast.autohide} > {`Hello, ${toasterKey} world! This is a toast ${toasterKey} message.`} ) })} ))}
) } export default Toaster