@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.
@@ -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
- 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
- };
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,2 @@
1
+ export * from './components/toaster/toaster-store'
2
+ export {}
@@ -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
- import { jsx as o, jsxs as y } from "react/jsx-runtime";
2
- import { e as T, d as v, o as N, g as C } from "./solid-CpJcQLq3.js";
3
- import { FontAwesomeIcon as c } from "@fortawesome/react-fontawesome";
4
- import { n as S } from "./index.browser-E4KzWirf.js";
5
- import { useSyncExternalStore as A, useRef as F, useState as E, useEffect as k } from "react";
6
- import { TransitionGroup as P, CSSTransition as R } from "react-transition-group";
7
- import { twJoin as j } from "tailwind-merge";
8
- import { tv as q } from "tailwind-variants";
9
- let i = [];
10
- const f = /* @__PURE__ */ new Set();
11
- function d() {
12
- f.forEach((t) => t());
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 p(t) {
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: e,
57
- nodeRef: s
16
+ onRemove: a,
17
+ nodeRef: o
58
18
  }) {
59
- const [n, x] = E(100);
60
- k(() => {
61
- const h = performance.now();
62
- let m;
63
- const l = (w) => {
64
- const b = w - h, u = Math.max(0, 100 - b / t.timeout * 100);
65
- x(u), u > 0 && (m = requestAnimationFrame(l));
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 m = requestAnimationFrame(l), () => {
68
- cancelAnimationFrame(m);
27
+ return i = requestAnimationFrame(c), () => {
28
+ cancelAnimationFrame(i);
69
29
  };
70
30
  }, [t.timeout]);
71
- const r = q({
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__ */ y("button", { onClick: () => e(t.id), ref: s, className: r.toast(), children: [
96
- t.type === "info" && /* @__PURE__ */ o(c, { className: r.icon(), icon: T }),
97
- t.type === "success" && /* @__PURE__ */ o(c, { className: r.icon(), icon: v }),
98
- t.type === "warning" && /* @__PURE__ */ o(c, { className: r.icon(), icon: N }),
99
- t.type === "error" && /* @__PURE__ */ o(c, { className: r.icon(), icon: C }),
100
- /* @__PURE__ */ o("span", { className: r.message(), children: t.message }),
101
- /* @__PURE__ */ o("span", { className: r.progress(), style: { width: `${n}%` }, "aria-hidden": "true" })
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
- function Q() {
105
- const t = z(), e = j(
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__ */ o(P, { component: "div", className: e, children: t.map((s) => /* @__PURE__ */ o(J, { toast: s, onRemove: G.remove }, s.id)) });
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
- Q as Toaster,
121
- G as toast,
122
- z as useToaster
113
+ M as Toaster,
114
+ F as toast
123
115
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uoguelph/react-components",
3
- "version": "1.10.0-rc.3",
3
+ "version": "1.10.0-rc.5",
4
4
  "description": "University of Guelph React Components Library",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -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>;
@@ -1,2 +0,0 @@
1
- export * from './components/toaster/toaster-context'
2
- export {}
@@ -1,5 +0,0 @@
1
- import { createContext as t } from "react";
2
- const e = t(null);
3
- export {
4
- e as ToastContext
5
- };