@sincpro/web-ui 2.13.0 → 2.14.1
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/README.md +16 -6
- package/dist/components/gallery/Gallery.d.ts +29 -0
- package/dist/components/gallery/Gallery.js +78 -0
- package/dist/components/gallery/Lightbox.d.ts +28 -0
- package/dist/components/gallery/Lightbox.js +59 -0
- package/dist/components/gallery/index.d.ts +2 -0
- package/dist/components/gallery/index.js +3 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/listing/ColumnsMenu.js +4 -2
- package/dist/components/listing/columns.d.ts +3 -0
- package/dist/components/listing/columns.js +4 -0
- package/dist/components/plans/PlanCard.d.ts +43 -0
- package/dist/components/plans/PlanCard.js +35 -0
- package/dist/components/plans/index.d.ts +1 -0
- package/dist/components/plans/index.js +2 -0
- package/dist/components/search/CriteriaChips.d.ts +14 -1
- package/dist/components/search/CriteriaChips.js +131 -14
- package/dist/components/search/JoinWord.js +8 -14
- package/dist/components/search/SearchBar.d.ts +10 -1
- package/dist/components/search/SearchBar.js +715 -176
- package/dist/components/search/WordChoice.d.ts +19 -0
- package/dist/components/search/WordChoice.js +8 -0
- package/dist/components/search/criteria.d.ts +47 -4
- package/dist/components/search/criteria.js +75 -2
- package/dist/components/search/index.d.ts +2 -2
- package/dist/components/search/index.js +2 -2
- package/dist/components/search/query.d.ts +24 -0
- package/dist/components/search/query.js +29 -0
- package/dist/components/shell/AppFrame.d.ts +4 -0
- package/dist/components/shell/AppFrame.js +4 -1
- package/dist/components/shell/Inbox.d.ts +53 -0
- package/dist/components/shell/Inbox.js +55 -0
- package/dist/components/shell/SearchEntry.js +2 -3
- package/dist/components/shell/TopBar.d.ts +4 -2
- package/dist/components/shell/TopBar.js +3 -3
- package/dist/components/shell/index.d.ts +1 -0
- package/dist/components/shell/index.js +3 -0
- package/dist/foundations/copy.es.js +60 -1
- package/dist/foundations/form.d.ts +7 -0
- package/dist/foundations/form.js +1 -0
- package/dist/foundations/uiCopy.d.ts +85 -2
- package/dist/foundations/uiCopy.js +60 -1
- package/dist/primitives/choice/RadioGroup.d.ts +1 -1
- package/dist/primitives/choice/RadioGroup.js +29 -0
- package/dist/primitives/choice/Rating.d.ts +32 -0
- package/dist/primitives/choice/Rating.js +75 -0
- package/dist/primitives/choice/Slider.d.ts +19 -0
- package/dist/primitives/choice/Slider.js +27 -2
- package/dist/primitives/choice/index.d.ts +2 -1
- package/dist/primitives/choice/index.js +4 -1
- package/dist/primitives/choice/options.d.ts +4 -0
- package/dist/primitives/field/Field.js +1 -0
- package/dist/primitives/hint/Kbd.d.ts +23 -0
- package/dist/primitives/hint/Kbd.js +23 -0
- package/dist/primitives/hint/index.d.ts +1 -0
- package/dist/primitives/hint/index.js +2 -0
- package/dist/primitives/menu/ContextMenu.d.ts +29 -0
- package/dist/primitives/menu/ContextMenu.js +74 -0
- package/dist/primitives/menu/Menu.d.ts +4 -1
- package/dist/primitives/menu/Menu.js +2 -2
- package/dist/primitives/menu/index.d.ts +1 -0
- package/dist/primitives/menu/index.js +2 -0
- package/dist/primitives/notice/Banner.d.ts +27 -0
- package/dist/primitives/notice/Banner.js +21 -0
- package/dist/primitives/notice/Callout.d.ts +4 -4
- package/dist/primitives/notice/Callout.js +8 -19
- package/dist/primitives/notice/Notice.d.ts +38 -10
- package/dist/primitives/notice/Notice.js +48 -9
- package/dist/primitives/notice/index.d.ts +3 -1
- package/dist/primitives/notice/index.js +3 -0
- package/dist/primitives/notice/tones.d.ts +8 -0
- package/dist/primitives/notice/tones.js +22 -0
- package/dist/primitives/table/DataTable.js +2 -1
- package/dist/primitives/table/index.d.ts +1 -0
- package/dist/primitives/table/index.js +1 -0
- package/dist/primitives/table/levels.d.ts +13 -0
- package/dist/primitives/table/levels.js +11 -0
- package/dist/primitives/value/Price.d.ts +31 -0
- package/dist/primitives/value/Price.js +32 -0
- package/dist/primitives/value/QrCode.d.ts +32 -0
- package/dist/primitives/value/QrCode.js +53 -0
- package/dist/primitives/value/index.d.ts +3 -0
- package/dist/primitives/value/index.js +6 -0
- package/dist/primitives/value/priceFormat.d.ts +12 -0
- package/dist/primitives/value/priceFormat.js +22 -0
- package/dist/tokens.css +39 -0
- package/dist/views/list/ListView.js +24 -4
- package/dist/views/list/derive.js +3 -2
- package/dist/views/list/types.d.ts +8 -0
- package/package.json +3 -2
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type MenuGroup } from "./Menu.js";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
export type ContextMenuProps = {
|
|
4
|
+
/** What the menu is about, read when it opens: «Acciones de la factura 0047». */
|
|
5
|
+
label: string;
|
|
6
|
+
groups: readonly MenuGroup[];
|
|
7
|
+
onSelect?: (id: string) => void;
|
|
8
|
+
/** The row, the card, the event — what is right-clicked or held. As a function it is told
|
|
9
|
+
* whether its menu is open, so the row can stay marked: with the menu over the list, which
|
|
10
|
+
* row it belongs to is otherwise a guess. */
|
|
11
|
+
children: ReactNode | ((state: {
|
|
12
|
+
open: boolean;
|
|
13
|
+
}) => ReactNode);
|
|
14
|
+
/** Off for now (a row being saved): the browser's own menu answers instead. */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The verbs of ONE thing, where the hand already is: right click on a row or a card, a finger
|
|
19
|
+
* held on it, or Shift+F10 / the Menu key on it.
|
|
20
|
+
*
|
|
21
|
+
* Context: an ERP list's frequent verbs — open, duplicate, send, cancel — live in the record's
|
|
22
|
+
* `⋯`, three moves away from the row; a board's card and a calendar's event have no room for a
|
|
23
|
+
* `⋯` at all. This is the same menu (`MenuList`: the same groups, icons, shortcuts and danger
|
|
24
|
+
* rows as `Menu`) opened AT the pointer. It is a shortcut, never the only way: whatever is here
|
|
25
|
+
* must also be reachable by a visible control, because nobody finds a right click by looking.
|
|
26
|
+
* It wraps its child without a box of its own (`display: contents`), so a table's row or a
|
|
27
|
+
* grid's card keeps its layout; the keyboard opens it from the focused element inside.
|
|
28
|
+
*/
|
|
29
|
+
export declare function ContextMenu({ label, groups, onSelect, children, disabled, }: ContextMenuProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
|
+
import { indexOptions, MenuList } from "./Menu.js";
|
|
5
|
+
import { Popover } from "../overlay/Popover.js";
|
|
6
|
+
import { useRef, useState, } from "react";
|
|
7
|
+
/* How long a finger rests before it is a «press and hold», and how far it may drift and still
|
|
8
|
+
be one — the platforms' own numbers, near enough. */
|
|
9
|
+
const HOLD_MS = 500;
|
|
10
|
+
const DRIFT = 10;
|
|
11
|
+
/**
|
|
12
|
+
* The verbs of ONE thing, where the hand already is: right click on a row or a card, a finger
|
|
13
|
+
* held on it, or Shift+F10 / the Menu key on it.
|
|
14
|
+
*
|
|
15
|
+
* Context: an ERP list's frequent verbs — open, duplicate, send, cancel — live in the record's
|
|
16
|
+
* `⋯`, three moves away from the row; a board's card and a calendar's event have no room for a
|
|
17
|
+
* `⋯` at all. This is the same menu (`MenuList`: the same groups, icons, shortcuts and danger
|
|
18
|
+
* rows as `Menu`) opened AT the pointer. It is a shortcut, never the only way: whatever is here
|
|
19
|
+
* must also be reachable by a visible control, because nobody finds a right click by looking.
|
|
20
|
+
* It wraps its child without a box of its own (`display: contents`), so a table's row or a
|
|
21
|
+
* grid's card keeps its layout; the keyboard opens it from the focused element inside.
|
|
22
|
+
*/
|
|
23
|
+
export function ContextMenu({ label, groups, onSelect, children, disabled = false, }) {
|
|
24
|
+
const copy = useUiCopy();
|
|
25
|
+
const [at, setAt] = useState(null);
|
|
26
|
+
const anchor = useRef(null);
|
|
27
|
+
const hold = useRef(null);
|
|
28
|
+
const byId = indexOptions(groups.flatMap((g) => g.options));
|
|
29
|
+
const cancelHold = () => {
|
|
30
|
+
if (hold.current !== null)
|
|
31
|
+
window.clearTimeout(hold.current.timer);
|
|
32
|
+
hold.current = null;
|
|
33
|
+
};
|
|
34
|
+
const onContextMenu = (event) => {
|
|
35
|
+
if (disabled)
|
|
36
|
+
return;
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
cancelHold();
|
|
39
|
+
setAt({ x: event.clientX, y: event.clientY });
|
|
40
|
+
};
|
|
41
|
+
/* iOS fires no `contextmenu` on a long press; Android does, and then the hold has already
|
|
42
|
+
been cancelled by it. */
|
|
43
|
+
const onPointerDown = (event) => {
|
|
44
|
+
if (disabled || event.pointerType !== "touch")
|
|
45
|
+
return;
|
|
46
|
+
const { clientX: x, clientY: y } = event;
|
|
47
|
+
hold.current = { x, y, timer: window.setTimeout(() => setAt({ x, y }), HOLD_MS) };
|
|
48
|
+
};
|
|
49
|
+
const onPointerMove = (event) => {
|
|
50
|
+
const start = hold.current;
|
|
51
|
+
if (start === null)
|
|
52
|
+
return;
|
|
53
|
+
if (Math.hypot(event.clientX - start.x, event.clientY - start.y) > DRIFT)
|
|
54
|
+
cancelHold();
|
|
55
|
+
};
|
|
56
|
+
const onKeyDown = (event) => {
|
|
57
|
+
if (disabled)
|
|
58
|
+
return;
|
|
59
|
+
if (event.key !== "ContextMenu" && !(event.shiftKey && event.key === "F10"))
|
|
60
|
+
return;
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
const box = event.target.getBoundingClientRect();
|
|
63
|
+
setAt({ x: box.left, y: box.bottom });
|
|
64
|
+
};
|
|
65
|
+
return (_jsxs("div", { "data-ui": "context-menu", className: "contents", onContextMenu: onContextMenu, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: cancelHold, onPointerCancel: cancelHold, onKeyDown: onKeyDown, children: [typeof children === "function" ? children({ open: at !== null }) : children, _jsx("span", { ref: anchor, "aria-hidden": true, className: "pointer-events-none fixed size-0", style: at === null ? undefined : { left: at.x, top: at.y } }), _jsx(Popover, { triggerRef: anchor, isOpen: at !== null, onOpenChange: (open) => {
|
|
66
|
+
if (!open)
|
|
67
|
+
setAt(null);
|
|
68
|
+
}, placement: "bottom start", offset: 2, className: "w-max min-w-48 max-w-(--container-short)", children: _jsx(MenuList, { label: label, groups: groups, closeOnSelect: true, autoFocus: true, emptyText: copy.menu.empty, onAction: (key) => {
|
|
69
|
+
const option = byId.get(String(key));
|
|
70
|
+
option?.onSelect?.();
|
|
71
|
+
onSelect?.(String(key));
|
|
72
|
+
setAt(null);
|
|
73
|
+
} }) })] }));
|
|
74
|
+
}
|
|
@@ -137,7 +137,7 @@ chevron, active, iconOnly, variant, searchPlaceholder, emptyText, width, role, s
|
|
|
137
137
|
* submenu is this same panel one level down, and a panel can be rendered on the server
|
|
138
138
|
* without the trigger's popover, which is how the tests see the rows.
|
|
139
139
|
*/
|
|
140
|
-
export declare function MenuList({ label, groups, onAction, closeOnSelect, emptyText, width, layout, foldable, }: {
|
|
140
|
+
export declare function MenuList({ label, groups, onAction, closeOnSelect, emptyText, width, layout, foldable, autoFocus, }: {
|
|
141
141
|
label: string;
|
|
142
142
|
groups: readonly MenuGroup[];
|
|
143
143
|
onAction: (key: Key) => void;
|
|
@@ -147,4 +147,7 @@ export declare function MenuList({ label, groups, onAction, closeOnSelect, empty
|
|
|
147
147
|
layout?: "list" | "columns";
|
|
148
148
|
/** `false` shows every `collapsible` section open — under a search box. */
|
|
149
149
|
foldable?: boolean;
|
|
150
|
+
/** Focus the first row when it appears. A `MenuTrigger` does it by itself; a panel opened
|
|
151
|
+
* without one — the `ContextMenu` — asks for it. */
|
|
152
|
+
autoFocus?: boolean;
|
|
150
153
|
}): import("react").JSX.Element;
|
|
@@ -78,7 +78,7 @@ chevron = true, active = false, iconOnly = false, variant = "button", searchPlac
|
|
|
78
78
|
* submenu is this same panel one level down, and a panel can be rendered on the server
|
|
79
79
|
* without the trigger's popover, which is how the tests see the rows.
|
|
80
80
|
*/
|
|
81
|
-
export function MenuList({ label, groups, onAction, closeOnSelect, emptyText, width = "md", layout = "list", foldable = true, }) {
|
|
81
|
+
export function MenuList({ label, groups, onAction, closeOnSelect, emptyText, width = "md", layout = "list", foldable = true, autoFocus = false, }) {
|
|
82
82
|
const sectionKey = (g, index) => g.label ?? String(index);
|
|
83
83
|
const folds = (g) => foldable && g.collapsible === true && g.label !== undefined;
|
|
84
84
|
/* Which folded sections are open. One that holds something ticked starts open: otherwise
|
|
@@ -117,7 +117,7 @@ export function MenuList({ label, groups, onAction, closeOnSelect, emptyText, wi
|
|
|
117
117
|
? "font-medium text-ink"
|
|
118
118
|
: "text-ink"}`, children: o.label }), o.badge === undefined ? null : typeof o.badge === "number" ? (_jsx("span", { className: "ml-auto flex shrink-0", children: _jsx(Count, { value: o.badge }) })) : typeof o.badge === "string" ? (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-warn/30 bg-warn/10 px-2 py-0.5 text-micro text-warn", children: o.badge })) : (_jsx("span", { className: "ml-auto shrink-0", children: o.badge }))] }), o.hint === undefined ? null : (_jsx("span", { className: "mt-0.5 block truncate text-micro text-muted", children: o.hint }))] }), o.shortcut === undefined ? null : (_jsx(Keyboard, { className: "shrink-0 self-center pl-3 font-mono text-micro text-muted", children: o.shortcut })), opens ? (_jsx(ChevronRight, { className: "size-(--size-icon-sm) shrink-0 self-center text-muted", strokeWidth: 2, "aria-hidden": true })) : null] }, o.id));
|
|
119
119
|
};
|
|
120
|
-
return (_jsx(AriaMenu, { "data-ui": "menu", "aria-label": label, shouldCloseOnSelect: closeOnSelect, onAction: act, renderEmptyState: () => (_jsx("p", { className: "px-3 py-3 text-meta text-muted italic", children: emptyText })), className: `max-h-[inherit] overflow-y-auto p-1 outline-0 ${layout === "columns" ? "flex flex-col sm:flex-row sm:items-stretch" : ""}`, children: groups.map((g, gi) => {
|
|
120
|
+
return (_jsx(AriaMenu, { "data-ui": "menu", "aria-label": label, shouldCloseOnSelect: closeOnSelect, ...(autoFocus ? { autoFocus: "first" } : {}), onAction: act, renderEmptyState: () => (_jsx("p", { className: "px-3 py-3 text-meta text-muted italic", children: emptyText })), className: `max-h-[inherit] overflow-y-auto p-1 outline-0 ${layout === "columns" ? "flex flex-col sm:flex-row sm:items-stretch" : ""}`, children: groups.map((g, gi) => {
|
|
121
121
|
const key = sectionKey(g, gi);
|
|
122
122
|
const folding = folds(g);
|
|
123
123
|
const open = !folding || unfolded.has(key);
|
|
@@ -2,3 +2,5 @@
|
|
|
2
2
|
export { Menu } from "./Menu.js";
|
|
3
3
|
/* A trigger's look without the menu, without `"use client"`: a server component calls it. */
|
|
4
4
|
export { menuTriggerClasses } from "./classes.js";
|
|
5
|
+
/* The same menu opened AT the pointer: right click, a finger held, Shift+F10 on a row or a card. */
|
|
6
|
+
export { ContextMenu, } from "./ContextMenu.js";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type NoticeTone } from "./tones.js";
|
|
2
|
+
import { type LucideIcon } from "lucide-react";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
export type BannerProps = {
|
|
5
|
+
/** What is happening, in one sentence: «El sistema se actualiza hoy a las 22:00». */
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
/** Without this, `info`. The same four degrees as `Callout`. */
|
|
8
|
+
tone?: NoticeTone;
|
|
9
|
+
/** What resolves it, if there is something to press — usually a link: «Renovar el plan». */
|
|
10
|
+
action?: ReactNode;
|
|
11
|
+
/** Present = it can be closed. Absent = it stays, because it stays true for whoever looks. */
|
|
12
|
+
onDismiss?: () => void;
|
|
13
|
+
/** An icon of its own, when the tone's does not say enough (a truck for «envío gratis»). */
|
|
14
|
+
icon?: LucideIcon;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A notice about the whole APPLICATION, across the top of the frame: a maintenance window, a
|
|
18
|
+
* plan about to expire, «envío gratis desde Bs 300», a company in a test environment.
|
|
19
|
+
*
|
|
20
|
+
* Context: a `Callout` speaks about the view it sits in and lives inside it; this speaks about
|
|
21
|
+
* everything, so it goes in `AppFrame banner` — above the bar, edge to edge, scrolled away with
|
|
22
|
+
* the page instead of stuck on top taking a line from every screen. It is the same four tones
|
|
23
|
+
* as the `Callout` (one table, `tones.ts`), the sentence in ink and the tone on the icon and
|
|
24
|
+
* the edge. A `status`, never an `alert`: it was there when the screen opened, it interrupts
|
|
25
|
+
* nothing.
|
|
26
|
+
*/
|
|
27
|
+
export declare function Banner({ children, tone, action, onDismiss, icon }: BannerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
|
+
import { NOTICE_DISMISS, NOTICE_ICON, NOTICE_SKIN, } from "./tones.js";
|
|
5
|
+
import { X } from "lucide-react";
|
|
6
|
+
/**
|
|
7
|
+
* A notice about the whole APPLICATION, across the top of the frame: a maintenance window, a
|
|
8
|
+
* plan about to expire, «envío gratis desde Bs 300», a company in a test environment.
|
|
9
|
+
*
|
|
10
|
+
* Context: a `Callout` speaks about the view it sits in and lives inside it; this speaks about
|
|
11
|
+
* everything, so it goes in `AppFrame banner` — above the bar, edge to edge, scrolled away with
|
|
12
|
+
* the page instead of stuck on top taking a line from every screen. It is the same four tones
|
|
13
|
+
* as the `Callout` (one table, `tones.ts`), the sentence in ink and the tone on the icon and
|
|
14
|
+
* the edge. A `status`, never an `alert`: it was there when the screen opened, it interrupts
|
|
15
|
+
* nothing.
|
|
16
|
+
*/
|
|
17
|
+
export function Banner({ children, tone = "info", action, onDismiss, icon }) {
|
|
18
|
+
const copy = useUiCopy();
|
|
19
|
+
const Icon = icon ?? NOTICE_ICON[tone];
|
|
20
|
+
return (_jsxs("div", { role: "status", "data-ui": "banner", "data-tone": tone, className: `flex min-h-(--size-control-md) min-w-0 items-center gap-3 border-b px-4 py-1 print:hidden ${NOTICE_SKIN[tone]}`, children: [_jsxs("div", { className: "flex min-w-0 flex-1 flex-wrap items-center justify-center gap-x-3 gap-y-1", children: [_jsxs("span", { className: "inline-flex min-w-0 items-center gap-2", children: [_jsx(Icon, { className: "size-(--size-icon-sm) shrink-0", strokeWidth: 2, "aria-hidden": true }), _jsx("span", { className: "min-w-0 text-meta text-ink", children: children })] }), action === undefined ? null : (_jsx("span", { className: "shrink-0 text-meta", "data-ui": "banner.action", children: action }))] }), onDismiss === undefined ? null : (_jsx("button", { type: "button", onClick: onDismiss, "aria-label": copy.shell.closeNotice, title: copy.shell.closeNotice, className: NOTICE_DISMISS, children: _jsx(X, { className: "size-(--size-icon-sm)", strokeWidth: 2 }) }))] }));
|
|
21
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
1
|
+
import { type NoticeTone } from "./tones.js";
|
|
2
|
+
import { type LucideIcon } from "lucide-react";
|
|
3
3
|
import type { ReactNode } from "react";
|
|
4
4
|
/**
|
|
5
5
|
* A NOTICE about what is being looked at.
|
|
@@ -32,7 +32,7 @@ export type CalloutProps = {
|
|
|
32
32
|
/** What is happening. One sentence, in the product's voice. */
|
|
33
33
|
children: ReactNode;
|
|
34
34
|
/** Without this, `info`. */
|
|
35
|
-
tone?:
|
|
35
|
+
tone?: NoticeTone;
|
|
36
36
|
/** The heading, when the sentence alone is not enough. Most do not
|
|
37
37
|
* need it: a two-line notice with a title is a poster. */
|
|
38
38
|
title?: ReactNode;
|
|
@@ -41,7 +41,7 @@ export type CalloutProps = {
|
|
|
41
41
|
/** Present = it can be closed. Absent = it cannot, because what it says stays
|
|
42
42
|
* true whoever looks at it. */
|
|
43
43
|
onDismiss?: () => void;
|
|
44
|
-
/** The accessible label of the ×. */
|
|
44
|
+
/** The accessible label of the ×. «Descartar el aviso» by default. */
|
|
45
45
|
dismissLabel?: string;
|
|
46
46
|
/** An icon of its own, when the tone's does not say enough. */
|
|
47
47
|
icon?: LucideIcon;
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
3
4
|
import { byDensity, useDensity } from "../../foundations/density.js";
|
|
4
5
|
import { currentPage, ErrorCopy, errorReport, } from "./Notice.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
info: Info,
|
|
8
|
-
warn: AlertTriangle,
|
|
9
|
-
bad: OctagonAlert,
|
|
10
|
-
good: CheckCircle2,
|
|
11
|
-
};
|
|
12
|
-
/* The background is a layer of the colour over the paper and not a colour of its own: so the
|
|
13
|
-
notice reads on the floor and on white paper without two sets of tokens, and
|
|
14
|
-
keeps working the day the palette changes. */
|
|
15
|
-
const SKIN = {
|
|
16
|
-
info: "border-info/25 bg-info/8 text-info",
|
|
17
|
-
warn: "border-warn/30 bg-warn/10 text-warn",
|
|
18
|
-
bad: "border-bad/25 bg-bad/8 text-bad",
|
|
19
|
-
good: "border-good/25 bg-good/8 text-good",
|
|
20
|
-
};
|
|
6
|
+
import { NOTICE_DISMISS, NOTICE_ICON, NOTICE_SKIN, } from "./tones.js";
|
|
7
|
+
import { X } from "lucide-react";
|
|
21
8
|
export function Callout({ children, tone = "info", title, action, onDismiss, dismissLabel, icon, report, }) {
|
|
22
9
|
const d = useDensity();
|
|
23
|
-
const
|
|
10
|
+
const copy = useUiCopy();
|
|
11
|
+
const Icon = icon ?? NOTICE_ICON[tone];
|
|
12
|
+
const dismiss = dismissLabel ?? copy.shell.closeNotice;
|
|
24
13
|
/* The text a person would paste: the sentence, or what the caller names. A title that
|
|
25
14
|
is text becomes the report's heading; without one the sentence is the heading. */
|
|
26
15
|
const sentence = report ?? (typeof children === "string" ? children : "");
|
|
@@ -29,10 +18,10 @@ export function Callout({ children, tone = "info", title, action, onDismiss, dis
|
|
|
29
18
|
/* `status` and not `alert`: `alert` interrupts the screen reader and is
|
|
30
19
|
reserved for what happened RIGHT NOW. A notice that was already there when the
|
|
31
20
|
screen opened interrupts nothing. */
|
|
32
|
-
role: "status", className: `flex min-w-0 items-start gap-2.5 rounded-box border ${
|
|
21
|
+
role: "status", className: `flex min-w-0 items-start gap-2.5 rounded-box border ${NOTICE_SKIN[tone]} ${byDensity(d, "px-3 py-2.5", "px-2.5 py-2")}`, children: [_jsx(Icon, { className: "mt-0.5 size-(--size-icon-sm) shrink-0", strokeWidth: 2, "aria-hidden": true }), _jsxs("div", { className: "flex min-w-0 flex-1 flex-wrap items-start gap-x-3 gap-y-2", children: [_jsxs("div", { className: "flex min-w-0 flex-1 basis-(--container-name) flex-col gap-1", children: [title === undefined ? null : (_jsx("p", { className: "text-meta font-medium text-ink", children: title })), _jsx("div", { className: "min-w-0 text-meta text-ink", children: children })] }), action === undefined ? null : _jsx("span", { className: "shrink-0", children: action }), copyable ? (_jsx("span", { className: "shrink-0", children: _jsx(ErrorCopy, { report: () => errorReport({
|
|
33
22
|
heading: typeof title === "string" ? title : "",
|
|
34
23
|
sentence: typeof title === "string" ? sentence : undefined,
|
|
35
24
|
at: new Date(),
|
|
36
25
|
page: currentPage(),
|
|
37
|
-
}) }) })) : null] }), onDismiss === undefined ? null : (_jsx("button", { type: "button", onClick: onDismiss, "aria-label":
|
|
26
|
+
}) }) })) : null] }), onDismiss === undefined ? null : (_jsx("button", { type: "button", onClick: onDismiss, "aria-label": dismiss, title: dismiss, className: NOTICE_DISMISS, children: _jsx(X, { className: "size-(--size-icon-sm)", strokeWidth: 2 }) }))] }));
|
|
38
27
|
}
|
|
@@ -1,22 +1,50 @@
|
|
|
1
1
|
import { type LucideIcon } from "lucide-react";
|
|
2
2
|
import { type ReactNode } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/** The silhouette's shape: the one of what is coming. */
|
|
4
|
+
export type SkeletonShape = "rows" | "table" | "tiles" | "board";
|
|
5
|
+
/** Quiet stand-in for what has not arrived, in ITS shape.
|
|
6
|
+
*
|
|
7
|
+
* Context: the bars are the content's scan held in place — a list's name and figure, a
|
|
8
|
+
* table's columns, a grid's cards, a board's lanes — so the page does not jump when the data
|
|
9
|
+
* lands. Rows for a grid of products was a jump from lines to boxes; each presentation now
|
|
10
|
+
* waits in its own shape (`List` picks it). There is no shimmer: a pulse already means «this
|
|
11
|
+
* state is alive» (`StatusDot`), a second one would spend motion on a wait. The sentence is for
|
|
12
|
+
* the screen reader — the bars are not the message. */
|
|
13
|
+
export declare function Skeleton({ rows, label, shape, }: {
|
|
14
|
+
/** How many silhouettes — rows, or cards in a grid. Six is a screen, not a guess at the
|
|
15
|
+
* real count. */
|
|
6
16
|
rows?: number;
|
|
7
17
|
/** What a screen reader hears. The bars stay silent. */
|
|
8
18
|
label: string;
|
|
19
|
+
shape?: SkeletonShape;
|
|
9
20
|
}): import("react").JSX.Element;
|
|
10
|
-
|
|
11
|
-
* that resolves it if there is one. Never a drawing. */
|
|
12
|
-
export declare function Empty({ sentence, action,
|
|
13
|
-
/** Centered for an empty list; left-aligned inside a block, where centering it
|
|
14
|
-
* detaches it from everything else. */
|
|
15
|
-
align, }: {
|
|
21
|
+
export type EmptyProps = {
|
|
16
22
|
sentence: string;
|
|
17
23
|
action?: ReactNode;
|
|
24
|
+
/** Centered for an empty list; left-aligned inside a block, where centering it
|
|
25
|
+
* detaches it from everything else. */
|
|
18
26
|
align?: "center" | "start";
|
|
19
|
-
|
|
27
|
+
/** A heading over the sentence, for an empty that IS the page — «Todavía no tenés pedidos» —
|
|
28
|
+
* rather than a quiet line inside a panel. */
|
|
29
|
+
title?: string;
|
|
30
|
+
/** A mark in a soft disc above the title: what the place holds (a cart, an invoice). */
|
|
31
|
+
icon?: LucideIcon;
|
|
32
|
+
/** The application's own art, in place of the icon: a shop's drawing, a brand's mascot. It
|
|
33
|
+
* is decoration — the title and the sentence carry the meaning — so it is hidden from a
|
|
34
|
+
* screen reader. */
|
|
35
|
+
illustration?: ReactNode;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Nothing here yet — or the filter left nothing. It is NORMAL, and it says what to do.
|
|
39
|
+
*
|
|
40
|
+
* Context: two sizes from the same piece. Bare — a sentence and maybe a button — it is the
|
|
41
|
+
* quiet line inside a panel (an empty chart, no attachments), as it always was. With a `title`
|
|
42
|
+
* and an `icon` or an `illustration` it is the empty that IS the screen — a shop's empty cart,
|
|
43
|
+
* a portal's «no orders yet», a module the company has not used — where a lone grey sentence
|
|
44
|
+
* in the middle of a white page reads as broken. The picture is never the message: it is
|
|
45
|
+
* hidden from a screen reader, and the title says what the drawing shows.
|
|
46
|
+
*/
|
|
47
|
+
export declare function Empty({ sentence, action, align, title, icon: Icon, illustration, }: EmptyProps): import("react").JSX.Element;
|
|
20
48
|
/**
|
|
21
49
|
* The sentence the backend wrote, whole and verbatim.
|
|
22
50
|
*
|
|
@@ -28,20 +28,59 @@ import { useEffect, useRef, useState } from "react";
|
|
|
28
28
|
* (`StatusDot`); a second one would spend motion on a wait. The sentence is
|
|
29
29
|
* for the screen reader — the bars are not the message. */
|
|
30
30
|
const SKELETON_NAME = ["w-48", "w-36", "w-56", "w-40", "w-44", "w-32"];
|
|
31
|
-
|
|
31
|
+
const BAR = "rounded-control bg-ink/8";
|
|
32
|
+
const BAR_QUIET = "rounded-control bg-ink/5";
|
|
33
|
+
function SkeletonRows({ rows }) {
|
|
32
34
|
const d = useDensity();
|
|
35
|
+
return Array.from({ length: rows }, (_, i) => (_jsxs("div", { "aria-hidden": true, className: `flex items-center ${byDensity(d, "gap-3 px-2 py-2", "gap-2 px-1.5 py-1")}`, children: [_jsx("span", { className: `h-3.5 ${BAR} ${SKELETON_NAME[i % SKELETON_NAME.length]}` }), _jsx("span", { className: `ml-auto h-3 w-14 ${BAR_QUIET}` })] }, i)));
|
|
36
|
+
}
|
|
37
|
+
/* A header and four columns: a name, two short facts, a figure on the right — the scan of a
|
|
38
|
+
table, so the columns land where the bars were. */
|
|
39
|
+
function SkeletonTable({ rows }) {
|
|
40
|
+
const d = useDensity();
|
|
41
|
+
const cell = byDensity(d, "px-3 py-2.5", "px-2 py-1.5");
|
|
42
|
+
return (_jsxs("div", { "aria-hidden": true, className: "flex flex-col", children: [_jsxs("div", { className: `flex items-center gap-6 border-b border-line ${cell}`, children: [_jsx("span", { className: `h-2.5 w-20 ${BAR_QUIET}` }), _jsx("span", { className: `h-2.5 w-16 ${BAR_QUIET}` }), _jsx("span", { className: `h-2.5 w-14 ${BAR_QUIET}` }), _jsx("span", { className: `ml-auto h-2.5 w-14 ${BAR_QUIET}` })] }), Array.from({ length: rows }, (_, i) => (_jsxs("div", { className: `flex items-center gap-6 border-b border-line/60 ${cell}`, children: [_jsx("span", { className: `h-3.5 ${BAR} ${SKELETON_NAME[i % SKELETON_NAME.length]}` }), _jsx("span", { className: `h-3 w-16 ${BAR_QUIET}` }), _jsx("span", { className: `h-3 w-12 ${BAR_QUIET}` }), _jsx("span", { className: `ml-auto h-3 w-16 ${BAR}` })] }, i)))] }));
|
|
43
|
+
}
|
|
44
|
+
/* Cards of the grid's width: the picture's box at the tile's proportion, a name, a figure. */
|
|
45
|
+
function SkeletonTiles({ rows }) {
|
|
46
|
+
return (_jsx("div", { "aria-hidden": true, className: "grid grid-cols-(--grid-tiles-md) gap-3 p-3", children: Array.from({ length: rows }, (_, i) => (_jsxs("div", { className: "flex flex-col gap-2 rounded-ui-record-card border border-line p-2", children: [_jsx("span", { className: `aspect-(--aspect-tile) w-full ${BAR_QUIET}` }), _jsx("span", { className: `h-3.5 w-3/4 ${BAR}` }), _jsx("span", { className: `h-3 w-1/3 ${BAR_QUIET}` })] }, i))) }));
|
|
47
|
+
}
|
|
48
|
+
/* Three lanes with a few cards each — not the real count, the board's shape. */
|
|
49
|
+
function SkeletonBoard() {
|
|
50
|
+
const cards = [3, 2, 1];
|
|
51
|
+
return (_jsx("div", { "aria-hidden": true, className: "flex items-start gap-3 overflow-hidden p-3", children: cards.map((n, lane) => (_jsxs("div", { className: "flex w-(--container-lane) shrink-0 flex-col gap-2 rounded-box bg-ink/3 p-2", children: [_jsx("span", { className: `h-3 w-24 ${BAR}` }), Array.from({ length: n }, (_, i) => (_jsxs("div", { className: "flex flex-col gap-2 rounded-ui-record-card border border-line bg-surface p-3", children: [_jsx("span", { className: `h-3.5 ${BAR} ${SKELETON_NAME[(lane + i) % SKELETON_NAME.length]}` }), _jsx("span", { className: `h-3 w-20 ${BAR_QUIET}` })] }, i)))] }, lane))) }));
|
|
52
|
+
}
|
|
53
|
+
/** Quiet stand-in for what has not arrived, in ITS shape.
|
|
54
|
+
*
|
|
55
|
+
* Context: the bars are the content's scan held in place — a list's name and figure, a
|
|
56
|
+
* table's columns, a grid's cards, a board's lanes — so the page does not jump when the data
|
|
57
|
+
* lands. Rows for a grid of products was a jump from lines to boxes; each presentation now
|
|
58
|
+
* waits in its own shape (`List` picks it). There is no shimmer: a pulse already means «this
|
|
59
|
+
* state is alive» (`StatusDot`), a second one would spend motion on a wait. The sentence is for
|
|
60
|
+
* the screen reader — the bars are not the message. */
|
|
61
|
+
export function Skeleton({ rows = 6, label, shape = "rows", }) {
|
|
33
62
|
return (
|
|
34
63
|
/* It appears late (`animate-reveal-late`): a read faster than 200ms never shows it. */
|
|
35
|
-
_jsxs("div", { "aria-busy": "true", className: "flex animate-reveal-late flex-col", children: [_jsx("span", { className: "sr-only", children: label }),
|
|
64
|
+
_jsxs("div", { "aria-busy": "true", "data-ui": "skeleton", "data-shape": shape, className: "flex animate-reveal-late flex-col", children: [_jsx("span", { className: "sr-only", children: label }), shape === "table" ? (_jsx(SkeletonTable, { rows: rows })) : shape === "tiles" ? (_jsx(SkeletonTiles, { rows: rows })) : shape === "board" ? (_jsx(SkeletonBoard, {})) : (_jsx(SkeletonRows, { rows: rows }))] }));
|
|
36
65
|
}
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
*
|
|
42
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Nothing here yet — or the filter left nothing. It is NORMAL, and it says what to do.
|
|
68
|
+
*
|
|
69
|
+
* Context: two sizes from the same piece. Bare — a sentence and maybe a button — it is the
|
|
70
|
+
* quiet line inside a panel (an empty chart, no attachments), as it always was. With a `title`
|
|
71
|
+
* and an `icon` or an `illustration` it is the empty that IS the screen — a shop's empty cart,
|
|
72
|
+
* a portal's «no orders yet», a module the company has not used — where a lone grey sentence
|
|
73
|
+
* in the middle of a white page reads as broken. The picture is never the message: it is
|
|
74
|
+
* hidden from a screen reader, and the title says what the drawing shows.
|
|
75
|
+
*/
|
|
76
|
+
export function Empty({ sentence, action, align = "center", title, icon: Icon, illustration, }) {
|
|
43
77
|
const centered = align === "center";
|
|
44
|
-
|
|
78
|
+
const visual = illustration !== undefined ? (_jsx("div", { "aria-hidden": true, "data-ui": "empty.visual", className: "flex max-w-48 justify-center text-muted", children: illustration })) : Icon === undefined ? null : (_jsx("span", { "aria-hidden": true, "data-ui": "empty.visual", className: "flex size-14 items-center justify-center rounded-pill bg-ink/5 text-muted", children: _jsx(Icon, { className: "size-7", strokeWidth: 1.5 }) }));
|
|
79
|
+
/* The bare form keeps its old shape: a sentence and its action on one wrapping line. */
|
|
80
|
+
if (title === undefined && visual === null) {
|
|
81
|
+
return (_jsxs("div", { "data-ui": "empty", className: `flex flex-wrap gap-3 px-4 py-10 ${centered ? "flex-col items-center text-center" : "items-center"}`, children: [_jsx("p", { className: "max-w-short text-body text-muted", children: sentence }), action] }));
|
|
82
|
+
}
|
|
83
|
+
return (_jsxs("div", { "data-ui": "empty", "data-size": "page", className: `flex flex-col gap-3 px-4 py-12 ${centered ? "items-center text-center" : "items-start"}`, children: [visual, _jsxs("div", { className: `flex max-w-short flex-col gap-1 ${centered ? "items-center" : ""}`, children: [title === undefined ? null : (_jsx("p", { "data-ui": "empty.title", className: "text-lead font-semibold text-ink", children: title })), _jsx("p", { className: "text-body text-muted", children: sentence })] }), action === undefined ? null : (_jsx("div", { className: `flex flex-wrap gap-2 pt-1 ${centered ? "justify-center" : ""}`, children: action }))] }));
|
|
45
84
|
}
|
|
46
85
|
/**
|
|
47
86
|
* The sentence the backend wrote, whole and verbatim.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export { Banner, type BannerProps } from "./Banner.js";
|
|
1
2
|
export { Callout, type CalloutProps } from "./Callout.js";
|
|
2
3
|
export { Flag, type FlagProps, type FlagTone } from "./Flag.js";
|
|
3
|
-
export { Empty, Failed, ICONO_ROTO, Missing, Skeleton, } from "./Notice.js";
|
|
4
|
+
export { Empty, type EmptyProps, Failed, ICONO_ROTO, Missing, Skeleton, type SkeletonShape, } from "./Notice.js";
|
|
4
5
|
export { Outcome, type OutcomeProps } from "./Outcome.js";
|
|
5
6
|
export { ToastProvider, type ToastSpec, useToast, useToastIfAny, } from "./Toast.js";
|
|
7
|
+
export { type NoticeTone } from "./tones.js";
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/* How a view says that there is nothing, that it failed, or that nobody knows
|
|
2
2
|
how to draw it. */
|
|
3
|
+
/* A notice about the whole application, across the top of the frame (`AppFrame banner`). */
|
|
4
|
+
export { Banner } from "./Banner.js";
|
|
3
5
|
export { Callout } from "./Callout.js";
|
|
4
6
|
export { Flag } from "./Flag.js";
|
|
5
7
|
export { Empty, Failed, ICONO_ROTO, Missing, Skeleton, } from "./Notice.js";
|
|
6
8
|
/* The END of an operation, said big: a kiosk's «tu número es 118», a paid checkout. */
|
|
7
9
|
export { Outcome } from "./Outcome.js";
|
|
8
10
|
export { ToastProvider, useToast, useToastIfAny, } from "./Toast.js";
|
|
11
|
+
export {} from "./tones.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Tone } from "../../foundations/types.js";
|
|
2
|
+
import { type LucideIcon } from "lucide-react";
|
|
3
|
+
/** The four degrees of a notice that stays on screen — `Callout` inside a view, `Banner`
|
|
4
|
+
* across the whole application. */
|
|
5
|
+
export type NoticeTone = Extract<Tone, "info" | "warn" | "bad" | "good">;
|
|
6
|
+
export declare const NOTICE_ICON: Record<NoticeTone, LucideIcon>;
|
|
7
|
+
export declare const NOTICE_SKIN: Record<NoticeTone, string>;
|
|
8
|
+
export declare const NOTICE_DISMISS = "hit-target -mr-1 shrink-0 rounded-control p-0.5 text-muted transition-colors duration-(--duration-instant) hover:bg-ink/6 hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AlertTriangle, CheckCircle2, Info, OctagonAlert, } from "lucide-react";
|
|
2
|
+
/* Context: one table for both, so the same urgency is painted the same way in a view and
|
|
3
|
+
across the frame. The icon comes from the tone and is not chosen: a red notice with a green
|
|
4
|
+
tick inside is a contradiction someone will write if we let them. */
|
|
5
|
+
export const NOTICE_ICON = {
|
|
6
|
+
info: Info,
|
|
7
|
+
warn: AlertTriangle,
|
|
8
|
+
bad: OctagonAlert,
|
|
9
|
+
good: CheckCircle2,
|
|
10
|
+
};
|
|
11
|
+
/* The background is a layer of the colour over what is below and not a colour of its own: the
|
|
12
|
+
notice reads on the floor and on white paper without two sets of tokens, and keeps working
|
|
13
|
+
the day the palette changes. The text stays ink — the tone is on the icon and the edge. */
|
|
14
|
+
export const NOTICE_SKIN = {
|
|
15
|
+
info: "border-info/25 bg-info/8 text-info",
|
|
16
|
+
warn: "border-warn/30 bg-warn/10 text-warn",
|
|
17
|
+
bad: "border-bad/25 bg-bad/8 text-bad",
|
|
18
|
+
good: "border-good/25 bg-good/8 text-good",
|
|
19
|
+
};
|
|
20
|
+
/* The × answers to a whole target (`hit-target`) though it is drawn at 18px, and shows where
|
|
21
|
+
the focus is — it had no ring, so a keyboard reached it unseen. */
|
|
22
|
+
export const NOTICE_DISMISS = "hit-target -mr-1 shrink-0 rounded-control p-0.5 text-muted transition-colors duration-(--duration-instant) hover:bg-ink/6 hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary";
|
|
@@ -7,6 +7,7 @@ import { Switch } from "../choice/Switch.js";
|
|
|
7
7
|
import { CellCopy } from "./CellCopy.js";
|
|
8
8
|
import { CellEditor } from "./CellEditor.js";
|
|
9
9
|
import { EditRow, firstControl } from "./EditableTable.js";
|
|
10
|
+
import { levelNameOf } from "./levels.js";
|
|
10
11
|
import { PileFootLine } from "./PileFootLine.js";
|
|
11
12
|
import { RowActions } from "./RowActions.js";
|
|
12
13
|
import { useRowWindow } from "./rowWindow.js";
|
|
@@ -187,7 +188,7 @@ function entriesOfPiles(piles, columns, keyOf, collapsed, onToggle, onMore) {
|
|
|
187
188
|
kind: "pile",
|
|
188
189
|
id: `\u0000pile${key}`,
|
|
189
190
|
depth: pile.depth,
|
|
190
|
-
level: pile.field,
|
|
191
|
+
level: levelNameOf(pile.field, columns),
|
|
191
192
|
label: pile.label,
|
|
192
193
|
count: pile.count,
|
|
193
194
|
detail: pile.detail,
|
|
@@ -2,6 +2,7 @@ export { CELL_TONE } from "./cellTone.js";
|
|
|
2
2
|
export { type Aggregate, type DataColumn, DataTable, type DataTableCreate, type GroupColumn, type YesNoColumn, } from "./DataTable.js";
|
|
3
3
|
export { EditableTable, type EditAdd, type EditBands, type EditCellState, type EditColumn, type EditFlag, type EditLayout, type EditRowState, } from "./EditableTable.js";
|
|
4
4
|
export { sectionLines, type StackPlace, stackPlaces, type TabTarget, tabTarget, } from "./editRules.js";
|
|
5
|
+
export { levelNameOf } from "./levels.js";
|
|
5
6
|
export { PileFootLine } from "./PileFootLine.js";
|
|
6
7
|
export { PivotTable, type PivotTableProps, } from "./PivotTable.js";
|
|
7
8
|
export { type ReportColumn, type ReportRow, type ReportRowKind, ReportTable, } from "./ReportTable.js";
|
|
@@ -4,6 +4,7 @@ export { CELL_TONE } from "./cellTone.js";
|
|
|
4
4
|
export { DataTable, } from "./DataTable.js";
|
|
5
5
|
export { EditableTable, } from "./EditableTable.js";
|
|
6
6
|
export { sectionLines, stackPlaces, tabTarget, } from "./editRules.js";
|
|
7
|
+
export { levelNameOf } from "./levels.js";
|
|
7
8
|
export { PileFootLine } from "./PileFootLine.js";
|
|
8
9
|
export { PivotTable, } from "./PivotTable.js";
|
|
9
10
|
export { ReportTable, } from "./ReportTable.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a level of a grouping reads: by the header of the column that answers for its field — the
|
|
3
|
+
* word the person reads over that column («Estado») —, never the field's key («status»). A field
|
|
4
|
+
* no column shows reads as itself. A table's pile, a list's group header and a report's group
|
|
5
|
+
* line all name their level this way.
|
|
6
|
+
*
|
|
7
|
+
* levelNameOf("status", [{ id: "status", header: "Estado", … }]) -> "Estado"
|
|
8
|
+
*/
|
|
9
|
+
export declare function levelNameOf(field: string, columns: readonly {
|
|
10
|
+
id: string;
|
|
11
|
+
field?: string | undefined;
|
|
12
|
+
header: string;
|
|
13
|
+
}[] | undefined): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a level of a grouping reads: by the header of the column that answers for its field — the
|
|
3
|
+
* word the person reads over that column («Estado») —, never the field's key («status»). A field
|
|
4
|
+
* no column shows reads as itself. A table's pile, a list's group header and a report's group
|
|
5
|
+
* line all name their level this way.
|
|
6
|
+
*
|
|
7
|
+
* levelNameOf("status", [{ id: "status", header: "Estado", … }]) -> "Estado"
|
|
8
|
+
*/
|
|
9
|
+
export function levelNameOf(field, columns) {
|
|
10
|
+
return (columns?.find((column) => column.id === field || column.field === field)?.header ?? field);
|
|
11
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare const SIZE: {
|
|
2
|
+
readonly sm: "text-body";
|
|
3
|
+
readonly md: "text-lead";
|
|
4
|
+
readonly lg: "text-display";
|
|
5
|
+
};
|
|
6
|
+
export type PriceProps = {
|
|
7
|
+
value: number;
|
|
8
|
+
/** ISO 4217 — `BOB`, `USD`. Without it the number goes with two decimals and no symbol. */
|
|
9
|
+
currency?: string;
|
|
10
|
+
/** The price before: drawn struck through, beside the discount it makes. Not drawn when
|
|
11
|
+
* it is not higher — a «before» that is not more is not a discount. */
|
|
12
|
+
compareAt?: number;
|
|
13
|
+
/** What the price is for — «mes», «kg», «persona» — written after it: «Bs 120,00 / mes». */
|
|
14
|
+
per?: string;
|
|
15
|
+
size?: keyof typeof SIZE;
|
|
16
|
+
/** Any `Intl.NumberFormatOptions` over the currency's (no decimals for a whole price). */
|
|
17
|
+
format?: Intl.NumberFormatOptions;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A price as a shelf says it: the one to pay big, the one before struck through, and how much
|
|
21
|
+
* less in a tag — a product's card, a cart's line, a plan.
|
|
22
|
+
*
|
|
23
|
+
* Context: «Bs 80,00» beside «Bs 100,00» is a riddle until one is struck — and a struck
|
|
24
|
+
* number alone says nothing to a screen reader, so each is named («Antes», «Ahora»). The
|
|
25
|
+
* discount is computed, not written by hand: a «−25 %» typed beside 80 for 100 is how a shop
|
|
26
|
+
* ends up promising what it does not give (`discountPercent`, rounded down). In `good`: it is
|
|
27
|
+
* news in the person's favour, and the gold is kept for the action of buying it. Zero is
|
|
28
|
+
* «Gratis», not «Bs 0,00».
|
|
29
|
+
*/
|
|
30
|
+
export declare function Price({ value, currency, compareAt, per, size, format }: PriceProps): import("react").JSX.Element;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
4
|
+
import { Tag } from "../tag/Tag.js";
|
|
5
|
+
import { formatWith } from "./format.js";
|
|
6
|
+
import { discountPercent, formatPrice } from "./priceFormat.js";
|
|
7
|
+
const SIZE = {
|
|
8
|
+
/* A line of a cart, a row of a price list. */
|
|
9
|
+
sm: "text-body",
|
|
10
|
+
/* A product's card — the size of a card's figure. */
|
|
11
|
+
md: "text-lead",
|
|
12
|
+
/* A product's page, a plan's card: the price IS the figure of the screen. */
|
|
13
|
+
lg: "text-display",
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A price as a shelf says it: the one to pay big, the one before struck through, and how much
|
|
17
|
+
* less in a tag — a product's card, a cart's line, a plan.
|
|
18
|
+
*
|
|
19
|
+
* Context: «Bs 80,00» beside «Bs 100,00» is a riddle until one is struck — and a struck
|
|
20
|
+
* number alone says nothing to a screen reader, so each is named («Antes», «Ahora»). The
|
|
21
|
+
* discount is computed, not written by hand: a «−25 %» typed beside 80 for 100 is how a shop
|
|
22
|
+
* ends up promising what it does not give (`discountPercent`, rounded down). In `good`: it is
|
|
23
|
+
* news in the person's favour, and the gold is kept for the action of buying it. Zero is
|
|
24
|
+
* «Gratis», not «Bs 0,00».
|
|
25
|
+
*/
|
|
26
|
+
export function Price({ value, currency, compareAt, per, size = "md", format }) {
|
|
27
|
+
const copy = useUiCopy();
|
|
28
|
+
const write = (n) => formatPrice(n, { currency, format }, copy.locale);
|
|
29
|
+
const off = discountPercent(value, compareAt);
|
|
30
|
+
const before = off === undefined ? undefined : compareAt;
|
|
31
|
+
return (_jsxs("span", { "data-ui": "price", "data-size": size, className: "inline-flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5", children: [_jsxs("span", { className: `font-semibold whitespace-nowrap text-ink tabular-nums ${SIZE[size]}`, children: [before === undefined ? null : _jsxs("span", { className: "sr-only", children: [copy.price.now, " "] }), value === 0 ? copy.price.free : write(value), per === undefined ? null : (_jsxs("span", { className: "text-meta font-normal text-muted", children: [_jsx("span", { "aria-hidden": true, children: " / " }), _jsxs("span", { className: "sr-only", children: [" ", copy.price.per, " "] }), per] }))] }), before === undefined || off === undefined ? null : (_jsxs(_Fragment, { children: [_jsxs("del", { className: "text-meta whitespace-nowrap text-muted tabular-nums", "data-ui": "price.before", children: [_jsxs("span", { className: "sr-only", children: [copy.price.before, " "] }), write(before)] }), _jsx(Tag, { tone: "good", title: fillCopy(copy.price.off, { percent: String(off) }), children: formatWith(-off / 100, { style: "percent", signDisplay: "always" }, copy.locale) })] }))] }));
|
|
32
|
+
}
|