@sincpro/web-ui 2.10.0 → 2.11.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 CHANGED
@@ -266,7 +266,7 @@ of classes that change with the next refactor:
266
266
 
267
267
  The parts: `button`, `icon-button`, `control`, `popover`, `menu`, `menu.trigger`,
268
268
  `menu.section`, `menu.item`, `menu.fold`, `dialog`, `block`, `record-card`, `board.tile`,
269
- `board.stat`, `board.stat.value`, `activity.changes`, `file-list`, `file-list.file`, `metric`, `metric.detail`, `tag`, `tags.item`, `search`, `search.field`, `search.chip`,
269
+ `board.stat`, `board.stat.value`, `activity.changes`, `file-list`, `file-list.file`, `file-value`, `metric`, `metric.detail`, `tag`, `tags.item`, `search`, `search.field`, `search.chip`,
270
270
  `search.panel`, `search.suggestions`, `search.suggestion`, `search.record`, `search.advanced`,
271
271
  `search.keys`, `search-entry`, `search-entry.keys`, `table`, `table.pile`, `yes-no`,
272
272
  `table.head`, `row.ways`, `topbar`, `topbar.brand`, `topbar.menus`, `topbar.actions`, `topbar.user`,
@@ -0,0 +1,10 @@
1
+ import { type AttachmentFile } from "./files.js";
2
+ export type FileValueProps = {
3
+ /** The file — nothing at all when there is none. */
4
+ file: AttachmentFile | null | undefined;
5
+ /** `sm` (default): a table's line. `md`: a record's field, with its type and size. */
6
+ size?: "sm" | "md";
7
+ /** Download by code. Present = the name is a button that calls it, busy while it runs. */
8
+ onDownload?: (file: AttachmentFile) => void | Promise<unknown>;
9
+ };
10
+ export declare function FileValue({ file, size, onDownload }: FileValueProps): import("react").JSX.Element | null;
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { attachmentKind, fileExtension, formatFileSize, } from "./files.js";
4
+ import { FileThumb } from "./FileThumb.js";
5
+ import { useUiCopy } from "../../foundations/copy.js";
6
+ import { useState } from "react";
7
+ /* A row opens its record on a click; downloading its file must not ALSO open it. */
8
+ const stay = (event) => event.stopPropagation();
9
+ /* The ring every name shares, as a button or as a link — `FileList`'s. */
10
+ const NAME = "min-w-0 cursor-pointer truncate rounded-control text-left font-medium text-ink outline-primary outline-offset-2 hover:underline hover:underline-offset-4 focus-visible:outline-2 forced-colors:outline-[Highlight] aria-busy:cursor-progress aria-busy:opacity-70";
11
+ export function FileValue({ file, size = "sm", onDownload }) {
12
+ const copy = useUiCopy();
13
+ const [busy, setBusy] = useState(false);
14
+ if (file === null || file === undefined)
15
+ return null;
16
+ const kind = attachmentKind(file.name, file.type);
17
+ const picture = kind === "image" ? (file.thumbnail ?? file.url) : undefined;
18
+ const download = async () => {
19
+ if (onDownload === undefined || busy)
20
+ return;
21
+ setBusy(true);
22
+ try {
23
+ await onDownload(file);
24
+ }
25
+ finally {
26
+ setBusy(false);
27
+ }
28
+ };
29
+ const name = onDownload !== undefined ? (_jsx("button", { type: "button", title: file.name, "aria-busy": busy || undefined, onClick: (event) => {
30
+ stay(event);
31
+ void download();
32
+ }, className: NAME, children: file.name })) : file.url !== undefined ? (_jsx("a", { href: file.url, download: file.name, title: file.name, onClick: stay, className: NAME, children: file.name })) : (_jsx("span", { title: file.name, className: "min-w-0 truncate font-medium text-ink", children: file.name }));
33
+ if (size === "md") {
34
+ const extension = fileExtension(file.name).toUpperCase();
35
+ return (_jsxs("span", { "data-ui": "file-value", "data-size": "md", className: "flex max-w-full min-w-0 items-center gap-3", children: [_jsx(FileThumb, { file: file, kind: kind, size: "md" }), _jsxs("span", { className: "flex min-w-0 flex-col gap-0.5 text-meta", children: [name, _jsxs("span", { className: "flex min-w-0 flex-wrap items-center gap-x-2 text-micro text-muted tabular-nums", children: [extension === "" ? null : _jsx("span", { children: extension }), extension !== "" && file.size !== undefined ? _jsx("span", { "aria-hidden": true, children: "\u00B7" }) : null, file.size === undefined ? null : (_jsx("span", { className: "whitespace-nowrap", children: formatFileSize(file.size, copy.locale) }))] })] })] }));
36
+ }
37
+ return (_jsxs("span", { "data-ui": "file-value", "data-size": "sm", className: "inline-flex max-w-full min-w-0 items-center gap-2 align-middle", children: [picture === undefined ? (_jsx(FileThumb, { file: file, kind: kind, size: "sm" })) : (
38
+ /* Decorative: the name beside it says which file it is. */
39
+ _jsx("img", { src: picture, alt: "", loading: "lazy", className: "size-(--size-control-sm) shrink-0 rounded-control border border-line object-cover" })), name] }));
40
+ }
@@ -2,3 +2,4 @@ export { Attachments, type AttachmentsProps, } from "./Attachments.js";
2
2
  export { downloadFile } from "./download.js";
3
3
  export { FileList, type FileListLayout, type FileListProps, } from "./FileList.js";
4
4
  export { type AttachmentFile, type AttachmentKind, attachmentKind, type AttachmentStatus, fileExtension, formatFileSize, } from "./files.js";
5
+ export { FileValue, type FileValueProps, } from "./FileValue.js";
@@ -1,6 +1,8 @@
1
1
  /* ATTACHMENTS — the files of a record (`Attachments`: add, remove, undo), files shown inside a
2
- message, a card or a section (`FileList`), and how to save one fetched by code. */
2
+ message, a card or a section (`FileList`), one file as a value (`FileValue`), and how to save
3
+ one fetched by code. */
3
4
  export { Attachments, } from "./Attachments.js";
4
5
  export { downloadFile } from "./download.js";
5
6
  export { FileList, } from "./FileList.js";
6
7
  export { attachmentKind, fileExtension, formatFileSize, } from "./files.js";
8
+ export { FileValue, } from "./FileValue.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-ui",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "description": "An enterprise web design system for business software — ERPs, back offices, management tools — in React and Tailwind: tokens, primitives, components and the two views every management screen is made of.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",