@sincpro/web-ui 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -0
- package/dist/components/attachments/Attachments.d.ts +7 -1
- package/dist/components/attachments/Attachments.js +8 -2
- package/dist/components/board/Board.d.ts +32 -2
- package/dist/components/board/Board.js +27 -4
- package/dist/components/board/index.d.ts +1 -1
- package/dist/components/board/index.js +2 -1
- package/dist/components/listing/Row.js +2 -2
- package/dist/components/navigation/NavigationTree.js +2 -2
- package/dist/components/search/SearchBar.js +30 -7
- package/dist/components/shell/AppFrame.d.ts +9 -2
- package/dist/components/shell/AppFrame.js +99 -11
- package/dist/components/shell/Sidebar.d.ts +34 -0
- package/dist/components/shell/Sidebar.js +32 -0
- package/dist/components/shell/TopBar.d.ts +2 -0
- package/dist/components/shell/TopBar.js +13 -9
- package/dist/components/shell/index.d.ts +2 -0
- package/dist/components/shell/index.js +4 -0
- package/dist/components/shell/sidebarDrawer.d.ts +26 -0
- package/dist/components/shell/sidebarDrawer.js +22 -0
- package/dist/foundations/copy.d.ts +13 -0
- package/dist/foundations/copy.es.js +9 -2
- package/dist/foundations/copy.js +9 -2
- package/dist/primitives/field/DropZone.d.ts +22 -3
- package/dist/primitives/field/DropZone.js +33 -12
- package/dist/primitives/menu/Menu.d.ts +7 -3
- package/dist/primitives/menu/Menu.js +4 -3
- package/dist/primitives/tabs/Tabs.js +2 -28
- package/dist/primitives/tag/Count.d.ts +23 -0
- package/dist/primitives/tag/Count.js +59 -0
- package/dist/primitives/tag/index.d.ts +1 -0
- package/dist/primitives/tag/index.js +3 -0
- package/dist/primitives/value/Metric.d.ts +7 -2
- package/dist/primitives/value/Metric.js +12 -4
- package/dist/tokens.css +147 -40
- package/package.json +1 -1
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { SidebarToggle } from "./sidebarDrawer.js";
|
|
3
4
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
5
|
import { SurfaceProvider } from "../../foundations/surface.js";
|
|
5
6
|
import { Menu } from "../../primitives/menu/Menu.js";
|
|
7
|
+
import { Count, countText } from "../../primitives/tag/Count.js";
|
|
6
8
|
import { Avatar } from "../../primitives/value/Person.js";
|
|
7
9
|
import { Grid3x3 } from "lucide-react";
|
|
8
|
-
import { useState } from "react";
|
|
10
|
+
import { useMemo, useState } from "react";
|
|
9
11
|
export function TopBar({ app, apps, currentApp, onAppSelect, menus, onMenuSelect, systray, user, onUserSelect, userGroups, }) {
|
|
10
12
|
const copy = useUiCopy();
|
|
11
13
|
const actual = apps?.find((a) => a.id === currentApp);
|
|
12
14
|
const brand = app ?? actual;
|
|
13
|
-
return (_jsx(SurfaceProvider, { value: "chrome", children: _jsxs("header", { className: "flex h-(--size-appbar) min-w-0 items-center gap-1 border-b border-chrome-edge bg-chrome px-2", children: [apps === undefined || apps.length === 0 ? null : (_jsx(AppSwitcher, { apps: apps, current: currentApp, ...(onAppSelect === undefined ? {} : { onSelect: onAppSelect }) })), brand === undefined ? null : (_jsxs("span", { className: "flex shrink-0 items-center gap-2 pr-2 pl-1", children: [brand.icon === undefined ? null : (_jsx(brand.icon, { className: "size-(--size-icon-md) text-chrome-link", strokeWidth: 2, "aria-hidden": true })), _jsx("span", { className: "text-lead font-medium text-chrome-ink", children: brand.label })] })), menus === undefined ? null : (_jsx("nav", { className: "scroll-quiet flex min-w-0 items-center gap-0.5", "aria-label": copy.shell.menus, children: menus.map((m) => (_jsx(Menu, { label: m.label, groups: m.groups, surface: "chrome", variant: "text", chevron: false, onSelect: (id) => onMenuSelect?.(m.id, id) }, m.id))) })), _jsxs("div", { className: "ml-auto flex shrink-0 items-center gap-1 pl-2", children: [systray, user === undefined ? null : (_jsx(UserMenu, { name: user.name, ...(user.detail === undefined ? {} : { detail: user.detail }), groups: userGroups ?? [], ...(onUserSelect === undefined ? {} : { onSelect: onUserSelect }) }))] })] }) }));
|
|
15
|
+
return (_jsx(SurfaceProvider, { value: "chrome", children: _jsxs("header", { className: "flex h-(--size-appbar) min-w-0 items-center gap-1 border-b border-chrome-edge bg-chrome px-2", children: [_jsx(SidebarToggle, {}), apps === undefined || apps.length === 0 ? null : (_jsx(AppSwitcher, { apps: apps, current: currentApp, ...(onAppSelect === undefined ? {} : { onSelect: onAppSelect }) })), brand === undefined ? null : (_jsxs("span", { className: "flex shrink-0 items-center gap-2 pr-2 pl-1", children: [brand.icon === undefined ? null : (_jsx(brand.icon, { className: "size-(--size-icon-md) text-chrome-link", strokeWidth: 2, "aria-hidden": true })), _jsx("span", { className: "text-lead font-medium text-chrome-ink", children: brand.label })] })), menus === undefined ? null : (_jsx("nav", { className: "scroll-quiet flex min-w-0 items-center gap-0.5", "aria-label": copy.shell.menus, children: menus.map((m) => (_jsx(Menu, { label: m.label, groups: m.groups, surface: "chrome", variant: "text", chevron: false, ...(m.count === undefined ? {} : { count: m.count }), onSelect: (id) => onMenuSelect?.(m.id, id) }, m.id))) })), _jsxs("div", { className: "ml-auto flex shrink-0 items-center gap-1 pl-2", children: [systray, user === undefined ? null : (_jsx(UserMenu, { name: user.name, ...(user.detail === undefined ? {} : { detail: user.detail }), groups: userGroups ?? [], ...(onUserSelect === undefined ? {} : { onSelect: onUserSelect }) }))] })] }) }));
|
|
14
16
|
}
|
|
15
17
|
/** The app switcher: a grid, not a list.
|
|
16
18
|
*
|
|
@@ -31,20 +33,22 @@ export function AppSwitcher({ apps, current, onSelect, }) {
|
|
|
31
33
|
}, className: `flex flex-col items-center gap-1.5 rounded-box px-2 py-3 text-center transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${here ? "bg-primary/8 text-primary" : "text-ink hover:bg-ink/5"}`, children: [_jsx(a.icon, { className: "size-(--size-icon-lg)", strokeWidth: 1.75, "aria-hidden": true }), _jsx("span", { className: "text-micro leading-tight", children: a.label })] }, a.id));
|
|
32
34
|
}) })] }))] }));
|
|
33
35
|
}
|
|
36
|
+
/** A badge over an icon is read in a glance: past two digits it says «a lot». */
|
|
37
|
+
const SYSTRAY_MAX = 99;
|
|
34
38
|
/** A systray icon with its count.
|
|
35
39
|
*
|
|
36
40
|
* Zero is NOT drawn: a bell with a «0» next to it forces you to read a number
|
|
37
41
|
* to discover there is nothing. With no count you can already see there is
|
|
38
42
|
* nothing. */
|
|
39
43
|
export function SystrayButton({ icon: Icon, label, count = 0, tone = "info", onClick, active = false, }) {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return (_jsxs("button", { type: "button", onClick: onClick, title: count > 0 ? `${label} (${
|
|
44
|
+
const copy = useUiCopy();
|
|
45
|
+
const number = useMemo(() => new Intl.NumberFormat(copy.locale), [copy.locale]);
|
|
46
|
+
/* The button says the number in its name, so the badge is only seen — and both say the
|
|
47
|
+
same «99+», not a badge that is cut and a name that is not. */
|
|
48
|
+
const said = countText(count, number.format, SYSTRAY_MAX);
|
|
49
|
+
return (_jsxs("button", { type: "button", onClick: onClick, title: count > 0 ? `${label} (${said})` : label, "aria-label": count > 0 ? `${label}: ${said}` : label, className: `relative inline-flex size-(--size-control-md) items-center justify-center rounded-pill transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-chrome-link ${active
|
|
46
50
|
? "bg-chrome-ink/12 text-chrome-ink"
|
|
47
|
-
: "text-chrome-muted hover:bg-chrome-ink/10 hover:text-chrome-ink"}`, children: [_jsx(Icon, { className: "size-(--size-icon-md)", strokeWidth: 2, "aria-hidden": true }), count <= 0 ? null : (_jsx("span", {
|
|
51
|
+
: "text-chrome-muted hover:bg-chrome-ink/10 hover:text-chrome-ink"}`, children: [_jsx(Icon, { className: "size-(--size-icon-md)", strokeWidth: 2, "aria-hidden": true }), count <= 0 ? null : (_jsx("span", { className: "absolute -top-0.5 -right-0.5 flex", children: _jsx(Count, { value: count, tone: tone, solid: true, max: SYSTRAY_MAX, surface: "chrome", "aria-hidden": true }) }))] }));
|
|
48
52
|
}
|
|
49
53
|
/** Who I am and how I leave. The name is drawn when there is width; when narrow
|
|
50
54
|
* only the avatar stays, which is what gets recognised without reading. */
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { AppFrame } from "./AppFrame.js";
|
|
2
|
+
export { Sidebar, type SidebarAction, type SidebarProps, } from "./Sidebar.js";
|
|
3
|
+
export { type SidebarDrawer, SidebarToggle, useSidebarDrawer, } from "./sidebarDrawer.js";
|
|
2
4
|
export { type AppEntry, SystrayButton, TopBar, type TopMenu, } from "./TopBar.js";
|
|
3
5
|
export { Pane, Panes } from "./Panes.js";
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/* THE APPLICATION FRAME — what sits above every view. */
|
|
2
2
|
export { AppFrame } from "./AppFrame.js";
|
|
3
|
+
/* The whole chrome in one column, for a back office with no bar on top. */
|
|
4
|
+
export { Sidebar, } from "./Sidebar.js";
|
|
5
|
+
/* The sidebar's phone drawer, for a bar an application writes itself. */
|
|
6
|
+
export { SidebarToggle, useSidebarDrawer, } from "./sidebarDrawer.js";
|
|
3
7
|
export { SystrayButton, TopBar, } from "./TopBar.js";
|
|
4
8
|
/* A screen of N sets side by side — the reconciliation: each pane scrolls on its own. */
|
|
5
9
|
export { Pane, Panes } from "./Panes.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context: **the sidebar on a phone.** Below `sm` (`--container-handheld`) a 15 rem column
|
|
3
|
+
* beside the view is two thirds of a 390 px screen, so `AppFrame` hides it and offers the
|
|
4
|
+
* SAME sidebar as a drawer from the start edge. What opens the drawer lives in the bar on
|
|
5
|
+
* top — the application's `TopBar`, or the bar the frame draws when the sidebar is the
|
|
6
|
+
* only chrome — and the frame is the one that knows there is a drawer. This is that
|
|
7
|
+
* contract: `null` outside a frame with a sidebar, so a `TopBar` without one draws no
|
|
8
|
+
* button that opens nothing.
|
|
9
|
+
*/
|
|
10
|
+
export type SidebarDrawer = {
|
|
11
|
+
isOpen: boolean;
|
|
12
|
+
open: () => void;
|
|
13
|
+
close: () => void;
|
|
14
|
+
/** The drawer's id, for `aria-controls`. */
|
|
15
|
+
id: string;
|
|
16
|
+
};
|
|
17
|
+
export declare const SidebarDrawerContext: import("react").Context<SidebarDrawer | null>;
|
|
18
|
+
/** The phone drawer of the frame's sidebar, for a bar or a control an application writes
|
|
19
|
+
* itself. `null` when the frame has no sidebar. */
|
|
20
|
+
export declare function useSidebarDrawer(): SidebarDrawer | null;
|
|
21
|
+
/** The button that opens the sidebar on a phone. It draws nothing on a wider screen — the
|
|
22
|
+
* sidebar is in view there — nor outside a frame with a sidebar. `TopBar` draws it first
|
|
23
|
+
* on its own; write it only in a bar of your own. */
|
|
24
|
+
export declare function SidebarToggle({ surface }: {
|
|
25
|
+
surface?: "canvas" | "chrome";
|
|
26
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
|
+
import { IconButton } from "../../primitives/button/Button.js";
|
|
5
|
+
import { Menu as Hamburger } from "lucide-react";
|
|
6
|
+
import { createContext, useContext } from "react";
|
|
7
|
+
export const SidebarDrawerContext = createContext(null);
|
|
8
|
+
/** The phone drawer of the frame's sidebar, for a bar or a control an application writes
|
|
9
|
+
* itself. `null` when the frame has no sidebar. */
|
|
10
|
+
export function useSidebarDrawer() {
|
|
11
|
+
return useContext(SidebarDrawerContext);
|
|
12
|
+
}
|
|
13
|
+
/** The button that opens the sidebar on a phone. It draws nothing on a wider screen — the
|
|
14
|
+
* sidebar is in view there — nor outside a frame with a sidebar. `TopBar` draws it first
|
|
15
|
+
* on its own; write it only in a bar of your own. */
|
|
16
|
+
export function SidebarToggle({ surface = "chrome" }) {
|
|
17
|
+
const copy = useUiCopy();
|
|
18
|
+
const drawer = useSidebarDrawer();
|
|
19
|
+
if (drawer === null)
|
|
20
|
+
return null;
|
|
21
|
+
return (_jsx("span", { className: "flex shrink-0 sm:hidden", children: _jsx(IconButton, { icon: Hamburger, label: copy.shell.openNavigation, size: "md", surface: surface, expanded: drawer.isOpen, haspopup: "dialog", ...(drawer.isOpen ? { "aria-controls": drawer.id } : {}), onClick: drawer.open }) }));
|
|
22
|
+
}
|
|
@@ -104,10 +104,19 @@ export type UiCopy = {
|
|
|
104
104
|
closePreview: string;
|
|
105
105
|
account: string;
|
|
106
106
|
openAsPanel: string;
|
|
107
|
+
/** The button that opens the sidebar as a drawer on a phone. */
|
|
108
|
+
openNavigation: string;
|
|
109
|
+
/** The drawer's name: what a screen reader hears when it opens. */
|
|
110
|
+
navigation: string;
|
|
107
111
|
};
|
|
108
112
|
field: {
|
|
109
113
|
drop: string;
|
|
114
|
+
/** The drop zone's sentence when it takes several files at once. */
|
|
115
|
+
dropMany: string;
|
|
110
116
|
chooseFile: string;
|
|
117
|
+
chooseFiles: string;
|
|
118
|
+
/** A batch over the zone's `max`: `{max}` were taken out of `{count}`. */
|
|
119
|
+
tooManyFiles: string;
|
|
111
120
|
cancel: string;
|
|
112
121
|
uploadProgress: string;
|
|
113
122
|
fileUnreadable: string;
|
|
@@ -751,6 +760,10 @@ export type UiCopy = {
|
|
|
751
760
|
};
|
|
752
761
|
/** The board by stages (`BoardColumns`). */
|
|
753
762
|
board: {
|
|
763
|
+
/** A board tile that could not be read. `{title}` is the tile's. */
|
|
764
|
+
tileFailed: string;
|
|
765
|
+
/** The board's own reading (its headline numbers) failed. */
|
|
766
|
+
failed: string;
|
|
754
767
|
emptyLane: string;
|
|
755
768
|
moveHint: string;
|
|
756
769
|
moved: string;
|
|
@@ -97,10 +97,15 @@ export const SPANISH_COPY = {
|
|
|
97
97
|
closePreview: "Cerrar la vista previa",
|
|
98
98
|
account: "Mi cuenta",
|
|
99
99
|
openAsPanel: "Abrir como panel",
|
|
100
|
+
openNavigation: "Abrir la navegación",
|
|
101
|
+
navigation: "Navegación",
|
|
100
102
|
},
|
|
101
103
|
field: {
|
|
102
104
|
drop: "Soltá un archivo acá, o elegí uno.",
|
|
105
|
+
dropMany: "Soltá archivos acá, o elegilos.",
|
|
103
106
|
chooseFile: "Elegir archivo",
|
|
107
|
+
chooseFiles: "Elegir archivos",
|
|
108
|
+
tooManyFiles: "Se tomaron los primeros {max} de {count}: se pueden subir hasta {max} a la vez.",
|
|
104
109
|
cancel: "Cancelar",
|
|
105
110
|
uploadProgress: "progreso de la subida",
|
|
106
111
|
fileUnreadable: "No pudimos leer el archivo",
|
|
@@ -509,6 +514,8 @@ export const SPANISH_COPY = {
|
|
|
509
514
|
none: "sin prioridad",
|
|
510
515
|
},
|
|
511
516
|
board: {
|
|
517
|
+
tileFailed: "No se pudo leer «{title}»",
|
|
518
|
+
failed: "No se pudieron leer los números del tablero",
|
|
512
519
|
emptyLane: "Nada en esta etapa.",
|
|
513
520
|
moveHint: "Arrastrala, o Alt + ← / → para pasarla a otra etapa",
|
|
514
521
|
moved: "{name} pasó a {column}",
|
|
@@ -566,8 +573,8 @@ export const SPANISH_COPY = {
|
|
|
566
573
|
attachments: {
|
|
567
574
|
label: "Adjuntos",
|
|
568
575
|
empty: "Todavía no hay archivos adjuntos.",
|
|
569
|
-
emptyAdd: "Todavía no hay archivos adjuntos.
|
|
570
|
-
add: "Soltá
|
|
576
|
+
emptyAdd: "Todavía no hay archivos adjuntos. Soltalos acá o elegilos.",
|
|
577
|
+
add: "Soltá más archivos acá o elegilos.",
|
|
571
578
|
download: "Descargar",
|
|
572
579
|
remove: "Quitar el archivo",
|
|
573
580
|
removed: "Se quitó «{name}».",
|
package/dist/foundations/copy.js
CHANGED
|
@@ -73,10 +73,15 @@ export const ENGLISH_COPY = {
|
|
|
73
73
|
closePreview: "Close preview",
|
|
74
74
|
account: "My account",
|
|
75
75
|
openAsPanel: "Open as panel",
|
|
76
|
+
openNavigation: "Open the navigation",
|
|
77
|
+
navigation: "Navigation",
|
|
76
78
|
},
|
|
77
79
|
field: {
|
|
78
80
|
drop: "Drop a file here, or choose one.",
|
|
81
|
+
dropMany: "Drop files here, or choose them.",
|
|
79
82
|
chooseFile: "Choose file",
|
|
83
|
+
chooseFiles: "Choose files",
|
|
84
|
+
tooManyFiles: "Only the first {max} of {count} were taken: up to {max} at a time.",
|
|
80
85
|
cancel: "Cancel",
|
|
81
86
|
uploadProgress: "upload progress",
|
|
82
87
|
fileUnreadable: "We could not read the file",
|
|
@@ -499,6 +504,8 @@ export const ENGLISH_COPY = {
|
|
|
499
504
|
none: "no priority",
|
|
500
505
|
},
|
|
501
506
|
board: {
|
|
507
|
+
tileFailed: "«{title}» could not be read",
|
|
508
|
+
failed: "The board's numbers could not be read",
|
|
502
509
|
emptyLane: "Nothing in this stage.",
|
|
503
510
|
moveHint: "Drag it, or Alt + ← / → to move it to another stage",
|
|
504
511
|
moved: "{name} moved to {column}",
|
|
@@ -561,8 +568,8 @@ export const ENGLISH_COPY = {
|
|
|
561
568
|
attachments: {
|
|
562
569
|
label: "Attachments",
|
|
563
570
|
empty: "No files attached yet.",
|
|
564
|
-
emptyAdd: "No files attached yet. Drop
|
|
565
|
-
add: "Drop
|
|
571
|
+
emptyAdd: "No files attached yet. Drop them here, or choose them.",
|
|
572
|
+
add: "Drop more files here, or choose them.",
|
|
566
573
|
download: "Download",
|
|
567
574
|
remove: "Remove the file",
|
|
568
575
|
removed: "Removed «{name}».",
|
|
@@ -17,8 +17,17 @@ import { type FormMode } from "../../foundations/form.js";
|
|
|
17
17
|
* say a dragged file's extension until it lands, and a drop that silently does
|
|
18
18
|
* nothing reads as a broken zone. The file reaches `onFile`, and the consumer
|
|
19
19
|
* answers with `error` when it cannot read it.
|
|
20
|
+
*
|
|
21
|
+
* ── One file, or several ─────────────────────────────────────────────
|
|
22
|
+
*
|
|
23
|
+
* `multiple` takes every file of a drop or of the dialog in ONE call to `onFiles` —
|
|
24
|
+
* a gallery gets its thirty photos as one batch, not thirty events. Listing what
|
|
25
|
+
* was chosen, with its thumbnails and per-file removal, is `Attachments`, which
|
|
26
|
+
* draws this zone: the zone takes files, it does not keep them. `max` caps the
|
|
27
|
+
* batch: the first `max` go through and the zone SAYS how many were left out — a
|
|
28
|
+
* silent cut is a photo nobody knows is missing.
|
|
20
29
|
*/
|
|
21
|
-
|
|
30
|
+
type DropZoneCommon = {
|
|
22
31
|
/** The browser's `accept` list: extensions and MIME types, comma-separated
|
|
23
32
|
* (`".pdf,application/pdf"`). */
|
|
24
33
|
accept?: string;
|
|
@@ -29,7 +38,6 @@ export type DropZoneProps = {
|
|
|
29
38
|
fileName?: string;
|
|
30
39
|
fileDetail?: string;
|
|
31
40
|
error?: string | null;
|
|
32
|
-
onFile: (file: File) => void;
|
|
33
41
|
onCancel?: () => void;
|
|
34
42
|
onRetry?: () => void;
|
|
35
43
|
id?: string;
|
|
@@ -39,4 +47,15 @@ export type DropZoneProps = {
|
|
|
39
47
|
* file's name. */
|
|
40
48
|
mode?: FormMode;
|
|
41
49
|
};
|
|
42
|
-
export
|
|
50
|
+
export type DropZoneProps = DropZoneCommon & ({
|
|
51
|
+
multiple?: false;
|
|
52
|
+
onFile: (file: File) => void;
|
|
53
|
+
} | {
|
|
54
|
+
multiple: true;
|
|
55
|
+
/** Every file of one drop, paste or choice, in their order. */
|
|
56
|
+
onFiles: (files: File[]) => void;
|
|
57
|
+
/** At most this many per batch; the rest are left out, and the zone says so. */
|
|
58
|
+
max?: number;
|
|
59
|
+
});
|
|
60
|
+
export declare function DropZone(props: DropZoneProps): import("react").JSX.Element;
|
|
61
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
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
|
+
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
4
4
|
import { useFieldIds } from "../../foundations/form.js";
|
|
5
5
|
import { useFormMode } from "../../foundations/form.js";
|
|
6
6
|
import { cn } from "../../foundations/variants.js";
|
|
@@ -8,9 +8,13 @@ import { Button, buttonClasses } from "../button/Button.js";
|
|
|
8
8
|
import { ReadValue } from "./Field.js";
|
|
9
9
|
import { Failed } from "../notice/Notice.js";
|
|
10
10
|
import { ProgressBar } from "../value/ProgressBar.js";
|
|
11
|
+
import { useState } from "react";
|
|
11
12
|
import { Button as AriaButton, DropZone as AriaDropZone, FileTrigger, } from "react-aria-components";
|
|
12
|
-
export function DropZone(
|
|
13
|
+
export function DropZone(props) {
|
|
14
|
+
const { accept, label, busy = false, progress, fileName, fileDetail, error, onCancel, onRetry, id: ownId, describedBy: ownDescribedBy, invalid: ownInvalid, mode, } = props;
|
|
13
15
|
const copy = useUiCopy();
|
|
16
|
+
/* How many the last batch left out, said under the zone until the next batch. */
|
|
17
|
+
const [leftOut, setLeftOut] = useState(null);
|
|
14
18
|
const { id, labelledBy, describedBy, invalid } = useFieldIds({
|
|
15
19
|
id: ownId,
|
|
16
20
|
describedBy: ownDescribedBy,
|
|
@@ -19,20 +23,36 @@ export function DropZone({ accept, label, busy = false, progress, fileName, file
|
|
|
19
23
|
const readMode = useFormMode(mode) === "read";
|
|
20
24
|
if (readMode)
|
|
21
25
|
return _jsx(ReadValue, { value: fileName ?? null });
|
|
22
|
-
const
|
|
26
|
+
const many = props.multiple === true;
|
|
27
|
+
const sentence = label ?? (many ? copy.field.dropMany : copy.field.drop);
|
|
23
28
|
const types = accept
|
|
24
29
|
?.split(",")
|
|
25
30
|
.map((t) => t.trim())
|
|
26
31
|
.filter((t) => t !== "");
|
|
32
|
+
function take(files) {
|
|
33
|
+
if (files.length === 0)
|
|
34
|
+
return;
|
|
35
|
+
if (props.multiple !== true) {
|
|
36
|
+
props.onFile(files[0]);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const max = props.max;
|
|
40
|
+
const taken = max === undefined ? files : files.slice(0, max);
|
|
41
|
+
setLeftOut(taken.length < files.length ? { taken: taken.length, of: files.length } : null);
|
|
42
|
+
props.onFiles([...taken]);
|
|
43
|
+
}
|
|
27
44
|
async function onDrop(items) {
|
|
28
45
|
if (busy)
|
|
29
46
|
return;
|
|
47
|
+
const files = [];
|
|
30
48
|
for (const item of items) {
|
|
31
|
-
if (item.kind
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
if (item.kind !== "file")
|
|
50
|
+
continue;
|
|
51
|
+
files.push(await item.getFile());
|
|
52
|
+
if (!many)
|
|
53
|
+
break;
|
|
35
54
|
}
|
|
55
|
+
take(files);
|
|
36
56
|
}
|
|
37
57
|
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-2", children: [_jsxs(AriaDropZone, { ...(labelledBy === undefined
|
|
38
58
|
? { "aria-label": sentence }
|
|
@@ -40,11 +60,12 @@ export function DropZone({ accept, label, busy = false, progress, fileName, file
|
|
|
40
60
|
? "border-primary bg-primary/8 forced-colors:border-[Highlight]"
|
|
41
61
|
: invalid
|
|
42
62
|
? "border-danger bg-surface"
|
|
43
|
-
: "border-line-strong bg-surface", isFocusVisible ? "outline-2" : "outline-0"), children: [_jsx("p", { className: "text-body text-muted", children: sentence }), busy ? (_jsxs("div", { className: "flex w-full max-w-sm flex-col items-center gap-2", children: [fileName === undefined ? null : (_jsx("p", { className: "max-w-full truncate text-body text-ink", children: fileName })), _jsx("div", { className: "w-full", children: _jsx(ProgressBar, { value: progress ?? 0, label: copy.field.uploadProgress, width: "w-full" }) }), fileDetail === undefined ? null : (_jsx("p", { className: "text-meta text-muted", children: fileDetail }))] })) : (_jsxs("div", { className: "flex flex-wrap items-center justify-center gap-3", children: [_jsx(FileTrigger, { ...(types === undefined ? {} : { acceptedFileTypes: types }), onSelect: (files) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
63
|
+
: "border-line-strong bg-surface", isFocusVisible ? "outline-2" : "outline-0"), children: [_jsx("p", { className: "text-body text-muted", children: sentence }), busy ? (_jsxs("div", { className: "flex w-full max-w-sm flex-col items-center gap-2", children: [fileName === undefined ? null : (_jsx("p", { className: "max-w-full truncate text-body text-ink", children: fileName })), _jsx("div", { className: "w-full", children: _jsx(ProgressBar, { value: progress ?? 0, label: copy.field.uploadProgress, width: "w-full" }) }), fileDetail === undefined ? null : (_jsx("p", { className: "text-meta text-muted", children: fileDetail }))] })) : (_jsxs("div", { className: "flex flex-wrap items-center justify-center gap-3", children: [_jsx(FileTrigger, { ...(types === undefined ? {} : { acceptedFileTypes: types }), allowsMultiple: many, onSelect: (files) => take(files === null ? [] : Array.from(files)), children: _jsx(AriaButton, { id: id, "data-emphasis": "secondary", className: buttonClasses("secondary", "md"), children: many ? copy.field.chooseFiles : copy.field.chooseFile }) }), onCancel === undefined ? null : (_jsx(Button, { role: "ghost", onClick: onCancel, children: copy.field.cancel }))] }))] }), _jsx("p", { role: "status", className: leftOut === null ? "sr-only" : "text-meta text-warn", children: leftOut === null
|
|
64
|
+
? null
|
|
65
|
+
: fillCopy(copy.field.tooManyFiles, {
|
|
66
|
+
max: leftOut.taken.toLocaleString(copy.locale),
|
|
67
|
+
count: leftOut.of.toLocaleString(copy.locale),
|
|
68
|
+
}) }), error === undefined || error === null ? null : (_jsx(Failed, { heading: copy.field.fileUnreadable, sentence: error, ...(onRetry === undefined
|
|
48
69
|
? {}
|
|
49
70
|
: {
|
|
50
71
|
action: (_jsx(Button, { role: "ghost", onClick: onRetry, children: copy.field.tryAnother })),
|
|
@@ -21,8 +21,8 @@ export interface MenuOption {
|
|
|
21
21
|
onRemove?: () => void;
|
|
22
22
|
disabled?: boolean;
|
|
23
23
|
/** Visual mark at the end of the label. A string is drawn as a pill
|
|
24
|
-
* —"maqueta", "nuevo"—;
|
|
25
|
-
*
|
|
24
|
+
* —"maqueta", "nuevo"—; a number as a `Count` —«Por aprobar 3», no zero—;
|
|
25
|
+
* anything else is drawn as is, which is how a status `Tag` comes in. */
|
|
26
26
|
badge?: ReactNode;
|
|
27
27
|
/** What THIS option does. It exists on top of the menu's `onSelect` because a
|
|
28
28
|
* menu built from a registry —twenty-five operations, each one with its own
|
|
@@ -84,7 +84,7 @@ export declare function menuTriggerClasses({ variant, surface, active, open, foc
|
|
|
84
84
|
export declare function Menu({ label, groups, onSelect, surface, align, icon: Trigger,
|
|
85
85
|
/** The menu as a control of a list ("filters ▾") carries the chevron; the
|
|
86
86
|
* actions `⋯` does not, because the icon already says there is more. */
|
|
87
|
-
chevron, active, iconOnly, variant, searchPlaceholder, emptyText, width, role, size, title, closeOnSelect, }: {
|
|
87
|
+
chevron, active, iconOnly, variant, searchPlaceholder, emptyText, width, role, size, title, closeOnSelect, count, }: {
|
|
88
88
|
label: string;
|
|
89
89
|
groups: readonly MenuGroup[];
|
|
90
90
|
onSelect?: (id: string) => void;
|
|
@@ -126,6 +126,10 @@ chevron, active, iconOnly, variant, searchPlaceholder, emptyText, width, role, s
|
|
|
126
126
|
/** Column and filter menus toggle several options in a row. Closing after
|
|
127
127
|
* each click turns three hides into three open-close round trips. */
|
|
128
128
|
closeOnSelect?: boolean;
|
|
129
|
+
/** What is waiting inside, on the trigger: «Pagos 5» in an application bar says it
|
|
130
|
+
* without opening the menu. Zero is not drawn. Not with `iconOnly`, where there is no
|
|
131
|
+
* label for it to belong to. */
|
|
132
|
+
count?: number;
|
|
129
133
|
}): import("react").JSX.Element;
|
|
130
134
|
/**
|
|
131
135
|
* The panel of a `Menu`: its groups and rows, and the submenus hanging from them. Internal —
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
4
|
import { buttonClasses, } from "../button/Button.js";
|
|
5
5
|
import { Popover } from "../overlay/Popover.js";
|
|
6
|
+
import { Count } from "../tag/Count.js";
|
|
6
7
|
import { Check, ChevronDown, ChevronRight } from "lucide-react";
|
|
7
8
|
import { Autocomplete, Button as AriaButton, Header, Input, Keyboard, Menu as AriaMenu, MenuItem, MenuSection, MenuTrigger, SearchField, Separator, SubmenuTrigger, useFilter, } from "react-aria-components";
|
|
8
9
|
const WIDTH = {
|
|
@@ -52,7 +53,7 @@ export function menuTriggerClasses({ variant = "button", surface = "canvas", act
|
|
|
52
53
|
export function Menu({ label, groups, onSelect, surface = "canvas", align = "start", icon: Trigger,
|
|
53
54
|
/** The menu as a control of a list ("filters ▾") carries the chevron; the
|
|
54
55
|
* actions `⋯` does not, because the icon already says there is more. */
|
|
55
|
-
chevron = true, active = false, iconOnly = false, variant = "button", searchPlaceholder, emptyText, width = "md", role, size = "md", title, closeOnSelect = true, }) {
|
|
56
|
+
chevron = true, active = false, iconOnly = false, variant = "button", searchPlaceholder, emptyText, width = "md", role, size = "md", title, closeOnSelect = true, count, }) {
|
|
56
57
|
const copy = useUiCopy();
|
|
57
58
|
const { contains } = useFilter({ sensitivity: "base" });
|
|
58
59
|
const byId = indexOptions(groups.flatMap((g) => g.options));
|
|
@@ -70,7 +71,7 @@ chevron = true, active = false, iconOnly = false, variant = "button", searchPlac
|
|
|
70
71
|
focusVisible: isFocusVisible,
|
|
71
72
|
iconOnly,
|
|
72
73
|
})
|
|
73
|
-
: `${buttonClasses(role, size, surface)} gap-1.5`, children: _jsxs("span", { className: "contents", title: title ?? (iconOnly ? label : undefined), children: [Trigger === undefined ? (iconOnly ? (_jsx(ChevronDown, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true })) : null) : (_jsx(Trigger, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true })), iconOnly ? null : label, chevron && !iconOnly ? (_jsx(ChevronDown, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true })) : null] }) }), _jsx(Popover, { placement: align === "end" ? "bottom end" : "bottom start", className: WIDTH[width], children: searchPlaceholder === undefined ? (menu) : (
|
|
74
|
+
: `${buttonClasses(role, size, surface)} gap-1.5`, children: _jsxs("span", { className: "contents", title: title ?? (iconOnly ? label : undefined), children: [Trigger === undefined ? (iconOnly ? (_jsx(ChevronDown, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true })) : null) : (_jsx(Trigger, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true })), iconOnly ? null : label, iconOnly || count === undefined ? null : _jsx(Count, { value: count, surface: surface }), chevron && !iconOnly ? (_jsx(ChevronDown, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-hidden": true })) : null] }) }), _jsx(Popover, { placement: align === "end" ? "bottom end" : "bottom start", className: WIDTH[width], children: searchPlaceholder === undefined ? (menu) : (
|
|
74
75
|
/* The search box stays at the top: in a menu of twenty-five entries,
|
|
75
76
|
scrolling loses exactly the control that explains why only three are
|
|
76
77
|
visible. It filters on label AND hint — half the entries of this
|
|
@@ -91,7 +92,7 @@ export function MenuList({ label, groups, onAction, closeOnSelect, emptyText, wi
|
|
|
91
92
|
const Icon = o.icon;
|
|
92
93
|
const opens = o.items !== undefined;
|
|
93
94
|
const checked = !opens && o.checked === true;
|
|
94
|
-
return (_jsxs(MenuItem, { id: o.id, textValue: o.hint === undefined ? o.label : `${o.label} ${o.hint}`, isDisabled: o.disabled, className: `flex w-full cursor-default rounded-control ${hasHints ? "items-start py-1.5" : "items-center py-1"} gap-2 px-2 text-left outline-0 transition-colors duration-(--duration-instant) data-focused:bg-primary/8 data-open:bg-primary/8 disabled:opacity-45`, children: [hasMarks ? (_jsx("span", { className: `${hasHints ? "mt-0.5" : ""} flex size-(--size-icon-sm) shrink-0 items-center justify-center`, children: checked ? (_jsx(Check, { className: "size-(--size-icon-sm) text-primary", strokeWidth: 2.5, "aria-hidden": true })) : Icon !== undefined ? (_jsx(Icon, { className: "size-(--size-icon-sm) text-muted", strokeWidth: 2, "aria-hidden": true })) : null })) : null, _jsxs("span", { className: "min-w-0 flex-1", children: [_jsxs("span", { className: "flex items-center gap-1.5", children: [_jsx("span", { className: `truncate text-meta ${checked ? "font-medium text-ink" : "text-ink"}`, children: o.label }), o.badge === undefined ? null : 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));
|
|
95
|
+
return (_jsxs(MenuItem, { id: o.id, textValue: o.hint === undefined ? o.label : `${o.label} ${o.hint}`, isDisabled: o.disabled, className: `flex w-full cursor-default rounded-control ${hasHints ? "items-start py-1.5" : "items-center py-1"} gap-2 px-2 text-left outline-0 transition-colors duration-(--duration-instant) data-focused:bg-primary/8 data-open:bg-primary/8 disabled:opacity-45`, children: [hasMarks ? (_jsx("span", { className: `${hasHints ? "mt-0.5" : ""} flex size-(--size-icon-sm) shrink-0 items-center justify-center`, children: checked ? (_jsx(Check, { className: "size-(--size-icon-sm) text-primary", strokeWidth: 2.5, "aria-hidden": true })) : Icon !== undefined ? (_jsx(Icon, { className: "size-(--size-icon-sm) text-muted", strokeWidth: 2, "aria-hidden": true })) : null })) : null, _jsxs("span", { className: "min-w-0 flex-1", children: [_jsxs("span", { className: "flex items-center gap-1.5", children: [_jsx("span", { className: `truncate text-meta ${checked ? "font-medium text-ink" : "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));
|
|
95
96
|
};
|
|
96
97
|
return (_jsx(AriaMenu, { "aria-label": label, shouldCloseOnSelect: closeOnSelect, onAction: onAction, 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", children: groups.map((g, gi) => (_jsxs(MenuSection, { className: "[&:not(:first-child)]:mt-1 [&:not(:first-child)]:border-t [&:not(:first-child)]:border-line [&:not(:first-child)]:pt-1", children: [g.label === undefined ? null : (
|
|
97
98
|
/* Same skeleton as the row: the label sits on the text column. */
|
|
@@ -1,26 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
|
+
import { Count } from "../tag/Count.js";
|
|
4
5
|
import { createContext, useContext, useId, useRef, } from "react";
|
|
5
|
-
/* The notification's colour. Static and in a table because Tailwind cannot
|
|
6
|
-
compose a class with a variable piece: `bg-${tone}/12` does not exist in the
|
|
7
|
-
stylesheet. */
|
|
8
|
-
const NOTICE_TONE = {
|
|
9
|
-
neutral: "bg-ink/8 text-muted",
|
|
10
|
-
info: "bg-info/12 text-info",
|
|
11
|
-
good: "bg-good/12 text-good",
|
|
12
|
-
warn: "bg-warn/14 text-warn",
|
|
13
|
-
bad: "bg-bad/12 text-bad",
|
|
14
|
-
accent: "bg-accent/14 text-accent",
|
|
15
|
-
};
|
|
16
|
-
const NOTICE_DOT = {
|
|
17
|
-
neutral: "bg-muted",
|
|
18
|
-
info: "bg-info",
|
|
19
|
-
good: "bg-good",
|
|
20
|
-
warn: "bg-warn",
|
|
21
|
-
bad: "bg-bad",
|
|
22
|
-
accent: "bg-accent",
|
|
23
|
-
};
|
|
24
6
|
/**
|
|
25
7
|
* The strip only: what each tab opens is drawn by whoever uses it (`Record`, `Activity`).
|
|
26
8
|
*
|
|
@@ -89,7 +71,6 @@ export function Tabs({ tabs, current, onSelect, label, }) {
|
|
|
89
71
|
};
|
|
90
72
|
return (_jsx("div", { ref: strip, role: "tablist", "aria-label": label ?? copy.record.faces, onKeyDown: onKeyDown, className: "flex min-w-0 flex-wrap items-end gap-1", children: tabs.map((a) => {
|
|
91
73
|
const Icon = a.icon;
|
|
92
|
-
const empty = a.count === 0;
|
|
93
74
|
/* A zero asks for nothing, so it is not drawn. That is the difference from the
|
|
94
75
|
counter, where «0» is an answer. */
|
|
95
76
|
const notice = a.notice?.count === 0 ? undefined : a.notice;
|
|
@@ -98,13 +79,6 @@ export function Tabs({ tabs, current, onSelect, label, }) {
|
|
|
98
79
|
? {}
|
|
99
80
|
: { id: tabIdOf(base, a.id), "aria-controls": panelIdOf(base, a.id) }), onClick: () => onSelect?.(a.id), className: `inline-flex shrink-0 cursor-default items-center px-3 py-2 text-meta outline-0 transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary ${isSelected
|
|
100
81
|
? "-mb-px rounded-t-control border border-b-0 border-line-strong bg-surface font-medium text-ink"
|
|
101
|
-
: "border border-transparent text-muted hover:text-ink"}`, children: _jsxs("span", { className: "inline-flex items-center gap-1.5", ...(notice === undefined ? {} : { title: notice.label }), children: [Icon === undefined ? null : (_jsx(Icon, { className: `size-(--size-icon-sm) shrink-0 ${isSelected ? "text-ink" : "text-muted"}`, strokeWidth: 2, "aria-hidden": true })), a.label, a.count === undefined ? null : (_jsx("span", { className:
|
|
102
|
-
? "bg-ink/5 text-muted"
|
|
103
|
-
: isSelected
|
|
104
|
-
? "bg-ink/8 text-ink"
|
|
105
|
-
: "bg-ink/8 text-muted"}`, children: a.count.toLocaleString(copy.locale) })), notice === undefined ? null : (_jsx("span", { className: "sr-only", children: ` · ${notice.label}` })), notice === undefined ? null : notice.count === undefined ? (
|
|
106
|
-
/* Without a number, a dot. The word is not drawn but it is there: in the
|
|
107
|
-
`title` and in the tab's accessible name. */
|
|
108
|
-
_jsx("span", { className: `size-1.5 shrink-0 rounded-pill ${NOTICE_DOT[notice.tone ?? "bad"]}`, "aria-hidden": true })) : (_jsx("span", { className: `rounded-pill px-1.5 text-micro font-medium tabular-nums ${NOTICE_TONE[notice.tone ?? "bad"]}`, "aria-hidden": true, children: notice.count.toLocaleString(copy.locale) }))] }) }, a.id));
|
|
82
|
+
: "border border-transparent text-muted hover:text-ink"}`, children: _jsxs("span", { className: "inline-flex items-center gap-1.5", ...(notice === undefined ? {} : { title: notice.label }), children: [Icon === undefined ? null : (_jsx(Icon, { className: `size-(--size-icon-sm) shrink-0 ${isSelected ? "text-ink" : "text-muted"}`, strokeWidth: 2, "aria-hidden": true })), a.label, a.count === undefined ? null : (_jsx(Count, { value: a.count, showZero: true, current: isSelected })), notice === undefined ? null : (_jsx("span", { className: "sr-only", children: ` · ${notice.label}` })), notice === undefined ? null : (_jsx(Count, { ...(notice.count === undefined ? {} : { value: notice.count }), tone: notice.tone ?? "bad", "aria-hidden": true }))] }) }, a.id));
|
|
109
83
|
}) }));
|
|
110
84
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Surface, Tone } from "../../foundations/types.js";
|
|
2
|
+
export type CountProps = {
|
|
3
|
+
/** How many. Without it the count is a dot: something is there, not counted. */
|
|
4
|
+
value?: number;
|
|
5
|
+
/** `neutral` counts; any other tone says that something asks for attention. */
|
|
6
|
+
tone?: Tone;
|
|
7
|
+
/** Filled: the badge over an icon (a bell, a cart), which has to read on its own. */
|
|
8
|
+
solid?: boolean;
|
|
9
|
+
/** Past this it reads «99+». Without it every number is written in full. */
|
|
10
|
+
max?: number;
|
|
11
|
+
/** Draw the zero, fainter: where «0» is an answer and not noise (a tab). */
|
|
12
|
+
showZero?: boolean;
|
|
13
|
+
/** The thing it counts is the current one — the count takes its host's colour. */
|
|
14
|
+
current?: boolean;
|
|
15
|
+
surface?: Surface;
|
|
16
|
+
/** When the host already says the number in its name (`aria-label`), the count is only
|
|
17
|
+
* seen: hidden from assistive technology so it is not read twice. */
|
|
18
|
+
"aria-hidden"?: boolean;
|
|
19
|
+
};
|
|
20
|
+
/** The text of a count: formatted for the locale, and «99+» past `max`. Exported for the
|
|
21
|
+
* hosts that also need it in words — a button's `aria-label`, a `title`. */
|
|
22
|
+
export declare function countText(value: number, format: (n: number) => string, max?: number): string;
|
|
23
|
+
export declare function Count({ value, tone, solid, max, showZero, current, surface, "aria-hidden": hidden, }: CountProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
|
+
import { useSurface } from "../../foundations/surface.js";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
/* Static and in a table: Tailwind cannot compose `bg-${tone}/12`. The gold is never text on
|
|
7
|
+
the canvas (2.43:1), so there its count is ink on a gold wash — the same rule as `Tag`. */
|
|
8
|
+
const SOFT = {
|
|
9
|
+
neutral: { canvas: "bg-ink/8 text-muted", chrome: "bg-chrome-ink/10 text-chrome-muted" },
|
|
10
|
+
info: { canvas: "bg-info/12 text-info", chrome: "bg-chrome-link/15 text-chrome-link" },
|
|
11
|
+
good: { canvas: "bg-good/12 text-good", chrome: "bg-chrome-good/15 text-chrome-good" },
|
|
12
|
+
warn: { canvas: "bg-warn/14 text-warn", chrome: "bg-chrome-warn/15 text-chrome-warn" },
|
|
13
|
+
bad: { canvas: "bg-bad/12 text-bad", chrome: "bg-chrome-bad/15 text-chrome-bad" },
|
|
14
|
+
accent: {
|
|
15
|
+
canvas: "bg-accent/20 text-ink",
|
|
16
|
+
chrome: "bg-chrome-accent/15 text-chrome-accent",
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
const SOLID = {
|
|
20
|
+
neutral: { canvas: "bg-ink text-surface", chrome: "bg-chrome-ink text-chrome" },
|
|
21
|
+
info: { canvas: "bg-info text-surface", chrome: "bg-chrome-link text-chrome" },
|
|
22
|
+
good: { canvas: "bg-good text-surface", chrome: "bg-chrome-good text-chrome" },
|
|
23
|
+
warn: { canvas: "bg-warn text-surface", chrome: "bg-chrome-warn text-chrome" },
|
|
24
|
+
bad: { canvas: "bg-bad text-surface", chrome: "bg-chrome-bad text-chrome" },
|
|
25
|
+
accent: { canvas: "bg-accent text-on-accent", chrome: "bg-chrome-accent text-chrome" },
|
|
26
|
+
};
|
|
27
|
+
const DOT = {
|
|
28
|
+
neutral: { canvas: "bg-muted", chrome: "bg-chrome-muted" },
|
|
29
|
+
info: { canvas: "bg-info", chrome: "bg-chrome-link" },
|
|
30
|
+
good: { canvas: "bg-good", chrome: "bg-chrome-good" },
|
|
31
|
+
warn: { canvas: "bg-warn", chrome: "bg-chrome-warn" },
|
|
32
|
+
bad: { canvas: "bg-bad", chrome: "bg-chrome-bad" },
|
|
33
|
+
accent: { canvas: "bg-accent", chrome: "bg-chrome-accent" },
|
|
34
|
+
};
|
|
35
|
+
/** The text of a count: formatted for the locale, and «99+» past `max`. Exported for the
|
|
36
|
+
* hosts that also need it in words — a button's `aria-label`, a `title`. */
|
|
37
|
+
export function countText(value, format, max) {
|
|
38
|
+
return max !== undefined && value > max ? `${format(max)}+` : format(value);
|
|
39
|
+
}
|
|
40
|
+
function skinOf(tone, surface, { solid, current, zero }) {
|
|
41
|
+
if (solid)
|
|
42
|
+
return SOLID[tone][surface];
|
|
43
|
+
if (zero)
|
|
44
|
+
return surface === "chrome" ? "bg-chrome-ink/6 text-chrome-muted" : "bg-ink/5 text-muted";
|
|
45
|
+
if (current && tone === "neutral")
|
|
46
|
+
return "bg-current/12 text-current";
|
|
47
|
+
return SOFT[tone][surface];
|
|
48
|
+
}
|
|
49
|
+
export function Count({ value, tone = "neutral", solid = false, max, showZero = false, current = false, surface, "aria-hidden": hidden, }) {
|
|
50
|
+
const copy = useUiCopy();
|
|
51
|
+
const sup = useSurface(surface);
|
|
52
|
+
const number = useMemo(() => new Intl.NumberFormat(copy.locale), [copy.locale]);
|
|
53
|
+
if (value === undefined) {
|
|
54
|
+
return (_jsx("span", { "data-count": "dot", className: `inline-block size-1.5 shrink-0 rounded-pill ${DOT[tone][sup]}`, "aria-hidden": true }));
|
|
55
|
+
}
|
|
56
|
+
if (value <= 0 && !showZero)
|
|
57
|
+
return null;
|
|
58
|
+
return (_jsx("span", { "data-count": value, ...(hidden === true ? { "aria-hidden": true } : {}), className: `inline-flex min-w-4 shrink-0 items-center justify-center rounded-pill text-micro tabular-nums ${solid ? "px-1 leading-none font-semibold" : "px-1.5 leading-normal font-medium"} ${skinOf(tone, sup, { solid, current, zero: value <= 0 })}`, children: countText(value, number.format, max) }));
|
|
59
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/* Saying a state without writing a sentence: the capsule and the dot. */
|
|
2
2
|
export { StatusDot, Tag } from "./Tag.js";
|
|
3
|
+
/* How many things are behind something, or that something asks for: one counter for the
|
|
4
|
+
sidebar, the tabs, the systray, a menu and an application's own button. */
|
|
5
|
+
export { Count, countText } from "./Count.js";
|
|
3
6
|
/* The strip of chips: the same in the bar, in the dropdown and anywhere
|
|
4
7
|
a list of short words is drawn. */
|
|
5
8
|
export { Tags } from "./Tags.js";
|
|
@@ -25,8 +25,13 @@ import { type LucideIcon } from "lucide-react";
|
|
|
25
25
|
* the NUMBER.
|
|
26
26
|
*/
|
|
27
27
|
export type MetricProps = {
|
|
28
|
-
|
|
28
|
+
/** The figure. Without it — and not `loading` — it reads «—»: not counted, which is not
|
|
29
|
+
* zero. */
|
|
30
|
+
value?: number | string;
|
|
29
31
|
label: string;
|
|
32
|
+
/** The figure is being read. The label stays and the box keeps its size, so a row of
|
|
33
|
+
* metrics does not jump when the numbers land one at a time. */
|
|
34
|
+
loading?: boolean;
|
|
30
35
|
tone?: Tone;
|
|
31
36
|
icon?: LucideIcon;
|
|
32
37
|
/** Present = narrows the list. Absent = only informs, and doesn't get pressed. */
|
|
@@ -45,7 +50,7 @@ export type MetricProps = {
|
|
|
45
50
|
better?: "up" | "down";
|
|
46
51
|
};
|
|
47
52
|
};
|
|
48
|
-
export declare function Metric({ value, label, tone, icon: Icon, onClick, active, change, }: MetricProps): import("react").JSX.Element;
|
|
53
|
+
export declare function Metric({ value, label, tone, icon: Icon, onClick, active, change, loading, }: MetricProps): import("react").JSX.Element;
|
|
49
54
|
/** The row of metrics. It wraps if they don't fit; it doesn't scroll: a hidden
|
|
50
55
|
* metric is a filter nobody finds. */
|
|
51
56
|
export declare function Metrics({ children }: {
|