@openwarelabs/ui 0.14.1 → 0.16.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 +5 -5
- package/dist/components/ActivityHeatmap/ActivityHeatmap.d.cts +8 -0
- package/dist/components/ActivityHeatmap/ActivityHeatmap.d.ts +8 -0
- package/dist/components/ActivityHeatmap/ActivityHeatmap.types.d.cts +73 -0
- package/dist/components/ActivityHeatmap/ActivityHeatmap.types.d.ts +73 -0
- package/dist/components/DiffViewer/DiffViewer.d.cts +8 -0
- package/dist/components/DiffViewer/DiffViewer.d.ts +8 -0
- package/dist/components/DiffViewer/DiffViewer.types.d.cts +131 -0
- package/dist/components/DiffViewer/DiffViewer.types.d.ts +131 -0
- package/dist/components/DiffViewer/diff.d.cts +10 -0
- package/dist/components/DiffViewer/diff.d.ts +10 -0
- package/dist/components/InlineEdit/InlineEdit.d.cts +8 -0
- package/dist/components/InlineEdit/InlineEdit.d.ts +8 -0
- package/dist/components/InlineEdit/InlineEdit.types.d.cts +74 -0
- package/dist/components/InlineEdit/InlineEdit.types.d.ts +74 -0
- package/dist/components/Markdown/Markdown.d.cts +8 -0
- package/dist/components/Markdown/Markdown.d.ts +8 -0
- package/dist/components/Markdown/Markdown.types.d.cts +59 -0
- package/dist/components/Markdown/Markdown.types.d.ts +59 -0
- package/dist/components/MediaPlayer/MediaPlayer.d.cts +8 -0
- package/dist/components/MediaPlayer/MediaPlayer.d.ts +8 -0
- package/dist/components/MediaPlayer/MediaPlayer.types.d.cts +109 -0
- package/dist/components/MediaPlayer/MediaPlayer.types.d.ts +109 -0
- package/dist/components/MentionInput/MentionInput.d.cts +9 -0
- package/dist/components/MentionInput/MentionInput.d.ts +9 -0
- package/dist/components/MentionInput/MentionInput.types.d.cts +125 -0
- package/dist/components/MentionInput/MentionInput.types.d.ts +125 -0
- package/dist/components/MentionInput/useMentions.d.cts +8 -0
- package/dist/components/MentionInput/useMentions.d.ts +8 -0
- package/dist/components/NavigationMenu/NavigationMenu.d.cts +14 -0
- package/dist/components/NavigationMenu/NavigationMenu.d.ts +14 -0
- package/dist/components/NavigationMenu/NavigationMenu.types.d.cts +84 -0
- package/dist/components/NavigationMenu/NavigationMenu.types.d.ts +84 -0
- package/dist/components/NotificationCenter/NotificationCenter.d.cts +12 -0
- package/dist/components/NotificationCenter/NotificationCenter.d.ts +12 -0
- package/dist/components/NotificationCenter/NotificationCenter.types.d.cts +129 -0
- package/dist/components/NotificationCenter/NotificationCenter.types.d.ts +129 -0
- package/dist/components/QRCode/QRCode.d.cts +18 -0
- package/dist/components/QRCode/QRCode.d.ts +18 -0
- package/dist/components/QRCode/QRCode.types.d.cts +53 -0
- package/dist/components/QRCode/QRCode.types.d.ts +53 -0
- package/dist/components/QRCode/qr.d.cts +8 -0
- package/dist/components/QRCode/qr.d.ts +8 -0
- package/dist/components/SignaturePad/SignaturePad.d.cts +8 -0
- package/dist/components/SignaturePad/SignaturePad.d.ts +8 -0
- package/dist/components/SignaturePad/SignaturePad.types.d.cts +102 -0
- package/dist/components/SignaturePad/SignaturePad.types.d.ts +102 -0
- package/dist/components/SortableList/SortableList.d.cts +7 -0
- package/dist/components/SortableList/SortableList.d.ts +7 -0
- package/dist/components/SortableList/SortableList.types.d.cts +82 -0
- package/dist/components/SortableList/SortableList.types.d.ts +82 -0
- package/dist/components/TransferList/TransferList.d.cts +7 -0
- package/dist/components/TransferList/TransferList.d.ts +7 -0
- package/dist/components/TransferList/TransferList.types.d.cts +75 -0
- package/dist/components/TransferList/TransferList.types.d.ts +75 -0
- package/dist/components/TreeView/TreeView.d.cts +8 -0
- package/dist/components/TreeView/TreeView.d.ts +8 -0
- package/dist/components/TreeView/TreeView.types.d.cts +88 -0
- package/dist/components/TreeView/TreeView.types.d.ts +88 -0
- package/dist/components/UploadList/UploadList.d.cts +9 -0
- package/dist/components/UploadList/UploadList.d.ts +9 -0
- package/dist/components/UploadList/UploadList.types.d.cts +113 -0
- package/dist/components/UploadList/UploadList.types.d.ts +113 -0
- package/dist/components/UploadList/useUploadQueue.d.cts +8 -0
- package/dist/components/UploadList/useUploadQueue.d.ts +8 -0
- package/dist/components/VirtualList/VirtualList.d.cts +9 -0
- package/dist/components/VirtualList/VirtualList.d.ts +9 -0
- package/dist/components/VirtualList/VirtualList.types.d.cts +80 -0
- package/dist/components/VirtualList/VirtualList.types.d.ts +80 -0
- package/dist/components/VirtualList/useVirtualizer.d.cts +60 -0
- package/dist/components/VirtualList/useVirtualizer.d.ts +60 -0
- package/dist/components.css +1840 -113
- package/dist/index.cjs +6770 -2144
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.cts +32 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +6790 -2124
- package/dist/index.js.map +4 -4
- package/dist/openware-ui.iife.js +24 -8
- package/dist/styles.css +1840 -113
- package/package.json +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface TransferListOption {
|
|
3
|
+
/** What goes in the value when it's chosen. Unique among the options. */
|
|
4
|
+
value: string;
|
|
5
|
+
/** The text in the list, matched by the search and read out when it moves. */
|
|
6
|
+
label: string;
|
|
7
|
+
/** A muted line under the label; matched by the search when it's a string. */
|
|
8
|
+
description?: ReactNode;
|
|
9
|
+
/** Stays on its side: it can't be selected or moved. */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** A heading to show it under. Options with the same group are listed together, groups in the order they first appear. */
|
|
12
|
+
group?: string;
|
|
13
|
+
}
|
|
14
|
+
/** One side of the transfer list. Internal. */
|
|
15
|
+
export type TransferListSide = "source" | "target";
|
|
16
|
+
export interface TransferListProps {
|
|
17
|
+
/** Everything that can be chosen. The available side lists them in this order. */
|
|
18
|
+
options: TransferListOption[];
|
|
19
|
+
/** The chosen values, in order, when you control them. */
|
|
20
|
+
value?: string[];
|
|
21
|
+
/** The chosen values at first, when it controls them itself.
|
|
22
|
+
* @default [] */
|
|
23
|
+
defaultValue?: string[];
|
|
24
|
+
/** Called with the chosen values when they move or are reordered. Moved values join the end. */
|
|
25
|
+
onChange?(value: string[]): void;
|
|
26
|
+
/** The heading over the available list, which also names it.
|
|
27
|
+
* @default "Available" */
|
|
28
|
+
sourceLabel?: string;
|
|
29
|
+
/** The heading over the chosen list, which also names it.
|
|
30
|
+
* @default "Selected" */
|
|
31
|
+
targetLabel?: string;
|
|
32
|
+
/** A search box over each list that filters it by label and description.
|
|
33
|
+
* @default false */
|
|
34
|
+
searchable?: boolean;
|
|
35
|
+
/** Adds buttons that move every item (that the search shows) from one side to the other.
|
|
36
|
+
* @default false */
|
|
37
|
+
showMoveAll?: boolean;
|
|
38
|
+
/** Adds Move up and Move down buttons under the chosen list (and Alt+Up/Down in it), for an order that matters.
|
|
39
|
+
* The chosen list is then shown without group headings, in the value's order.
|
|
40
|
+
* @default false */
|
|
41
|
+
orderable?: boolean;
|
|
42
|
+
/** Submits each chosen value under this name, in a hidden input, so a Form or a plain form sends them as a list. */
|
|
43
|
+
name?: string;
|
|
44
|
+
/** Fades both lists and the buttons, and takes them out of the tab order.
|
|
45
|
+
* @default false */
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
/** The lists' height, e.g. 320 or "40vh"; they scroll past it.
|
|
48
|
+
* @default 280 */
|
|
49
|
+
height?: number | string;
|
|
50
|
+
id?: string;
|
|
51
|
+
/** The words it uses, for other languages. `to` is the side's label. */
|
|
52
|
+
labels?: {
|
|
53
|
+
/** The count under each heading. @default (selected, total) => `${selected} of ${total} selected` */
|
|
54
|
+
count?(selected: number, total: number): string;
|
|
55
|
+
/** The button that moves the selected items. @default (count, to) => `Move 2 selected to ${to}`, or `Move selected to ${to}` with none */
|
|
56
|
+
moveSelected?(count: number, to: string): string;
|
|
57
|
+
/** The button that moves them all, with `showMoveAll`. @default (to) => `Move all to ${to}` */
|
|
58
|
+
moveAll?(to: string): string;
|
|
59
|
+
/** Read out after a move. @default (names, to) => `Moved Ada and Grace to ${to}`, or `Moved 7 items to ${to}` past five */
|
|
60
|
+
moved?(names: string[], to: string): string;
|
|
61
|
+
/** With `orderable`. @default "Move up" */
|
|
62
|
+
moveUp?: string;
|
|
63
|
+
/** With `orderable`. @default "Move down" */
|
|
64
|
+
moveDown?: string;
|
|
65
|
+
/** Read out after reordering. @default (names, direction) => `Moved Ada up` */
|
|
66
|
+
reordered?(names: string[], direction: "up" | "down"): string;
|
|
67
|
+
/** Names a side's search box. @default (side) => `Search ${side}` */
|
|
68
|
+
search?(side: string): string;
|
|
69
|
+
/** Shown in an empty list. @default "No items" */
|
|
70
|
+
empty?: ReactNode;
|
|
71
|
+
/** Shown when the search matches nothing. @default "No matches" */
|
|
72
|
+
noMatches?: ReactNode;
|
|
73
|
+
};
|
|
74
|
+
className?: string;
|
|
75
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TreeViewProps } from "./TreeView.types.cjs";
|
|
2
|
+
export type { TreeItem, TreeViewLabels, TreeViewProps, TreeViewSelectionMode } from "./TreeView.types.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* A tree of rows that open and close, for categories, org charts, permissions, nested settings or navigation. Rows can
|
|
5
|
+
* be selected (one or many), checked with tri-state parents, activated, and their children fetched when they first open.
|
|
6
|
+
* It's one tab stop: the arrow keys move and open, Home/End jump, typing finds a row, Space selects and Enter activates.
|
|
7
|
+
*/
|
|
8
|
+
export declare function TreeView({ items, label, "aria-labelledby": ariaLabelledBy, expanded, defaultExpanded, onExpandedChange, selectionMode, selected, defaultSelected, onSelectedChange, checkboxes, loadChildren, onAction, renderLabel, labels: labelsProp, className, }: TreeViewProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TreeViewProps } from "./TreeView.types.js";
|
|
2
|
+
export type { TreeItem, TreeViewLabels, TreeViewProps, TreeViewSelectionMode } from "./TreeView.types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A tree of rows that open and close, for categories, org charts, permissions, nested settings or navigation. Rows can
|
|
5
|
+
* be selected (one or many), checked with tri-state parents, activated, and their children fetched when they first open.
|
|
6
|
+
* It's one tab stop: the arrow keys move and open, Home/End jump, typing finds a row, Space selects and Enter activates.
|
|
7
|
+
*/
|
|
8
|
+
export declare function TreeView({ items, label, "aria-labelledby": ariaLabelledBy, expanded, defaultExpanded, onExpandedChange, selectionMode, selected, defaultSelected, onSelectedChange, checkboxes, loadChildren, onAction, renderLabel, labels: labelsProp, className, }: TreeViewProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/** One row of the tree, and the rows under it. */
|
|
3
|
+
export interface TreeItem {
|
|
4
|
+
/** Unique in the whole tree: it's what `expanded` and `selected` hold. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** The row's text. It names the row for screen readers and is what type-ahead matches. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** A 16px icon before the label. */
|
|
9
|
+
icon?: ReactNode;
|
|
10
|
+
/** A muted line under the label. */
|
|
11
|
+
description?: ReactNode;
|
|
12
|
+
/** Muted content at the end of the row: a count, a badge, a status. Keep it non-interactive. */
|
|
13
|
+
end?: ReactNode;
|
|
14
|
+
/** It can be focused and opened, but not selected, checked or activated. */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/** The rows under this one. */
|
|
17
|
+
children?: TreeItem[];
|
|
18
|
+
/** It has children that `loadChildren` fetches the first time it opens. */
|
|
19
|
+
hasChildren?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export type TreeViewSelectionMode = "none" | "single" | "multiple";
|
|
22
|
+
export interface TreeViewLabels {
|
|
23
|
+
/** The row shown while children load.
|
|
24
|
+
* @default "Loading…" */
|
|
25
|
+
loading?: string;
|
|
26
|
+
/** The row shown when they couldn't load, before the retry text.
|
|
27
|
+
* @default "Couldn't load." */
|
|
28
|
+
error?: string;
|
|
29
|
+
/** The retry text in that row; activating the row tries again.
|
|
30
|
+
* @default "Retry" */
|
|
31
|
+
retry?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface TreeViewProps {
|
|
34
|
+
/** The top-level rows. */
|
|
35
|
+
items: TreeItem[];
|
|
36
|
+
/** Names the tree for screen readers: "Categories", "Permissions". */
|
|
37
|
+
label?: string;
|
|
38
|
+
/** Names the tree by another element's id instead, such as a heading's. */
|
|
39
|
+
"aria-labelledby"?: string;
|
|
40
|
+
/** The ids of the open rows, when you control them. */
|
|
41
|
+
expanded?: string[];
|
|
42
|
+
/** The ids open at first when uncontrolled.
|
|
43
|
+
* @default [] */
|
|
44
|
+
defaultExpanded?: string[];
|
|
45
|
+
/** Called with the open ids when a row opens or closes. */
|
|
46
|
+
onExpandedChange?(expanded: string[]): void;
|
|
47
|
+
/** `single` selects one row; `multiple` any number (Shift extends a range); `none` makes rows only activate.
|
|
48
|
+
* @default "single" */
|
|
49
|
+
selectionMode?: TreeViewSelectionMode;
|
|
50
|
+
/** The selected (or checked) ids, when you control them. */
|
|
51
|
+
selected?: string[];
|
|
52
|
+
/** The ids selected at first when uncontrolled.
|
|
53
|
+
* @default [] */
|
|
54
|
+
defaultSelected?: string[];
|
|
55
|
+
/** Called with the selected (or checked) ids, in the tree's order. */
|
|
56
|
+
onSelectedChange?(selected: string[]): void;
|
|
57
|
+
/** Shows a checkbox on each row for picking several. Checking a row checks the loaded rows under it, and a row whose
|
|
58
|
+
* rows are partly checked shows a dash. `selected` then holds every fully checked id. Implies multiple selection.
|
|
59
|
+
* @default false */
|
|
60
|
+
checkboxes?: boolean;
|
|
61
|
+
/** Fetches a row's children the first time it opens, for rows with `hasChildren`. A loading row shows meanwhile,
|
|
62
|
+
* and if it rejects, a row to retry. */
|
|
63
|
+
loadChildren?(item: TreeItem): Promise<TreeItem[]>;
|
|
64
|
+
/** Called when a row is activated: Enter, a double-click, or a click when `selectionMode` is `none`. */
|
|
65
|
+
onAction?(item: TreeItem): void;
|
|
66
|
+
/** Draws each row's label instead of the plain text, e.g. to highlight a search match. */
|
|
67
|
+
renderLabel?(item: TreeItem): ReactNode;
|
|
68
|
+
/** The words it shows, for other languages. */
|
|
69
|
+
labels?: TreeViewLabels;
|
|
70
|
+
className?: string;
|
|
71
|
+
}
|
|
72
|
+
/** A row's checkbox: checked, not, or partly (some of the rows under it). Internal. */
|
|
73
|
+
export type TreeViewChecked = boolean | "mixed";
|
|
74
|
+
/** A visible row: an item, or the loading or error row under an item whose children are being fetched. Internal. */
|
|
75
|
+
export interface TreeViewRow {
|
|
76
|
+
id: string;
|
|
77
|
+
item?: TreeItem;
|
|
78
|
+
status?: "loading" | "error";
|
|
79
|
+
parent?: TreeViewRow;
|
|
80
|
+
/** Its place in the visible rows. */
|
|
81
|
+
index: number;
|
|
82
|
+
level: number;
|
|
83
|
+
pos: number;
|
|
84
|
+
size: number;
|
|
85
|
+
expandable: boolean;
|
|
86
|
+
open: boolean;
|
|
87
|
+
kids: TreeViewRow[];
|
|
88
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/** One row of the tree, and the rows under it. */
|
|
3
|
+
export interface TreeItem {
|
|
4
|
+
/** Unique in the whole tree: it's what `expanded` and `selected` hold. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** The row's text. It names the row for screen readers and is what type-ahead matches. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** A 16px icon before the label. */
|
|
9
|
+
icon?: ReactNode;
|
|
10
|
+
/** A muted line under the label. */
|
|
11
|
+
description?: ReactNode;
|
|
12
|
+
/** Muted content at the end of the row: a count, a badge, a status. Keep it non-interactive. */
|
|
13
|
+
end?: ReactNode;
|
|
14
|
+
/** It can be focused and opened, but not selected, checked or activated. */
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/** The rows under this one. */
|
|
17
|
+
children?: TreeItem[];
|
|
18
|
+
/** It has children that `loadChildren` fetches the first time it opens. */
|
|
19
|
+
hasChildren?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export type TreeViewSelectionMode = "none" | "single" | "multiple";
|
|
22
|
+
export interface TreeViewLabels {
|
|
23
|
+
/** The row shown while children load.
|
|
24
|
+
* @default "Loading…" */
|
|
25
|
+
loading?: string;
|
|
26
|
+
/** The row shown when they couldn't load, before the retry text.
|
|
27
|
+
* @default "Couldn't load." */
|
|
28
|
+
error?: string;
|
|
29
|
+
/** The retry text in that row; activating the row tries again.
|
|
30
|
+
* @default "Retry" */
|
|
31
|
+
retry?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface TreeViewProps {
|
|
34
|
+
/** The top-level rows. */
|
|
35
|
+
items: TreeItem[];
|
|
36
|
+
/** Names the tree for screen readers: "Categories", "Permissions". */
|
|
37
|
+
label?: string;
|
|
38
|
+
/** Names the tree by another element's id instead, such as a heading's. */
|
|
39
|
+
"aria-labelledby"?: string;
|
|
40
|
+
/** The ids of the open rows, when you control them. */
|
|
41
|
+
expanded?: string[];
|
|
42
|
+
/** The ids open at first when uncontrolled.
|
|
43
|
+
* @default [] */
|
|
44
|
+
defaultExpanded?: string[];
|
|
45
|
+
/** Called with the open ids when a row opens or closes. */
|
|
46
|
+
onExpandedChange?(expanded: string[]): void;
|
|
47
|
+
/** `single` selects one row; `multiple` any number (Shift extends a range); `none` makes rows only activate.
|
|
48
|
+
* @default "single" */
|
|
49
|
+
selectionMode?: TreeViewSelectionMode;
|
|
50
|
+
/** The selected (or checked) ids, when you control them. */
|
|
51
|
+
selected?: string[];
|
|
52
|
+
/** The ids selected at first when uncontrolled.
|
|
53
|
+
* @default [] */
|
|
54
|
+
defaultSelected?: string[];
|
|
55
|
+
/** Called with the selected (or checked) ids, in the tree's order. */
|
|
56
|
+
onSelectedChange?(selected: string[]): void;
|
|
57
|
+
/** Shows a checkbox on each row for picking several. Checking a row checks the loaded rows under it, and a row whose
|
|
58
|
+
* rows are partly checked shows a dash. `selected` then holds every fully checked id. Implies multiple selection.
|
|
59
|
+
* @default false */
|
|
60
|
+
checkboxes?: boolean;
|
|
61
|
+
/** Fetches a row's children the first time it opens, for rows with `hasChildren`. A loading row shows meanwhile,
|
|
62
|
+
* and if it rejects, a row to retry. */
|
|
63
|
+
loadChildren?(item: TreeItem): Promise<TreeItem[]>;
|
|
64
|
+
/** Called when a row is activated: Enter, a double-click, or a click when `selectionMode` is `none`. */
|
|
65
|
+
onAction?(item: TreeItem): void;
|
|
66
|
+
/** Draws each row's label instead of the plain text, e.g. to highlight a search match. */
|
|
67
|
+
renderLabel?(item: TreeItem): ReactNode;
|
|
68
|
+
/** The words it shows, for other languages. */
|
|
69
|
+
labels?: TreeViewLabels;
|
|
70
|
+
className?: string;
|
|
71
|
+
}
|
|
72
|
+
/** A row's checkbox: checked, not, or partly (some of the rows under it). Internal. */
|
|
73
|
+
export type TreeViewChecked = boolean | "mixed";
|
|
74
|
+
/** A visible row: an item, or the loading or error row under an item whose children are being fetched. Internal. */
|
|
75
|
+
export interface TreeViewRow {
|
|
76
|
+
id: string;
|
|
77
|
+
item?: TreeItem;
|
|
78
|
+
status?: "loading" | "error";
|
|
79
|
+
parent?: TreeViewRow;
|
|
80
|
+
/** Its place in the visible rows. */
|
|
81
|
+
index: number;
|
|
82
|
+
level: number;
|
|
83
|
+
pos: number;
|
|
84
|
+
size: number;
|
|
85
|
+
expandable: boolean;
|
|
86
|
+
open: boolean;
|
|
87
|
+
kids: TreeViewRow[];
|
|
88
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { UploadListProps } from "./UploadList.types.cjs";
|
|
2
|
+
export type { UploadContext, Uploader, UploadListItem, UploadListLabels, UploadListProps, UploadQueue, UploadStatus, UseUploadQueueOptions, } from "./UploadList.types.cjs";
|
|
3
|
+
export { useUploadQueue } from "./useUploadQueue.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* The files being uploaded, under a FileDropZone: each with its size, a progress bar while it uploads, and its
|
|
6
|
+
* status. Retry, Cancel and Remove buttons call back with the file's id. Finished and failed files are announced
|
|
7
|
+
* politely. `useUploadQueue` does the uploading and keeps the `items` for you.
|
|
8
|
+
*/
|
|
9
|
+
export declare function UploadList({ items, onRetry, onCancel, onRemove, layout, density, showTimeRemaining, locale, labels: labelsProp, className, }: UploadListProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { UploadListProps } from "./UploadList.types.js";
|
|
2
|
+
export type { UploadContext, Uploader, UploadListItem, UploadListLabels, UploadListProps, UploadQueue, UploadStatus, UseUploadQueueOptions, } from "./UploadList.types.js";
|
|
3
|
+
export { useUploadQueue } from "./useUploadQueue.js";
|
|
4
|
+
/**
|
|
5
|
+
* The files being uploaded, under a FileDropZone: each with its size, a progress bar while it uploads, and its
|
|
6
|
+
* status. Retry, Cancel and Remove buttons call back with the file's id. Finished and failed files are announced
|
|
7
|
+
* politely. `useUploadQueue` does the uploading and keeps the `items` for you.
|
|
8
|
+
*/
|
|
9
|
+
export declare function UploadList({ items, onRetry, onCancel, onRemove, layout, density, showTimeRemaining, locale, labels: labelsProp, className, }: UploadListProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** Where a file's upload has got to. */
|
|
2
|
+
export type UploadStatus = "queued" | "uploading" | "done" | "error" | "canceled";
|
|
3
|
+
/** One file in an UploadList. */
|
|
4
|
+
export interface UploadListItem {
|
|
5
|
+
/** Tells the rows apart; stays the same while the file uploads. */
|
|
6
|
+
id: string;
|
|
7
|
+
/** The file's name, shown and used to name its buttons: "report.pdf". */
|
|
8
|
+
name: string;
|
|
9
|
+
/** The file's size in bytes. */
|
|
10
|
+
size: number;
|
|
11
|
+
/** The file's MIME type, such as "image/png". */
|
|
12
|
+
type?: string;
|
|
13
|
+
/** How far it's got, from 0 to 100. Leave it out while uploading for a bar of unknown length. */
|
|
14
|
+
progress?: number;
|
|
15
|
+
/** Where it's got to: `queued` waits its turn, `uploading` shows a bar, `done`, `error` and `canceled` say so. */
|
|
16
|
+
status: UploadStatus;
|
|
17
|
+
/** Why it failed, shown in place of the size when the status is "error". */
|
|
18
|
+
error?: string;
|
|
19
|
+
/** An image to show as its thumbnail, such as an object URL of the file. */
|
|
20
|
+
previewUrl?: string;
|
|
21
|
+
/** Where the uploaded file is: once it's done, the name links there. */
|
|
22
|
+
href?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface UploadListLabels {
|
|
25
|
+
/** Names the list for screen readers.
|
|
26
|
+
* @default "Uploads" */
|
|
27
|
+
list?: string;
|
|
28
|
+
/** @default "Waiting" */
|
|
29
|
+
queued?: string;
|
|
30
|
+
/** Shown while uploading when the progress isn't known.
|
|
31
|
+
* @default "Uploading" */
|
|
32
|
+
uploading?: string;
|
|
33
|
+
/** @default "Upload failed" */
|
|
34
|
+
failed?: string;
|
|
35
|
+
/** @default "Canceled" */
|
|
36
|
+
canceled?: string;
|
|
37
|
+
/** How much has gone up, from sizes already formatted.
|
|
38
|
+
* @default (loaded, total) => `${loaded} of ${total}` */
|
|
39
|
+
progress?(loaded: string, total: string): string;
|
|
40
|
+
/** The time left, in seconds.
|
|
41
|
+
* @default (seconds) => "About 12 sec left" */
|
|
42
|
+
remaining?(seconds: number): string;
|
|
43
|
+
/** Formats a size in bytes.
|
|
44
|
+
* @default 2.1 MB, 340 kB, with Intl.NumberFormat */
|
|
45
|
+
size?(bytes: number): string;
|
|
46
|
+
/** @default (name) => `Retry upload of ${name}` */
|
|
47
|
+
retry?(name: string): string;
|
|
48
|
+
/** @default (name) => `Cancel upload of ${name}` */
|
|
49
|
+
cancel?(name: string): string;
|
|
50
|
+
/** @default (name) => `Remove ${name}` */
|
|
51
|
+
remove?(name: string): string;
|
|
52
|
+
/** Announced when a file finishes.
|
|
53
|
+
* @default (name) => `${name} uploaded` */
|
|
54
|
+
done?(name: string): string;
|
|
55
|
+
/** Announced when a file fails.
|
|
56
|
+
* @default (name, error) => `${name} failed to upload: ${error}` */
|
|
57
|
+
error?(name: string, error?: string): string;
|
|
58
|
+
}
|
|
59
|
+
export interface UploadListProps {
|
|
60
|
+
/** The files, in the order to show them. `useUploadQueue` keeps a list like this for you. */
|
|
61
|
+
items: UploadListItem[];
|
|
62
|
+
/** Called when Retry is pressed on a file that failed or was canceled. Without it there's no Retry button. */
|
|
63
|
+
onRetry?(id: string): void;
|
|
64
|
+
/** Called when Cancel is pressed on a file that's waiting or uploading. Without it there's no Cancel button. */
|
|
65
|
+
onCancel?(id: string): void;
|
|
66
|
+
/** Called when Remove is pressed. Without it there's no Remove button. */
|
|
67
|
+
onRemove?(id: string): void;
|
|
68
|
+
/** `list` is a row per file; `grid` is a tile per file, with a large thumbnail, for images.
|
|
69
|
+
* @default "list" */
|
|
70
|
+
layout?: "list" | "grid";
|
|
71
|
+
/** `compact` fits each file on one short line, for a sidebar or a long list.
|
|
72
|
+
* @default "comfortable" */
|
|
73
|
+
density?: "comfortable" | "compact";
|
|
74
|
+
/** Shows an estimate of the time left on files that are uploading.
|
|
75
|
+
* @default false */
|
|
76
|
+
showTimeRemaining?: boolean;
|
|
77
|
+
/** The locale sizes and times are formatted in.
|
|
78
|
+
* @default "en" */
|
|
79
|
+
locale?: string;
|
|
80
|
+
/** The words it uses, for other languages. */
|
|
81
|
+
labels?: UploadListLabels;
|
|
82
|
+
className?: string;
|
|
83
|
+
}
|
|
84
|
+
/** What an uploader is given along with the file. */
|
|
85
|
+
export interface UploadContext {
|
|
86
|
+
/** Report how far it's got, from 0 to 100, or undefined when it can't tell. */
|
|
87
|
+
onProgress(progress: number | undefined): void;
|
|
88
|
+
/** Aborted when the upload is canceled or removed: pass it to fetch, or listen for "abort". */
|
|
89
|
+
signal: AbortSignal;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Uploads one file. Resolve when it's done, with the uploaded file's URL if you have one (the name then links to it);
|
|
93
|
+
* throw or reject to fail it, and the error's message is shown.
|
|
94
|
+
*/
|
|
95
|
+
export type Uploader = (file: File, context: UploadContext) => Promise<string | void>;
|
|
96
|
+
export interface UseUploadQueueOptions {
|
|
97
|
+
/** How many files upload at once.
|
|
98
|
+
* @default 3 */
|
|
99
|
+
concurrency?: number;
|
|
100
|
+
}
|
|
101
|
+
/** What `useUploadQueue` returns: the items for UploadList and the actions for its buttons. */
|
|
102
|
+
export interface UploadQueue {
|
|
103
|
+
/** The files and how they're going, for `UploadList`'s `items`. */
|
|
104
|
+
items: UploadListItem[];
|
|
105
|
+
/** Adds files to the queue, such as those from `FileDropZone`'s `onFiles`. */
|
|
106
|
+
add(files: File[]): void;
|
|
107
|
+
/** Puts a failed or canceled file back in the queue. */
|
|
108
|
+
retry(id: string): void;
|
|
109
|
+
/** Stops a file that's waiting or uploading, aborting its signal. */
|
|
110
|
+
cancel(id: string): void;
|
|
111
|
+
/** Stops a file if it's going, and takes it off the list. */
|
|
112
|
+
remove(id: string): void;
|
|
113
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** Where a file's upload has got to. */
|
|
2
|
+
export type UploadStatus = "queued" | "uploading" | "done" | "error" | "canceled";
|
|
3
|
+
/** One file in an UploadList. */
|
|
4
|
+
export interface UploadListItem {
|
|
5
|
+
/** Tells the rows apart; stays the same while the file uploads. */
|
|
6
|
+
id: string;
|
|
7
|
+
/** The file's name, shown and used to name its buttons: "report.pdf". */
|
|
8
|
+
name: string;
|
|
9
|
+
/** The file's size in bytes. */
|
|
10
|
+
size: number;
|
|
11
|
+
/** The file's MIME type, such as "image/png". */
|
|
12
|
+
type?: string;
|
|
13
|
+
/** How far it's got, from 0 to 100. Leave it out while uploading for a bar of unknown length. */
|
|
14
|
+
progress?: number;
|
|
15
|
+
/** Where it's got to: `queued` waits its turn, `uploading` shows a bar, `done`, `error` and `canceled` say so. */
|
|
16
|
+
status: UploadStatus;
|
|
17
|
+
/** Why it failed, shown in place of the size when the status is "error". */
|
|
18
|
+
error?: string;
|
|
19
|
+
/** An image to show as its thumbnail, such as an object URL of the file. */
|
|
20
|
+
previewUrl?: string;
|
|
21
|
+
/** Where the uploaded file is: once it's done, the name links there. */
|
|
22
|
+
href?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface UploadListLabels {
|
|
25
|
+
/** Names the list for screen readers.
|
|
26
|
+
* @default "Uploads" */
|
|
27
|
+
list?: string;
|
|
28
|
+
/** @default "Waiting" */
|
|
29
|
+
queued?: string;
|
|
30
|
+
/** Shown while uploading when the progress isn't known.
|
|
31
|
+
* @default "Uploading" */
|
|
32
|
+
uploading?: string;
|
|
33
|
+
/** @default "Upload failed" */
|
|
34
|
+
failed?: string;
|
|
35
|
+
/** @default "Canceled" */
|
|
36
|
+
canceled?: string;
|
|
37
|
+
/** How much has gone up, from sizes already formatted.
|
|
38
|
+
* @default (loaded, total) => `${loaded} of ${total}` */
|
|
39
|
+
progress?(loaded: string, total: string): string;
|
|
40
|
+
/** The time left, in seconds.
|
|
41
|
+
* @default (seconds) => "About 12 sec left" */
|
|
42
|
+
remaining?(seconds: number): string;
|
|
43
|
+
/** Formats a size in bytes.
|
|
44
|
+
* @default 2.1 MB, 340 kB, with Intl.NumberFormat */
|
|
45
|
+
size?(bytes: number): string;
|
|
46
|
+
/** @default (name) => `Retry upload of ${name}` */
|
|
47
|
+
retry?(name: string): string;
|
|
48
|
+
/** @default (name) => `Cancel upload of ${name}` */
|
|
49
|
+
cancel?(name: string): string;
|
|
50
|
+
/** @default (name) => `Remove ${name}` */
|
|
51
|
+
remove?(name: string): string;
|
|
52
|
+
/** Announced when a file finishes.
|
|
53
|
+
* @default (name) => `${name} uploaded` */
|
|
54
|
+
done?(name: string): string;
|
|
55
|
+
/** Announced when a file fails.
|
|
56
|
+
* @default (name, error) => `${name} failed to upload: ${error}` */
|
|
57
|
+
error?(name: string, error?: string): string;
|
|
58
|
+
}
|
|
59
|
+
export interface UploadListProps {
|
|
60
|
+
/** The files, in the order to show them. `useUploadQueue` keeps a list like this for you. */
|
|
61
|
+
items: UploadListItem[];
|
|
62
|
+
/** Called when Retry is pressed on a file that failed or was canceled. Without it there's no Retry button. */
|
|
63
|
+
onRetry?(id: string): void;
|
|
64
|
+
/** Called when Cancel is pressed on a file that's waiting or uploading. Without it there's no Cancel button. */
|
|
65
|
+
onCancel?(id: string): void;
|
|
66
|
+
/** Called when Remove is pressed. Without it there's no Remove button. */
|
|
67
|
+
onRemove?(id: string): void;
|
|
68
|
+
/** `list` is a row per file; `grid` is a tile per file, with a large thumbnail, for images.
|
|
69
|
+
* @default "list" */
|
|
70
|
+
layout?: "list" | "grid";
|
|
71
|
+
/** `compact` fits each file on one short line, for a sidebar or a long list.
|
|
72
|
+
* @default "comfortable" */
|
|
73
|
+
density?: "comfortable" | "compact";
|
|
74
|
+
/** Shows an estimate of the time left on files that are uploading.
|
|
75
|
+
* @default false */
|
|
76
|
+
showTimeRemaining?: boolean;
|
|
77
|
+
/** The locale sizes and times are formatted in.
|
|
78
|
+
* @default "en" */
|
|
79
|
+
locale?: string;
|
|
80
|
+
/** The words it uses, for other languages. */
|
|
81
|
+
labels?: UploadListLabels;
|
|
82
|
+
className?: string;
|
|
83
|
+
}
|
|
84
|
+
/** What an uploader is given along with the file. */
|
|
85
|
+
export interface UploadContext {
|
|
86
|
+
/** Report how far it's got, from 0 to 100, or undefined when it can't tell. */
|
|
87
|
+
onProgress(progress: number | undefined): void;
|
|
88
|
+
/** Aborted when the upload is canceled or removed: pass it to fetch, or listen for "abort". */
|
|
89
|
+
signal: AbortSignal;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Uploads one file. Resolve when it's done, with the uploaded file's URL if you have one (the name then links to it);
|
|
93
|
+
* throw or reject to fail it, and the error's message is shown.
|
|
94
|
+
*/
|
|
95
|
+
export type Uploader = (file: File, context: UploadContext) => Promise<string | void>;
|
|
96
|
+
export interface UseUploadQueueOptions {
|
|
97
|
+
/** How many files upload at once.
|
|
98
|
+
* @default 3 */
|
|
99
|
+
concurrency?: number;
|
|
100
|
+
}
|
|
101
|
+
/** What `useUploadQueue` returns: the items for UploadList and the actions for its buttons. */
|
|
102
|
+
export interface UploadQueue {
|
|
103
|
+
/** The files and how they're going, for `UploadList`'s `items`. */
|
|
104
|
+
items: UploadListItem[];
|
|
105
|
+
/** Adds files to the queue, such as those from `FileDropZone`'s `onFiles`. */
|
|
106
|
+
add(files: File[]): void;
|
|
107
|
+
/** Puts a failed or canceled file back in the queue. */
|
|
108
|
+
retry(id: string): void;
|
|
109
|
+
/** Stops a file that's waiting or uploading, aborting its signal. */
|
|
110
|
+
cancel(id: string): void;
|
|
111
|
+
/** Stops a file if it's going, and takes it off the list. */
|
|
112
|
+
remove(id: string): void;
|
|
113
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UploadQueue, Uploader, UseUploadQueueOptions } from "./UploadList.types.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Keeps a queue of files for `UploadList`: uploads them with your `uploader`, a few at a time, and tracks each one's
|
|
4
|
+
* progress and status. Cancel and remove abort the upload's signal; retry puts a file back in the queue.
|
|
5
|
+
*
|
|
6
|
+
* `const queue = useUploadQueue((file, { onProgress, signal }) => upload(file, onProgress, signal));`
|
|
7
|
+
*/
|
|
8
|
+
export declare function useUploadQueue(uploader: Uploader, { concurrency }?: UseUploadQueueOptions): UploadQueue;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UploadQueue, Uploader, UseUploadQueueOptions } from "./UploadList.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Keeps a queue of files for `UploadList`: uploads them with your `uploader`, a few at a time, and tracks each one's
|
|
4
|
+
* progress and status. Cancel and remove abort the upload's signal; retry puts a file back in the queue.
|
|
5
|
+
*
|
|
6
|
+
* `const queue = useUploadQueue((file, { onProgress, signal }) => upload(file, onProgress, signal));`
|
|
7
|
+
*/
|
|
8
|
+
export declare function useUploadQueue(uploader: Uploader, { concurrency }?: UseUploadQueueOptions): UploadQueue;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactElement, type RefAttributes } from "react";
|
|
2
|
+
import type { VirtualListHandle, VirtualListProps } from "./VirtualList.types.cjs";
|
|
3
|
+
export type { VirtualListHandle, VirtualListLabels, VirtualListProps } from "./VirtualList.types.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* A scrolling list that renders only the rows in view, for long logs, chat histories and big datasets: 10,000 rows
|
|
6
|
+
* cost what 20 do. Rows have a fixed `itemSize`, or are measured as they render. `onEndReached` loads more as the
|
|
7
|
+
* reader nears the end, `followOutput` keeps a log's newest line in view, and a ref scrolls to any row.
|
|
8
|
+
*/
|
|
9
|
+
export declare const VirtualList: <T = unknown>(props: VirtualListProps<T> & RefAttributes<VirtualListHandle>) => ReactElement | null;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactElement, type RefAttributes } from "react";
|
|
2
|
+
import type { VirtualListHandle, VirtualListProps } from "./VirtualList.types.js";
|
|
3
|
+
export type { VirtualListHandle, VirtualListLabels, VirtualListProps } from "./VirtualList.types.js";
|
|
4
|
+
/**
|
|
5
|
+
* A scrolling list that renders only the rows in view, for long logs, chat histories and big datasets: 10,000 rows
|
|
6
|
+
* cost what 20 do. Rows have a fixed `itemSize`, or are measured as they render. `onEndReached` loads more as the
|
|
7
|
+
* reader nears the end, `followOutput` keeps a log's newest line in view, and a ref scrolls to any row.
|
|
8
|
+
*/
|
|
9
|
+
export declare const VirtualList: <T = unknown>(props: VirtualListProps<T> & RefAttributes<VirtualListHandle>) => ReactElement | null;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { CSSProperties, Key, ReactNode } from "react";
|
|
2
|
+
import type { ScrollToIndexOptions } from "./useVirtualizer.cjs";
|
|
3
|
+
export interface VirtualListLabels {
|
|
4
|
+
/** Announced to screen readers while more rows load.
|
|
5
|
+
* @default "Loading more" */
|
|
6
|
+
loading?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface VirtualListProps<T = unknown> {
|
|
9
|
+
/** The rows' data. Leave it out and pass `count` to render rows from their index alone. */
|
|
10
|
+
items?: readonly T[];
|
|
11
|
+
/** How many rows there are.
|
|
12
|
+
* @default items.length */
|
|
13
|
+
count?: number;
|
|
14
|
+
/** Renders one row. With `count` alone, `item` is undefined: use the index. */
|
|
15
|
+
renderItem(item: T, index: number): ReactNode;
|
|
16
|
+
/** A stable key for each row, such as its id. Give one when rows can be added at the top (older messages), so
|
|
17
|
+
* the view stays where it was, and so measured heights follow their row.
|
|
18
|
+
* @default (item, index) => index */
|
|
19
|
+
getKey?(item: T, index: number): Key;
|
|
20
|
+
/** Every row's height in pixels, when they're all the same. The fastest: nothing is measured. */
|
|
21
|
+
itemSize?: number;
|
|
22
|
+
/** A guess at a row's height in pixels when they vary. Each row is measured once it renders, and replaces the
|
|
23
|
+
* guess without the view jumping; the closer the guess, the steadier the scrollbar.
|
|
24
|
+
* @default 48 */
|
|
25
|
+
estimateSize?: number | ((index: number) => number);
|
|
26
|
+
/** How many rows to render beyond each edge of the view, so fast scrolling doesn't show blank space.
|
|
27
|
+
* @default 4 */
|
|
28
|
+
overscan?: number;
|
|
29
|
+
/** Space between rows, in pixels.
|
|
30
|
+
* @default 0 */
|
|
31
|
+
gap?: number;
|
|
32
|
+
/** The list's height. Without `height` or `maxHeight`, it fills its parent, which needs a height. */
|
|
33
|
+
height?: number | string;
|
|
34
|
+
/** Lets the list grow with its rows up to this height, then scroll. */
|
|
35
|
+
maxHeight?: number | string;
|
|
36
|
+
/** Called when the reader scrolls near the end, to load more rows. Called once per number of rows, and not
|
|
37
|
+
* while `loading` or once `hasMore` is false. */
|
|
38
|
+
onEndReached?(): void;
|
|
39
|
+
/** Called when the reader scrolls near the start, to load older rows (a chat's history). Rows added at the top
|
|
40
|
+
* keep the view where it was, as long as `getKey` gives real keys. */
|
|
41
|
+
onStartReached?(): void;
|
|
42
|
+
/** How close to either end, in pixels, calls `onEndReached` or `onStartReached`.
|
|
43
|
+
* @default 200 */
|
|
44
|
+
endReachedThreshold?: number;
|
|
45
|
+
/** Shows a spinner after the last row and tells screen readers more is loading.
|
|
46
|
+
* @default false */
|
|
47
|
+
loading?: boolean;
|
|
48
|
+
/** Whether there are more rows to load at the end; false stops `onEndReached`.
|
|
49
|
+
* @default true */
|
|
50
|
+
hasMore?: boolean;
|
|
51
|
+
/** Opens at the end and keeps the newest row in view as rows are added or grow, while the reader is at the end:
|
|
52
|
+
* for logs and chats. Scrolling up to read stops it; scrolling back down starts it again.
|
|
53
|
+
* @default false */
|
|
54
|
+
followOutput?: boolean;
|
|
55
|
+
/** `list` for a list of rows. `feed` for an endless stream of articles people read one by one (posts, news):
|
|
56
|
+
* each row is a focusable article, and Page Down and Page Up move between them.
|
|
57
|
+
* @default "list" */
|
|
58
|
+
role?: "list" | "feed";
|
|
59
|
+
/** Names the list for screen readers. */
|
|
60
|
+
label?: string;
|
|
61
|
+
/** The id of a visible heading that names the list, in place of `label`. */
|
|
62
|
+
"aria-labelledby"?: string;
|
|
63
|
+
/** Shown in place of the rows when there are none and nothing is loading. */
|
|
64
|
+
empty?: ReactNode;
|
|
65
|
+
/** The words it uses, for other languages. */
|
|
66
|
+
labels?: VirtualListLabels;
|
|
67
|
+
/** A class for each row's wrapper. */
|
|
68
|
+
itemClassName?: string;
|
|
69
|
+
id?: string;
|
|
70
|
+
className?: string;
|
|
71
|
+
style?: CSSProperties;
|
|
72
|
+
}
|
|
73
|
+
export interface VirtualListHandle {
|
|
74
|
+
/** Scrolls a row into view, rendering it first. `behavior: "smooth"` animates, except under reduced motion. */
|
|
75
|
+
scrollToIndex(index: number, options?: ScrollToIndexOptions): void;
|
|
76
|
+
/** Scrolls to the last row, and follows new rows again with `followOutput`. */
|
|
77
|
+
scrollToEnd(options?: Pick<ScrollToIndexOptions, "behavior">): void;
|
|
78
|
+
/** The element that scrolls. */
|
|
79
|
+
readonly element: HTMLDivElement | null;
|
|
80
|
+
}
|