@argon8/react 0.1.0 → 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 ADDED
@@ -0,0 +1,12 @@
1
+ # @argon8/react
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2bd6c82: Add `Page` (`full`, `split`, `narrow`) with `PageMain` and `PagePane`, and `StatusPanel` with its parts. `PageHeader` now carries `data-slot="page-header"`.
8
+ - 706be34: Add the `Sidebar` app shell (`SidebarProvider`, `SidebarTopBar`, `SidebarTrigger`, `Sidebar` and its parts, `SidebarInset`, `SystemBanners`, `useSidebar`) and `Slot` for `asChild`.
9
+ - 77bed1f: Add `Tabs`, `TabsLink` and `TabsCount`: tabs as links, each a URL.
10
+ - 0df6bdb: Add `Toaster` and `toast()` for success acknowledgements.
11
+ - 2c053a5: Add `Sheet` and its parts, on the native `<dialog>`.
12
+ - 1218d8f: Add `Menu`, `MenuTrigger`, `MenuContent`, `MenuItem` and `MenuSeparator`.
package/dist/button.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { type VariantProps } from "class-variance-authority";
2
2
  import { type ComponentProps, type ReactNode } from "react";
3
3
  export declare const buttonVariants: (props?: ({
4
- variant?: "link" | "primary" | "secondary" | "ghost" | "destructive" | null | undefined;
5
- size?: "sm" | "md" | "lg" | null | undefined;
4
+ variant?: "destructive" | "ghost" | "link" | "primary" | "secondary" | null | undefined;
5
+ size?: "lg" | "md" | "sm" | null | undefined;
6
6
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
7
  export declare function Spinner({ className, label }: {
8
8
  className?: string;
package/dist/code.js CHANGED
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useRef, useState } from "react";
3
3
  import { Button } from "./button.js";
4
4
  import { cn } from "./cn.js";
package/dist/dialog.js CHANGED
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useId, useRef, useState } from "react";
3
3
  import { Button } from "./button.js";
4
4
  import { cn } from "./cn.js";
package/dist/index.d.ts CHANGED
@@ -11,3 +11,10 @@ export { Breadcrumb, linkVariants, PageHeader, SkipLink, StepMarker } from "./na
11
11
  export { Term } from "./term.js";
12
12
  export { Ago, Day, DayRange, dayRangeText, dayText, formatLocal, relativeText, When } from "./time.js";
13
13
  export { ConfirmDialog, Dialog } from "./dialog.js";
14
+ export { Slot } from "./slot.js";
15
+ export { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupLabel, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarProvider, SidebarTopBar, SidebarTrigger, SystemBanners, useSidebar, } from "./sidebar.js";
16
+ export { Page, PageMain, PagePane, pageVariants, StatusPanel, StatusPanelActions, StatusPanelDetail, StatusPanelFacts, StatusPanelFigure, StatusPanelSummary, StatusPanelText, StatusPanelVerdict, } from "./page.js";
17
+ export { Tabs, TabsCount, TabsLink } from "./tabs.js";
18
+ export { type ToastItem, Toaster, toast } from "./toast.js";
19
+ export { Sheet, SheetBody, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from "./sheet.js";
20
+ export { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger } from "./menu.js";
package/dist/index.js CHANGED
@@ -11,3 +11,10 @@ export { Breadcrumb, linkVariants, PageHeader, SkipLink, StepMarker } from "./na
11
11
  export { Term } from "./term.js";
12
12
  export { Ago, Day, DayRange, dayRangeText, dayText, formatLocal, relativeText, When } from "./time.js";
13
13
  export { ConfirmDialog, Dialog } from "./dialog.js";
14
+ export { Slot } from "./slot.js";
15
+ export { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupLabel, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarProvider, SidebarTopBar, SidebarTrigger, SystemBanners, useSidebar, } from "./sidebar.js";
16
+ export { Page, PageMain, PagePane, pageVariants, StatusPanel, StatusPanelActions, StatusPanelDetail, StatusPanelFacts, StatusPanelFigure, StatusPanelSummary, StatusPanelText, StatusPanelVerdict, } from "./page.js";
17
+ export { Tabs, TabsCount, TabsLink } from "./tabs.js";
18
+ export { Toaster, toast } from "./toast.js";
19
+ export { Sheet, SheetBody, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from "./sheet.js";
20
+ export { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger } from "./menu.js";
package/dist/menu.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { type ComponentProps, type ReactNode } from "react";
2
+ export declare function Menu({ className, children, ...props }: ComponentProps<"div">): import("react").JSX.Element;
3
+ export declare function MenuTrigger({ asChild, onClick, onKeyDown, ...props }: ComponentProps<"button"> & {
4
+ asChild?: boolean;
5
+ }): import("react").JSX.Element;
6
+ export declare function MenuContent({ align, className, onKeyDown, ...props }: ComponentProps<"div"> & {
7
+ align?: "start" | "end";
8
+ }): import("react").JSX.Element;
9
+ /** One action. A button by default; `asChild` for a link. `onSelect` runs, then the menu closes. */
10
+ export declare function MenuItem({ asChild, variant, onSelect, onClick, className, disabled, ...props }: Omit<ComponentProps<"button">, "onSelect"> & {
11
+ asChild?: boolean;
12
+ variant?: "default" | "destructive";
13
+ onSelect?: () => void;
14
+ children?: ReactNode;
15
+ }): import("react").JSX.Element;
16
+ export declare function MenuSeparator({ className }: {
17
+ className?: string;
18
+ }): import("react").JSX.Element;
package/dist/menu.js ADDED
@@ -0,0 +1,117 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useId, useMemo, useRef, useState, } from "react";
3
+ import { cn } from "./cn.js";
4
+ import { Slot } from "./slot.js";
5
+ const MenuContext = createContext(null);
6
+ function useMenu() {
7
+ const ctx = useContext(MenuContext);
8
+ if (!ctx)
9
+ throw new Error("Menu parts must be used inside <Menu>.");
10
+ return ctx;
11
+ }
12
+ const items = (contentId) => Array.from(document.getElementById(contentId)?.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])') ?? []);
13
+ export function Menu({ className, children, ...props }) {
14
+ const id = useId();
15
+ const [open, setOpenState] = useState(false);
16
+ const wrapper = useRef(null);
17
+ const value = useMemo(() => ({
18
+ open,
19
+ setOpen: (next, focusTrigger) => {
20
+ setOpenState(next);
21
+ if (!next && focusTrigger)
22
+ document.getElementById(`${id}-trigger`)?.focus();
23
+ },
24
+ triggerId: `${id}-trigger`,
25
+ contentId: `${id}-content`,
26
+ }), [id, open]);
27
+ useEffect(() => {
28
+ if (!open)
29
+ return;
30
+ const onDown = (e) => {
31
+ if (wrapper.current && !wrapper.current.contains(e.target))
32
+ setOpenState(false);
33
+ };
34
+ document.addEventListener("pointerdown", onDown);
35
+ return () => document.removeEventListener("pointerdown", onDown);
36
+ }, [open]);
37
+ return (_jsx(MenuContext.Provider, { value: value, children: _jsx("div", { ref: wrapper, "data-slot": "menu", className: cn("relative inline-flex", className), ...props, children: children }) }));
38
+ }
39
+ export function MenuTrigger({ asChild, onClick, onKeyDown, ...props }) {
40
+ const { open, setOpen, triggerId, contentId } = useMenu();
41
+ const Comp = asChild ? Slot : "button";
42
+ const openAt = (which) => {
43
+ setOpen(true);
44
+ requestAnimationFrame(() => {
45
+ const list = items(contentId);
46
+ (which === "first" ? list[0] : list[list.length - 1])?.focus();
47
+ });
48
+ };
49
+ return (_jsx(Comp, { id: triggerId, "data-slot": "menu-trigger", type: asChild ? undefined : "button", "aria-haspopup": "menu", "aria-expanded": open, "aria-controls": contentId, onClick: (e) => {
50
+ onClick?.(e);
51
+ if (e.defaultPrevented)
52
+ return;
53
+ if (open)
54
+ setOpen(false);
55
+ else
56
+ openAt("first");
57
+ }, onKeyDown: (e) => {
58
+ onKeyDown?.(e);
59
+ if (e.defaultPrevented)
60
+ return;
61
+ if (e.key === "ArrowDown") {
62
+ e.preventDefault();
63
+ openAt("first");
64
+ }
65
+ else if (e.key === "ArrowUp") {
66
+ e.preventDefault();
67
+ openAt("last");
68
+ }
69
+ }, ...props }));
70
+ }
71
+ export function MenuContent({ align = "end", className, onKeyDown, ...props }) {
72
+ const { open, setOpen, triggerId, contentId } = useMenu();
73
+ return (_jsx("div", { id: contentId, role: "menu", "aria-labelledby": triggerId, "data-slot": "menu-content", hidden: !open, onKeyDown: (e) => {
74
+ onKeyDown?.(e);
75
+ if (e.defaultPrevented)
76
+ return;
77
+ const list = items(contentId);
78
+ const at = list.indexOf(document.activeElement);
79
+ const move = (i) => {
80
+ e.preventDefault();
81
+ list[(i + list.length) % list.length]?.focus();
82
+ };
83
+ if (e.key === "ArrowDown")
84
+ move(at + 1);
85
+ else if (e.key === "ArrowUp")
86
+ move(at - 1);
87
+ else if (e.key === "Home")
88
+ move(0);
89
+ else if (e.key === "End")
90
+ move(list.length - 1);
91
+ else if (e.key === "Escape") {
92
+ e.preventDefault();
93
+ setOpen(false, true);
94
+ }
95
+ else if (e.key === "Tab")
96
+ setOpen(false);
97
+ }, className: cn("absolute top-full z-40 mt-1 flex min-w-44 flex-col rounded-control border border-line bg-surface-raised py-1 shadow-float", align === "end" ? "right-0" : "left-0", className), ...props }));
98
+ }
99
+ /** One action. A button by default; `asChild` for a link. `onSelect` runs, then the menu closes. */
100
+ export function MenuItem({ asChild, variant = "default", onSelect, onClick, className, disabled, ...props }) {
101
+ const { setOpen } = useMenu();
102
+ const Comp = asChild ? Slot : "button";
103
+ return (_jsx(Comp, { role: "menuitem", tabIndex: -1, "data-slot": "menu-item", "data-variant": variant, type: asChild ? undefined : "button", "aria-disabled": disabled || undefined, onClick: (e) => {
104
+ if (disabled) {
105
+ e.preventDefault();
106
+ return;
107
+ }
108
+ onClick?.(e);
109
+ if (e.defaultPrevented)
110
+ return;
111
+ onSelect?.();
112
+ setOpen(false, true);
113
+ }, className: cn("flex w-full items-center gap-2 px-3 py-2 text-left text-body whitespace-nowrap text-ink outline-none hover:bg-surface-hover focus-visible:bg-surface-hover focus:bg-surface-hover sm:py-1.5", "data-[variant=destructive]:text-danger aria-disabled:cursor-not-allowed aria-disabled:text-ink-subtle", className), ...props }));
114
+ }
115
+ export function MenuSeparator({ className }) {
116
+ return _jsx("div", { role: "separator", "data-slot": "menu-separator", className: cn("my-1 h-px bg-line", className) });
117
+ }
@@ -1,7 +1,7 @@
1
1
  import { type ReactNode } from "react";
2
2
  /** `inline`: underlined, in running text. `quiet`: underline on hover (lists, breadcrumbs). `strong`: a quiet link that leads a row. */
3
3
  export declare const linkVariants: (props?: ({
4
- variant?: "strong" | "inline" | "quiet" | null | undefined;
4
+ variant?: "inline" | "quiet" | "strong" | null | undefined;
5
5
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
6
6
  /** The trail back to the list a page belongs to. Each item but the last is a link; the last is this page. */
7
7
  export declare function Breadcrumb({ items, className }: {
@@ -27,7 +27,7 @@ export function Breadcrumb({ items, className }) {
27
27
  */
28
28
  export function PageHeader({ title, description, meta, actions, breadcrumb, live, metaAfter, }) {
29
29
  const metaLine = meta ? _jsx("p", { className: "mt-0.5 text-meta text-ink-muted", children: meta }) : null;
30
- return (_jsxs("div", { className: "mb-6 flex flex-wrap items-end justify-between gap-x-6 gap-y-3", children: [_jsxs("div", { className: "min-w-0", children: [breadcrumb ? _jsx(Breadcrumb, { items: breadcrumb, className: "mb-1" }) : null, _jsx("h1", { className: "text-page font-semibold tracking-tight text-ink", children: title }), metaAfter ? null : metaLine, description ? (_jsx("div", { "aria-live": live ? "polite" : undefined, className: "mt-1 max-w-prose text-body text-ink-muted", children: description })) : null, metaAfter ? metaLine : null] }), actions ? _jsx("div", { className: "flex flex-wrap items-center gap-2", children: actions }) : null] }));
30
+ return (_jsxs("div", { "data-slot": "page-header", className: "mb-6 flex flex-wrap items-end justify-between gap-x-6 gap-y-3", children: [_jsxs("div", { className: "min-w-0", children: [breadcrumb ? _jsx(Breadcrumb, { items: breadcrumb, className: "mb-1" }) : null, _jsx("h1", { className: "text-page font-semibold tracking-tight text-ink", children: title }), metaAfter ? null : metaLine, description ? (_jsx("div", { "aria-live": live ? "polite" : undefined, className: "mt-1 max-w-prose text-body text-ink-muted", children: description })) : null, metaAfter ? metaLine : null] }), actions ? _jsx("div", { className: "flex flex-wrap items-center gap-2", children: actions }) : null] }));
31
31
  }
32
32
  /** The marker of a numbered step: its number, a check once done, a ring while current. Decorative: the step's words say it. */
33
33
  export function StepMarker({ n, state }) {
package/dist/page.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { type VariantProps } from "class-variance-authority";
2
+ import type { ComponentProps, ReactNode } from "react";
3
+ import { type Tone } from "./status.js";
4
+ export declare const pageVariants: (props?: ({
5
+ width?: "full" | "narrow" | "split" | null | undefined;
6
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
+ /** The page's frame at one of three widths: `full` (lists), `split` (main + 320 px pane), `narrow` (forms). */
8
+ export declare function Page({ width, className, ...props }: ComponentProps<"div"> & VariantProps<typeof pageVariants>): import("react").JSX.Element;
9
+ /** The subject of the page, in the order of layout.md §4. Sections 24 px apart. */
10
+ export declare function PageMain({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
11
+ /**
12
+ * What supports the subject (facts, credentials, where the data comes from). Beside the main column
13
+ * from `lg`, under it below. Never a second subject.
14
+ */
15
+ export declare function PagePane({ className, "aria-label": label, ...props }: ComponentProps<"aside">): import("react").JSX.Element;
16
+ /** The state of one object: tone edge, verdict on the left, the figure on the right. */
17
+ export declare function StatusPanel({ tone, className, "aria-label": label, ...props }: ComponentProps<"section"> & {
18
+ tone?: Tone;
19
+ }): import("react").JSX.Element;
20
+ /** Left: verdict, sentence, the actions that fix it. Below `lg` it follows the figure. */
21
+ export declare function StatusPanelSummary({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
22
+ /** The condition badge and when it began. Announced politely when a refresh changes it. */
23
+ export declare function StatusPanelVerdict({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
24
+ export declare function StatusPanelText({ className, ...props }: ComponentProps<"p">): import("react").JSX.Element;
25
+ /** Only the actions that resolve this condition. When there is one, the header's buttons are secondary. */
26
+ export declare function StatusPanelActions({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
27
+ /** Right: the key figure, its visual and up to three small facts. First below `lg`. */
28
+ export declare function StatusPanelDetail({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
29
+ /** The one number the object is about, with its label and how old it is. */
30
+ export declare function StatusPanelFigure({ label, hint, className, children, ...props }: ComponentProps<"div"> & {
31
+ label: ReactNode;
32
+ hint?: ReactNode;
33
+ }): import("react").JSX.Element;
34
+ /** Up to three small facts under the figure. Pass `KeyValues`-style pairs. */
35
+ export declare function StatusPanelFacts({ items, className }: {
36
+ items: [ReactNode, ReactNode][];
37
+ className?: string;
38
+ }): import("react").JSX.Element;
package/dist/page.js ADDED
@@ -0,0 +1,80 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cva } from "class-variance-authority";
3
+ import { cn } from "./cn.js";
4
+ import { toneEdge } from "./status.js";
5
+ // docs/layout.md §3 and §4. A page picks one width; pages never write max-w-* or page grids.
6
+ //
7
+ // <Page width="split">
8
+ // <PageHeader … /> full width, above both columns
9
+ // <PageMain>status, tabs, sections</PageMain>
10
+ // <PagePane>facts, credentials, help</PagePane>
11
+ // </Page>
12
+ export const pageVariants = cva("mx-auto w-full px-4 py-6 sm:px-6 [&>[data-slot=page-header]]:mb-0", {
13
+ variants: {
14
+ width: {
15
+ full: "flex max-w-7xl flex-col gap-6",
16
+ split: "grid max-w-7xl grid-cols-1 gap-6 lg:grid-cols-[minmax(0,1fr)_20rem] lg:[&>:not([data-slot=page-main]):not([data-slot=page-pane])]:col-span-2",
17
+ narrow: "flex max-w-2xl flex-col gap-6",
18
+ },
19
+ },
20
+ defaultVariants: { width: "full" },
21
+ });
22
+ /** The page's frame at one of three widths: `full` (lists), `split` (main + 320 px pane), `narrow` (forms). */
23
+ export function Page({ width, className, ...props }) {
24
+ return _jsx("div", { "data-slot": "page", "data-width": width ?? "full", className: cn(pageVariants({ width }), className), ...props });
25
+ }
26
+ /** The subject of the page, in the order of layout.md §4. Sections 24 px apart. */
27
+ export function PageMain({ className, ...props }) {
28
+ return _jsx("div", { "data-slot": "page-main", className: cn("flex min-w-0 flex-col gap-6", className), ...props });
29
+ }
30
+ /**
31
+ * What supports the subject (facts, credentials, where the data comes from). Beside the main column
32
+ * from `lg`, under it below. Never a second subject.
33
+ */
34
+ export function PagePane({ className, "aria-label": label = "Details", ...props }) {
35
+ return _jsx("aside", { "data-slot": "page-pane", "aria-label": label, className: cn("flex min-w-0 flex-col gap-6 lg:sticky lg:top-6 lg:self-start", className), ...props });
36
+ }
37
+ // docs/patterns.md §5. One per detail page, under the page header (and any page notice).
38
+ //
39
+ // <StatusPanel tone="warning">
40
+ // <StatusPanelSummary>
41
+ // <StatusPanelVerdict><Badge tone="warning">Behind</Badge> since …</StatusPanelVerdict>
42
+ // <StatusPanelText>What it means and whether you need to act.</StatusPanelText>
43
+ // <StatusPanelActions><Button>Load the missing days</Button></StatusPanelActions>
44
+ // </StatusPanelSummary>
45
+ // <StatusPanelDetail>
46
+ // <StatusPanelFigure label="Data through" hint="3 days ago">14 Nov 2026</StatusPanelFigure>
47
+ // <Coverage … />
48
+ // </StatusPanelDetail>
49
+ // </StatusPanel>
50
+ /** The state of one object: tone edge, verdict on the left, the figure on the right. */
51
+ export function StatusPanel({ tone = "neutral", className, "aria-label": label = "Status", ...props }) {
52
+ return (_jsx("section", { "data-slot": "status-panel", "data-tone": tone, "aria-label": label, className: cn("grid gap-6 rounded-control border border-l-4 border-line bg-surface p-4 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]", toneEdge(tone), className), ...props }));
53
+ }
54
+ /** Left: verdict, sentence, the actions that fix it. Below `lg` it follows the figure. */
55
+ export function StatusPanelSummary({ className, ...props }) {
56
+ return _jsx("div", { "data-slot": "status-panel-summary", className: cn("order-2 flex min-w-0 flex-col gap-2 lg:order-1", className), ...props });
57
+ }
58
+ /** The condition badge and when it began. Announced politely when a refresh changes it. */
59
+ export function StatusPanelVerdict({ className, ...props }) {
60
+ return _jsx("div", { "data-slot": "status-panel-verdict", "aria-live": "polite", className: cn("flex flex-wrap items-center gap-2 text-meta text-ink-muted", className), ...props });
61
+ }
62
+ export function StatusPanelText({ className, ...props }) {
63
+ return _jsx("p", { "data-slot": "status-panel-text", className: cn("max-w-prose text-body text-ink", className), ...props });
64
+ }
65
+ /** Only the actions that resolve this condition. When there is one, the header's buttons are secondary. */
66
+ export function StatusPanelActions({ className, ...props }) {
67
+ return _jsx("div", { "data-slot": "status-panel-actions", className: cn("flex flex-wrap gap-2 pt-1", className), ...props });
68
+ }
69
+ /** Right: the key figure, its visual and up to three small facts. First below `lg`. */
70
+ export function StatusPanelDetail({ className, ...props }) {
71
+ return _jsx("div", { "data-slot": "status-panel-detail", className: cn("order-1 flex min-w-0 flex-col gap-3 lg:order-2", className), ...props });
72
+ }
73
+ /** The one number the object is about, with its label and how old it is. */
74
+ export function StatusPanelFigure({ label, hint, className, children, ...props }) {
75
+ return (_jsxs("div", { "data-slot": "status-panel-figure", className: cn("flex flex-wrap items-baseline gap-x-3 gap-y-1", className), ...props, children: [_jsx("span", { className: "text-meta font-medium text-ink-muted", children: label }), _jsx("span", { className: "text-figure font-semibold tabular-nums", children: children }), hint ? _jsx("span", { className: "text-meta text-ink-muted", children: hint }) : null] }));
76
+ }
77
+ /** Up to three small facts under the figure. Pass `KeyValues`-style pairs. */
78
+ export function StatusPanelFacts({ items, className }) {
79
+ return (_jsx("dl", { "data-slot": "status-panel-facts", className: cn("grid grid-cols-2 gap-4 text-body sm:grid-cols-3", className), children: items.slice(0, 3).map(([k, v], i) => (_jsxs("div", { children: [_jsx("dt", { className: "text-meta text-ink-muted", children: k }), _jsx("dd", { className: "tabular-nums", children: v ?? _jsx("span", { className: "text-ink-subtle", children: "none" }) })] }, i))) }));
80
+ }
@@ -0,0 +1,20 @@
1
+ import { type ComponentProps, type ReactNode } from "react";
2
+ export declare function Sheet({ open: openProp, onOpenChange, defaultOpen, children }: {
3
+ open?: boolean;
4
+ onOpenChange?: (open: boolean) => void;
5
+ defaultOpen?: boolean;
6
+ children: ReactNode;
7
+ }): import("react").JSX.Element;
8
+ export declare function SheetTrigger({ asChild, onClick, ...props }: ComponentProps<"button"> & {
9
+ asChild?: boolean;
10
+ }): import("react").JSX.Element;
11
+ export declare function SheetContent({ className, children, ...props }: ComponentProps<"dialog">): import("react").JSX.Element;
12
+ export declare function SheetHeader({ className, children, ...props }: ComponentProps<"div">): import("react").JSX.Element;
13
+ export declare function SheetTitle({ className, ...props }: ComponentProps<"h2">): import("react").JSX.Element;
14
+ export declare function SheetDescription({ className, ...props }: ComponentProps<"p">): import("react").JSX.Element;
15
+ export declare function SheetBody({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
16
+ /** Cancel then the primary, at the bottom right (patterns.md §9). */
17
+ export declare function SheetFooter({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
18
+ export declare function SheetClose({ asChild, onClick, ...props }: ComponentProps<"button"> & {
19
+ asChild?: boolean;
20
+ }): import("react").JSX.Element;
package/dist/sheet.js ADDED
@@ -0,0 +1,96 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
3
+ import { cn } from "./cn.js";
4
+ import { Slot } from "./slot.js";
5
+ const SheetContext = createContext(null);
6
+ function useSheet() {
7
+ const ctx = useContext(SheetContext);
8
+ if (!ctx)
9
+ throw new Error("Sheet parts must be used inside <Sheet>.");
10
+ return ctx;
11
+ }
12
+ export function Sheet({ open: openProp, onOpenChange, defaultOpen = false, children }) {
13
+ const id = useId();
14
+ const [own, setOwn] = useState(defaultOpen);
15
+ const open = openProp ?? own;
16
+ const value = useMemo(() => ({
17
+ open,
18
+ setOpen: (next) => {
19
+ if (openProp === undefined)
20
+ setOwn(next);
21
+ onOpenChange?.(next);
22
+ },
23
+ titleId: `${id}-title`,
24
+ descriptionId: `${id}-description`,
25
+ }), [id, open, openProp, onOpenChange]);
26
+ return _jsx(SheetContext.Provider, { value: value, children: children });
27
+ }
28
+ export function SheetTrigger({ asChild, onClick, ...props }) {
29
+ const { open, setOpen } = useSheet();
30
+ const Comp = asChild ? Slot : "button";
31
+ return (_jsx(Comp, { "data-slot": "sheet-trigger", type: asChild ? undefined : "button", "aria-haspopup": "dialog", "aria-expanded": open, onClick: (e) => {
32
+ onClick?.(e);
33
+ if (!e.defaultPrevented)
34
+ setOpen(true);
35
+ }, ...props }));
36
+ }
37
+ export function SheetContent({ className, children, ...props }) {
38
+ const { open, setOpen, titleId, descriptionId } = useSheet();
39
+ const ref = useRef(null);
40
+ const returnTo = useRef(null);
41
+ useEffect(() => {
42
+ const d = ref.current;
43
+ if (!d)
44
+ return;
45
+ if (open && !d.open) {
46
+ returnTo.current = document.activeElement;
47
+ d.showModal();
48
+ d.querySelector("[data-autofocus]")?.focus();
49
+ }
50
+ else if (!open && d.open) {
51
+ d.close();
52
+ }
53
+ }, [open]);
54
+ return (_jsx("dialog", { ref: ref, "data-slot": "sheet-content", "aria-labelledby": titleId, "aria-describedby": descriptionId, onCancel: (e) => {
55
+ e.preventDefault();
56
+ setOpen(false);
57
+ }, onClose: () => {
58
+ if (returnTo.current instanceof HTMLElement)
59
+ returnTo.current.focus();
60
+ if (open)
61
+ setOpen(false);
62
+ },
63
+ // A click on the backdrop lands on the <dialog> itself; the panel's own content is inside the div.
64
+ onClick: (e) => {
65
+ if (e.target === e.currentTarget)
66
+ setOpen(false);
67
+ }, className: cn("fixed inset-y-0 right-0 left-auto m-0 h-dvh max-h-none w-full max-w-none border-l border-line bg-surface-raised p-0 text-ink shadow-float sm:max-w-md", "lg:backdrop:bg-transparent", className), ...props, children: _jsx("div", { className: "flex h-full flex-col", children: children }) }));
68
+ }
69
+ export function SheetHeader({ className, children, ...props }) {
70
+ const { setOpen } = useSheet();
71
+ return (_jsxs("div", { "data-slot": "sheet-header", className: cn("flex items-start gap-3 border-b border-line px-5 py-4", className), ...props, children: [_jsx("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: children }), _jsx("button", { type: "button", "aria-label": "Close", onClick: () => setOpen(false), className: "-mt-1 -mr-2 grid size-8 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" }) }) })] }));
72
+ }
73
+ export function SheetTitle({ className, ...props }) {
74
+ const { titleId } = useSheet();
75
+ return _jsx("h2", { id: titleId, "data-slot": "sheet-title", className: cn("text-section font-semibold", className), ...props });
76
+ }
77
+ export function SheetDescription({ className, ...props }) {
78
+ const { descriptionId } = useSheet();
79
+ return _jsx("p", { id: descriptionId, "data-slot": "sheet-description", className: cn("text-body text-ink-muted", className), ...props });
80
+ }
81
+ export function SheetBody({ className, ...props }) {
82
+ return _jsx("div", { "data-slot": "sheet-body", className: cn("flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-5 py-4", className), ...props });
83
+ }
84
+ /** Cancel then the primary, at the bottom right (patterns.md §9). */
85
+ export function SheetFooter({ className, ...props }) {
86
+ return _jsx("div", { "data-slot": "sheet-footer", className: cn("flex flex-wrap justify-end gap-2 border-t border-line px-5 py-3", className), ...props });
87
+ }
88
+ export function SheetClose({ asChild, onClick, ...props }) {
89
+ const { setOpen } = useSheet();
90
+ const Comp = asChild ? Slot : "button";
91
+ return (_jsx(Comp, { "data-slot": "sheet-close", type: asChild ? undefined : "button", onClick: (e) => {
92
+ onClick?.(e);
93
+ if (!e.defaultPrevented)
94
+ setOpen(false);
95
+ }, ...props }));
96
+ }
@@ -0,0 +1,56 @@
1
+ import { type ComponentProps, type ReactNode } from "react";
2
+ import { Button } from "./button.js";
3
+ type SidebarState = {
4
+ id: string;
5
+ open: boolean;
6
+ setOpen: (open: boolean) => void;
7
+ toggle: () => void;
8
+ };
9
+ /** The sidebar's state: whether the menu is open below `lg`. Close it on route change. */
10
+ export declare function useSidebar(): SidebarState;
11
+ export declare function SidebarProvider({ open: openProp, onOpenChange, defaultOpen, className, children, ...props }: ComponentProps<"div"> & {
12
+ open?: boolean;
13
+ onOpenChange?: (open: boolean) => void;
14
+ defaultOpen?: boolean;
15
+ }): import("react").JSX.Element;
16
+ /** Below `lg` only: the wordmark and the Menu button, 48 px, sticky. */
17
+ export declare function SidebarTopBar({ className, ...props }: ComponentProps<"header">): import("react").JSX.Element;
18
+ /** The Menu button below `lg`. Shows the total attention count when given one. */
19
+ export declare function SidebarTrigger({ children, count, countLabel, className, onClick, ...props }: ComponentProps<typeof Button> & {
20
+ count?: number;
21
+ countLabel?: string;
22
+ }): import("react").JSX.Element;
23
+ /** The sidebar itself: a column from `lg`; below it, hidden until the Menu opens it under the top bar. */
24
+ export declare function Sidebar({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
25
+ /** Top of the sidebar: the wordmark and the switcher. Give the wordmark `hidden lg:block`: below `lg` the top bar shows it. */
26
+ export declare function SidebarHeader({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
27
+ /** The scrolling middle: the app's main navigation landmark. */
28
+ export declare function SidebarContent({ className, "aria-label": label, ...props }: ComponentProps<"nav">): import("react").JSX.Element;
29
+ /** Bottom of the sidebar: the account line. Outside the navigation landmark. */
30
+ export declare function SidebarFooter({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
31
+ /** One labelled group of places (Watch, Set up). */
32
+ export declare function SidebarGroup({ className, children, ...props }: ComponentProps<"div">): import("react").JSX.Element;
33
+ export declare function SidebarGroupLabel({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
34
+ export declare function SidebarMenu({ className, ...props }: ComponentProps<"ul">): import("react").JSX.Element;
35
+ export declare function SidebarMenuItem({ className, ...props }: ComponentProps<"li">): import("react").JSX.Element;
36
+ /**
37
+ * A place in the app. An `<a>` by default; `asChild` hands its props to the app's router link.
38
+ * `isActive` marks the current section (and stays on for its detail pages). Choosing one closes the
39
+ * menu below `lg`.
40
+ */
41
+ export declare function SidebarMenuButton({ asChild, isActive, className, onClick, ...props }: ComponentProps<"a"> & {
42
+ asChild?: boolean;
43
+ isActive?: boolean;
44
+ children?: ReactNode;
45
+ }): import("react").JSX.Element;
46
+ /** What needs the user in that place ("2 need you"). Nothing for totals; nothing when zero. */
47
+ export declare function SidebarMenuBadge({ value, label, className }: {
48
+ value: number;
49
+ label: string;
50
+ className?: string;
51
+ }): import("react").JSX.Element | null;
52
+ /** Everything right of the sidebar: system banners, then the page's <main id="main">. */
53
+ export declare function SidebarInset({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
54
+ /** The system banners' place: what stops everything, on every page. Empty renders nothing. */
55
+ export declare function SystemBanners({ className, ...props }: ComponentProps<"div">): import("react").JSX.Element;
56
+ export {};
@@ -0,0 +1,112 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useId, useMemo, useState } from "react";
3
+ import { Button } from "./button.js";
4
+ import { cn } from "./cn.js";
5
+ import { Slot } from "./slot.js";
6
+ import { Count } from "./status.js";
7
+ const SidebarContext = createContext(null);
8
+ /** The sidebar's state: whether the menu is open below `lg`. Close it on route change. */
9
+ export function useSidebar() {
10
+ const ctx = useContext(SidebarContext);
11
+ if (!ctx)
12
+ throw new Error("useSidebar must be used inside <SidebarProvider>.");
13
+ return ctx;
14
+ }
15
+ export function SidebarProvider({ open: openProp, onOpenChange, defaultOpen = false, className, children, ...props }) {
16
+ const id = useId();
17
+ const [own, setOwn] = useState(defaultOpen);
18
+ const open = openProp ?? own;
19
+ const value = useMemo(() => {
20
+ const setOpen = (next) => {
21
+ if (openProp === undefined)
22
+ setOwn(next);
23
+ onOpenChange?.(next);
24
+ };
25
+ return { id: `${id}-sidebar`, open, setOpen, toggle: () => setOpen(!open) };
26
+ }, [id, open, openProp, onOpenChange]);
27
+ useEffect(() => {
28
+ if (!open)
29
+ return;
30
+ const onKey = (e) => {
31
+ if (e.key === "Escape")
32
+ value.setOpen(false);
33
+ };
34
+ window.addEventListener("keydown", onKey);
35
+ return () => window.removeEventListener("keydown", onKey);
36
+ }, [open, value]);
37
+ return (_jsx(SidebarContext.Provider, { value: value, children: _jsx("div", { "data-slot": "sidebar-wrapper", className: cn("min-h-svh lg:grid lg:grid-cols-[14rem_minmax(0,1fr)]", className), ...props, children: children }) }));
38
+ }
39
+ /** Below `lg` only: the wordmark and the Menu button, 48 px, sticky. */
40
+ export function SidebarTopBar({ className, ...props }) {
41
+ return _jsx("header", { "data-slot": "sidebar-top-bar", className: cn("sticky top-0 z-30 flex h-12 items-center gap-3 border-b border-line bg-surface px-4 lg:hidden", className), ...props });
42
+ }
43
+ /** The Menu button below `lg`. Shows the total attention count when given one. */
44
+ export function SidebarTrigger({ children = "Menu", count, countLabel, className, onClick, ...props }) {
45
+ const { id, open, toggle } = useSidebar();
46
+ return (_jsxs(Button, { "data-slot": "sidebar-trigger", variant: "ghost", "aria-expanded": open, "aria-controls": id, className: cn("ml-auto", className), onClick: (e) => {
47
+ onClick?.(e);
48
+ if (!e.defaultPrevented)
49
+ toggle();
50
+ }, ...props, children: [children, count ? _jsx(Count, { value: count, label: countLabel ?? `${count} need you` }) : null] }));
51
+ }
52
+ /** The sidebar itself: a column from `lg`; below it, hidden until the Menu opens it under the top bar. */
53
+ export function Sidebar({ className, ...props }) {
54
+ const { id, open } = useSidebar();
55
+ return (_jsx("div", { id: id, "data-slot": "sidebar", "data-open": open, className: cn("hidden flex-col border-b border-line bg-surface data-[open=true]:flex", "lg:sticky lg:top-0 lg:flex lg:h-svh lg:border-r lg:border-b-0", className), ...props }));
56
+ }
57
+ /** Top of the sidebar: the wordmark and the switcher. Give the wordmark `hidden lg:block`: below `lg` the top bar shows it. */
58
+ export function SidebarHeader({ className, ...props }) {
59
+ return _jsx("div", { "data-slot": "sidebar-header", className: cn("flex flex-col gap-2 px-3 pt-3 pb-2", className), ...props });
60
+ }
61
+ /** The scrolling middle: the app's main navigation landmark. */
62
+ export function SidebarContent({ className, "aria-label": label = "Main", ...props }) {
63
+ return _jsx("nav", { "data-slot": "sidebar-content", "aria-label": label, className: cn("flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-3 py-2", className), ...props });
64
+ }
65
+ /** Bottom of the sidebar: the account line. Outside the navigation landmark. */
66
+ export function SidebarFooter({ className, ...props }) {
67
+ return _jsx("div", { "data-slot": "sidebar-footer", className: cn("flex flex-col gap-2 border-t border-line px-3 py-3", className), ...props });
68
+ }
69
+ const GroupContext = createContext(undefined);
70
+ /** One labelled group of places (Watch, Set up). */
71
+ export function SidebarGroup({ className, children, ...props }) {
72
+ const labelId = useId();
73
+ return (_jsx(GroupContext.Provider, { value: labelId, children: _jsx("div", { "data-slot": "sidebar-group", role: "group", "aria-labelledby": labelId, className: cn("flex flex-col gap-1", className), ...props, children: children }) }));
74
+ }
75
+ export function SidebarGroupLabel({ className, ...props }) {
76
+ const id = useContext(GroupContext);
77
+ return _jsx("div", { id: id, "data-slot": "sidebar-group-label", className: cn("px-2 text-meta font-medium text-ink-muted", className), ...props });
78
+ }
79
+ export function SidebarMenu({ className, ...props }) {
80
+ return _jsx("ul", { "data-slot": "sidebar-menu", className: cn("flex flex-col gap-0.5", className), ...props });
81
+ }
82
+ export function SidebarMenuItem({ className, ...props }) {
83
+ return _jsx("li", { "data-slot": "sidebar-menu-item", className: cn("relative flex items-center", className), ...props });
84
+ }
85
+ /**
86
+ * A place in the app. An `<a>` by default; `asChild` hands its props to the app's router link.
87
+ * `isActive` marks the current section (and stays on for its detail pages). Choosing one closes the
88
+ * menu below `lg`.
89
+ */
90
+ export function SidebarMenuButton({ asChild, isActive, className, onClick, ...props }) {
91
+ const { setOpen } = useSidebar();
92
+ const Comp = asChild ? Slot : "a";
93
+ return (_jsx(Comp, { "data-slot": "sidebar-menu-button", "data-active": isActive || undefined, "aria-current": isActive ? "page" : undefined, className: cn("flex w-full min-w-0 items-center gap-2 rounded-control px-2 py-3 text-prose text-ink-muted hover:bg-surface-hover hover:text-ink lg:py-1.5 lg:text-body", "data-active:bg-surface-sunk data-active:font-medium data-active:text-ink", className), onClick: (e) => {
94
+ onClick?.(e);
95
+ if (!e.defaultPrevented)
96
+ setOpen(false);
97
+ }, ...props }));
98
+ }
99
+ /** What needs the user in that place ("2 need you"). Nothing for totals; nothing when zero. */
100
+ export function SidebarMenuBadge({ value, label, className }) {
101
+ if (!value)
102
+ return null;
103
+ return (_jsx("span", { "data-slot": "sidebar-menu-badge", className: cn("pointer-events-none absolute right-2", className), children: _jsx(Count, { value: value, label: label }) }));
104
+ }
105
+ /** Everything right of the sidebar: system banners, then the page's <main id="main">. */
106
+ export function SidebarInset({ className, ...props }) {
107
+ return _jsx("div", { "data-slot": "sidebar-inset", className: cn("flex min-w-0 flex-col", className), ...props });
108
+ }
109
+ /** The system banners' place: what stops everything, on every page. Empty renders nothing. */
110
+ export function SystemBanners({ className, ...props }) {
111
+ return _jsx("div", { "data-slot": "system-banners", className: cn("flex flex-col gap-3 px-4 pt-4 empty:hidden sm:px-6", className), ...props });
112
+ }
package/dist/slot.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { type HTMLAttributes, type ReactElement, type ReactNode } from "react";
2
+ export declare function Slot({ children, ...props }: HTMLAttributes<HTMLElement> & {
3
+ children?: ReactNode;
4
+ } & Record<string, unknown>): ReactElement<Record<string, unknown>, string | import("react").JSXElementConstructor<any>> | null;
package/dist/slot.js ADDED
@@ -0,0 +1,25 @@
1
+ import { Children, cloneElement, isValidElement } from "react";
2
+ import { cn } from "./cn.js";
3
+ // `asChild` (the shadcn and Radix pattern): a component renders its one child instead of its own
4
+ // element and gives it its props, so an app's router <Link> can be a sidebar item or a tab.
5
+ // className is merged; event handlers run the child's first, then ours unless the child prevented it.
6
+ export function Slot({ children, ...props }) {
7
+ const child = Children.only(children);
8
+ if (!isValidElement(child))
9
+ return null;
10
+ const own = child.props;
11
+ const merged = { ...props, ...own };
12
+ for (const key of Object.keys(props)) {
13
+ const ours = props[key];
14
+ const theirs = own[key];
15
+ if (/^on[A-Z]/.test(key) && typeof ours === "function" && typeof theirs === "function") {
16
+ merged[key] = (event, ...rest) => {
17
+ theirs(event, ...rest);
18
+ if (!event?.defaultPrevented)
19
+ ours(event, ...rest);
20
+ };
21
+ }
22
+ }
23
+ merged.className = cn(props.className, own.className);
24
+ return cloneElement(child, merged);
25
+ }
package/dist/status.js CHANGED
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { cn } from "./cn.js";
3
3
  export const TONES = ["danger", "warning", "info", "neutral", "success"];
4
4
  /** A view's tone is the worst of its parts. */
package/dist/tabs.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { ComponentProps, ReactNode } from "react";
2
+ export declare function Tabs({ className, children, ...props }: ComponentProps<"nav"> & {
3
+ "aria-label": string;
4
+ }): import("react").JSX.Element;
5
+ /** One tab. An `<a>` by default; `asChild` hands its props to the app's router link. */
6
+ export declare function TabsLink({ asChild, isActive, className, children, ...props }: ComponentProps<"a"> & {
7
+ asChild?: boolean;
8
+ isActive?: boolean;
9
+ children?: ReactNode;
10
+ }): import("react").JSX.Element;
11
+ /** What inside the tab needs the user (Rejected rows 12). Not for plain totals. */
12
+ export declare function TabsCount({ value, label, className }: {
13
+ value: number;
14
+ label: string;
15
+ className?: string;
16
+ }): import("react").JSX.Element | null;
package/dist/tabs.js ADDED
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cn } from "./cn.js";
3
+ import { Slot } from "./slot.js";
4
+ import { Count } from "./status.js";
5
+ // docs/patterns.md §7. Tabs on a detail page, below its status panel. Each tab is a URL, so they
6
+ // are links in a <nav> with aria-current, not an ARIA tablist; Back, refresh and a copied link all
7
+ // land on the same tab. 2 to 5 tabs; the row scrolls sideways instead of wrapping.
8
+ //
9
+ // <Tabs aria-label="Run">
10
+ // <TabsLink asChild isActive><Link to="." search={{ tab: undefined }}>Summary</Link></TabsLink>
11
+ // <TabsLink asChild><Link to="." search={{ tab: "rows" }}>Rejected rows <TabsCount value={12} label="12 rejected rows" /></Link></TabsLink>
12
+ // </Tabs>
13
+ export function Tabs({ className, children, ...props }) {
14
+ return (_jsx("nav", { "data-slot": "tabs", className: cn("-mx-4 overflow-x-auto px-4 sm:mx-0 sm:px-0", className), ...props, children: _jsx("ul", { className: "flex min-w-max gap-5 border-b border-line", children: children }) }));
15
+ }
16
+ /** One tab. An `<a>` by default; `asChild` hands its props to the app's router link. */
17
+ export function TabsLink({ asChild, isActive, className, children, ...props }) {
18
+ const Comp = asChild ? Slot : "a";
19
+ return (_jsx("li", { className: "flex", children: _jsx(Comp, { "data-slot": "tabs-link", "data-active": isActive || undefined, "aria-current": isActive ? "page" : undefined, className: cn("-mb-px inline-flex items-center gap-1.5 border-b-2 border-transparent pt-1 pb-2 text-body whitespace-nowrap text-ink-muted hover:border-line-strong hover:text-ink", "data-active:border-ink data-active:font-medium data-active:text-ink", className), ...props, children: children }) }));
20
+ }
21
+ /** What inside the tab needs the user (Rejected rows 12). Not for plain totals. */
22
+ export function TabsCount({ value, label, className }) {
23
+ if (!value)
24
+ return null;
25
+ return _jsx(Count, { value: value, label: label, tone: "neutral", className: className });
26
+ }
package/dist/time.js CHANGED
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
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
3
  // know the reader's zone); the browser switches to local time once the page is running.
4
4
  // Days in the data (watermarks, periods) are calendar days: "Nov 9", the year only when it is not
@@ -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,6 @@
1
1
  {
2
2
  "name": "@argon8/react",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Argon8 React components: the primitives and composites of the Argon8 product apps, on @argon8/tokens",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {