@uoguelph/react-components 1.10.0-rc.2 → 1.10.0-rc.4

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.
@@ -1,5 +1,19 @@
1
- import { ReactNode } from 'react';
2
- export declare const useToaster: () => import('./toaster-context').ToastContextValue;
3
- export declare function ToasterProvider({ children }: {
4
- children: ReactNode;
5
- }): import("react/jsx-runtime").JSX.Element;
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 declare function Toaster(): import("react/jsx-runtime").JSX.Element;
19
+ export {};
@@ -0,0 +1,9 @@
1
+ let n = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", r = (t = 21) => {
2
+ let e = "", l = crypto.getRandomValues(new Uint8Array(t |= 0));
3
+ for (; t--; )
4
+ e += n[l[t] & 63];
5
+ return e;
6
+ };
7
+ export {
8
+ r as n
9
+ };
@@ -1,14 +1,15 @@
1
1
  "use client";
2
- import { jsxs as l, jsx as t } from "react/jsx-runtime";
3
- import { h as x } from "./solid-CpJcQLq3.js";
2
+ import { jsxs as n, jsx as t } from "react/jsx-runtime";
3
+ import { h as v } from "./solid-CpJcQLq3.js";
4
4
  import { FontAwesomeIcon as f } from "@fortawesome/react-fontawesome";
