design-react-kit
Version:
Componenti React per Bootstrap 5
1 lines • 2.55 kB
Source Map (JSON)
{"version":3,"sources":["../../src/Notification/Notification.tsx"],"sourcesContent":["import React, { CSSProperties, FC, PropsWithChildren, useEffect } from 'react';\nimport { cssTransition, ToastProps, useToast } from 'react-toastify';\nimport { NotificationToastProps } from './NotificationContent';\nimport { NotificationCommonProps } from './types';\n\nexport type NotificationProps = Omit<ToastProps, 'transition'> & NotificationCommonProps & NotificationToastProps;\n\nconst dummyTransition = /* @__PURE__ */ cssTransition({ enter: '', exit: '' });\n\nexport const Notification: FC<PropsWithChildren<NotificationProps>> = (props) => {\n const { toastRef, eventHandlers } = useToast({\n ...props,\n transition: dummyTransition\n });\n const { children, autoClose, onClick, role, toastId, deleteToast, closeToast, isIn } = props;\n\n const customStyle: CSSProperties = {\n display: isIn ? 'block' : 'none'\n };\n\n useEffect(() => {\n if (!isIn) deleteToast();\n }, [isIn]);\n\n useEffect(() => {\n let timer: NodeJS.Timeout | number;\n if (autoClose) {\n timer = setTimeout(() => closeToast(), autoClose);\n }\n return () => {\n if (timer != null) {\n clearTimeout(Number(timer));\n }\n };\n }, [autoClose, closeToast]);\n return (\n <div\n id={toastId as string}\n onClick={onClick}\n {...eventHandlers}\n style={customStyle}\n ref={toastRef}\n {...(isIn && { role: role })}\n >\n {children}\n </div>\n );\n};\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAuE,sBACvEC,EAAoD,0BAM9CC,KAAkC,iBAAc,CAAE,MAAO,GAAI,KAAM,EAAG,CAAC,EAEhEJ,EAA0DK,GAAU,CAC/E,GAAM,CAAE,SAAAC,EAAU,cAAAC,CAAc,KAAI,YAAS,CAC3C,GAAGF,EACH,WAAYD,CACd,CAAC,EACK,CAAE,SAAAI,EAAU,UAAAC,EAAW,QAAAC,EAAS,KAAAC,EAAM,QAAAC,EAAS,YAAAC,EAAa,WAAAC,EAAY,KAAAC,CAAK,EAAIV,EAEjFW,EAA6B,CACjC,QAASD,EAAO,QAAU,MAC5B,EAEA,sBAAU,IAAM,CACTA,GAAMF,EAAY,CACzB,EAAG,CAACE,CAAI,CAAC,KAET,aAAU,IAAM,CACd,IAAIE,EACJ,OAAIR,IACFQ,EAAQ,WAAW,IAAMH,EAAW,EAAGL,CAAS,GAE3C,IAAM,CACPQ,GAAS,MACX,aAAa,OAAOA,CAAK,CAAC,CAE9B,CACF,EAAG,CAACR,EAAWK,CAAU,CAAC,EAExB,EAAAI,QAAA,cAAC,OACC,GAAIN,EACJ,QAASF,EACR,GAAGH,EACJ,MAAOS,EACP,IAAKV,EACJ,GAAIS,GAAQ,CAAE,KAAMJ,CAAK,GAEzBH,CACH,CAEJ","names":["Notification_exports","__export","Notification","__toCommonJS","import_react","import_react_toastify","dummyTransition","props","toastRef","eventHandlers","children","autoClose","onClick","role","toastId","deleteToast","closeToast","isIn","customStyle","timer","React"]}