welcome-ui
Version:
Customizable design system with react, typescript, tailwindcss and ariakit.
462 lines (457 loc) • 17 kB
JavaScript
"use client";
import { jsx as k, Fragment as re } from "react/jsx-runtime";
import * as f from "react";
import { useRef as U, useCallback as _, useEffect as I, useState as se, forwardRef as W, cloneElement as oe } from "react";
import { c as P } from "./index-PAaZGbyz.js";
import { Alert as Y } from "./Alert.js";
import { Button as ie } from "./Button.js";
import { f as ne } from "./forwardRefWithAs-8eP3ZN15.js";
let le = { data: "" }, ce = (e) => typeof window == "object" ? ((e ? e.querySelector("#_goober") : window._goober) || Object.assign((e || document.head).appendChild(document.createElement("style")), { innerHTML: " ", id: "_goober" })).firstChild : e || le, de = /(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g, me = /\/\*[^]*?\*\/| +/g, H = /\n+/g, x = (e, t) => {
let a = "", s = "", i = "";
for (let o in e) {
let r = e[o];
o[0] == "@" ? o[1] == "i" ? a = o + " " + r + ";" : s += o[1] == "f" ? x(r, o) : o + "{" + x(r, o[1] == "k" ? "" : t) + "}" : typeof r == "object" ? s += x(r, t ? t.replace(/([^,])+/g, (n) => o.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g, (l) => /&/.test(l) ? l.replace(/&/g, n) : n ? n + " " + l : l)) : o) : r != null && (o = /^--/.test(o) ? o : o.replace(/[A-Z]/g, "-$&").toLowerCase(), i += x.p ? x.p(o, r) : o + ":" + r + ";");
}
return a + (t && i ? t + "{" + i + "}" : i) + s;
}, b = {}, Z = (e) => {
if (typeof e == "object") {
let t = "";
for (let a in e) t += a + Z(e[a]);
return t;
}
return e;
}, pe = (e, t, a, s, i) => {
let o = Z(e), r = b[o] || (b[o] = ((l) => {
let d = 0, m = 11;
for (; d < l.length; ) m = 101 * m + l.charCodeAt(d++) >>> 0;
return "go" + m;
})(o));
if (!b[r]) {
let l = o !== e ? e : ((d) => {
let m, c, u = [{}];
for (; m = de.exec(d.replace(me, "")); ) m[4] ? u.shift() : m[3] ? (c = m[3].replace(H, " ").trim(), u.unshift(u[0][c] = u[0][c] || {})) : u[0][m[1]] = m[2].replace(H, " ").trim();
return u[0];
})(e);
b[r] = x(i ? { ["@keyframes " + r]: l } : l, a ? "" : "." + r);
}
let n = a && b.g ? b.g : null;
return a && (b.g = b[r]), ((l, d, m, c) => {
c ? d.data = d.data.replace(c, l) : d.data.indexOf(l) === -1 && (d.data = m ? l + d.data : d.data + l);
})(b[r], t, s, n), r;
}, ue = (e, t, a) => e.reduce((s, i, o) => {
let r = t[o];
if (r && r.call) {
let n = r(a), l = n && n.props && n.props.className || /^go/.test(n) && n;
r = l ? "." + l : n && typeof n == "object" ? n.props ? "" : x(n, "") : n === !1 ? "" : n;
}
return s + i + (r ?? "");
}, "");
function O(e) {
let t = this || {}, a = e.call ? e(t.p) : e;
return pe(a.unshift ? a.raw ? ue(a, [].slice.call(arguments, 1), t.p) : a.reduce((s, i) => Object.assign(s, i && i.call ? i(t.p) : i), {}) : a, ce(t.target), t.g, t.o, t.k);
}
let q, S, T;
O.bind({ g: 1 });
let v = O.bind({ k: 1 });
function fe(e, t, a, s) {
x.p = t, q = e, S = a, T = s;
}
function w(e, t) {
let a = this || {};
return function() {
let s = arguments;
function i(o, r) {
let n = Object.assign({}, o), l = n.className || i.className;
a.p = Object.assign({ theme: S && S() }, n), a.o = / *go\d+/.test(l), n.className = O.apply(a, s) + (l ? " " + l : "");
let d = e;
return e[0] && (d = n.as || e, delete n.as), T && d[0] && T(n), q(d, n);
}
return i;
};
}
var ge = (e) => typeof e == "function", C = (e, t) => ge(e) ? e(t) : e, he = /* @__PURE__ */ (() => {
let e = 0;
return () => (++e).toString();
})(), K = /* @__PURE__ */ (() => {
let e;
return () => {
if (e === void 0 && typeof window < "u") {
let t = matchMedia("(prefers-reduced-motion: reduce)");
e = !t || t.matches;
}
return e;
};
})(), ye = 20, F = "default", Q = (e, t) => {
let { toastLimit: a } = e.settings;
switch (t.type) {
case 0:
return { ...e, toasts: [t.toast, ...e.toasts].slice(0, a) };
case 1:
return { ...e, toasts: e.toasts.map((r) => r.id === t.toast.id ? { ...r, ...t.toast } : r) };
case 2:
let { toast: s } = t;
return Q(e, { type: e.toasts.find((r) => r.id === s.id) ? 1 : 0, toast: s });
case 3:
let { toastId: i } = t;
return { ...e, toasts: e.toasts.map((r) => r.id === i || i === void 0 ? { ...r, dismissed: !0, visible: !1 } : r) };
case 4:
return t.toastId === void 0 ? { ...e, toasts: [] } : { ...e, toasts: e.toasts.filter((r) => r.id !== t.toastId) };
case 5:
return { ...e, pausedAt: t.time };
case 6:
let o = t.time - (e.pausedAt || 0);
return { ...e, pausedAt: void 0, toasts: e.toasts.map((r) => ({ ...r, pauseDuration: r.pauseDuration + o })) };
}
}, j = [], V = { toasts: [], pausedAt: void 0, settings: { toastLimit: ye } }, y = {}, J = (e, t = F) => {
y[t] = Q(y[t] || V, e), j.forEach(([a, s]) => {
a === t && s(y[t]);
});
}, X = (e) => Object.keys(y).forEach((t) => J(e, t)), be = (e) => Object.keys(y).find((t) => y[t].toasts.some((a) => a.id === e)), D = (e = F) => (t) => {
J(t, e);
}, ve = { blank: 4e3, error: 4e3, success: 2e3, loading: 1 / 0, custom: 4e3 }, xe = (e = {}, t = F) => {
let [a, s] = se(y[t] || V), i = U(y[t]);
I(() => (i.current !== y[t] && s(y[t]), j.push([t, s]), () => {
let r = j.findIndex(([n]) => n === t);
r > -1 && j.splice(r, 1);
}), [t]);
let o = a.toasts.map((r) => {
var n, l, d;
return { ...e, ...e[r.type], ...r, removeDelay: r.removeDelay || ((n = e[r.type]) == null ? void 0 : n.removeDelay) || (e == null ? void 0 : e.removeDelay), duration: r.duration || ((l = e[r.type]) == null ? void 0 : l.duration) || (e == null ? void 0 : e.duration) || ve[r.type], style: { ...e.style, ...(d = e[r.type]) == null ? void 0 : d.style, ...r.style } };
});
return { ...a, toasts: o };
}, we = (e, t = "blank", a) => ({ createdAt: Date.now(), visible: !0, dismissed: !1, type: t, ariaProps: { role: "status", "aria-live": "polite" }, message: e, pauseDuration: 0, ...a, id: (a == null ? void 0 : a.id) || he() }), $ = (e) => (t, a) => {
let s = we(t, e, a);
return D(s.toasterId || be(s.id))({ type: 2, toast: s }), s.id;
}, p = (e, t) => $("blank")(e, t);
p.error = $("error");
p.success = $("success");
p.loading = $("loading");
p.custom = $("custom");
p.dismiss = (e, t) => {
let a = { type: 3, toastId: e };
t ? D(t)(a) : X(a);
};
p.dismissAll = (e) => p.dismiss(void 0, e);
p.remove = (e, t) => {
let a = { type: 4, toastId: e };
t ? D(t)(a) : X(a);
};
p.removeAll = (e) => p.remove(void 0, e);
p.promise = (e, t, a) => {
let s = p.loading(t.loading, { ...a, ...a == null ? void 0 : a.loading });
return typeof e == "function" && (e = e()), e.then((i) => {
let o = t.success ? C(t.success, i) : void 0;
return o ? p.success(o, { id: s, ...a, ...a == null ? void 0 : a.success }) : p.dismiss(s), i;
}).catch((i) => {
let o = t.error ? C(t.error, i) : void 0;
o ? p.error(o, { id: s, ...a, ...a == null ? void 0 : a.error }) : p.dismiss(s);
}), e;
};
var ke = 1e3, _e = (e, t = "default") => {
let { toasts: a, pausedAt: s } = xe(e, t), i = U(/* @__PURE__ */ new Map()).current, o = _((c, u = ke) => {
if (i.has(c)) return;
let g = setTimeout(() => {
i.delete(c), r({ type: 4, toastId: c });
}, u);
i.set(c, g);
}, []);
I(() => {
if (s) return;
let c = Date.now(), u = a.map((g) => {
if (g.duration === 1 / 0) return;
let E = (g.duration || 0) + g.pauseDuration - (c - g.createdAt);
if (E < 0) {
g.visible && p.dismiss(g.id);
return;
}
return setTimeout(() => p.dismiss(g.id, t), E);
});
return () => {
u.forEach((g) => g && clearTimeout(g));
};
}, [a, s, t]);
let r = _(D(t), [t]), n = _(() => {
r({ type: 5, time: Date.now() });
}, [r]), l = _((c, u) => {
r({ type: 1, toast: { id: c, height: u } });
}, [r]), d = _(() => {
s && r({ type: 6, time: Date.now() });
}, [s, r]), m = _((c, u) => {
let { reverseOrder: g = !1, gutter: E = 8, defaultPosition: L } = u || {}, A = a.filter((h) => (h.position || L) === (c.position || L) && h.height), ae = A.findIndex((h) => h.id === c.id), M = A.filter((h, z) => z < ae && h.visible).length;
return A.filter((h) => h.visible).slice(...g ? [M + 1] : [0, M]).reduce((h, z) => h + (z.height || 0) + E, 0);
}, [a]);
return I(() => {
a.forEach((c) => {
if (c.dismissed) o(c.id, c.removeDelay);
else {
let u = i.get(c.id);
u && (clearTimeout(u), i.delete(c.id));
}
});
}, [a, o]), { toasts: a, handlers: { updateHeight: l, startPause: n, endPause: d, calculateOffset: m } };
}, $e = v`
from {
transform: scale(0) rotate(45deg);
opacity: 0;
}
to {
transform: scale(1) rotate(45deg);
opacity: 1;
}`, Ee = v`
from {
transform: scale(0);
opacity: 0;
}
to {
transform: scale(1);
opacity: 1;
}`, Ne = v`
from {
transform: scale(0) rotate(90deg);
opacity: 0;
}
to {
transform: scale(1) rotate(90deg);
opacity: 1;
}`, je = w("div")`
width: 20px;
opacity: 0;
height: 20px;
border-radius: 10px;
background: ${(e) => e.primary || "#ff4b4b"};
position: relative;
transform: rotate(45deg);
animation: ${$e} 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275)
forwards;
animation-delay: 100ms;
&:after,
&:before {
content: '';
animation: ${Ee} 0.15s ease-out forwards;
animation-delay: 150ms;
position: absolute;
border-radius: 3px;
opacity: 0;
background: ${(e) => e.secondary || "#fff"};
bottom: 9px;
left: 4px;
height: 2px;
width: 12px;
}
&:before {
animation: ${Ne} 0.15s ease-out forwards;
animation-delay: 180ms;
transform: rotate(90deg);
}
`, Ce = v`
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
`, Oe = w("div")`
width: 12px;
height: 12px;
box-sizing: border-box;
border: 2px solid;
border-radius: 100%;
border-color: ${(e) => e.secondary || "#e0e0e0"};
border-right-color: ${(e) => e.primary || "#616161"};
animation: ${Ce} 1s linear infinite;
`, De = v`
from {
transform: scale(0) rotate(45deg);
opacity: 0;
}
to {
transform: scale(1) rotate(45deg);
opacity: 1;
}`, Ae = v`
0% {
height: 0;
width: 0;
opacity: 0;
}
40% {
height: 0;
width: 6px;
opacity: 1;
}
100% {
opacity: 1;
height: 10px;
}`, ze = w("div")`
width: 20px;
opacity: 0;
height: 20px;
border-radius: 10px;
background: ${(e) => e.primary || "#61d345"};
position: relative;
transform: rotate(45deg);
animation: ${De} 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275)
forwards;
animation-delay: 100ms;
&:after {
content: '';
box-sizing: border-box;
animation: ${Ae} 0.2s ease-out forwards;
opacity: 0;
animation-delay: 200ms;
position: absolute;
border-right: 2px solid;
border-bottom: 2px solid;
border-color: ${(e) => e.secondary || "#fff"};
bottom: 6px;
left: 6px;
height: 10px;
width: 6px;
}
`, Ie = w("div")`
position: absolute;
`, Se = w("div")`
position: relative;
display: flex;
justify-content: center;
align-items: center;
min-width: 20px;
min-height: 20px;
`, Te = v`
from {
transform: scale(0.6);
opacity: 0.4;
}
to {
transform: scale(1);
opacity: 1;
}`, Pe = w("div")`
position: relative;
transform: scale(0.6);
opacity: 0.4;
min-width: 20px;
animation: ${Te} 0.3s 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275)
forwards;
`, Fe = ({ toast: e }) => {
let { icon: t, type: a, iconTheme: s } = e;
return t !== void 0 ? typeof t == "string" ? f.createElement(Pe, null, t) : t : a === "blank" ? null : f.createElement(Se, null, f.createElement(Oe, { ...s }), a !== "loading" && f.createElement(Ie, null, a === "error" ? f.createElement(je, { ...s }) : f.createElement(ze, { ...s })));
}, Re = (e) => `
0% {transform: translate3d(0,${e * -200}%,0) scale(.6); opacity:.5;}
100% {transform: translate3d(0,0,0) scale(1); opacity:1;}
`, Le = (e) => `
0% {transform: translate3d(0,0,-1px) scale(1); opacity:1;}
100% {transform: translate3d(0,${e * -150}%,-1px) scale(.6); opacity:0;}
`, Me = "0%{opacity:0;} 100%{opacity:1;}", He = "0%{opacity:1;} 100%{opacity:0;}", Be = w("div")`
display: flex;
align-items: center;
background: #fff;
color: #363636;
line-height: 1.3;
will-change: transform;
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1), 0 3px 3px rgba(0, 0, 0, 0.05);
max-width: 350px;
pointer-events: auto;
padding: 8px 10px;
border-radius: 8px;
`, Ge = w("div")`
display: flex;
justify-content: center;
margin: 4px 10px;
color: inherit;
flex: 1 1 auto;
white-space: pre-line;
`, Ue = (e, t) => {
let a = e.includes("top") ? 1 : -1, [s, i] = K() ? [Me, He] : [Re(a), Le(a)];
return { animation: t ? `${v(s)} 0.35s cubic-bezier(.21,1.02,.73,1) forwards` : `${v(i)} 0.4s forwards cubic-bezier(.06,.71,.55,1)` };
}, We = f.memo(({ toast: e, position: t, style: a, children: s }) => {
let i = e.height ? Ue(e.position || t || "top-center", e.visible) : { opacity: 0 }, o = f.createElement(Fe, { toast: e }), r = f.createElement(Ge, { ...e.ariaProps }, C(e.message, e));
return f.createElement(Be, { className: e.className, style: { ...i, ...a, ...e.style } }, typeof s == "function" ? s({ icon: o, message: r }) : f.createElement(f.Fragment, null, o, r));
});
fe(f.createElement);
var Ye = ({ id: e, className: t, style: a, onHeightUpdate: s, children: i }) => {
let o = f.useCallback((r) => {
if (r) {
let n = () => {
let l = r.getBoundingClientRect().height;
s(e, l);
};
n(), new MutationObserver(n).observe(r, { subtree: !0, childList: !0, characterData: !0 });
}
}, [e, s]);
return f.createElement("div", { ref: o, className: t, style: a }, i);
}, Ze = (e, t) => {
let a = e.includes("top"), s = a ? { top: 0 } : { bottom: 0 }, i = e.includes("center") ? { justifyContent: "center" } : e.includes("right") ? { justifyContent: "flex-end" } : {};
return { left: 0, right: 0, display: "flex", position: "absolute", transition: K() ? void 0 : "all 230ms cubic-bezier(.21,1.02,.73,1)", transform: `translateY(${t * (a ? 1 : -1)}px)`, ...s, ...i };
}, qe = O`
z-index: 9999;
> * {
pointer-events: auto;
}
`, N = 16, Ke = ({ reverseOrder: e, position: t = "top-center", toastOptions: a, gutter: s, children: i, toasterId: o, containerStyle: r, containerClassName: n }) => {
let { toasts: l, handlers: d } = _e(a, o);
return f.createElement("div", { "data-rht-toaster": o || "", style: { position: "fixed", zIndex: 9999, top: N, left: N, right: N, bottom: N, pointerEvents: "none", ...r }, className: n, onMouseEnter: d.startPause, onMouseLeave: d.endPause }, l.map((m) => {
let c = m.position || t, u = d.calculateOffset(m, { reverseOrder: e, gutter: s, defaultPosition: t }), g = Ze(c, u);
return f.createElement(Ye, { id: m.id, key: m.id, onHeightUpdate: d.updateHeight, className: m.visible ? qe : "", style: g }, m.type === "custom" ? C(m.message, m) : i ? i(m) : f.createElement(We, { toast: m, position: c }));
}));
};
const Qe = "_title_fnmmh_2", Ve = "_growl_fnmmh_12", Je = "_snackbar_fnmmh_27", Xe = "_info_fnmmh_48", et = "_success_fnmmh_51", tt = "_warning_fnmmh_54", at = "_danger_fnmmh_57", R = {
title: Qe,
growl: Ve,
snackbar: Je,
"snackbar-separator": "_snackbar-separator_fnmmh_43",
info: Xe,
success: et,
warning: tt,
danger: at
}, B = P(R), ee = W(
({ children: e, className: t, hasCloseButton: a = !0, onClose: s, variant: i, ...o }, r) => /* @__PURE__ */ k(
Y,
{
className: B("growl", t),
handleClose: a ? s : void 0,
ref: r,
variant: i,
...o,
children: /* @__PURE__ */ k("div", { className: B("pr-xl"), children: e })
}
)
);
ee.displayName = "Growl";
const G = P(R), te = W(
({ children: e, className: t, cta: a, hasCloseButton: s = !0, onClose: i, variant: o, ...r }, n) => /* @__PURE__ */ k(
Y,
{
className: G("snackbar", t),
cta: a ? /* @__PURE__ */ k(re, { children: /* @__PURE__ */ k("div", { className: G("snackbar-separator", `${o}`, "pr-xl"), children: a }) }) : null,
handleClose: s ? i : void 0,
ref: n,
variant: o,
...r,
children: e
}
)
), rt = ne((e, t) => /* @__PURE__ */ k(ie, { ref: t, size: "xs", variant: "ghost", ...e }));
te.displayName = "Snackbar";
const st = P(R), ot = ({ children: e, className: t, ...a }) => /* @__PURE__ */ k("p", { className: st("title", t), ...a, children: e }), pt = (e, t) => {
const s = ("type" in e ? e.type.displayName || e.type.name : void 0) === "Growl" ? "top-right" : "bottom-center", i = () => {
t.onClose && t.onClose(), p.dismiss(t.id);
}, o = {
duration: 7e3,
position: s,
style: {
backgroundColor: "transparent",
boxShadow: "none",
padding: 0
},
...t
};
return p(oe(e, { onClose: i }), o);
}, ut = Object.assign(Ke, {
Growl: ee,
Snackbar: te,
SnackbarAction: rt,
Title: ot
});
export {
ut as Toast,
pt as toast
};