synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
93 lines (92 loc) • 2.26 kB
JavaScript
import { jsx as n } from "react/jsx-runtime";
import { uniqueId as p } from "lodash-es";
import { useRef as y } from "react";
import { toast as d, Toaster as k, ToastBar as T } from "react-hot-toast";
import { TransitionGroup as S, CSSTransition as h } from "react-transition-group";
import v from "../FullWidthAlert/FullWidthAlert.js";
function x({
text: o,
show: r,
autohide: e
}) {
const i = y(null);
return /* @__PURE__ */ n(S, { children: r && /* @__PURE__ */ n(
h,
{
nodeRef: i,
classNames: "SRC-card",
timeout: e ? { enter: 500, exit: 300 } : {},
children: /* @__PURE__ */ n("div", { className: "SRC-modal", ref: i, children: o })
}
) });
}
function w() {
return /* @__PURE__ */ n(
k,
{
containerClassName: "SynapseToastContainer",
position: "bottom-center",
children: (o) => /* @__PURE__ */ n(
T,
{
toast: o,
style: {
...o.style,
animation: o.visible ? "fadeInUp 0.5s ease" : "fadeOutDown 1s ease"
// The exit animation needs to be long enough for the element to be removed, or else it will pop back in
}
}
)
}
);
}
const G = (o, r, e = {}) => {
const i = p("synToast-"), a = () => {
d.dismiss(i);
}, {
title: f = void 0,
primaryButtonConfig: s = void 0,
secondaryButtonConfig: t = void 0,
dismissOnPrimaryButtonClick: u = !1,
dismissOnSecondaryButtonClick: C = !1
} = e;
if (s && "onClick" in s && u) {
const c = s.onClick;
s.onClick = (m) => {
c(m), a();
};
}
if (t && "onClick" in t && C) {
const c = t.onClick;
t.onClick = (m) => {
c(m), a();
};
}
let { autoCloseInMs: l = 15e3 } = e;
return l === 0 && (l = 1 / 0), d(
/* @__PURE__ */ n(
v,
{
isGlobal: !1,
onClose: a,
variant: r ?? "info",
show: !0,
title: f,
description: o,
primaryButtonConfig: s,
secondaryButtonConfig: t
}
),
{
id: i,
className: "SynapseToastMessage",
duration: l
}
), a;
};
export {
w as SynapseToastContainer,
x as ToastMessage,
G as displayToast
};
//# sourceMappingURL=ToastMessage.js.map