@uoguelph/react-components 1.10.0-rc.4 → 1.10.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/toaster/toaster-store.d.ts +18 -0
- package/dist/components/toaster/toaster.d.ts +2 -18
- package/dist/toaster-store.d.ts +2 -0
- package/dist/toaster-store.js +47 -0
- package/dist/toaster.js +72 -81
- package/package.json +1 -1
- package/dist/components/toaster/toaster-context.d.ts +0 -10
- package/dist/toaster-context.d.ts +0 -2
- package/dist/toaster-context.js +0 -5
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Toast = {
|
|
2
|
+
message: string;
|
|
3
|
+
type: 'error' | 'success' | 'info' | 'warning';
|
|
4
|
+
id: string;
|
|
5
|
+
timeout: number;
|
|
6
|
+
};
|
|
7
|
+
declare function removeToast(id: string): void;
|
|
8
|
+
declare function addToast(message: Toast['message'], type?: Toast['type'], timeout?: Toast['timeout']): void;
|
|
9
|
+
export declare function useToaster(): Toast[];
|
|
10
|
+
export declare const toast: {
|
|
11
|
+
add: typeof addToast;
|
|
12
|
+
remove: typeof removeToast;
|
|
13
|
+
info: (message: Toast["message"], timeout?: Toast["timeout"]) => void;
|
|
14
|
+
success: (message: Toast["message"], timeout?: Toast["timeout"]) => void;
|
|
15
|
+
warning: (message: Toast["message"], timeout?: Toast["timeout"]) => void;
|
|
16
|
+
error: (message: Toast["message"], timeout?: Toast["timeout"]) => void;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
message: string;
|
|
3
|
-
type: 'error' | 'success' | 'info' | 'warning';
|
|
4
|
-
id: string;
|
|
5
|
-
timeout: number;
|
|
6
|
-
};
|
|
7
|
-
declare function removeToast(id: string): void;
|
|
8
|
-
declare function addToast(message: Toast['message'], type?: Toast['type'], timeout?: Toast['timeout']): void;
|
|
9
|
-
export declare function useToaster(): Toast[];
|
|
10
|
-
export declare const toast: {
|
|
11
|
-
add: typeof addToast;
|
|
12
|
-
remove: typeof removeToast;
|
|
13
|
-
info: (message: Toast["message"], timeout?: Toast["timeout"]) => void;
|
|
14
|
-
success: (message: Toast["message"], timeout?: Toast["timeout"]) => void;
|
|
15
|
-
warning: (message: Toast["message"], timeout?: Toast["timeout"]) => void;
|
|
16
|
-
error: (message: Toast["message"], timeout?: Toast["timeout"]) => void;
|
|
17
|
-
};
|
|
1
|
+
import { toast } from './toaster-store';
|
|
18
2
|
export declare function Toaster(): import("react/jsx-runtime").JSX.Element;
|
|
19
|
-
export {};
|
|
3
|
+
export { toast };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { n as f } from "./index.browser-E4KzWirf.js";
|
|
2
|
+
import { useSyncExternalStore as d } from "react";
|
|
3
|
+
let e = [];
|
|
4
|
+
const r = /* @__PURE__ */ new Set();
|
|
5
|
+
function c() {
|
|
6
|
+
r.forEach((n) => n());
|
|
7
|
+
}
|
|
8
|
+
function u(n) {
|
|
9
|
+
e = e.filter((o) => o.id !== n), c();
|
|
10
|
+
}
|
|
11
|
+
function t(n, o = "info", s = 3e3) {
|
|
12
|
+
const i = f();
|
|
13
|
+
e = [
|
|
14
|
+
...e,
|
|
15
|
+
{
|
|
16
|
+
id: i,
|
|
17
|
+
message: n,
|
|
18
|
+
type: o,
|
|
19
|
+
timeout: s
|
|
20
|
+
}
|
|
21
|
+
], c(), window.setTimeout(() => {
|
|
22
|
+
u(i);
|
|
23
|
+
}, s);
|
|
24
|
+
}
|
|
25
|
+
function m(n) {
|
|
26
|
+
return r.add(n), () => {
|
|
27
|
+
r.delete(n);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function a() {
|
|
31
|
+
return e;
|
|
32
|
+
}
|
|
33
|
+
function l() {
|
|
34
|
+
return d(m, a, a);
|
|
35
|
+
}
|
|
36
|
+
const p = {
|
|
37
|
+
add: t,
|
|
38
|
+
remove: u,
|
|
39
|
+
info: (n, o) => t(n, "info", o),
|
|
40
|
+
success: (n, o) => t(n, "success", o),
|
|
41
|
+
warning: (n, o) => t(n, "warning", o),
|
|
42
|
+
error: (n, o) => t(n, "error", o)
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
p as toast,
|
|
46
|
+
l as useToaster
|
|
47
|
+
};
|
package/dist/toaster.js
CHANGED
|
@@ -1,75 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { e as
|
|
4
|
-
import { FontAwesomeIcon as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
f.forEach((e) => e());
|
|
2
|
+
import { jsx as e, jsxs as d } from "react/jsx-runtime";
|
|
3
|
+
import { e as y, d as h, o as x, g as w } from "./solid-CpJcQLq3.js";
|
|
4
|
+
import { FontAwesomeIcon as r } from "@fortawesome/react-fontawesome";
|
|
5
|
+
import { useEffect as l, useRef as S, useState as b } from "react";
|
|
6
|
+
import { TransitionGroup as C, CSSTransition as v } from "react-transition-group";
|
|
7
|
+
import { twJoin as N } from "tailwind-merge";
|
|
8
|
+
import { tv as T } from "tailwind-variants";
|
|
9
|
+
import { useToaster as A, toast as F } from "./toaster-store.js";
|
|
10
|
+
function X({ toast: t, onRemove: a, ...o }) {
|
|
11
|
+
const n = S(null);
|
|
12
|
+
return /* @__PURE__ */ e(v, { ...o, nodeRef: n, timeout: 300, classNames: "uofg-toast-transition", children: /* @__PURE__ */ e(k, { toast: t, onRemove: a, nodeRef: n }) });
|
|
14
13
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const n = S();
|
|
20
|
-
i = [
|
|
21
|
-
...i,
|
|
22
|
-
{
|
|
23
|
-
id: n,
|
|
24
|
-
message: e,
|
|
25
|
-
type: t,
|
|
26
|
-
timeout: s
|
|
27
|
-
}
|
|
28
|
-
], d(), window.setTimeout(() => {
|
|
29
|
-
p(n);
|
|
30
|
-
}, s);
|
|
31
|
-
}
|
|
32
|
-
function I(e) {
|
|
33
|
-
return f.add(e), () => {
|
|
34
|
-
f.delete(e);
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function g() {
|
|
38
|
-
return i;
|
|
39
|
-
}
|
|
40
|
-
function z() {
|
|
41
|
-
return A(I, g, g);
|
|
42
|
-
}
|
|
43
|
-
const G = {
|
|
44
|
-
add: a,
|
|
45
|
-
remove: p,
|
|
46
|
-
info: (e, t) => a(e, "info", t),
|
|
47
|
-
success: (e, t) => a(e, "success", t),
|
|
48
|
-
warning: (e, t) => a(e, "warning", t),
|
|
49
|
-
error: (e, t) => a(e, "error", t)
|
|
50
|
-
};
|
|
51
|
-
function J({ toast: e, onRemove: t, ...s }) {
|
|
52
|
-
const n = F(null);
|
|
53
|
-
return /* @__PURE__ */ o(R, { ...s, nodeRef: n, timeout: 300, classNames: "uofg-toast-transition", children: /* @__PURE__ */ o(M, { toast: e, onRemove: t, nodeRef: n }) });
|
|
54
|
-
}
|
|
55
|
-
function M({
|
|
56
|
-
toast: e,
|
|
57
|
-
onRemove: t,
|
|
58
|
-
nodeRef: s
|
|
14
|
+
function k({
|
|
15
|
+
toast: t,
|
|
16
|
+
onRemove: a,
|
|
17
|
+
nodeRef: o
|
|
59
18
|
}) {
|
|
60
|
-
const [n,
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
let
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
|
|
19
|
+
const [n, f] = b(100);
|
|
20
|
+
l(() => {
|
|
21
|
+
const p = performance.now();
|
|
22
|
+
let i;
|
|
23
|
+
const c = (u) => {
|
|
24
|
+
const g = u - p, m = Math.max(0, 100 - g / t.timeout * 100);
|
|
25
|
+
f(m), m > 0 && (i = requestAnimationFrame(c));
|
|
67
26
|
};
|
|
68
|
-
return
|
|
69
|
-
cancelAnimationFrame(
|
|
27
|
+
return i = requestAnimationFrame(c), () => {
|
|
28
|
+
cancelAnimationFrame(i);
|
|
70
29
|
};
|
|
71
|
-
}, [
|
|
72
|
-
const
|
|
30
|
+
}, [t.timeout]);
|
|
31
|
+
const s = T({
|
|
73
32
|
slots: {
|
|
74
33
|
toast: "uofg-toast relative flex max-w-[50ch] gap-2 overflow-hidden p-6 text-left text-lg",
|
|
75
34
|
progress: "uofg-toast-progress absolute right-0 bottom-0 left-0 h-1 origin-left bg-current opacity-70",
|
|
@@ -92,18 +51,51 @@ function M({
|
|
|
92
51
|
}
|
|
93
52
|
}
|
|
94
53
|
}
|
|
95
|
-
})({ type:
|
|
96
|
-
return /* @__PURE__ */
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/* @__PURE__ */
|
|
102
|
-
/* @__PURE__ */
|
|
54
|
+
})({ type: t.type });
|
|
55
|
+
return /* @__PURE__ */ d("button", { onClick: () => a(t.id), ref: o, className: s.toast(), children: [
|
|
56
|
+
t.type === "info" && /* @__PURE__ */ e(r, { className: s.icon(), icon: y }),
|
|
57
|
+
t.type === "success" && /* @__PURE__ */ e(r, { className: s.icon(), icon: h }),
|
|
58
|
+
t.type === "warning" && /* @__PURE__ */ e(r, { className: s.icon(), icon: x }),
|
|
59
|
+
t.type === "error" && /* @__PURE__ */ e(r, { className: s.icon(), icon: w }),
|
|
60
|
+
/* @__PURE__ */ e("span", { className: s.message(), children: t.message }),
|
|
61
|
+
/* @__PURE__ */ e("span", { className: s.progress(), style: { width: `${n}%` }, "aria-hidden": "true" })
|
|
103
62
|
] });
|
|
104
63
|
}
|
|
105
|
-
|
|
106
|
-
|
|
64
|
+
const P = `
|
|
65
|
+
.uofg-toast-transition-enter {
|
|
66
|
+
opacity: 0;
|
|
67
|
+
transform: translateX(100%);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.uofg-toast-transition-enter-active {
|
|
71
|
+
opacity: 1;
|
|
72
|
+
transform: translateX(0);
|
|
73
|
+
transition: opacity 300ms ease,
|
|
74
|
+
transform 300ms ease;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.uofg-toast-transition-exit {
|
|
78
|
+
opacity: 1;
|
|
79
|
+
transform: translateX(0);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.uofg-toast-transition-exit-active {
|
|
83
|
+
opacity: 0;
|
|
84
|
+
transform: translateX(100%);
|
|
85
|
+
transition: opacity 300ms ease,
|
|
86
|
+
transform 300ms ease;
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
function M() {
|
|
90
|
+
const t = A();
|
|
91
|
+
l(() => {
|
|
92
|
+
"CSSStyleSheet" in window || console.error(
|
|
93
|
+
"@uoguelph/react-components: Toaster animations will not work because Constructable Stylesheets is not supported in this browser"
|
|
94
|
+
);
|
|
95
|
+
const o = new CSSStyleSheet();
|
|
96
|
+
o.replaceSync(P), document.adoptedStyleSheets.push(o);
|
|
97
|
+
}, []);
|
|
98
|
+
const a = N(
|
|
107
99
|
"uofg-toaster",
|
|
108
100
|
"fixed",
|
|
109
101
|
"right-4",
|
|
@@ -115,10 +107,9 @@ function Q() {
|
|
|
115
107
|
"items-end",
|
|
116
108
|
"gap-3"
|
|
117
109
|
);
|
|
118
|
-
return /* @__PURE__ */
|
|
110
|
+
return /* @__PURE__ */ e(C, { component: "div", className: a, children: t.map((o) => /* @__PURE__ */ e(X, { toast: o, onRemove: F.remove }, o.id)) });
|
|
119
111
|
}
|
|
120
112
|
export {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
z as useToaster
|
|
113
|
+
M as Toaster,
|
|
114
|
+
F as toast
|
|
124
115
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type Toast = {
|
|
2
|
-
message: string;
|
|
3
|
-
type: 'error' | 'success' | 'info' | 'warning';
|
|
4
|
-
id: string;
|
|
5
|
-
timeout: number;
|
|
6
|
-
};
|
|
7
|
-
export type ToastContextValue = {
|
|
8
|
-
addToast: (message: Toast['message'], type?: Toast['type'], timeout?: number) => void;
|
|
9
|
-
};
|
|
10
|
-
export declare const ToastContext: import('react').Context<ToastContextValue | null>;
|