@sincpro/web-ui 2.13.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 +15 -5
- 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 +118 -10
- 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/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/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 +22 -3
- package/dist/views/list/types.d.ts +8 -0
- package/package.json +3 -2
|
@@ -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";
|
|
@@ -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
|
+
}
|
|
@@ -6,7 +6,10 @@ 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";
|
|
@@ -9,7 +9,13 @@ 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";
|
|
@@ -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
|
+
}
|