@argon8/react 0.0.0-stage → 0.2.0
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/CHANGELOG.md +12 -0
- package/LICENSE +202 -0
- package/README.md +15 -2
- package/dist/alert.d.ts +51 -0
- package/dist/alert.js +29 -0
- package/dist/button.d.ts +20 -0
- package/dist/button.js +47 -0
- package/dist/choice.d.ts +53 -0
- package/dist/choice.js +31 -0
- package/dist/cn.d.ts +2 -0
- package/dist/cn.js +14 -0
- package/dist/code.d.ts +22 -0
- package/dist/code.js +40 -0
- package/dist/containers.d.ts +39 -0
- package/dist/containers.js +36 -0
- package/dist/dialog.d.ts +28 -0
- package/dist/dialog.js +62 -0
- package/dist/field.d.ts +26 -0
- package/dist/field.js +25 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +20 -0
- package/dist/menu.d.ts +18 -0
- package/dist/menu.js +117 -0
- package/dist/navigation.d.ts +35 -0
- package/dist/navigation.js +39 -0
- package/dist/page.d.ts +38 -0
- package/dist/page.js +80 -0
- package/dist/sheet.d.ts +20 -0
- package/dist/sheet.js +96 -0
- package/dist/sidebar.d.ts +56 -0
- package/dist/sidebar.js +112 -0
- package/dist/slot.d.ts +4 -0
- package/dist/slot.js +25 -0
- package/dist/status.d.ts +40 -0
- package/dist/status.js +48 -0
- package/dist/strict.css +2 -0
- package/dist/styles.css +30 -0
- package/dist/table.d.ts +26 -0
- package/dist/table.js +36 -0
- package/dist/tabs.d.ts +16 -0
- package/dist/tabs.js +26 -0
- package/dist/term.d.ts +9 -0
- package/dist/term.js +26 -0
- package/dist/time.d.ts +32 -0
- package/dist/time.js +76 -0
- package/dist/toast.d.ts +19 -0
- package/dist/toast.js +55 -0
- package/package.json +56 -3
package/dist/time.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// docs/components.md 3.4 (DateTime). Times: in the reader's own time zone, with UTC on hover. The server renders UTC (it does not
|
|
3
|
+
// know the reader's zone); the browser switches to local time once the page is running.
|
|
4
|
+
// Days in the data (watermarks, periods) are calendar days: "Nov 9", the year only when it is not
|
|
5
|
+
// this year, ISO and UTC on hover. Figures are tabular so dates line up in columns.
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
import { cn } from "./cn.js";
|
|
8
|
+
const utc = (d) => `${d.toISOString().slice(0, 16).replace("T", " ")} UTC`;
|
|
9
|
+
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
10
|
+
const thisYear = () => new Date().getUTCFullYear();
|
|
11
|
+
function local(d, withDate) {
|
|
12
|
+
const year = d.getFullYear() !== new Date().getFullYear() ? "numeric" : undefined;
|
|
13
|
+
return d.toLocaleString(undefined, withDate ? { year, month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" } : { hour: "2-digit", minute: "2-digit" });
|
|
14
|
+
}
|
|
15
|
+
/** "3 min ago", "in 2 hours". */
|
|
16
|
+
export function relativeText(d, now) {
|
|
17
|
+
const s = Math.round((d.getTime() - now) / 1000);
|
|
18
|
+
const a = Math.abs(s);
|
|
19
|
+
const plural = (n, one) => `${n} ${one}${n === 1 ? "" : "s"}`;
|
|
20
|
+
const text = a < 90 ? `${a} s` : a < 5400 ? `${Math.round(a / 60)} min` : a < 129600 ? plural(Math.round(a / 3600), "hour") : plural(Math.round(a / 86400), "day");
|
|
21
|
+
return s >= 0 ? `in ${text}` : `${text} ago`;
|
|
22
|
+
}
|
|
23
|
+
function useMounted() {
|
|
24
|
+
const [m, setM] = useState(false);
|
|
25
|
+
useEffect(() => setM(true), []);
|
|
26
|
+
return m;
|
|
27
|
+
}
|
|
28
|
+
/** An instant: local date and time (no year when it is this year), UTC in the tooltip. `relative` adds "· 3 min ago". */
|
|
29
|
+
export function When({ at, relative: rel = false, fallback = "never", timeOnly = false }) {
|
|
30
|
+
const mounted = useMounted();
|
|
31
|
+
if (!at)
|
|
32
|
+
return _jsx("span", { className: "text-ink-subtle", children: fallback });
|
|
33
|
+
const d = new Date(at);
|
|
34
|
+
if (Number.isNaN(d.getTime()))
|
|
35
|
+
return _jsx("span", { children: String(at) });
|
|
36
|
+
const text = mounted ? (timeOnly ? d.toLocaleTimeString(undefined, { hour: "2-digit", minute: "2-digit", second: "2-digit" }) : local(d, true)) : timeOnly ? d.toISOString().slice(11, 19) : utc(d);
|
|
37
|
+
return (_jsxs("time", { dateTime: d.toISOString(), title: utc(d), className: "whitespace-nowrap tabular-nums", children: [text, rel && mounted ? _jsxs("span", { className: "text-ink-muted", children: [" \u00B7 ", relativeText(d, Date.now())] }) : null] }));
|
|
38
|
+
}
|
|
39
|
+
/** A calendar day as people say it: "Nov 9" ("Nov 9, 2025" in another year). The same on the server and in the browser. */
|
|
40
|
+
export function dayText(at) {
|
|
41
|
+
const d = new Date(at);
|
|
42
|
+
return `${MONTHS[d.getUTCMonth()]} ${d.getUTCDate()}${d.getUTCFullYear() !== thisYear() ? `, ${d.getUTCFullYear()}` : ""}`;
|
|
43
|
+
}
|
|
44
|
+
/** A date that is a calendar day in the data (a watermark): the day, ISO and UTC in the tooltip. */
|
|
45
|
+
export function Day({ at, fallback = "-", className }) {
|
|
46
|
+
if (!at)
|
|
47
|
+
return _jsx("span", { className: "text-ink-subtle", children: fallback });
|
|
48
|
+
const d = new Date(at);
|
|
49
|
+
return _jsx("time", { dateTime: d.toISOString(), title: `${d.toISOString().slice(0, 10)} (${utc(d)})`, className: cn("whitespace-nowrap tabular-nums", className), children: dayText(d) });
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A period: "Oct 26 – Nov 9". Periods end at midnight of the day after their last day, so the end
|
|
53
|
+
* shown is the last day the period covers.
|
|
54
|
+
*/
|
|
55
|
+
export function DayRange({ start, end }) {
|
|
56
|
+
if (!start || !end)
|
|
57
|
+
return _jsx("span", { className: "text-ink-subtle", children: "-" });
|
|
58
|
+
const last = lastDay(end);
|
|
59
|
+
return _jsxs("span", { className: "whitespace-nowrap tabular-nums", children: [_jsx(Day, { at: start }), last.getTime() > new Date(start).getTime() ? _jsxs(_Fragment, { children: [" \u2013 ", _jsx(Day, { at: last })] }) : null] });
|
|
60
|
+
}
|
|
61
|
+
export function dayRangeText(start, end) {
|
|
62
|
+
const last = lastDay(end);
|
|
63
|
+
return last.getTime() > new Date(start).getTime() ? `${dayText(start)} to ${dayText(last)}` : dayText(start);
|
|
64
|
+
}
|
|
65
|
+
/** The last day an exclusive end covers: an end at midnight belongs to the day before. */
|
|
66
|
+
function lastDay(end) {
|
|
67
|
+
const e = new Date(end);
|
|
68
|
+
return e.getUTCHours() === 0 && e.getUTCMinutes() === 0 && e.getUTCSeconds() === 0 ? new Date(e.getTime() - 86_400_000) : e;
|
|
69
|
+
}
|
|
70
|
+
export function Ago({ seconds }) {
|
|
71
|
+
if (seconds === null)
|
|
72
|
+
return _jsx("span", { children: "never" });
|
|
73
|
+
const a = Math.round(seconds);
|
|
74
|
+
return _jsxs("span", { className: "tabular-nums", children: [a < 90 ? `${a} s` : a < 5400 ? `${Math.round(a / 60)} min` : a < 129600 ? `${Math.round(a / 3600)} h` : `${Math.round(a / 86400)} days`, " ago"] });
|
|
75
|
+
}
|
|
76
|
+
export { local as formatLocal };
|
package/dist/toast.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type ToastItem = {
|
|
2
|
+
id: number;
|
|
3
|
+
message: string;
|
|
4
|
+
};
|
|
5
|
+
/** Show a success message. Replaces the one showing. Returns its id. */
|
|
6
|
+
export declare function toast(message: string): number;
|
|
7
|
+
export declare namespace toast {
|
|
8
|
+
export var dismiss: (id?: number) => void;
|
|
9
|
+
var _a: () => ToastItem | null;
|
|
10
|
+
export { _a as current };
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Where toasts appear. The live region is always in the page (a region added at the same time as
|
|
14
|
+
* its text is not announced), and is polite: a toast never interrupts.
|
|
15
|
+
*/
|
|
16
|
+
export declare function Toaster({ duration, className }: {
|
|
17
|
+
duration?: number;
|
|
18
|
+
className?: string;
|
|
19
|
+
}): import("react").JSX.Element;
|
package/dist/toast.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
+
import { cn } from "./cn.js";
|
|
4
|
+
import { ToneIcon } from "./status.js";
|
|
5
|
+
let current = null;
|
|
6
|
+
let nextId = 1;
|
|
7
|
+
const listeners = new Set();
|
|
8
|
+
const emit = () => {
|
|
9
|
+
for (const l of listeners)
|
|
10
|
+
l();
|
|
11
|
+
};
|
|
12
|
+
/** Show a success message. Replaces the one showing. Returns its id. */
|
|
13
|
+
export function toast(message) {
|
|
14
|
+
current = { id: nextId++, message };
|
|
15
|
+
emit();
|
|
16
|
+
return current.id;
|
|
17
|
+
}
|
|
18
|
+
/** Remove the toast showing (or only the one with this id). */
|
|
19
|
+
toast.dismiss = (id) => {
|
|
20
|
+
if (!current || (id !== undefined && current.id !== id))
|
|
21
|
+
return;
|
|
22
|
+
current = null;
|
|
23
|
+
emit();
|
|
24
|
+
};
|
|
25
|
+
/** The toast showing, for tests and for apps that render their own region. */
|
|
26
|
+
toast.current = () => current;
|
|
27
|
+
const subscribe = (l) => {
|
|
28
|
+
listeners.add(l);
|
|
29
|
+
return () => listeners.delete(l);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Where toasts appear. The live region is always in the page (a region added at the same time as
|
|
33
|
+
* its text is not announced), and is polite: a toast never interrupts.
|
|
34
|
+
*/
|
|
35
|
+
export function Toaster({ duration = 6000, className }) {
|
|
36
|
+
const item = useSyncExternalStore(subscribe, () => current, () => null);
|
|
37
|
+
const [paused, setPaused] = useState(false);
|
|
38
|
+
const left = useRef(duration);
|
|
39
|
+
const started = useRef(0);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
left.current = Math.max(duration, 6000);
|
|
42
|
+
setPaused(false);
|
|
43
|
+
}, [item?.id, duration]);
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!item || paused)
|
|
46
|
+
return;
|
|
47
|
+
started.current = Date.now();
|
|
48
|
+
const t = setTimeout(() => toast.dismiss(item.id), left.current);
|
|
49
|
+
return () => {
|
|
50
|
+
clearTimeout(t);
|
|
51
|
+
left.current -= Date.now() - started.current;
|
|
52
|
+
};
|
|
53
|
+
}, [item, paused]);
|
|
54
|
+
return (_jsx("div", { "data-slot": "toaster", role: "status", "aria-live": "polite", "aria-atomic": "true", className: cn("pointer-events-none fixed right-4 bottom-4 left-4 z-50 flex justify-end sm:left-auto", className), children: item ? (_jsxs("div", { "data-slot": "toast", onMouseEnter: () => setPaused(true), onMouseLeave: () => setPaused(false), onFocus: () => setPaused(true), onBlur: () => setPaused(false), className: "pointer-events-auto flex w-full max-w-sm items-center gap-3 rounded-control border border-line bg-surface-raised py-2.5 pr-2 pl-3 text-body text-ink shadow-float", children: [_jsx(ToneIcon, { tone: "success" }), _jsx("p", { className: "min-w-0 flex-1", children: item.message }), _jsx("button", { type: "button", "aria-label": "Close", onClick: () => toast.dismiss(item.id), className: "grid size-7 shrink-0 place-items-center rounded-tag text-ink-muted hover:bg-surface-hover hover:text-ink", children: _jsx("svg", { viewBox: "0 0 12 12", "aria-hidden": true, className: "size-3", children: _jsx("path", { d: "M2.5 2.5l7 7M9.5 2.5l-7 7", className: "fill-none stroke-current", strokeWidth: "1.5", strokeLinecap: "round" }) }) })] }, item.id)) : null }));
|
|
55
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argon8/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Argon8 React components: the primitives and composites of the Argon8 product apps, on @argon8/tokens",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/argon8hq/design-system.git",
|
|
9
|
+
"directory": "packages/react"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./styles.css": "./dist/styles.css",
|
|
18
|
+
"./strict.css": "./dist/strict.css",
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"CHANGELOG.md"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": [
|
|
30
|
+
"**/*.css"
|
|
31
|
+
],
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": "^19.0.0",
|
|
34
|
+
"react-dom": "^19.0.0",
|
|
35
|
+
"tailwindcss": "^4.0.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"class-variance-authority": "0.7.1",
|
|
39
|
+
"clsx": "2.1.1",
|
|
40
|
+
"tailwind-merge": "3.7.0",
|
|
41
|
+
"@argon8/tokens": "^0.1.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@tailwindcss/vite": "4.3.5",
|
|
45
|
+
"@types/react": "19.3.0",
|
|
46
|
+
"@types/react-dom": "19.3.0",
|
|
47
|
+
"@vitejs/plugin-react": "6.3.0",
|
|
48
|
+
"react": "19.3.1",
|
|
49
|
+
"react-dom": "19.3.1",
|
|
50
|
+
"tailwindcss": "4.3.5",
|
|
51
|
+
"vite": "8.3.8"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json && cp src/*.css dist/",
|
|
55
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"lint:tokens": "argon8-token-lint src"
|
|
58
|
+
}
|
|
6
59
|
}
|