5
- import { useState as N, useEffect as V } from "react";
6
- import { twMerge as q } from "tailwind-merge";
7
- import { tv as B } from "tailwind-variants";
8
- import { c as w } from "./math-utils-CnAd98v6.js";
9
- import { Button as F } from "./button.js";
10
- import { NumberInput as G } from "./number-input.js";
11
- var U = {
5
+ import { n as q } from "./index.browser-E4KzWirf.js";
6
+ import { useState as x, useEffect as B } from "react";
7
+ import { twMerge as F } from "tailwind-merge";
8
+ import { tv as G } from "tailwind-variants";
9
+ import { c as N } from "./math-utils-CnAd98v6.js";
10
+ import { Button as V } from "./button.js";
11
+ import { NumberInput as _ } from "./number-input.js";
12
+ var D = {
12
13
  prefix: "fad",
13
14
  iconName: "chevrons-right",
14
15
  icon: [
@@ -18,7 +19,7 @@ var U = {
18
19
  "f324",
19
20
  ["M32 448c0 8.2 3.1 16.4 9.4 22.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3l-192-192C80.4 35.1 72.2 32 64 32s-16.4 3.1-22.6 9.4c-12.5 12.5-12.5 32.8 0 45.3L210.7 256 41.4 425.4C35.1 431.6 32 439.8 32 448z", "M470.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L402.7 256 233.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z"]
20
21
  ]
21
- }, _ = {
22
+ }, H = {
22
23
  prefix: "fad",
23
24
  iconName: "chevrons-left",
24
25
  icon: [
@@ -29,53 +30,47 @@ var U = {
29
30
  ["M224 256c0 8.2 3.1 16.4 9.4 22.6l192 192c6.2 6.2 14.4 9.4 22.6 9.4s16.4-3.1 22.6-9.4c12.5-12.5 12.5-32.8 0-45.3L301.3 256 470.6 86.6c12.5-12.5 12.5-32.8 0-45.3C464.4 35.1 456.2 32 448 32s-16.4 3.1-22.6 9.4l-192 192c-6.2 6.2-9.4 14.4-9.4 22.6z", "M41.4 278.6c-12.5-12.5-12.5-32.8 0-45.3l192-192c12.5-12.5 32.8-12.5 45.3 0s12.5 32.8 0 45.3L109.3 256 278.6 425.4c12.5 12.5 12.5 32.8 0 45.3s-32.8 12.5-45.3 0l-192-192z"]
30
31
  ]
31
32
  };
32
- let D = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", H = (i = 21) => {
33
- let e = "", m = crypto.getRandomValues(new Uint8Array(i |= 0));
34
- for (; i--; )
35
- e += D[m[i] & 63];
36
- return e;
37
- };
38
- function re({
39
- page: i,
33
+ function se({
34
+ page: d,
40
35
  count: e,
41
- visible: m,
42
- defaultPage: b,
36
+ visible: w,
37
+ defaultPage: h,
43
38
  onChange: P,
44
- color: d = "yellow",
39
+ color: m = "yellow",
45
40
  hideInput: C = !1,
46
41
  hideList: k = !1,
47
42
  className: $
48
43
  }) {
49
- const [r, I] = N(b ?? 0), [L, M] = N(b ?? 0), j = [...Array(e).keys()], o = Math.max(Math.ceil(m), 3), y = H();
50
- V(() => {
51
- c(i ?? 0);
52
- }, [i]);
53
- const c = (s) => {
54
- const u = w(s, 0, e - 1);
55
- P?.(u), I(u);
56
- }, h = (s) => {
57
- const u = r === s;
58
- return /* @__PURE__ */ l(
44
+ const [s, I] = x(h ?? 0), [L, M] = x(h ?? 0), j = [...Array(e).keys()], o = Math.max(Math.ceil(w), 3), b = q();
45
+ B(() => {
46
+ l(d ?? 0);
47
+ }, [d]);
48
+ const l = (r) => {
49
+ const g = N(r, 0, e - 1);
50
+ P?.(g), I(g);
51
+ }, u = (r) => {
52
+ const g = s === r;
53
+ return /* @__PURE__ */ n(
59
54
  "button",
60
55
  {
61
- className: `uofg-pagination-item ${W({ active: u })}`,
56
+ className: `uofg-pagination-item ${W({ active: g })}`,
62
57
  onClick: () => {
63
- c(s);
58
+ l(r);
64
59
  },
65
60
  children: [
66
61
  /* @__PURE__ */ t("span", { className: "sr-only", children: "Page" }),
67
62
  " ",
68
- s + 1,
63
+ r + 1,
69
64
  " ",
70
- u ? /* @__PURE__ */ t("span", { className: "sr-only", children: "(Current Page)" }) : ""
65
+ g ? /* @__PURE__ */ t("span", { className: "sr-only", children: "(Current Page)" }) : ""
71
66
  ]
72
67
  },
73
- s
68
+ r
74
69
  );
75
70
  };
76
- let a, n, p, g;
77
- e <= o || e < 5 ? (a = 1, n = e - 1, p = !1, g = !1) : r < o - 1 ? (a = 1, n = o, g = !0, p = !1) : r > e - o ? (a = e - o, n = e - 1, p = !0, g = !1) : (a = r - Math.floor(o / 2), n = a + o, p = a > 1, g = n < e);
78
- const { base: A, list: E, seperator: R, control: v, item: W, inputWrapper: z, goTo: S, input: T } = B({
71
+ let i, a, c, p;
72
+ e <= o || e < 5 ? (i = 1, a = e - 1, c = !1, p = !1) : s < o - 1 ? (i = 1, a = o, p = !0, c = !1) : s > e - o ? (i = e - o, a = e - 1, c = !0, p = !1) : (i = s - Math.floor(o / 2), a = i + o, c = i > 1, p = a < e);
73
+ const { base: z, list: E, seperator: A, control: y, item: W, inputWrapper: R, goTo: S, input: T } = G({
79
74
  slots: {
80
75
  base: "flex w-full flex-col items-center justify-center gap-4 md:flex-row",
81
76
  list: "flex items-center justify-center gap-4",
@@ -148,67 +143,67 @@ function re({
148
143
  }
149
144
  ]
150
145
  })({
151
- color: d ?? "yellow",
146
+ color: m ?? "yellow",
152
147
  hideList: k ?? !1,
153
148
  hideInput: C ?? !1
154
149
  });
155
- return /* @__PURE__ */ l("div", { className: `uofg-pagination ${q(A(), $)}`, children: [
156
- /* @__PURE__ */ t("a", { href: `#uofg-pagination-skip-${y}`, className: "sr-only! focus-visible:not-sr-only!", children: "Skip Pagination" }),
157
- /* @__PURE__ */ l("div", { className: `uofg-pagination-list ${E()}`, children: [
158
- /* @__PURE__ */ l(
150
+ return /* @__PURE__ */ n("div", { className: `uofg-pagination ${F(z(), $)}`, children: [
151
+ /* @__PURE__ */ t("a", { href: `#uofg-pagination-skip-${b}`, className: "sr-only! focus-visible:not-sr-only!", children: "Skip Pagination" }),
152
+ /* @__PURE__ */ n("div", { className: `uofg-pagination-list ${E()}`, children: [
153
+ /* @__PURE__ */ n(
159
154
  "button",
160
155
  {
161
- disabled: r <= 0,
162
- className: `uofg-pagination-previous ${v()}`,
163
- onClick: () => c(r - 1),
156
+ disabled: s <= 0,
157
+ className: `uofg-pagination-previous ${y()}`,
158
+ onClick: () => l(s - 1),
164
159
  children: [
165
- /* @__PURE__ */ t(f, { icon: _ }),
160
+ /* @__PURE__ */ t(f, { icon: H }),
166
161
  /* @__PURE__ */ t("span", { className: "sr-only", children: "Previous Page" })
167
162
  ]
168
163
  }
169
164
  ),
170
- h(0),
171
- p && /* @__PURE__ */ t(f, { icon: x }),
172
- j.slice(a, n).map(h),
173
- g && /* @__PURE__ */ t(f, { icon: x }),
174
- h(e - 1),
175
- /* @__PURE__ */ l(
165
+ u(0),
166
+ c && /* @__PURE__ */ t(f, { icon: v }),
167
+ j.slice(i, a).map(u),
168
+ p && /* @__PURE__ */ t(f, { icon: v }),
169
+ u(e - 1),
170
+ /* @__PURE__ */ n(
176
171
  "button",
177
172
  {
178
- disabled: r >= e - 1,
179
- className: `uofg-pagination-next ${v()}`,
180
- onClick: () => c(r + 1),
173
+ disabled: s >= e - 1,
174
+ className: `uofg-pagination-next ${y()}`,
175
+ onClick: () => l(s + 1),
181
176
  children: [
182
- /* @__PURE__ */ t(f, { icon: U }),
177
+ /* @__PURE__ */ t(f, { icon: D }),
183
178
  /* @__PURE__ */ t("span", { className: "sr-only", children: "Next Page" })
184
179
  ]
185
180
  }
186
181
  )
187
182
  ] }),
188
- /* @__PURE__ */ t("span", { className: `uofg-pagination-seperator ${R()}` }),
189
- /* @__PURE__ */ l("div", { className: `uofg-pagination-go-to-wrapper ${z()}`, children: [
183
+ /* @__PURE__ */ t("span", { className: `uofg-pagination-seperator ${A()}` }),
184
+ /* @__PURE__ */ n("div", { className: `uofg-pagination-go-to-wrapper ${R()}`, children: [
190
185
  /* @__PURE__ */ t(
191
- G,
186
+ _,
192
187
  {
193
- color: d,
188
+ color: m,
194
189
  min: 1,
195
190
  max: e,
196
- value: r + 1,
197
- onInput: (s) => {
198
- M(isNaN(s) ? 0 : w(s - 1, 0, e - 1));
191
+ value: s + 1,
192
+ onInput: (r) => {
193
+ M(isNaN(r) ? 0 : N(r - 1, 0, e - 1));
199
194
  },
200
195
  className: `uofg-pagination-go-to-input ${T()}`,
201
196
  children: /* @__PURE__ */ t("span", { className: "sr-only", children: "Input Page Number" })
202
197
  }
203
198
  ),
204
199
  /* @__PURE__ */ t(
205
- F,
200
+ V,
206
201
  {
207
- id: `uofg-pagination-skip-${y}`,
208
- color: d,
202
+ id: `uofg-pagination-skip-${b}`,
203
+ color: m,
209
204
  className: `uofg-pagination-go-to-button ${S()}`,
210
205
  onClick: () => {
211
- c(L);
206
+ l(L);
212
207
  },
213
208
  children: "Go to page"
214
209
  }
@@ -217,5 +212,5 @@ function re({
217
212
  ] });
218
213
  }
219
214
  export {
220
- re as Pagination
215
+ se as Pagination
221
216
  };
package/dist/toaster.js CHANGED
@@ -1,40 +1,75 @@
1
1
  "use client";
2
- import { jsxs as p, jsx as t } from "react/jsx-runtime";
3
- import { e as w, d as T, o as b, g as v } from "./solid-CpJcQLq3.js";
4
- import { FontAwesomeIcon as m } from "@fortawesome/react-fontawesome";
5
- import { useState as x, useCallback as d, useContext as y, useRef as C, useEffect as N } from "react";
6
- import { TransitionGroup as A, CSSTransition as P } from "react-transition-group";
7
- import { twJoin as F } from "tailwind-merge";
8
- import { tv as k } from "tailwind-variants";
9
- import { ToastContext as h } from "./toaster-context.js";
10
- const M = () => {
11
- const e = y(h);
12
- if (!e)
13
- throw new Error("useToast must be used within a ToasterProvider component");
14
- return e;
2
+ import { jsx as o, jsxs as y } from "react/jsx-runtime";
3
+ import { e as T, d as v, o as N, g as C } from "./solid-CpJcQLq3.js";
4
+ import { FontAwesomeIcon as c } from "@fortawesome/react-fontawesome";
5
+ import { n as S } from "./index.browser-E4KzWirf.js";
6
+ import { useSyncExternalStore as A, useRef as F, useState as E, useEffect as k } from "react";
7
+ import { TransitionGroup as P, CSSTransition as R } from "react-transition-group";
8
+ import { twJoin as j } from "tailwind-merge";
9
+ import { tv as q } from "tailwind-variants";
10
+ let i = [];
11
+ const f = /* @__PURE__ */ new Set();
12
+ function d() {
13
+ f.forEach((e) => e());
14
+ }
15
+ function p(e) {
16
+ i = i.filter((t) => t.id !== e), d();
17
+ }
18
+ function a(e, t = "info", s = 3e3) {
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)
15
50
  };
16
- function S({ toast: e, onRemove: c, ...i }) {
17
- const r = C(null);
18
- return /* @__PURE__ */ t(P, { ...i, nodeRef: r, timeout: 300, classNames: "uofg-toast-transition", children: /* @__PURE__ */ t(E, { toast: e, onRemove: c, nodeRef: r }) });
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 }) });
19
54
  }
20
- function E({
55
+ function M({
21
56
  toast: e,
22
- onRemove: c,
23
- nodeRef: i
57
+ onRemove: t,
58
+ nodeRef: s
24
59
  }) {
25
- const [r, f] = x(100);
26
- N(() => {
27
- const s = performance.now();
28
- let n;
29
- const a = (l) => {
30
- const u = l - s, g = Math.max(0, 100 - u / e.timeout * 100);
31
- f(g), g > 0 && (n = requestAnimationFrame(a));
60
+ const [n, x] = E(100);
61
+ k(() => {
62
+ const h = performance.now();
63
+ let m;
64
+ const l = (w) => {
65
+ const b = w - h, u = Math.max(0, 100 - b / e.timeout * 100);
66
+ x(u), u > 0 && (m = requestAnimationFrame(l));
32
67
  };
33
- return n = requestAnimationFrame(a), () => {
34
- cancelAnimationFrame(n);
68
+ return m = requestAnimationFrame(l), () => {
69
+ cancelAnimationFrame(m);
35
70
  };
36
71
  }, [e.timeout]);
37
- const o = k({
72
+ const r = q({
38
73
  slots: {
39
74
  toast: "uofg-toast relative flex max-w-[50ch] gap-2 overflow-hidden p-6 text-left text-lg",
40
75
  progress: "uofg-toast-progress absolute right-0 bottom-0 left-0 h-1 origin-left bg-current opacity-70",
@@ -58,35 +93,17 @@ function E({
58
93
  }
59
94
  }
60
95
  })({ type: e.type });
61
- return /* @__PURE__ */ p("button", { onClick: () => c(e.id), ref: i, className: o.toast(), children: [
62
- e.type === "info" && /* @__PURE__ */ t(m, { className: o.icon(), icon: w }),
63
- e.type === "success" && /* @__PURE__ */ t(m, { className: o.icon(), icon: T }),
64
- e.type === "warning" && /* @__PURE__ */ t(m, { className: o.icon(), icon: b }),
65
- e.type === "error" && /* @__PURE__ */ t(m, { className: o.icon(), icon: v }),
66
- /* @__PURE__ */ t("span", { className: o.message(), children: e.message }),
67
- /* @__PURE__ */ t("span", { className: o.progress(), style: { width: `${r}%` }, "aria-hidden": "true" })
96
+ return /* @__PURE__ */ y("button", { onClick: () => t(e.id), ref: s, className: r.toast(), children: [
97
+ e.type === "info" && /* @__PURE__ */ o(c, { className: r.icon(), icon: T }),
98
+ e.type === "success" && /* @__PURE__ */ o(c, { className: r.icon(), icon: v }),
99
+ e.type === "warning" && /* @__PURE__ */ o(c, { className: r.icon(), icon: N }),
100
+ e.type === "error" && /* @__PURE__ */ o(c, { className: r.icon(), icon: C }),
101
+ /* @__PURE__ */ o("span", { className: r.message(), children: e.message }),
102
+ /* @__PURE__ */ o("span", { className: r.progress(), style: { width: `${n}%` }, "aria-hidden": "true" })
68
103
  ] });
69
104
  }
70
- function X({ children: e }) {
71
- const [c, i] = x([]), r = d((s) => {
72
- i((n) => n.filter((a) => a.id !== s));
73
- }, []), f = d(
74
- (s, n = "info", a = 3e3) => {
75
- const l = Date.now().toString();
76
- console.log("Adding toast:", l, s, n, a), i((u) => [
77
- ...u,
78
- {
79
- id: l,
80
- message: s,
81
- type: n,
82
- timeout: a
83
- }
84
- ]), setTimeout(() => {
85
- r(l);
86
- }, a);
87
- },
88
- [r]
89
- ), o = F(
105
+ function Q() {
106
+ const e = z(), t = j(
90
107
  "uofg-toaster",
91
108
  "fixed",
92
109
  "right-4",
@@ -98,12 +115,10 @@ function X({ children: e }) {
98
115
  "items-end",
99
116
  "gap-3"
100
117
  );
101
- return /* @__PURE__ */ p(h.Provider, { value: { addToast: f }, children: [
102
- e,
103
- /* @__PURE__ */ t(A, { component: "div", className: o, children: c.map((s) => /* @__PURE__ */ t(S, { toast: s, onRemove: r }, s.id)) })
104
- ] });
118
+ return /* @__PURE__ */ o(P, { component: "div", className: t, children: e.map((s) => /* @__PURE__ */ o(J, { toast: s, onRemove: G.remove }, s.id)) });
105
119
  }
106
120
  export {
107
- X as ToasterProvider,
108
- M as useToaster
121
+ Q as Toaster,
122
+ G as toast,
123
+ z as useToaster
109
124
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uoguelph/react-components",
3
- "version": "1.10.0-rc.2",
3
+ "version": "1.10.0-rc.4",
4
4
  "description": "University of Guelph React Components Library",
5
5
  "type": "module",
6
6
  "scripts": {