UNPKG

@pheralb/toast

Version:

A lightweight, customizable, and dependency-free notification library for React.

1 lines 33.2 kB
{"version":3,"sources":["../src/main.tsx","#style-inject:#style-inject","../src/styles/globals.css","../src/components/toaster.tsx","../src/components/toast.tsx","../src/icons/index.tsx","../src/hooks/useTimeout.tsx","../src/utils/index.ts","../src/components/default-options.ts","../src/components/toast-functions.ts"],"sourcesContent":["/* eslint-disable react-refresh/only-export-components */\nimport \"./styles/globals.css\";\n\nexport { toast } from \"./components/toast-functions\";\nexport { Toaster } from \"./components/toaster\";\nexport type {\n Position as ToastPosition,\n ToastProps as ToastProperties,\n Variant as ToastVariant,\n Theme as ToastTheme,\n ToastOptions,\n ToasterProperties,\n ToastAnimations,\n} from \"./types/toast.types\";\n","\n export default function styleInject(css, { insertAt } = {}) {\n if (!css || typeof document === 'undefined') return\n \n const head = document.head || document.getElementsByTagName('head')[0]\n const style = document.createElement('style')\n style.type = 'text/css'\n \n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild)\n } else {\n head.appendChild(style)\n }\n } else {\n head.appendChild(style)\n }\n \n if (style.styleSheet) {\n style.styleSheet.cssText = css\n } else {\n style.appendChild(document.createTextNode(css))\n }\n }\n ","import styleInject from '#style-inject';styleInject(\":root{--pheralb-toast-animation-enter: .4s;--pheralb-toast-animation-exit: .4s}:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_light-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #ffffff;--hover-bg-color: #f5f5f5;--border-color: #e5e5e5;--text-color: #171717;--description-color: #262626;--focus-color: #a3a3a3}.t_dark-theme{--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}@media (prefers-color-scheme: dark){:where(.t_global){--box-shadow: rgba(0, 0, 0, .1);--background-color: #171717;--hover-bg-color: #27272a;--border-color: #262626;--text-color: #fafafa;--description-color: #e5e5e5;--focus-color: #404040}}.t_toasts{display:flex;flex-direction:column;gap:10px;padding:14px;position:fixed;z-index:999;overflow:hidden;transition:max-height .5s ease-in-out;width:100%}.t_default_font{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.t_top-left{top:0;left:0}.t_top-right{top:0;right:0}.t_top-center{top:0;left:50%;transform:translate(-50%)}.t_bottom-left{bottom:0;left:0}.t_bottom-right{bottom:0;right:0}.t_bottom-center{bottom:0;left:50%;transform:translate(-50%)}@media (min-width: 768px){.t_toasts{max-width:355px}}.t_global{display:flex;justify-content:space-between;padding:0;margin:0;list-style:none;outline:none;background-color:var(--background-color);width:auto;box-shadow:0 1px 3px 0 var(--box-shadow),0 1px 2px -1px var(--box-shadow);border:1px solid var(--border-color);border-radius:.375rem;font-size:.875rem;line-height:1.25rem;overflow:hidden}.t_global button{border:none;outline:none}.t_global button:focus{outline:1px solid var(--focus-color);outline-offset:0px;background-color:var(--hover-color)}.t_container{display:flex;flex-direction:row;align-items:center;width:100%;max-width:20rem;height:100wh;gap:.6rem;padding:12px;word-wrap:break-word;overflow-wrap:break-word}.t_icon{fill:var(--text-color);margin-top:.1rem;flex-shrink:0}.t_content{display:flex;flex-direction:column;justify-content:center;max-width:100%}.t_content p{font-weight:600;color:var(--text-color);margin:0}.t_content p:nth-of-type(2){font-weight:400;font-size:.75rem;color:var(--description-color)}.t_actions{display:flex;flex-direction:column;border-left:1px solid var(--border-color);height:100wh}.t_actions>button{flex:1 1 0%;width:100%;padding:6px 20px;font-size:13px;background-color:transparent;cursor:pointer;border:none}.t_actions>button:nth-child(1){color:var(--text-color);font-weight:500}.t_actions>button:nth-child(2){color:var(--text-color);border-top:1px solid var(--border-color)}.t_actions>button:hover{background-color:var(--hover-color)}.t_loading{animation:spin 1s linear infinite}@keyframes spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.t_slide-enter-top{animation:slide-top var(--pheralb-toast-animation-enter) ease}@keyframes slide-top{0%{opacity:0;transform:translateY(-100%)}to{opacity:1;transform:translateY(0)}}.t_slide-enter-bottom{animation:slide-bottom var(--pheralb-toast-animation-enter) ease}@keyframes slide-bottom{0%{opacity:0;transform:translateY(100%)}to{opacity:1;transform:translateY(0)}}.t-slide-exit-top,.t-slide-exit-bottom{will-change:transform,opacity}.t-slide-exit-top{animation:slide-top-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-top-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t-slide-exit-bottom{animation:slide-bottom-exit var(--pheralb-toast-animation-exit) ease}@keyframes slide-bottom-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(100%)}}.t_swipe-exit-center{animation:swipe-center-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-center-exit{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-100%)}}.t_swipe-exit-left{animation:swipe-left-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-left-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(-100%)}}.t_swipe-exit-right{animation:swipe-right-exit var(--pheralb-toast-animation-exit) ease}@keyframes swipe-right-exit{0%{opacity:1;transform:translate(0)}to{opacity:0;transform:translate(100%)}}\\n\")","import { useEffect, useState } from \"react\";\n\nimport type {\n ToastPropsWithVariant,\n ToasterProperties,\n} from \"../types/toast.types\";\n\nimport ToastComponent from \"./toast\";\nimport { cn, generateRandomId } from \"../utils\";\n\n// Ensure openToastGlobal is initialized correctly\nlet openToastGlobal: (data: ToastPropsWithVariant) => void;\n\nexport const Toaster = ({\n maxToasts = 4,\n position = \"bottom-right\",\n theme = \"system\",\n toastOptions,\n}: ToasterProperties) => {\n const [toasts, setToasts] = useState<ToastPropsWithVariant[]>([]);\n const [isMounted, setIsMounted] = useState<boolean>(false);\n\n useEffect(() => {\n setIsMounted(true);\n }, []);\n\n // Define the openToast function\n const openToast = (data: ToastPropsWithVariant) => {\n const newToast = {\n ...data,\n id: generateRandomId(),\n };\n setToasts((prevToasts) => {\n const isTopPosition =\n position === \"top-left\" ||\n position === \"top-right\" ||\n position === \"top-center\";\n\n if (prevToasts.length >= maxToasts) {\n return isTopPosition\n ? [newToast, ...prevToasts.slice(0, -1)]\n : [...prevToasts.slice(1), newToast];\n }\n\n return isTopPosition\n ? [newToast, ...prevToasts]\n : [...prevToasts, newToast];\n });\n };\n\n // Define the closeToast function\n const closeToast = (id: number) => {\n setToasts((prevToasts) => prevToasts.filter((toast) => toast.id !== id));\n };\n\n // Assign openToast to the global variable\n openToastGlobal = openToast;\n\n // Render the component\n return (\n isMounted &&\n toasts.length > 0 && (\n <section\n aria-label=\"Toast Notifications\"\n role=\"alert\"\n aria-live=\"polite\"\n className={cn(\n \"t_toasts\",\n position === \"top-left\" ? \"t_top-left\" : \"\",\n position === \"top-right\" ? \"t_top-right\" : \"\",\n position === \"top-center\" ? \"t_top-center\" : \"\",\n position === \"bottom-left\" ? \"t_bottom-left\" : \"\",\n position === \"bottom-right\" ? \"t_bottom-right\" : \"\",\n position === \"bottom-center\" ? \"t_bottom-center\" : \"\",\n toastOptions?.font ? toastOptions?.font : \"t_default_font\",\n )}\n >\n {toasts.map((toast) => (\n <ToastComponent\n key={toast.id}\n theme={theme}\n toastPosition={position}\n onClose={() => closeToast(toast.id!)}\n toastOptions={toastOptions}\n active={toasts.indexOf(toast) === toasts.length - 1}\n {...toast}\n />\n ))}\n </section>\n )\n );\n};\n\n// Export the openToast function:\n// eslint-disable-next-line react-refresh/only-export-components\nexport const openToast = (data: ToastPropsWithVariant): void => {\n if (openToastGlobal) {\n openToastGlobal(data);\n } else {\n console.error(\n \"🔔 <Toaster /> component is not mounted. Check toast.pheralb.dev/toaster for more information.\",\n );\n }\n};\n","import type {\n Position,\n ToastIcons,\n ToastOptions,\n ToastPropsWithLoading,\n Variant,\n} from \"../types/toast.types\";\n\nimport { useCallback, useEffect, useState } from \"react\";\n\nimport { Error, Info, Loading, Success, Warning } from \"../icons\";\nimport { useTimeout } from \"../hooks/useTimeout\";\nimport { cn, getSystemTheme, prefersReducedMotion } from \"../utils\";\n\nimport { iconsColors, getAnimationClass } from \"./default-options\";\n\ninterface ToastComponentProps extends ToastPropsWithLoading {\n toastPosition: Position;\n toastOptions?: ToastOptions;\n active?: boolean;\n onClose: () => void;\n}\n\nconst Toast = (props: ToastComponentProps) => {\n const [status, setStatus] = useState<Variant>(props.variant || \"info\");\n const [iconColor, setIconColor] = useState<string>(iconsColors[status]);\n const [toastText, setToastText] = useState<string>(props.text);\n const [isExiting, setIsExiting] = useState<boolean>(false);\n\n const delayDuration = props.delayDuration || 4000;\n\n const { pause, resume } = useTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n\n const iconClass = cn(\n \"t_icon\",\n props.variant === \"loading\" && status === \"loading\" ? \"t_loading\" : \"\",\n );\n\n const icons: ToastIcons = {\n success: (\n <Success\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n error: (\n <Error\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n warning: (\n <Warning\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n info: (\n <Info\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n loading: (\n <Loading\n width={18}\n height={18}\n style={{ fill: iconColor }}\n className={iconClass}\n />\n ),\n };\n\n const IconComponent = props.toastOptions?.icons\n ? props.toastOptions?.icons[status]\n : icons[status];\n\n const handleCloseToast = useCallback(() => {\n setIsExiting(true);\n const animationDisabled = prefersReducedMotion();\n if (!animationDisabled) {\n setTimeout(() => {\n if (props.onClose) {\n props.onClose();\n }\n }, 300);\n } else if (props.onClose) {\n props.onClose();\n }\n }, [props]);\n\n const handleMouseLeave = () => {\n resume();\n };\n\n const handleMouseEnter = () => {\n pause();\n };\n\n useEffect(() => {\n if (props.variant === \"loading\" && props.options) {\n pause();\n\n const executePromise =\n typeof props.options.promise === \"function\"\n ? props.options.promise()\n : Promise.resolve(props.options.promise);\n\n executePromise\n .then((data) => {\n resume();\n setStatus(\"success\");\n if (props.options!.autoDismiss) {\n setTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n }\n setToastText(props.options!.success);\n setIconColor(iconsColors.success);\n if (props.options?.onSuccess) {\n props.options.onSuccess(data);\n }\n })\n .catch((error) => {\n setStatus(\"error\");\n setToastText(props.options!.error);\n setIconColor(iconsColors.error);\n if (props.options!.autoDismiss) {\n setTimeout(() => {\n handleCloseToast();\n }, delayDuration);\n }\n if (props.options?.onError) {\n props.options.onError(error);\n }\n });\n }\n }, [\n delayDuration,\n handleCloseToast,\n pause,\n props.options,\n props.variant,\n resume,\n ]);\n\n return (\n <div\n role=\"alert\"\n aria-labelledby={`toast-title-${props.id}`}\n aria-describedby={`toast-description-${props.id}`}\n title={props.text}\n className={cn(\n !prefersReducedMotion()\n ? getAnimationClass(\n isExiting,\n props.toastOptions?.animationOnClose || \"slide\",\n props.toastPosition,\n )\n : \"\",\n !props.toastOptions?.headless && props.theme === \"system\"\n ? getSystemTheme()\n : \"\",\n !props.toastOptions?.headless && props.theme === \"dark\"\n ? \"t_dark-theme\"\n : \"\",\n !props.toastOptions?.headless && props.theme === \"light\"\n ? \"t_light-theme\"\n : \"\",\n !props.toastOptions?.headless ? \"t_global\" : \"\",\n props.toastOptions?.classNames?.toast,\n )}\n style={{\n zIndex: props.active ? 1000 : 999,\n }}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleMouseEnter}\n onBlur={handleMouseLeave}\n >\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_container\" : \"\",\n props.toastOptions?.classNames?.container,\n )}\n >\n {props.variant && !props.icon ? (\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_icon\" : \"\",\n props.toastOptions?.classNames?.icon,\n )}\n >\n {IconComponent}\n </div>\n ) : (\n props.icon && (\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_icon\" : \"\",\n props.toastOptions?.classNames?.icon,\n )}\n >\n {props.icon}\n </div>\n )\n )}\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_content\" : \"\",\n props.toastOptions?.classNames?.content,\n )}\n >\n <p id={`toast-title-${props.id}`}>{toastText}</p>\n {props.description && (\n <p id={`toast-description-${props.id}`}>{props.description}</p>\n )}\n </div>\n </div>\n <div\n className={cn(\n !props.toastOptions?.headless ? \"t_actions\" : \"\",\n props.toastOptions?.classNames?.actions?.container,\n )}\n >\n {props.action && (\n <button\n onClick={props.action.onClick}\n title={\n typeof props.action.content === \"string\"\n ? props.action.content\n : \"Action Button\"\n }\n className={cn(props.toastOptions?.classNames?.actions?.actionBtn)}\n >\n {props.action.content ??\n props.toastOptions?.defaultActionContent ??\n \"Action\"}\n </button>\n )}\n <button\n onClick={handleCloseToast}\n title=\"Close toast\"\n className={cn(props.toastOptions?.classNames?.actions?.closeBtn)}\n >\n {props.toastOptions?.defaultCloseContent ?? \"Close\"}\n </button>\n </div>\n </div>\n );\n};\n\nexport default Toast;\n","import type { ComponentProps, FC } from \"react\";\n\nexport const Success: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm45.66 85.66l-56 56a8 8 0 01-11.32 0l-24-24a8 8 0 0111.32-11.32L112 148.69l50.34-50.35a8 8 0 0111.32 11.32z\"></path>\n </svg>\n);\n\nexport const Warning: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M236.8 188.09L149.35 36.22a24.76 24.76 0 00-42.7 0L19.2 188.09a23.51 23.51 0 000 23.72A24.35 24.35 0 0040.55 224h174.9a24.35 24.35 0 0021.33-12.19 23.51 23.51 0 00.02-23.72zM120 104a8 8 0 0116 0v40a8 8 0 01-16 0zm8 88a12 12 0 1112-12 12 12 0 01-12 12z\"></path>\n </svg>\n);\n\nexport const Error: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-8 56a8 8 0 0116 0v56a8 8 0 01-16 0zm8 104a12 12 0 1112-12 12 12 0 01-12 12z\"></path>\n </svg>\n);\n\nexport const Info: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M128 24a104 104 0 10104 104A104.11 104.11 0 00128 24zm-4 48a12 12 0 11-12 12 12 12 0 0112-12zm12 112a16 16 0 01-16-16v-40a8 8 0 010-16 16 16 0 0116 16v40a8 8 0 010 16z\"></path>\n </svg>\n);\n\nexport const Loading: FC<ComponentProps<\"svg\">> = (props) => (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" {...props}>\n <path d=\"M136 32v32a8 8 0 01-16 0V32a8 8 0 0116 0zm37.25 58.75a8 8 0 005.66-2.35l22.63-22.62a8 8 0 00-11.32-11.32L167.6 77.09a8 8 0 005.65 13.66zM224 120h-32a8 8 0 000 16h32a8 8 0 000-16zm-45.09 47.6a8 8 0 00-11.31 11.31l22.62 22.63a8 8 0 0011.32-11.32zM128 184a8 8 0 00-8 8v32a8 8 0 0016 0v-32a8 8 0 00-8-8zm-50.91-16.4l-22.63 22.62a8 8 0 0011.32 11.32l22.62-22.63a8 8 0 00-11.31-11.31zM72 128a8 8 0 00-8-8H32a8 8 0 000 16h32a8 8 0 008-8zm-6.22-73.54a8 8 0 00-11.32 11.32L77.09 88.4A8 8 0 0088.4 77.09z\"></path>\n </svg>\n);\n","import { useCallback, useEffect, useRef } from \"react\";\n\ninterface UseTimeoutReturn {\n pause: () => void;\n resume: () => void;\n reset: () => void;\n isActive: boolean;\n}\n\nexport const useTimeout = (\n callback: () => void,\n delay: number,\n): UseTimeoutReturn => {\n const timeoutRef = useRef<number>(0);\n const callbackRef = useRef(callback);\n const startTimeRef = useRef<number>(0);\n const remainingRef = useRef(delay);\n const isActiveRef = useRef(true);\n\n const cleanup = useCallback(() => {\n if (timeoutRef.current) {\n window.clearTimeout(timeoutRef.current);\n }\n }, []);\n\n const pause = useCallback(() => {\n if (!isActiveRef.current || !startTimeRef.current) return;\n\n cleanup();\n remainingRef.current -= Date.now() - startTimeRef.current;\n isActiveRef.current = false;\n }, [cleanup]);\n\n const resume = useCallback(() => {\n if (isActiveRef.current) return;\n\n startTimeRef.current = Date.now();\n timeoutRef.current = window.setTimeout(\n callbackRef.current,\n remainingRef.current,\n );\n isActiveRef.current = true;\n }, []);\n\n const reset = useCallback(() => {\n cleanup();\n remainingRef.current = delay;\n startTimeRef.current = Date.now();\n timeoutRef.current = window.setTimeout(callbackRef.current, delay);\n isActiveRef.current = true;\n }, [cleanup, delay]);\n\n useEffect(() => {\n callbackRef.current = callback;\n }, [callback]);\n\n useEffect(() => {\n reset();\n return cleanup;\n }, [delay, reset, cleanup]);\n\n return {\n pause,\n resume,\n reset,\n isActive: isActiveRef.current,\n };\n};\n","export const cn = (...classes: (string | undefined)[]) => {\n return classes.filter(Boolean).join(\" \");\n};\n\nexport const generateRandomId = () => Math.floor(Math.random() * 1000000);\n\nexport const prefersReducedMotion = (() => {\n let shouldReduceMotion: boolean | undefined = undefined;\n return () => {\n if (shouldReduceMotion === undefined) {\n if (typeof window !== \"undefined\" && window.matchMedia !== undefined) {\n const mediaQuery = window.matchMedia(\n \"(prefers-reduced-motion: reduce)\",\n );\n shouldReduceMotion = mediaQuery.matches;\n } else {\n shouldReduceMotion = false;\n }\n }\n return shouldReduceMotion;\n };\n})();\n\n// Get system theme:\nexport const getSystemTheme = () => {\n if (typeof window !== \"undefined\") {\n return window.matchMedia(\"(prefers-color-scheme: dark)\").matches\n ? \"t_dark-theme\"\n : \"t_light-theme\";\n }\n return \"t_light-theme\";\n};\n","import type { Position, ToastAnimations, Variant } from \"../types/toast.types\";\n\n/* Default icon colors */\n\nexport const iconsColors: Record<Variant, string> = {\n success: \"#22c55e\",\n error: \"#ef4444\",\n warning: \"#eab308\",\n info: \"#3b82f6\",\n loading: \"currentColor\",\n};\n\n/* Default animations */\n\nconst ANIMATION_ENTER_MAP: Record<Position, string> = {\n \"top-left\": \"t_slide-enter-top\",\n \"top-right\": \"t_slide-enter-top\",\n \"top-center\": \"t_slide-enter-top\",\n \"bottom-left\": \"t_slide-enter-bottom\",\n \"bottom-right\": \"t_slide-enter-bottom\",\n \"bottom-center\": \"t_slide-enter-bottom\",\n};\n\nconst ANIMATION_EXIT_MAP: Record<Position, string> = {\n \"top-left\": \"t-slide-exit-top\",\n \"top-right\": \"t-slide-exit-top\",\n \"top-center\": \"t-slide-exit-top\",\n \"bottom-left\": \"t-slide-exit-bottom\",\n \"bottom-right\": \"t-slide-exit-bottom\",\n \"bottom-center\": \"t-slide-exit-bottom\",\n};\n\n/* Swipe exit animations */\n\nconst ANIMATION_SWIPE_EXIT_MAP: Record<Position, string> = {\n \"top-left\": \"t_swipe-exit-left\",\n \"top-right\": \"t_swipe-exit-right\",\n \"top-center\": \"t_swipe-exit-center\",\n \"bottom-left\": \"t_swipe-exit-left\",\n \"bottom-right\": \"t_swipe-exit-right\",\n \"bottom-center\": \"t_swipe-exit-center\",\n};\n\nexport const getAnimationClass = (\n isExiting: boolean,\n animationType: ToastAnimations,\n position: Position,\n) => {\n if (!isExiting) {\n return ANIMATION_ENTER_MAP[position];\n }\n\n if (animationType === \"swipe\") {\n return ANIMATION_SWIPE_EXIT_MAP[position];\n }\n\n return ANIMATION_EXIT_MAP[position];\n};\n","import type {\n ToastPropsWithLoading,\n ToastPropsWithVariant,\n} from '../types/toast.types';\nimport { openToast } from './toaster';\n\ninterface ToastFunctions {\n default: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n success: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n error: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n warning: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n info: (data: ToastPropsWithVariant) => ToastPropsWithVariant;\n loading: (data: ToastPropsWithLoading) => ToastPropsWithLoading;\n}\n\nexport const toast: ToastFunctions = {\n default: (data: ToastPropsWithVariant) => {\n openToast({ ...data });\n return data;\n },\n success: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'success' });\n return data;\n },\n error: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'error' });\n return data;\n },\n warning: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'warning' });\n return data;\n },\n info: (data: ToastPropsWithVariant) => {\n openToast({ ...data, variant: 'info' });\n return data;\n },\n loading: (data: ToastPropsWithLoading) => {\n openToast({ ...data, variant: 'loading' });\n return data;\n },\n};\n"],"mappings":";yaAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,aAAAE,EAAA,UAAAC,IAAA,eAAAC,EAAAJ,ICCyB,SAARK,EAA6BC,EAAK,CAAE,SAAAC,CAAS,EAAI,CAAC,EAAG,CAC1D,GAAI,CAACD,GAAO,OAAO,SAAa,IAAa,OAE7C,IAAME,EAAO,SAAS,MAAQ,SAAS,qBAAqB,MAAM,EAAE,CAAC,EAC/DC,EAAQ,SAAS,cAAc,OAAO,EAC5CA,EAAM,KAAO,WAETF,IAAa,OACXC,EAAK,WACPA,EAAK,aAAaC,EAAOD,EAAK,UAAU,EAK1CA,EAAK,YAAYC,CAAK,EAGpBA,EAAM,WACRA,EAAM,WAAW,QAAUH,EAE3BG,EAAM,YAAY,SAAS,eAAeH,CAAG,CAAC,CAElD,CCvB8BI,EAAY;AAAA,CAAu6I,ECA39I,IAAAC,EAAoC,iBCQpC,IAAAC,EA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,aAAcb,EACd,OAAQC,EAAO,QAAQY,CAAK,IAAMZ,EAAO,OAAS,EACjD,GAAGY,GANCA,EAAM,EAOb,CACD,EACH,CAGN,EAIaR,EAAaC,GAAsC,CAC1DX,EACFA,EAAgBW,CAAI,EAEpB,QAAQ,MACN,uGACF,CAEJ,EMxFO,IAAMU,EAAwB,CACnC,QAAUC,IACRC,EAAU,CAAE,GAAGD,CAAK,CAAC,EACdA,GAET,QAAUA,IACRC,EAAU,CAAE,GAAGD,EAAM,QAAS,SAAU,CAAC,EAClCA,GAET,MAAQA,IACNC,EAAU,CAAE,GAAGD,EAAM,QAAS,OAAQ,CAAC,EAChCA,GAET,QAAUA,IACRC,EAAU,CAAE,GAAGD,EAAM,QAAS,SAAU,CAAC,EAClCA,GAET,KAAOA,IACLC,EAAU,CAAE,GAAGD,EAAM,QAAS,MAAO,CAAC,EAC/BA,GAET,QAAUA,IACRC,EAAU,CAAE,GAAGD,EAAM,QAAS,SAAU,CAAC,EAClCA,EAEX","names":["main_exports","__export","Toaster","toast","__toCommonJS","styleInject","css","insertAt","head","style","styleInject","import_react","import_react","import_jsx_runtime","Success","props","Warning","Error","Info","Loading","import_react","useTimeout","callback","delay","timeoutRef","callbackRef","startTimeRef","remainingRef","isActiveRef","cleanup","pause","resume","reset","cn","classes","generateRandomId","prefersReducedMotion","shouldReduceMotion","getSystemTheme","iconsColors","ANIMATION_ENTER_MAP","ANIMATION_EXIT_MAP","ANIMATION_SWIPE_EXIT_MAP","getAnimationClass","isExiting","animationType","position","import_jsx_runtime","Toast","props","status","setStatus","iconColor","setIconColor","iconsColors","toastText","setToastText","isExiting","setIsExiting","delayDuration","pause","resume","useTimeout","handleCloseToast","iconClass","cn","icons","Success","Error","Warning","Info","Loading","IconComponent","prefersReducedMotion","handleMouseLeave","handleMouseEnter","data","error","getAnimationClass","getSystemTheme","toast_default","import_jsx_runtime","openToastGlobal","Toaster","maxToasts","position","theme","toastOptions","toasts","setToasts","isMounted","setIsMounted","openToast","data","newToast","generateRandomId","prevToasts","isTopPosition","closeToast","id","toast","cn","toast_default","toast","data","openToast"]}