@uoguelph/react-components 1.10.0-rc.3 → 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 +70 -78
- 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,74 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { TransitionGroup as
|
|
7
|
-
import { twJoin as
|
|
8
|
-
import { tv as
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
"use client";
|
|
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 }) });
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
i = i.filter((e) => e.id !== t), d();
|
|
16
|
-
}
|
|
17
|
-
function a(t, e = "info", s = 3e3) {
|
|
18
|
-
const n = S();
|
|
19
|
-
i = [
|
|
20
|
-
...i,
|
|
21
|
-
{
|
|
22
|
-
id: n,
|
|
23
|
-
message: t,
|
|
24
|
-
type: e,
|
|
25
|
-
timeout: s
|
|
26
|
-
}
|
|
27
|
-
], d(), window.setTimeout(() => {
|
|
28
|
-
p(n);
|
|
29
|
-
}, s);
|
|
30
|
-
}
|
|
31
|
-
function I(t) {
|
|
32
|
-
return f.add(t), () => {
|
|
33
|
-
f.delete(t);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function g() {
|
|
37
|
-
return i;
|
|
38
|
-
}
|
|
39
|
-
function z() {
|
|
40
|
-
return A(I, g, g);
|
|
41
|
-
}
|
|
42
|
-
const G = {
|
|
43
|
-
add: a,
|
|
44
|
-
remove: p,
|
|
45
|
-
info: (t, e) => a(t, "info", e),
|
|
46
|
-
success: (t, e) => a(t, "success", e),
|
|
47
|
-
warning: (t, e) => a(t, "warning", e),
|
|
48
|
-
error: (t, e) => a(t, "error", e)
|
|
49
|
-
};
|
|
50
|
-
function J({ toast: t, onRemove: e, ...s }) {
|
|
51
|
-
const n = F(null);
|
|
52
|
-
return /* @__PURE__ */ o(R, { ...s, nodeRef: n, timeout: 300, classNames: "uofg-toast-transition", children: /* @__PURE__ */ o(M, { toast: t, onRemove: e, nodeRef: n }) });
|
|
53
|
-
}
|
|
54
|
-
function M({
|
|
14
|
+
function k({
|
|
55
15
|
toast: t,
|
|
56
|
-
onRemove:
|
|
57
|
-
nodeRef:
|
|
16
|
+
onRemove: a,
|
|
17
|
+
nodeRef: o
|
|
58
18
|
}) {
|
|
59
|
-
const [n,
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
let
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
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));
|
|
66
26
|
};
|
|
67
|
-
return
|
|
68
|
-
cancelAnimationFrame(
|
|
27
|
+
return i = requestAnimationFrame(c), () => {
|
|
28
|
+
cancelAnimationFrame(i);
|
|
69
29
|
};
|
|
70
30
|
}, [t.timeout]);
|
|
71
|
-
const
|
|
31
|
+
const s = T({
|
|
72
32
|
slots: {
|
|
73
33
|
toast: "uofg-toast relative flex max-w-[50ch] gap-2 overflow-hidden p-6 text-left text-lg",
|
|
74
34
|
progress: "uofg-toast-progress absolute right-0 bottom-0 left-0 h-1 origin-left bg-current opacity-70",
|
|
@@ -92,17 +52,50 @@ function M({
|
|
|
92
52
|
}
|
|
93
53
|
}
|
|
94
54
|
})({ type: t.type });
|
|
95
|
-
return /* @__PURE__ */
|
|
96
|
-
t.type === "info" && /* @__PURE__ */
|
|
97
|
-
t.type === "success" && /* @__PURE__ */
|
|
98
|
-
t.type === "warning" && /* @__PURE__ */
|
|
99
|
-
t.type === "error" && /* @__PURE__ */
|
|
100
|
-
/* @__PURE__ */
|
|
101
|
-
/* @__PURE__ */
|
|
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" })
|
|
102
62
|
] });
|
|
103
63
|
}
|
|
104
|
-
|
|
105
|
-
|
|
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(
|
|
106
99
|
"uofg-toaster",
|
|
107
100
|
"fixed",
|
|
108
101
|
"right-4",
|
|
@@ -114,10 +107,9 @@ function Q() {
|
|
|
114
107
|
"items-end",
|
|
115
108
|
"gap-3"
|
|
116
109
|
);
|
|
117
|
-
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)) });
|
|
118
111
|
}
|
|
119
112
|
export {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
z as useToaster
|
|
113
|
+
M as Toaster,
|
|
114
|
+
F as toast
|
|
123
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>;
|