UNPKG

@scrumble-nl/react-quick-toaster

Version:

A quick and easy wrapper around react-bootstrap toasters, you can toast from anywhere in your application with a few simple steps.

13 lines (12 loc) 952 B
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useEffect } from 'react'; import { motion } from 'framer-motion'; import { Alert } from 'react-bootstrap'; const Toast = ({ defaultTimer, removeToast, toast }) => { useEffect(() => { const { dismissTimer, id } = toast; setTimeout(() => removeToast(id || 0), dismissTimer || defaultTimer); }, [toast, removeToast, defaultTimer]); return (_jsx(motion.div, Object.assign({ layout: "position", initial: { opacity: 0, y: -30, scale: 0.7 }, animate: { opacity: 1, y: 0, scale: 1 }, exit: { opacity: 0, scale: 0.7, transition: { type: 'tween', duration: 0.2 } } }, { children: _jsxs(Alert, Object.assign({ variant: toast.variant || 'success', dismissible: toast.dismissible !== false, onClose: () => removeToast(toast.id || 0) }, { children: [toast.header && _jsx(Alert.Heading, { children: toast.header }), toast.content] })) }))); }; export default Toast;