@sincpro/web-ui 2.12.0 → 2.14.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/README.md +56 -21
- 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 +3 -0
- package/dist/components/index.js +3 -0
- package/dist/components/listing/BoardColumns.js +10 -6
- package/dist/components/listing/ColumnsMenu.js +4 -2
- package/dist/components/listing/Listing.js +3 -1
- package/dist/components/listing/ListingBar.d.ts +16 -94
- package/dist/components/listing/ListingBar.js +24 -2
- package/dist/components/listing/RecordCard.d.ts +41 -3
- package/dist/components/listing/RecordCard.js +63 -22
- package/dist/components/listing/Row.js +5 -2
- package/dist/components/listing/columns.d.ts +3 -0
- package/dist/components/listing/columns.js +4 -0
- package/dist/components/listing/index.d.ts +2 -2
- package/dist/components/listing/index.js +2 -2
- package/dist/components/listing/set.d.ts +1 -1
- 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/receipt/Receipt.d.ts +51 -0
- package/dist/components/receipt/Receipt.js +23 -0
- package/dist/components/receipt/index.d.ts +1 -0
- package/dist/components/receipt/index.js +3 -0
- package/dist/components/search/CriteriaChips.d.ts +14 -1
- package/dist/components/search/CriteriaChips.js +123 -13
- 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 +27 -0
- package/dist/components/search/criteria.js +33 -0
- 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/KioskFrame.d.ts +35 -0
- package/dist/components/shell/KioskFrame.js +39 -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 +2 -0
- package/dist/components/shell/index.js +4 -0
- package/dist/foundations/clock.d.ts +3 -0
- package/dist/foundations/clock.js +41 -0
- package/dist/foundations/copy.es.js +86 -1
- package/dist/foundations/form.d.ts +7 -0
- package/dist/foundations/form.js +1 -0
- package/dist/foundations/idle.d.ts +1 -0
- package/dist/foundations/idle.js +34 -0
- package/dist/foundations/index.d.ts +3 -0
- package/dist/foundations/index.js +7 -0
- package/dist/foundations/pointer.d.ts +25 -0
- package/dist/foundations/pointer.js +28 -0
- package/dist/foundations/uiCopy.d.ts +123 -2
- package/dist/foundations/uiCopy.js +86 -1
- package/dist/primitives/choice/RadioGroup.d.ts +8 -1
- package/dist/primitives/choice/RadioGroup.js +38 -1
- 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 +7 -0
- package/dist/primitives/field/Field.js +1 -0
- package/dist/primitives/field/Keypad.d.ts +43 -0
- package/dist/primitives/field/Keypad.js +62 -0
- package/dist/primitives/field/Stepper.d.ts +28 -0
- package/dist/primitives/field/Stepper.js +52 -0
- package/dist/primitives/field/clipboard.js +1 -1
- package/dist/primitives/field/index.d.ts +3 -0
- package/dist/primitives/field/index.js +6 -0
- package/dist/primitives/field/keypadKeys.d.ts +24 -0
- package/dist/primitives/field/keypadKeys.js +80 -0
- package/dist/primitives/hint/Hint.js +1 -1
- 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/Flag.js +1 -1
- package/dist/primitives/notice/Notice.d.ts +38 -10
- package/dist/primitives/notice/Notice.js +48 -9
- package/dist/primitives/notice/Outcome.d.ts +28 -0
- package/dist/primitives/notice/Outcome.js +28 -0
- package/dist/primitives/notice/index.d.ts +4 -1
- package/dist/primitives/notice/index.js +5 -0
- package/dist/primitives/notice/tones.d.ts +8 -0
- package/dist/primitives/notice/tones.js +22 -0
- package/dist/primitives/table/CellCopy.js +1 -1
- package/dist/primitives/table/ReportTable.js +1 -1
- package/dist/primitives/table/RowActions.js +1 -1
- package/dist/primitives/table/Table.js +9 -5
- package/dist/primitives/tag/Tags.d.ts +22 -1
- package/dist/primitives/tag/Tags.js +57 -14
- package/dist/primitives/tag/index.d.ts +1 -1
- package/dist/primitives/value/Elapsed.d.ts +16 -0
- package/dist/primitives/value/Elapsed.js +37 -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/elapsedTime.d.ts +26 -0
- package/dist/primitives/value/elapsedTime.js +32 -0
- package/dist/primitives/value/index.d.ts +5 -0
- package/dist/primitives/value/index.js +10 -0
- package/dist/primitives/value/priceFormat.d.ts +12 -0
- package/dist/primitives/value/priceFormat.js +22 -0
- package/dist/tokens.css +126 -1
- package/dist/views/list/List.d.ts +11 -0
- package/dist/views/list/List.js +14 -3
- package/dist/views/list/ListView.d.ts +1 -1
- package/dist/views/list/ListView.js +48 -9
- package/dist/views/list/types.d.ts +15 -0
- package/dist/views/record/Record.js +1 -1
- package/package.json +3 -2
|
@@ -128,7 +128,7 @@ export function TrDetail({ children, detail, open, onToggle, columns, label, sel
|
|
|
128
128
|
return (_jsx(RowMark.Provider, { value: { selected, interactive: true }, children: _jsxs(_Fragment, { children: [_jsxs("tr", { onClick: onToggle, className: "group/row cursor-pointer", children: [_jsx("td", { className: `border-b border-line py-1.5 pr-0 pl-2.5 align-middle first:rounded-l-control ${rowWash({ selected, interactive: true })}`, children: _jsx("button", { type: "button", onClick: (e) => {
|
|
129
129
|
e.stopPropagation();
|
|
130
130
|
onToggle();
|
|
131
|
-
}, "aria-expanded": open, "aria-controls": id, "aria-label": label, className: "inline-flex size-5 items-center justify-center rounded-pill text-muted transition-colors duration-(--duration-instant) hover:bg-ink/6 hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary", children: _jsx(ChevronRight, { className: `size-(--size-icon-sm) transition-transform duration-(--duration-instant) ${open ? "rotate-90" : ""}`, strokeWidth: 2 }) }) }), children] }), _jsx("tr", { id: id, hidden: !open, children: _jsx("td", { colSpan: columns + 1, className: "border-b border-line bg-ground px-3 py-3", children: detail }) })] }) }));
|
|
131
|
+
}, "aria-expanded": open, "aria-controls": id, "aria-label": label, className: "hit-target inline-flex size-5 items-center justify-center rounded-pill text-muted transition-colors duration-(--duration-instant) hover:bg-ink/6 hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary", children: _jsx(ChevronRight, { className: `size-(--size-icon-sm) transition-transform duration-(--duration-instant) ${open ? "rotate-90" : ""}`, strokeWidth: 2 }) }) }), children] }), _jsx("tr", { id: id, hidden: !open, children: _jsx("td", { colSpan: columns + 1, className: "border-b border-line bg-ground px-3 py-3", children: detail }) })] }) }));
|
|
132
132
|
}
|
|
133
133
|
/* `CELL_TONE` is a plain table (`cellTone.ts`), without the directive, so a server component
|
|
134
134
|
reads it; re-exported so every path that read it here keeps reading it. */
|
|
@@ -159,8 +159,12 @@ tone, title, }) {
|
|
|
159
159
|
* three of forty rows selected lies in both directions — empty says «none»
|
|
160
160
|
* and filled says «all». */
|
|
161
161
|
export function SelectBox({ checked, indeterminate = false, onChange, label, }) {
|
|
162
|
-
return (
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
return (
|
|
163
|
+
/* The box is drawn small so a list keeps its density, and it answers to `--size-target`
|
|
164
|
+
around it (44px under a finger): the label is the target. A tap on it never reaches the
|
|
165
|
+
row, which would open the record instead of choosing it. */
|
|
166
|
+
_jsx("label", { className: "hit-target inline-flex shrink-0 cursor-pointer", onClick: (e) => e.stopPropagation(), children: _jsx("input", { type: "checkbox", checked: checked, "aria-label": label, ref: (el) => {
|
|
167
|
+
if (el !== null)
|
|
168
|
+
el.indeterminate = indeterminate && !checked;
|
|
169
|
+
}, onChange: (e) => onChange?.(e.target.checked), onClick: (e) => e.stopPropagation(), className: "size-3.5 shrink-0 cursor-pointer accent-primary touch:size-5" }) }));
|
|
166
170
|
}
|
|
@@ -19,6 +19,9 @@ export type TagItem = {
|
|
|
19
19
|
* the chip; this replaces the verb when the chip needs a more exact one
|
|
20
20
|
* («quitar el filtro»). */
|
|
21
21
|
removeLabel?: string;
|
|
22
|
+
/** How many records answer to it — «Bebidas 12», «Pagada 187». Drawn after the label in
|
|
23
|
+
* figures that line up, so a strip of filters reads as a small histogram. */
|
|
24
|
+
count?: number | string;
|
|
22
25
|
/** It is chosen right now. */
|
|
23
26
|
selected?: boolean;
|
|
24
27
|
/** It is MARKED by the keyboard of someone else — the search input that
|
|
@@ -31,7 +34,18 @@ export type TagItem = {
|
|
|
31
34
|
tone?: Tone;
|
|
32
35
|
title?: string;
|
|
33
36
|
};
|
|
34
|
-
|
|
37
|
+
/**
|
|
38
|
+
* How big a chip is drawn — a PLACE, like a button's size:
|
|
39
|
+
*
|
|
40
|
+
* sm a line of text: the chips of a field, of a search bar, of a row
|
|
41
|
+
* md a control of the bar: the quick filters over a list, a shop's facets
|
|
42
|
+
* lg a till's or a kiosk's categories — aimed at from arm's length
|
|
43
|
+
*
|
|
44
|
+
* `md` and `lg` are as tall as the controls (`--size-control-sm` / `-lg`), so under a finger
|
|
45
|
+
* they grow with the rest; `sm` grows to a size a thumb can aim at.
|
|
46
|
+
*/
|
|
47
|
+
export type TagsSize = "sm" | "md" | "lg";
|
|
48
|
+
export declare function Tags({ items, surface, label, labelledBy, stack, multiple, size, scroll, }: {
|
|
35
49
|
items: readonly TagItem[];
|
|
36
50
|
/** By default it inherits the surface that wraps it. */
|
|
37
51
|
surface?: Surface;
|
|
@@ -56,4 +70,11 @@ export declare function Tags({ items, surface, label, labelledBy, stack, multipl
|
|
|
56
70
|
* default the choice is ONE — a join, a grain, a period — and the strip is
|
|
57
71
|
* announced as single-select. */
|
|
58
72
|
multiple?: boolean;
|
|
73
|
+
size?: TagsSize;
|
|
74
|
+
/**
|
|
75
|
+
* One line that scrolls sideways, instead of wrapping. The categories of a till are read
|
|
76
|
+
* in a row and found by position — wrapped into three lines they move every time one is
|
|
77
|
+
* added. The edges fade while there is more to see.
|
|
78
|
+
*/
|
|
79
|
+
scroll?: boolean;
|
|
59
80
|
}): import("react").JSX.Element | null;
|
|
@@ -7,23 +7,38 @@ import { chosenTone, tagTone } from "./Tag.js";
|
|
|
7
7
|
import { Avatar } from "../value/Person.js";
|
|
8
8
|
import { X } from "lucide-react";
|
|
9
9
|
import { Button as AriaButton, Tag as AriaTag, TagGroup, TagList, } from "react-aria-components";
|
|
10
|
-
export function Tags({ items, surface, label, labelledBy, stack = false, multiple = false, }) {
|
|
10
|
+
export function Tags({ items, surface, label, labelledBy, stack = false, multiple = false, size = "sm", scroll = false, }) {
|
|
11
11
|
const sup = useSurface(surface);
|
|
12
12
|
if (items.length === 0)
|
|
13
13
|
return null;
|
|
14
14
|
const interactive = items.some((i) => i.onSelect !== undefined || i.onRemove !== undefined);
|
|
15
|
+
const layout = stack ? STACK : scroll ? SCROLL : STRIP[size];
|
|
15
16
|
if (!interactive)
|
|
16
|
-
return _jsx(StillStrip, { items: items, surface: sup, label: label, stack: stack });
|
|
17
|
-
return (_jsx(AriaLocale, { children: _jsx(ChipGroup, { items: items, surface: sup, label: label, labelledBy: labelledBy, stack: stack, multiple: multiple }) }));
|
|
17
|
+
return (_jsx(StillStrip, { items: items, surface: sup, label: label, stack: stack, layout: layout, size: size }));
|
|
18
|
+
return (_jsx(AriaLocale, { children: _jsx(ChipGroup, { items: items, surface: sup, label: label, labelledBy: labelledBy, stack: stack, multiple: multiple, layout: layout, size: size }) }));
|
|
18
19
|
}
|
|
19
|
-
const STRIP =
|
|
20
|
+
const STRIP = {
|
|
21
|
+
sm: "flex min-w-0 flex-wrap items-center gap-1",
|
|
22
|
+
md: "flex min-w-0 flex-wrap items-center gap-1.5",
|
|
23
|
+
lg: "flex min-w-0 flex-wrap items-center gap-2",
|
|
24
|
+
};
|
|
25
|
+
/* The fade at the edges is `scroll-hint`'s, over the surface the strip sits on; the bottom
|
|
26
|
+
padding keeps a focus ring from being clipped by the scroll box. */
|
|
27
|
+
const SCROLL = "scroll-hint scroll-quiet flex min-w-0 flex-nowrap items-center gap-2 overflow-x-auto py-1";
|
|
20
28
|
const STACK = "flex min-w-0 flex-col items-stretch gap-0.5";
|
|
21
29
|
/** A strip nobody presses: text in a row, a list only when it is named. */
|
|
22
|
-
function StillStrip({ items, surface, label, stack, }) {
|
|
30
|
+
function StillStrip({ items, surface, label, stack, layout, size, }) {
|
|
23
31
|
const listed = label !== undefined;
|
|
24
|
-
return (_jsx("span", { className:
|
|
32
|
+
return (_jsx("span", { className: layout, ...(listed ? { role: "list", "aria-label": label } : {}), children: items.map((item) => (_jsx("span", { "data-ui": "tags.item", ...(listed ? { role: "listitem" } : {}), ...(item.title === undefined ? {} : { title: item.title }), "data-size": size, className: shell({
|
|
33
|
+
item,
|
|
34
|
+
surface,
|
|
35
|
+
stack,
|
|
36
|
+
size,
|
|
37
|
+
removable: false,
|
|
38
|
+
pressable: false,
|
|
39
|
+
}), children: _jsx(Inside, { item: item }) }, item.id))) }));
|
|
25
40
|
}
|
|
26
|
-
function ChipGroup({ items, surface, label, labelledBy, stack, multiple, }) {
|
|
41
|
+
function ChipGroup({ items, surface, label, labelledBy, stack, multiple, layout, size, }) {
|
|
27
42
|
const byId = new Map(items.map((item) => [item.id, item]));
|
|
28
43
|
const removable = items.some((i) => i.onRemove !== undefined);
|
|
29
44
|
/* Selection is React Aria's only when the chips SAY whether they are chosen: then the
|
|
@@ -65,19 +80,29 @@ function ChipGroup({ items, surface, label, labelledBy, stack, multiple, }) {
|
|
|
65
80
|
: {}),
|
|
66
81
|
/* Escape belongs to whatever holds the strip — the popover it lives in closes with it —
|
|
67
82
|
and not to «clear the selection», which would erase the choice without a word. */
|
|
68
|
-
escapeKeyBehavior: "none", className: "min-w-0", children: _jsx(TagList, { items: items, className:
|
|
83
|
+
escapeKeyBehavior: "none", className: "min-w-0", children: _jsx(TagList, { items: items, className: layout, children: (item) => (_jsxs(AriaTag, { "data-ui": "tags.item", "data-size": size, id: item.id, textValue: item.note === undefined ? item.label : `${item.label} ${item.note}`, ...(!selecting && item.onSelect !== undefined
|
|
69
84
|
? { onAction: item.onSelect }
|
|
70
85
|
: {}), ...(item.title === undefined ? {} : { title: item.title }), className: ({ isFocusVisible, isHovered }) => cn(shell({
|
|
71
86
|
item,
|
|
72
87
|
surface,
|
|
73
88
|
stack,
|
|
89
|
+
size,
|
|
74
90
|
removable: item.onRemove !== undefined,
|
|
75
91
|
pressable: item.onSelect !== undefined,
|
|
76
|
-
}), item.onSelect !== undefined &&
|
|
92
|
+
}), item.onSelect !== undefined &&
|
|
93
|
+
isHovered &&
|
|
94
|
+
item.active !== true &&
|
|
95
|
+
!(item.selected === true && size !== "sm")
|
|
77
96
|
? bySurface(surface, "border-ink/40", "border-chrome-ink/40")
|
|
78
97
|
: "", "outline-offset-1", focusRing({ isFocusVisible })), children: [_jsx(Inside, { item: item }), item.onRemove === undefined ? null : _jsx(Remove, { item: item, surface: surface })] })) }) }));
|
|
79
98
|
}
|
|
80
|
-
function paint(item, surface) {
|
|
99
|
+
function paint(item, surface, size) {
|
|
100
|
+
/* A chosen chip of a filter row or a till's categories is the CHOICE the screen is in —
|
|
101
|
+
filled, like the chosen segment of a `SegmentedControl`. A chosen `sm` chip stays a tint:
|
|
102
|
+
there it is a value among values. */
|
|
103
|
+
if (item.selected === true && size !== "sm") {
|
|
104
|
+
return bySurface(surface, "border border-primary bg-primary text-surface", "border border-chrome-link bg-chrome-link text-chrome");
|
|
105
|
+
}
|
|
81
106
|
if (item.active === true) {
|
|
82
107
|
return bySurface(surface, "border border-primary bg-primary text-surface", "border border-chrome-link bg-chrome-link text-chrome");
|
|
83
108
|
}
|
|
@@ -90,18 +115,36 @@ function paint(item, surface) {
|
|
|
90
115
|
/* Stacked, each chip takes its whole line: a column of chips of different widths does not
|
|
91
116
|
read as a list, it reads as a mess — and the blank on the right is what lets it be
|
|
92
117
|
pressed without aiming. */
|
|
93
|
-
|
|
94
|
-
|
|
118
|
+
/* The height of each size, and the room the label gets inside it. `sm` is a line of text and
|
|
119
|
+
grows under a finger only if someone can press it. */
|
|
120
|
+
const SIZE = {
|
|
121
|
+
sm: { box: "gap-1 py-0.5 text-micro", pad: "px-2", removePad: "pr-0.5 pl-2" },
|
|
122
|
+
md: {
|
|
123
|
+
box: "h-(--size-control-sm) gap-1.5 text-meta",
|
|
124
|
+
pad: "px-3",
|
|
125
|
+
removePad: "pr-1.5 pl-3",
|
|
126
|
+
},
|
|
127
|
+
lg: {
|
|
128
|
+
box: "h-(--size-control-lg) gap-2 text-body font-medium",
|
|
129
|
+
pad: "px-4",
|
|
130
|
+
removePad: "pr-2 pl-4",
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
function shell({ item, surface, stack, size, removable, pressable, }) {
|
|
134
|
+
const box = SIZE[size];
|
|
135
|
+
return cn(stack ? "flex w-full justify-start" : "inline-flex shrink-0", "min-w-0 items-center rounded-ui-tag transition-colors duration-(--duration-instant)", box.box, size === "sm" && (pressable || removable) ? "touch:min-h-8 touch:text-meta" : "", paint(item, surface, size), removable ? box.removePad : box.pad, pressable ? "cursor-pointer" : "cursor-default");
|
|
95
136
|
}
|
|
96
137
|
function Inside({ item }) {
|
|
97
138
|
const Icon = item.icon;
|
|
98
139
|
return (_jsxs(_Fragment, { children: [Icon === undefined ? null : (_jsx(Icon, { className: "size-3 shrink-0 opacity-70", strokeWidth: 2, "aria-hidden": true })), item.avatar === undefined ? null : (_jsx("span", { "aria-hidden": true, className: "-my-0.5 -ml-1.5 flex shrink-0", children: _jsx(Avatar, { name: item.label, size: "sm", ...(typeof item.avatar === "string" ? { src: item.avatar } : {}) }) })), _jsx("span", { className: "min-w-0 truncate", children: item.label }), item.note === undefined ? null : (
|
|
99
140
|
/* Secondary by its separator and weight, not by fading: at 60 % the note fell
|
|
100
141
|
under 4.5:1 on a tinted chip. */
|
|
101
|
-
_jsxs("span", { className: "shrink-0 font-normal", children: ["\u00B7 ", item.note] }))
|
|
142
|
+
_jsxs("span", { className: "shrink-0 font-normal", children: ["\u00B7 ", item.note] })), item.count === undefined ? null : (
|
|
143
|
+
/* Apart by a gap and lighter, not dimmer — the same reason as the note. */
|
|
144
|
+
_jsx("span", { "data-ui": "tags.count", className: "shrink-0 font-normal tabular-nums", children: item.count }))] }));
|
|
102
145
|
}
|
|
103
146
|
/* The × is React Aria's `remove` slot: it removes THIS chip and never presses it, so
|
|
104
147
|
removing a pressable chip does not also choose it. */
|
|
105
148
|
function Remove({ item, surface }) {
|
|
106
|
-
return (_jsx(AriaButton, { slot: "remove", ...(item.removeLabel === undefined ? {} : { "aria-label": item.removeLabel }), className: ({ isFocusVisible }) => cn("inline-flex size-4 shrink-0 cursor-default items-center justify-center rounded-pill transition-colors duration-(--duration-instant)", bySurface(surface, "hover:bg-ink/15 pressed:bg-ink/20", "hover:bg-chrome-ink/25 pressed:bg-chrome-ink/30"), focusRing({ isFocusVisible })), children: _jsx(X, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }) }));
|
|
149
|
+
return (_jsx(AriaButton, { slot: "remove", ...(item.removeLabel === undefined ? {} : { "aria-label": item.removeLabel }), className: ({ isFocusVisible }) => cn("hit-target inline-flex size-4 shrink-0 cursor-default items-center justify-center rounded-pill transition-colors duration-(--duration-instant)", bySurface(surface, "hover:bg-ink/15 pressed:bg-ink/20", "hover:bg-chrome-ink/25 pressed:bg-chrome-ink/30"), focusRing({ isFocusVisible })), children: _jsx(X, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }) }));
|
|
107
150
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ElapsedSince, type ElapsedThresholds } from "./elapsedTime.js";
|
|
2
|
+
export type ElapsedProps = {
|
|
3
|
+
/** When the wait started. */
|
|
4
|
+
since: ElapsedSince;
|
|
5
|
+
/** For a test or a screenshot: a fixed «now» instead of the live clock. */
|
|
6
|
+
now?: number;
|
|
7
|
+
} & ElapsedThresholds;
|
|
8
|
+
/**
|
|
9
|
+
* How long it has been waiting, live: «4:05», amber past `warnAfter`, red past `badAfter`.
|
|
10
|
+
*
|
|
11
|
+
* Context: a kitchen display reads AGE, not arrival — the cook looks for the red ticket, not
|
|
12
|
+
* for «12:40». The figure ticks every second off one shared clock (`useNow`), and the clock
|
|
13
|
+
* icon with the written time keeps the colour from being the only channel. On the server it
|
|
14
|
+
* draws nothing: there is no «now» both sides agree on.
|
|
15
|
+
*/
|
|
16
|
+
export declare function Elapsed({ since, now: fixed, warnAfter, badAfter }: ElapsedProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useNow } from "../../foundations/clock.js";
|
|
4
|
+
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
5
|
+
import { elapsedMillis, elapsedTone, formatElapsed, } from "./elapsedTime.js";
|
|
6
|
+
import { Timer } from "lucide-react";
|
|
7
|
+
/* The figure in its tone — text on a card, so the readable ones. */
|
|
8
|
+
const TEXT = {
|
|
9
|
+
neutral: "text-muted",
|
|
10
|
+
info: "text-info",
|
|
11
|
+
good: "text-good",
|
|
12
|
+
warn: "text-warn",
|
|
13
|
+
bad: "text-bad",
|
|
14
|
+
accent: "text-ink",
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* How long it has been waiting, live: «4:05», amber past `warnAfter`, red past `badAfter`.
|
|
18
|
+
*
|
|
19
|
+
* Context: a kitchen display reads AGE, not arrival — the cook looks for the red ticket, not
|
|
20
|
+
* for «12:40». The figure ticks every second off one shared clock (`useNow`), and the clock
|
|
21
|
+
* icon with the written time keeps the colour from being the only channel. On the server it
|
|
22
|
+
* draws nothing: there is no «now» both sides agree on.
|
|
23
|
+
*/
|
|
24
|
+
export function Elapsed({ since, now: fixed, warnAfter, badAfter }) {
|
|
25
|
+
const copy = useUiCopy();
|
|
26
|
+
const live = useNow();
|
|
27
|
+
const now = fixed ?? live;
|
|
28
|
+
if (now === null)
|
|
29
|
+
return null;
|
|
30
|
+
const millis = elapsedMillis(since, now);
|
|
31
|
+
const tone = elapsedTone(millis, {
|
|
32
|
+
...(warnAfter === undefined ? {} : { warnAfter }),
|
|
33
|
+
...(badAfter === undefined ? {} : { badAfter }),
|
|
34
|
+
});
|
|
35
|
+
const text = formatElapsed(millis);
|
|
36
|
+
return (_jsxs("span", { "data-ui": "elapsed", "data-tone": tone ?? "neutral", title: fillCopy(copy.elapsed.waiting, { time: text }), className: `inline-flex shrink-0 items-center gap-1 text-meta font-semibold tabular-nums ${TEXT[tone ?? "neutral"]}`, children: [_jsx(Timer, { "aria-hidden": true, className: "size-(--size-icon-sm)", strokeWidth: 2.25 }), _jsx("span", { className: "sr-only", children: copy.elapsed.label }), text] }));
|
|
37
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
declare const SIZE: {
|
|
3
|
+
readonly sm: "size-28";
|
|
4
|
+
readonly md: "size-44";
|
|
5
|
+
readonly lg: "size-64";
|
|
6
|
+
};
|
|
7
|
+
export type QrCodeProps = {
|
|
8
|
+
/** What the code carries: a payment's string, an invoice's URL, a record's link. */
|
|
9
|
+
value: string;
|
|
10
|
+
/** What it is, said: «QR para pagar Bs 46,00». It is the image's name — a code is not
|
|
11
|
+
* readable by a person, so the words are the only way to know what it does. */
|
|
12
|
+
label: string;
|
|
13
|
+
size?: keyof typeof SIZE;
|
|
14
|
+
/** How much of it may be covered or worn and still read: `M` (15 %) by default; `H` (30 %)
|
|
15
|
+
* for a printed code that will be folded or scratched. */
|
|
16
|
+
level?: "L" | "M" | "Q" | "H";
|
|
17
|
+
/** A line under it: the amount, «Vence en 10 min». */
|
|
18
|
+
caption?: ReactNode;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A QR code — a payment by QR at a till or a portal, an invoice's verification link, a record
|
|
22
|
+
* to open on a phone.
|
|
23
|
+
*
|
|
24
|
+
* Context: QR is how much of Bolivia pays, so a till, a kiosk and an invoice draw one. The
|
|
25
|
+
* encoder (`uqr`, no dependencies) is reached with `import()` when a code is drawn: a screen
|
|
26
|
+
* without one never fetches it. The code is drawn here, as one SVG path in the system's two
|
|
27
|
+
* QR colours — black on white in BOTH themes, because a scanner reads dark on light — with its
|
|
28
|
+
* quiet zone, so it scans on a dark page. Until the encoder arrives (and on the server) a
|
|
29
|
+
* silent square holds its place. It is an image named by `label`: the words say what it does.
|
|
30
|
+
*/
|
|
31
|
+
export declare function QrCode({ value, label, size, level, caption }: QrCodeProps): import("react").JSX.Element;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
const SIZE = {
|
|
5
|
+
/* A receipt's corner, an invoice's footer. */
|
|
6
|
+
sm: "size-28",
|
|
7
|
+
/* A payment on a till's screen, a portal's «pagar con QR». */
|
|
8
|
+
md: "size-44",
|
|
9
|
+
/* A customer display, a kiosk: read from a step away. */
|
|
10
|
+
lg: "size-64",
|
|
11
|
+
};
|
|
12
|
+
/** The four modules of white around the code that a scanner needs to find it. */
|
|
13
|
+
const QUIET = 4;
|
|
14
|
+
/** One path for every dark module, in the code's own units. */
|
|
15
|
+
function modulesPath(data) {
|
|
16
|
+
let d = "";
|
|
17
|
+
data.forEach((row, y) => {
|
|
18
|
+
row.forEach((dark, x) => {
|
|
19
|
+
if (dark)
|
|
20
|
+
d += `M${x + QUIET} ${y + QUIET}h1v1h-1z`;
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
return d;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A QR code — a payment by QR at a till or a portal, an invoice's verification link, a record
|
|
27
|
+
* to open on a phone.
|
|
28
|
+
*
|
|
29
|
+
* Context: QR is how much of Bolivia pays, so a till, a kiosk and an invoice draw one. The
|
|
30
|
+
* encoder (`uqr`, no dependencies) is reached with `import()` when a code is drawn: a screen
|
|
31
|
+
* without one never fetches it. The code is drawn here, as one SVG path in the system's two
|
|
32
|
+
* QR colours — black on white in BOTH themes, because a scanner reads dark on light — with its
|
|
33
|
+
* quiet zone, so it scans on a dark page. Until the encoder arrives (and on the server) a
|
|
34
|
+
* silent square holds its place. It is an image named by `label`: the words say what it does.
|
|
35
|
+
*/
|
|
36
|
+
export function QrCode({ value, label, size = "md", level = "M", caption }) {
|
|
37
|
+
const [code, setCode] = useState(null);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
let live = true;
|
|
40
|
+
void import("uqr").then(({ encode }) => {
|
|
41
|
+
if (!live)
|
|
42
|
+
return;
|
|
43
|
+
const { data, size: side } = encode(value, { ecc: level, border: 0 });
|
|
44
|
+
setCode({ value, level, path: modulesPath(data), side });
|
|
45
|
+
});
|
|
46
|
+
return () => {
|
|
47
|
+
live = false;
|
|
48
|
+
};
|
|
49
|
+
}, [value, level]);
|
|
50
|
+
const ready = code !== null && code.value === value && code.level === level;
|
|
51
|
+
const box = code === null ? 0 : code.side + QUIET * 2;
|
|
52
|
+
return (_jsxs("figure", { "data-ui": "qr", "data-size": size, className: "inline-flex flex-col items-center gap-2", children: [_jsx("div", { role: "img", "aria-label": label, className: `overflow-hidden rounded-control ${SIZE[size]} ${ready ? "bg-qr-paper" : "animate-reveal-late bg-ink/5"}`, children: ready ? (_jsx("svg", { viewBox: `0 0 ${box} ${box}`, className: "size-full", shapeRendering: "crispEdges", "aria-hidden": true, children: _jsx("path", { d: code.path, className: "fill-qr-ink" }) })) : null }), caption === undefined ? null : (_jsx("figcaption", { className: "text-meta text-ink tabular-nums", children: caption }))] }));
|
|
53
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Tone } from "../../foundations/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* HOW LONG IT HAS BEEN WAITING — the arithmetic of `Elapsed`, pure so a server, a test or a
|
|
4
|
+
* sort can use it: «the oldest ticket first» is the same subtraction.
|
|
5
|
+
*
|
|
6
|
+
* Context: a kitchen's ticket, a support case under an SLA, an order at the counter. What is
|
|
7
|
+
* read is not the hour it arrived but how long ago, and whether that is already too long — so
|
|
8
|
+
* the time carries a tone by two thresholds the domain sets (in minutes): `warnAfter` turns it
|
|
9
|
+
* amber, `badAfter` red. The colour is never alone: the figure is always written.
|
|
10
|
+
*/
|
|
11
|
+
/** When it started: a `Date`, an ISO string or epoch milliseconds — what a record carries. */
|
|
12
|
+
export type ElapsedSince = Date | string | number;
|
|
13
|
+
/** The two thresholds, in minutes. Without them the time has no tone: it only informs. */
|
|
14
|
+
export type ElapsedThresholds = {
|
|
15
|
+
warnAfter?: number;
|
|
16
|
+
badAfter?: number;
|
|
17
|
+
};
|
|
18
|
+
export declare function sinceMillis(since: ElapsedSince): number;
|
|
19
|
+
/** Milliseconds from `since` to `now`; never negative — a clock a little behind the server's
|
|
20
|
+
* must not write «-0:03». */
|
|
21
|
+
export declare function elapsedMillis(since: ElapsedSince, now: number): number;
|
|
22
|
+
/** «4:05» under an hour, «1:02:03» over it — the way a stopwatch reads, in figures that line up. */
|
|
23
|
+
export declare function formatElapsed(millis: number): string;
|
|
24
|
+
/** The tone of a wait: `bad` past `badAfter`, `warn` past `warnAfter`, `good` before them,
|
|
25
|
+
* and `undefined` when no threshold was given (it only informs). */
|
|
26
|
+
export declare function elapsedTone(millis: number, limits: ElapsedThresholds): Tone | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function sinceMillis(since) {
|
|
2
|
+
return since instanceof Date ? since.getTime() : new Date(since).getTime();
|
|
3
|
+
}
|
|
4
|
+
/** Milliseconds from `since` to `now`; never negative — a clock a little behind the server's
|
|
5
|
+
* must not write «-0:03». */
|
|
6
|
+
export function elapsedMillis(since, now) {
|
|
7
|
+
return Math.max(0, now - sinceMillis(since));
|
|
8
|
+
}
|
|
9
|
+
/** «4:05» under an hour, «1:02:03» over it — the way a stopwatch reads, in figures that line up. */
|
|
10
|
+
export function formatElapsed(millis) {
|
|
11
|
+
const total = Math.floor(millis / 1000);
|
|
12
|
+
const hours = Math.floor(total / 3600);
|
|
13
|
+
const minutes = Math.floor((total % 3600) / 60);
|
|
14
|
+
const seconds = total % 60;
|
|
15
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
16
|
+
return hours > 0
|
|
17
|
+
? `${hours}:${pad(minutes)}:${pad(seconds)}`
|
|
18
|
+
: `${minutes}:${pad(seconds)}`;
|
|
19
|
+
}
|
|
20
|
+
/** The tone of a wait: `bad` past `badAfter`, `warn` past `warnAfter`, `good` before them,
|
|
21
|
+
* and `undefined` when no threshold was given (it only informs). */
|
|
22
|
+
export function elapsedTone(millis, limits) {
|
|
23
|
+
const { warnAfter, badAfter } = limits;
|
|
24
|
+
if (warnAfter === undefined && badAfter === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
const minutes = millis / 60_000;
|
|
27
|
+
if (badAfter !== undefined && minutes >= badAfter)
|
|
28
|
+
return "bad";
|
|
29
|
+
if (warnAfter !== undefined && minutes >= warnAfter)
|
|
30
|
+
return "warn";
|
|
31
|
+
return "good";
|
|
32
|
+
}
|
|
@@ -6,11 +6,16 @@ export { Meter, type MeterProps } from "./Meter.js";
|
|
|
6
6
|
export { type MeterLevel, meterLevel, type MeterThresholds, } from "./meterLevel.js";
|
|
7
7
|
export { Metric, type MetricProps, Metrics } from "./Metric.js";
|
|
8
8
|
export { Avatar, type AvatarSize, type PersonContact, UserChip, type UserChipProps, UserStack, } from "./Person.js";
|
|
9
|
+
export { Price, type PriceProps } from "./Price.js";
|
|
10
|
+
export { discountPercent, formatPrice } from "./priceFormat.js";
|
|
9
11
|
export { ProgressBar, type ProgressBarProps, } from "./ProgressBar.js";
|
|
12
|
+
export { QrCode, type QrCodeProps } from "./QrCode.js";
|
|
10
13
|
export { RelationCard, type RelationCardProps, type RelationSummary, RelationValue, type RelationValueProps, } from "./Relation.js";
|
|
11
14
|
export { RichTextValue, sanitizeRichText } from "./RichText.js";
|
|
12
15
|
export { isRichTextEmpty, richTextPlain, } from "./richTextPlain.js";
|
|
13
16
|
export { type Rounding, type RoundingMethod, roundTo, } from "./rounding.js";
|
|
17
|
+
export { Elapsed, type ElapsedProps } from "./Elapsed.js";
|
|
18
|
+
export { elapsedMillis, type ElapsedSince, type ElapsedThresholds, elapsedTone, formatElapsed, sinceMillis, } from "./elapsedTime.js";
|
|
14
19
|
export { Totals, type TotalsCredit, type TotalsDeduction, type TotalsFact, type TotalsProps, type TotalsRow, } from "./Totals.js";
|
|
15
20
|
export { Cell, KeyValue, Numeric } from "./Value.js";
|
|
16
21
|
export { YesNo, type YesNoLook } from "./YesNo.js";
|
|
@@ -9,12 +9,22 @@ export { Meter } from "./Meter.js";
|
|
|
9
9
|
export { meterLevel, } from "./meterLevel.js";
|
|
10
10
|
export { Metric, Metrics } from "./Metric.js";
|
|
11
11
|
export { Avatar, UserChip, UserStack, } from "./Person.js";
|
|
12
|
+
/* A price as a shelf says it: the one to pay, the one before struck through, how much less. */
|
|
13
|
+
export { Price } from "./Price.js";
|
|
14
|
+
export { discountPercent, formatPrice } from "./priceFormat.js";
|
|
15
|
+
/* A QR — a payment, an invoice's link — black on white in both themes; the encoder loads
|
|
16
|
+
when one is drawn. */
|
|
12
17
|
export { ProgressBar, } from "./ProgressBar.js";
|
|
18
|
+
export { QrCode } from "./QrCode.js";
|
|
13
19
|
export { RelationCard, RelationValue, } from "./Relation.js";
|
|
14
20
|
/* The HTML of a note, read — cleaned of anything that runs. */
|
|
15
21
|
export { RichTextValue, sanitizeRichText } from "./RichText.js";
|
|
16
22
|
export { isRichTextEmpty, richTextPlain, } from "./richTextPlain.js";
|
|
17
23
|
export { roundTo, } from "./rounding.js";
|
|
24
|
+
/* HOW LONG IT HAS BEEN WAITING — a kitchen's ticket, a case under an SLA: live, in a tone by
|
|
25
|
+
two thresholds. The arithmetic is pure (`elapsedTime.ts`), so a sort or a server reads it. */
|
|
26
|
+
export { Elapsed } from "./Elapsed.js";
|
|
27
|
+
export { elapsedMillis, elapsedTone, formatElapsed, sinceMillis, } from "./elapsedTime.js";
|
|
18
28
|
export { Totals, } from "./Totals.js";
|
|
19
29
|
export { Cell, KeyValue, Numeric } from "./Value.js";
|
|
20
30
|
export { YesNo } from "./YesNo.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** How much less the price is than the one before, as a whole percentage — `undefined` when
|
|
2
|
+
* it is not less (a «before» equal or lower is not a discount, and is not drawn as one).
|
|
3
|
+
*
|
|
4
|
+
* Context: rounded DOWN, never to the nearest: 80 for 99 is 19.2 % — «−20 %» would promise
|
|
5
|
+
* more than the shelf gives, and a price is a promise. */
|
|
6
|
+
export declare function discountPercent(value: number, compareAt: number | undefined): number | undefined;
|
|
7
|
+
/** A price written in the session's locale: with its currency when there is one («Bs 80,00»),
|
|
8
|
+
* with two decimals when there is none. `format` overrides either. */
|
|
9
|
+
export declare function formatPrice(value: number, { currency, format }?: {
|
|
10
|
+
currency?: string;
|
|
11
|
+
format?: Intl.NumberFormatOptions;
|
|
12
|
+
}, locale?: string): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { currentCopyLocale } from "../../foundations/uiCopy.js";
|
|
2
|
+
import { formatWith } from "./format.js";
|
|
3
|
+
/** How much less the price is than the one before, as a whole percentage — `undefined` when
|
|
4
|
+
* it is not less (a «before» equal or lower is not a discount, and is not drawn as one).
|
|
5
|
+
*
|
|
6
|
+
* Context: rounded DOWN, never to the nearest: 80 for 99 is 19.2 % — «−20 %» would promise
|
|
7
|
+
* more than the shelf gives, and a price is a promise. */
|
|
8
|
+
export function discountPercent(value, compareAt) {
|
|
9
|
+
if (compareAt === undefined || !(compareAt > 0) || !(value < compareAt) || value < 0) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const off = Math.floor(((compareAt - value) / compareAt) * 100);
|
|
13
|
+
return off > 0 ? off : undefined;
|
|
14
|
+
}
|
|
15
|
+
/** A price written in the session's locale: with its currency when there is one («Bs 80,00»),
|
|
16
|
+
* with two decimals when there is none. `format` overrides either. */
|
|
17
|
+
export function formatPrice(value, { currency, format } = {}, locale = currentCopyLocale()) {
|
|
18
|
+
const options = currency === undefined
|
|
19
|
+
? { minimumFractionDigits: 2, maximumFractionDigits: 2, ...format }
|
|
20
|
+
: { style: "currency", currency, ...format };
|
|
21
|
+
return formatWith(value, options, locale);
|
|
22
|
+
}
|