@zonsh/ui 0.2.0 → 0.5.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/LICENSE +22 -0
- package/README.md +19 -13
- package/dist/components/accordion.js +1 -1
- package/dist/components/alert-dialog.js +1 -1
- package/dist/components/ascii-field.d.ts +1 -1
- package/dist/components/ascii-field.js +2 -1
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +9 -0
- package/dist/components/breadcrumb.js +6 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/button-group.js +2 -2
- package/dist/components/button.js +1 -1
- package/dist/components/calendar.d.ts +1 -1
- package/dist/components/calendar.js +18 -3
- package/dist/components/carousel.d.ts +22 -3
- package/dist/components/carousel.js +25 -7
- package/dist/components/chart.d.ts +20 -0
- package/dist/components/chart.js +52 -3
- package/dist/components/code-block.d.ts +20 -10
- package/dist/components/code-block.js +54 -12
- package/dist/components/collapsible.js +3 -3
- package/dist/components/color-picker.d.ts +30 -8
- package/dist/components/color-picker.js +48 -27
- package/dist/components/combobox.d.ts +21 -3
- package/dist/components/combobox.js +79 -7
- package/dist/components/command.d.ts +23 -3
- package/dist/components/command.js +63 -18
- package/dist/components/conversation.d.ts +10 -1
- package/dist/components/conversation.js +24 -7
- package/dist/components/copy-button.d.ts +15 -6
- package/dist/components/copy-button.js +27 -10
- package/dist/components/data-table.d.ts +66 -6
- package/dist/components/data-table.js +376 -23
- package/dist/components/date-picker.d.ts +73 -4
- package/dist/components/date-picker.js +138 -7
- package/dist/components/dialog.d.ts +10 -1
- package/dist/components/dialog.js +6 -3
- package/dist/components/drawer.d.ts +10 -1
- package/dist/components/drawer.js +6 -3
- package/dist/components/feature-list.js +2 -2
- package/dist/components/field.d.ts +27 -8
- package/dist/components/field.js +49 -4
- package/dist/components/file-drop.d.ts +26 -4
- package/dist/components/file-drop.js +125 -64
- package/dist/components/filter-bar.d.ts +50 -3
- package/dist/components/filter-bar.js +71 -33
- package/dist/components/form.d.ts +4 -2
- package/dist/components/form.js +24 -2
- package/dist/components/graph.d.ts +41 -0
- package/dist/components/graph.js +106 -50
- package/dist/components/illustration.js +51 -4
- package/dist/components/input-group.d.ts +18 -7
- package/dist/components/input-group.js +41 -19
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/kbd.d.ts +17 -0
- package/dist/components/kbd.js +8 -1
- package/dist/components/layout.d.ts +2 -1
- package/dist/components/layout.js +55 -11
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +457 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.js +1 -1
- package/dist/components/menu.js +3 -1
- package/dist/components/menubar.js +60 -13
- package/dist/components/message.d.ts +3 -3
- package/dist/components/message.js +12 -8
- package/dist/components/meter.js +3 -1
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/navigation-menu.js +4 -2
- package/dist/components/number-field.d.ts +21 -2
- package/dist/components/number-field.js +53 -28
- package/dist/components/otp-field.d.ts +14 -1
- package/dist/components/otp-field.js +10 -2
- package/dist/components/pagination.d.ts +13 -7
- package/dist/components/pagination.js +18 -7
- package/dist/components/pdf-viewer.d.ts +67 -2
- package/dist/components/pdf-viewer.js +88 -21
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.js +1 -1
- package/dist/components/progress.js +3 -1
- package/dist/components/prompt-input.d.ts +34 -9
- package/dist/components/prompt-input.js +37 -17
- package/dist/components/radio-group.js +7 -2
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +16 -1
- package/dist/components/reasoning.js +10 -7
- package/dist/components/resizable.d.ts +10 -1
- package/dist/components/resizable.js +4 -1
- package/dist/components/response.d.ts +17 -5
- package/dist/components/response.js +58 -18
- package/dist/components/scroll-area.d.ts +1 -1
- package/dist/components/select.js +14 -3
- package/dist/components/separator.js +1 -1
- package/dist/components/sidebar.d.ts +20 -4
- package/dist/components/sidebar.js +70 -35
- package/dist/components/site-header.d.ts +46 -12
- package/dist/components/site-header.js +78 -19
- package/dist/components/skeleton.d.ts +1 -1
- package/dist/components/skeleton.js +1 -1
- package/dist/components/slider.js +3 -1
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1282 -0
- package/dist/components/sources.d.ts +17 -2
- package/dist/components/sources.js +11 -4
- package/dist/components/spinner.d.ts +13 -1
- package/dist/components/spinner.js +5 -2
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +2 -2
- package/dist/components/table.d.ts +13 -3
- package/dist/components/table.js +231 -41
- package/dist/components/tabs.js +8 -4
- package/dist/components/tags-input.d.ts +18 -2
- package/dist/components/tags-input.js +66 -34
- package/dist/components/theme.d.ts +16 -2
- package/dist/components/theme.js +34 -8
- package/dist/components/time-field.d.ts +24 -4
- package/dist/components/time-field.js +32 -9
- package/dist/components/timeline.d.ts +18 -2
- package/dist/components/timeline.js +13 -4
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +18 -2
- package/dist/components/toast.js +12 -3
- package/dist/components/toggle-group.js +1 -0
- package/dist/components/tool-call.d.ts +19 -8
- package/dist/components/tool-call.js +23 -7
- package/dist/components/toolbar.d.ts +1 -1
- package/dist/components/toolbar.js +10 -2
- package/dist/components/tooltip.d.ts +4 -2
- package/dist/components/tooltip.js +10 -4
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +673 -0
- package/dist/components/tree.js +45 -9
- package/dist/components/video-player.d.ts +10 -2
- package/dist/components/video-player.js +134 -38
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +11 -3
- package/dist/lib/code-highlight.d.ts +3 -16
- package/dist/lib/code-highlight.js +160 -10
- package/dist/lib/code-theme.js +3 -3
- package/dist/lib/digit-roll.js +8 -8
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/glide.d.ts +5 -4
- package/dist/lib/glide.js +5 -4
- package/dist/lib/graph-layout.js +11 -2
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +8 -3
- package/dist/lib/platform.js +13 -6
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +3 -2
- package/dist/lib/table-fit.js +52 -23
- package/dist/lib/theme-script.d.ts +15 -2
- package/dist/lib/theme-script.js +23 -3
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +60 -26
- package/dist/styles/index.css +11 -2
- package/dist/styles/material.css +47 -23
- package/dist/styles/parts/ai.css +4 -2
- package/dist/styles/parts/controls.css +85 -32
- package/dist/styles/parts/data.css +33 -5
- package/dist/styles/parts/feedback.css +110 -13
- package/dist/styles/parts/foundations.css +1 -1
- package/dist/styles/parts/navigation.css +230 -5
- package/dist/styles/parts/overlays.css +98 -11
- package/dist/styles/parts/pdf.css +13 -7
- package/dist/styles/tokens.css +28 -4
- package/dist/vite.d.ts +0 -50
- package/dist/vite.js +0 -100
- package/package.json +28 -33
- package/dist/components/code-highlight.d.ts +0 -13
- package/dist/components/code-highlight.js +0 -107
- package/dist/components/whiteboard.d.ts +0 -80
- package/dist/components/whiteboard.js +0 -389
- package/dist/styles/parts/whiteboard.css +0 -855
|
@@ -5,6 +5,8 @@ import * as React from "react";
|
|
|
5
5
|
import { cn, sx } from "../lib/cn.js";
|
|
6
6
|
import { mergeRefs } from "../lib/merge-refs.js";
|
|
7
7
|
import { Button } from "./button.js";
|
|
8
|
+
import { useMessages } from "./locale.js";
|
|
9
|
+
const defaultMessages = { scrollToLatest: "Scroll to the latest message" };
|
|
8
10
|
/** How close to the end (px) still counts as "at the latest message". */
|
|
9
11
|
const STICK_PX = 32;
|
|
10
12
|
const ConversationContext = React.createContext(null);
|
|
@@ -90,8 +92,13 @@ export function Conversation({ className, style, children, ref, onScroll, ...pro
|
|
|
90
92
|
return;
|
|
91
93
|
setStuck(true);
|
|
92
94
|
setAtBottom(true);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
// Smooth is the same glide that follows a reply (follow jumps under reduced motion), so the
|
|
96
|
+
// jump back lands like the stream does, and keeps landing if the reply grows on the way.
|
|
97
|
+
if (behavior === "smooth")
|
|
98
|
+
follow();
|
|
99
|
+
else
|
|
100
|
+
el.scrollTo({ top: el.scrollHeight, behavior });
|
|
101
|
+
}, [setStuck, follow]);
|
|
95
102
|
const focusLog = React.useCallback(() => scroller.current?.focus({ preventScroll: true }), []);
|
|
96
103
|
React.useEffect(() => () => {
|
|
97
104
|
const g = glide.current;
|
|
@@ -112,6 +119,12 @@ export function Conversation({ className, style, children, ref, onScroll, ...pro
|
|
|
112
119
|
// still in reach (text growing below fires no scroll event to say so). With nothing left to
|
|
113
120
|
// scroll, there is nothing to be away from: it follows again, for the next reply.
|
|
114
121
|
const changed = () => {
|
|
122
|
+
// Where layout left the view is not the reader's doing: when content shrinks and clamps the
|
|
123
|
+
// view, and grows back before the browser fires the scroll event (a slow frame in Firefox),
|
|
124
|
+
// that event must not read as a move up from where the view, or the glide, was before.
|
|
125
|
+
lastTop.current = el.scrollTop;
|
|
126
|
+
lastMax.current = el.scrollHeight - el.clientHeight;
|
|
127
|
+
glideTop.current = Number.NaN;
|
|
115
128
|
if (!stuck.current && el.scrollHeight - el.clientHeight <= 0.5)
|
|
116
129
|
setStuck(true);
|
|
117
130
|
if (stuck.current)
|
|
@@ -142,7 +155,8 @@ export function Conversation({ className, style, children, ref, onScroll, ...pro
|
|
|
142
155
|
/** Something inside the log (a message's own scroller) that this move scrolls instead. */
|
|
143
156
|
const inner = (target, up) => {
|
|
144
157
|
for (let node = target; node && node !== el; node = node.parentElement) {
|
|
145
|
-
if (!/(auto|scroll)/.test(getComputedStyle(node).overflowY) ||
|
|
158
|
+
if (!/(auto|scroll)/.test(getComputedStyle(node).overflowY) ||
|
|
159
|
+
node.scrollHeight <= node.clientHeight + 1)
|
|
146
160
|
continue;
|
|
147
161
|
if (up ? node.scrollTop > 0.5 : node.scrollTop + node.clientHeight < node.scrollHeight - 0.5)
|
|
148
162
|
return true;
|
|
@@ -262,7 +276,7 @@ export function Conversation({ className, style, children, ref, onScroll, ...pro
|
|
|
262
276
|
// Its corners are the conversation's: round that (`rounded-t-card` in a card), and the
|
|
263
277
|
// messages, the scrollbar and the focus ring follow, with no `overflow-hidden` to clip them.
|
|
264
278
|
// Its own scrolling is instant, whatever an app sets for `scroll-behavior`: the glide does the easing.
|
|
265
|
-
className: "min-h-0 flex-1 [border-radius:inherit] [--scrollbar-inset:var(--radius-card)]
|
|
279
|
+
className: "min-h-0 flex-1 overflow-y-auto overscroll-contain [scroll-behavior:auto] [border-radius:inherit] focus-ring [--scrollbar-inset:var(--radius-card)]", children: parts.filter((child) => !isButton(child)) }), parts.filter(isButton)] }) }));
|
|
266
280
|
}
|
|
267
281
|
/** The column of messages: 24px apart, padded, at a reading width. */
|
|
268
282
|
export function ConversationContent({ className, ...props }) {
|
|
@@ -273,12 +287,13 @@ export function ConversationContent({ className, ...props }) {
|
|
|
273
287
|
* latest message. It appears only once you have scrolled away from it. Put it inside
|
|
274
288
|
* `Conversation`, after `ConversationContent`.
|
|
275
289
|
*/
|
|
276
|
-
export function ConversationScrollButton({ label
|
|
290
|
+
export function ConversationScrollButton({ label, className, onClick, ...props }) {
|
|
291
|
+
const text = useMessages("conversation", defaultMessages);
|
|
277
292
|
const context = React.useContext(ConversationContext);
|
|
278
293
|
if (!context)
|
|
279
294
|
throw new Error("ConversationScrollButton must be used inside <Conversation>.");
|
|
280
295
|
const visible = !context.atBottom;
|
|
281
|
-
return (_jsx(Button, { "data-slot": "conversation-scroll-button", "data-visible": visible ? "" : undefined, variant: "secondary", size: "icon", "aria-label": label, "aria-hidden": !visible, tabIndex: visible ? 0 : -1, onClick: (event) => {
|
|
296
|
+
return (_jsx(Button, { "data-slot": "conversation-scroll-button", "data-visible": visible ? "" : undefined, variant: "secondary", size: "icon", "aria-label": label ?? text.scrollToLatest, "aria-hidden": !visible, tabIndex: visible ? 0 : -1, onClick: (event) => {
|
|
282
297
|
onClick?.(event);
|
|
283
298
|
if (event.defaultPrevented)
|
|
284
299
|
return;
|
|
@@ -287,7 +302,9 @@ export function ConversationScrollButton({ label = "Scroll to the latest message
|
|
|
287
302
|
context.focusLog();
|
|
288
303
|
context.scrollToBottom();
|
|
289
304
|
}, className: sx([
|
|
290
|
-
|
|
305
|
+
// The fade and the rise ride the material's own transition list (--material-motion): a
|
|
306
|
+
// transition utility would replace it, and the hover and the press would snap.
|
|
307
|
+
"absolute bottom-4 left-1/2 -translate-x-1/2 [--material-motion:opacity_var(--duration-fade)_var(--ease),translate_var(--duration)_var(--ease)]",
|
|
291
308
|
visible ? "opacity-100" : "pointer-events-none translate-y-2 opacity-0",
|
|
292
309
|
], className), ...props, children: _jsx(ArrowDownIcon, { "aria-hidden": true }) }));
|
|
293
310
|
}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { type ButtonProps } from "./button.js";
|
|
3
|
+
export interface CopyButtonMessages {
|
|
4
|
+
/** The name at rest. Say what is copied in `labels`: "Copy API key". */
|
|
5
|
+
copy: string;
|
|
6
|
+
/** Announced, and shown on a labelled button, once the text is on the clipboard. */
|
|
7
|
+
copied: string;
|
|
8
|
+
/** Announced when the clipboard refused the text. */
|
|
9
|
+
failed: string;
|
|
10
|
+
}
|
|
11
|
+
declare module "./locale" {
|
|
12
|
+
interface Messages {
|
|
13
|
+
copyButton: CopyButtonMessages;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
3
16
|
export interface CopyButtonProps extends Omit<ButtonProps, "value" | "onCopy" | "render" | "onError"> {
|
|
4
17
|
/**
|
|
5
18
|
* What to copy: a string, or a function that returns it (or a promise of it) at the moment of
|
|
@@ -18,13 +31,9 @@ export interface CopyButtonProps extends Omit<ButtonProps, "value" | "onCopy" |
|
|
|
18
31
|
/**
|
|
19
32
|
* The accessible names: `copy` names the button at rest (default "Copy"), `copied` and `failed`
|
|
20
33
|
* are announced after a click (default "Copied" and "Couldn't copy"). Say what is copied:
|
|
21
|
-
* "Copy API key".
|
|
34
|
+
* "Copy API key". A LocaleProvider sets them for every CopyButton (`messages.copyButton`).
|
|
22
35
|
*/
|
|
23
|
-
labels?:
|
|
24
|
-
copy?: string;
|
|
25
|
-
copied?: string;
|
|
26
|
-
failed?: string;
|
|
27
|
-
};
|
|
36
|
+
labels?: Partial<CopyButtonMessages>;
|
|
28
37
|
/**
|
|
29
38
|
* Draw another button instead of `Button` — most often `<InputGroupButton size="icon" />` in
|
|
30
39
|
* an `InputGroup`. It receives the click, the accessible name and the icon; its own variant
|
|
@@ -4,6 +4,12 @@ import { CheckIcon, CopyIcon, XIcon } from "lucide-react";
|
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import { cn } from "../lib/cn.js";
|
|
6
6
|
import { Button } from "./button.js";
|
|
7
|
+
import { useMessages } from "./locale.js";
|
|
8
|
+
const defaultMessages = {
|
|
9
|
+
copy: "Copy",
|
|
10
|
+
copied: "Copied",
|
|
11
|
+
failed: "Couldn't copy",
|
|
12
|
+
};
|
|
7
13
|
/**
|
|
8
14
|
* Writes text to the clipboard: the async Clipboard API where the page may use it, and the old
|
|
9
15
|
* `execCommand("copy")` on a hidden textarea where it may not (an `http:` page, an iframe without
|
|
@@ -35,11 +41,13 @@ async function writeClipboard(text) {
|
|
|
35
41
|
throw error;
|
|
36
42
|
}
|
|
37
43
|
}
|
|
38
|
-
/* Two faces stacked in one grid cell: the one at rest and the one that answers
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
44
|
+
/* Two faces stacked in one grid cell: the one at rest and the one that answers, so the button
|
|
45
|
+
never changes size. They cross-fade on --duration-fade and swap from 85% with a 2px blur on
|
|
46
|
+
--duration — never from nothing, and the blur hides the moment both are half there. Reduced
|
|
47
|
+
motion keeps the fade only. */
|
|
48
|
+
const face = "col-start-1 row-start-1 place-self-center transition-[opacity,scale,filter] [transition-duration:var(--duration-fade),var(--duration),var(--duration)] ease-(--ease)";
|
|
49
|
+
const shown = "scale-100 opacity-100 blur-none";
|
|
50
|
+
const hidden = "scale-[0.85] opacity-0 blur-[2px]";
|
|
43
51
|
/**
|
|
44
52
|
* CopyButton — copies a value to the clipboard and says so: the copy icon turns into a check for
|
|
45
53
|
* a moment and a polite live region announces "Copied". If the clipboard refuses, it shows a
|
|
@@ -71,9 +79,16 @@ export function CopyButton({ value, onCopy, onError, timeout = 1500, labels, ren
|
|
|
71
79
|
timer.current = setTimeout(() => setState("idle"), timeout);
|
|
72
80
|
};
|
|
73
81
|
const copy = async (event) => {
|
|
82
|
+
// The rendered element's own click handler runs too, then the one passed to CopyButton.
|
|
83
|
+
render?.props.onClick?.(event);
|
|
74
84
|
onClick?.(event);
|
|
75
85
|
if (event.defaultPrevented)
|
|
76
86
|
return;
|
|
87
|
+
// A second click while "Copied" still shows empties the live region first, so it is announced again.
|
|
88
|
+
if (state !== "idle") {
|
|
89
|
+
clearTimeout(timer.current);
|
|
90
|
+
setState("idle");
|
|
91
|
+
}
|
|
77
92
|
let text;
|
|
78
93
|
try {
|
|
79
94
|
const next = typeof value === "function" ? value() : value;
|
|
@@ -89,9 +104,10 @@ export function CopyButton({ value, onCopy, onError, timeout = 1500, labels, ren
|
|
|
89
104
|
settle("copied");
|
|
90
105
|
onCopy?.(text);
|
|
91
106
|
};
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const
|
|
107
|
+
const text = useMessages("copyButton", defaultMessages, labels);
|
|
108
|
+
const copyLabel = text.copy;
|
|
109
|
+
const copiedLabel = text.copied;
|
|
110
|
+
const failedLabel = text.failed;
|
|
95
111
|
const labelled = children != null;
|
|
96
112
|
const announcement = state === "copied" ? copiedLabel : state === "failed" ? failedLabel : "";
|
|
97
113
|
const buttonSize = size ?? (labelled ? "sm" : "icon-sm");
|
|
@@ -102,8 +118,9 @@ export function CopyButton({ value, onCopy, onError, timeout = 1500, labels, ren
|
|
|
102
118
|
const shared = {
|
|
103
119
|
"data-copied": state === "copied" ? "" : undefined,
|
|
104
120
|
"data-copy-failed": state === "failed" ? "" : undefined,
|
|
105
|
-
// A labelled button is named by its visible label; an icon-only one by `labels`.
|
|
106
|
-
"
|
|
121
|
+
// A labelled button is named by its visible label; an icon-only one by `labels`. The name stays
|
|
122
|
+
// "Copy": the live region says "Copied", and a name that changed as well would be read twice.
|
|
123
|
+
"aria-label": labelled ? undefined : copyLabel,
|
|
107
124
|
onClick: copy,
|
|
108
125
|
};
|
|
109
126
|
return (_jsxs(_Fragment, { children: [render ? (
|
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
import { type CellContext, type ColumnDef, type Row, type RowData, type SortingState } from "@tanstack/react-table";
|
|
2
2
|
import * as React from "react";
|
|
3
|
+
export interface DataTableMessages {
|
|
4
|
+
/** The search field's placeholder; its name is the same without the "…". */
|
|
5
|
+
search: string;
|
|
6
|
+
/** The column menu's button, and the heading in it. */
|
|
7
|
+
columns: string;
|
|
8
|
+
showColumns: string;
|
|
9
|
+
/** The select-all checkbox, where every row can be selected — or only this page's. */
|
|
10
|
+
selectAll: string;
|
|
11
|
+
selectPage: string;
|
|
12
|
+
/** Each row's checkbox. */
|
|
13
|
+
selectRow: string;
|
|
14
|
+
/** The one row shown when nothing matches. */
|
|
15
|
+
empty: string;
|
|
16
|
+
/** When `fetchRows` fails, and the button that asks again. */
|
|
17
|
+
loadError: string;
|
|
18
|
+
retry: string;
|
|
19
|
+
/** The footer's count of selected rows. */
|
|
20
|
+
selected: (count: number, total: number) => string;
|
|
21
|
+
/** The footer of a grouped table. */
|
|
22
|
+
groupCount: (rows: number, groups: number) => string;
|
|
23
|
+
/** The rows-per-page select's label. */
|
|
24
|
+
rowsPerPage: string;
|
|
25
|
+
/** The rows on this page: "1–10 of 42". */
|
|
26
|
+
range: (first: number, last: number, total: number) => string;
|
|
27
|
+
previous: string;
|
|
28
|
+
next: string;
|
|
29
|
+
}
|
|
30
|
+
declare module "./locale" {
|
|
31
|
+
interface Messages {
|
|
32
|
+
dataTable: DataTableMessages;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
3
35
|
/** Per-column options read by `DataTable`. Set them on a column's `meta`. */
|
|
4
36
|
export interface DataTableColumnMeta {
|
|
5
37
|
/** The column's name in the "Columns" menu when its `header` is not a plain string. */
|
|
@@ -56,6 +88,24 @@ export type DataTableRow<TData extends RowData> = Row<DataTableFeatures, TData>;
|
|
|
56
88
|
/** The argument of a column's `cell` renderer. */
|
|
57
89
|
export type DataTableCellContext<TData extends RowData, TValue = unknown> = CellContext<DataTableFeatures, TData, TValue>;
|
|
58
90
|
export type DataTableSortingState = SortingState;
|
|
91
|
+
/** What `fetchRows` is asked for: rows `start` up to `end` of the result, sorted and searched. */
|
|
92
|
+
export interface DataTableQuery {
|
|
93
|
+
start: number;
|
|
94
|
+
end: number;
|
|
95
|
+
/** The columns to sort by, in order: `[{ id, desc }]`. */
|
|
96
|
+
sorting: SortingState;
|
|
97
|
+
/** The search text, or "" — over every column, or `searchKey`'s. */
|
|
98
|
+
search: string;
|
|
99
|
+
/** The column `search` is for, when the table has a `searchKey`. */
|
|
100
|
+
searchKey?: string;
|
|
101
|
+
/** Aborted when the rows are no longer wanted: the sorting or the search changed. */
|
|
102
|
+
signal: AbortSignal;
|
|
103
|
+
}
|
|
104
|
+
/** What `fetchRows` resolves to: the rows asked for, and how many the whole result has. */
|
|
105
|
+
export interface DataTableResult<TData> {
|
|
106
|
+
rows: TData[];
|
|
107
|
+
total: number;
|
|
108
|
+
}
|
|
59
109
|
/**
|
|
60
110
|
* Typed helpers for `DataTable` columns: `accessor(key, def)`, `display(def)` and
|
|
61
111
|
* `columns([...])`. Create one per row type at module scope.
|
|
@@ -89,11 +139,18 @@ export declare function createDataTableColumnHelper<TData extends RowData>(): im
|
|
|
89
139
|
export interface DataTableProps<TData extends RowData> extends Omit<React.ComponentProps<"div">, "children" | "onChange"> {
|
|
90
140
|
/** Column definitions. Keep them stable: module scope or `useMemo`. */
|
|
91
141
|
columns: ReadonlyArray<DataTableColumnDef<TData>>;
|
|
92
|
-
/** The rows. Keep the array stable between real changes. */
|
|
93
|
-
data
|
|
142
|
+
/** The rows. Keep the array stable between real changes. Not with `fetchRows`. */
|
|
143
|
+
data?: ReadonlyArray<TData>;
|
|
144
|
+
/**
|
|
145
|
+
* Rows from a server, in place of `data`: called for each run of rows as it comes into view (or
|
|
146
|
+
* its page), with the sorting and the search, and resolving to those rows and the total. Rows
|
|
147
|
+
* on their way show as placeholders. Pass `getRowId`, so a selection survives a new sort. Not
|
|
148
|
+
* with `groupBy`.
|
|
149
|
+
*/
|
|
150
|
+
fetchRows?: (query: DataTableQuery) => Promise<DataTableResult<TData>>;
|
|
94
151
|
/** Search one column (its id or accessor key). Omit to search every text and number column. */
|
|
95
152
|
searchKey?: string;
|
|
96
|
-
/** Placeholder for the search field. */
|
|
153
|
+
/** Placeholder for the search field. Default `labels.search`. */
|
|
97
154
|
searchPlaceholder?: string;
|
|
98
155
|
/** Show the search field. Defaults to `true`. */
|
|
99
156
|
searchable?: boolean;
|
|
@@ -125,13 +182,16 @@ export interface DataTableProps<TData extends RowData> extends Omit<React.Compon
|
|
|
125
182
|
initialSorting?: SortingState;
|
|
126
183
|
/**
|
|
127
184
|
* A BCP 47 locale whose order text sorts in, e.g. `"sv"` puts "Å" after "Z". Default: the
|
|
128
|
-
* Unicode collation order, the same on the server and in every
|
|
185
|
+
* LocaleProvider's, else the Unicode collation order, the same on the server and in every
|
|
186
|
+
* browser.
|
|
129
187
|
*/
|
|
130
188
|
locale?: string;
|
|
131
189
|
/** Columns hidden at first, e.g. `{ id: false }`. */
|
|
132
190
|
initialColumnVisibility?: Record<string, boolean>;
|
|
133
|
-
/** Shown in one full-width row when nothing matches. */
|
|
191
|
+
/** Shown in one full-width row when nothing matches. Default `labels.empty`. */
|
|
134
192
|
emptyMessage?: React.ReactNode;
|
|
193
|
+
/** The table's own words — toolbar, selection, footer; a LocaleProvider sets them for every DataTable. */
|
|
194
|
+
labels?: Partial<DataTableMessages>;
|
|
135
195
|
/** Extra controls at the end of the toolbar (a secondary "Export", a filter select). */
|
|
136
196
|
toolbar?: React.ReactNode;
|
|
137
197
|
/** A short visible description under the table. */
|
|
@@ -172,4 +232,4 @@ export interface DataTableProps<TData extends RowData> extends Omit<React.Compon
|
|
|
172
232
|
* break: reaching for it for a handful of rows. Under ~10 rows with nothing to sort, use a
|
|
173
233
|
* plain `Table`.
|
|
174
234
|
*/
|
|
175
|
-
export declare function DataTable<TData extends RowData>({ columns, data, searchKey, searchPlaceholder, searchable, pageSize, pageSizeOptions, selectable, onRowSelectionChange, getRowId, columnToggle, dense, variant, fit, initialSorting, locale, initialColumnVisibility, emptyMessage, toolbar, caption, label, groupBy, groupSummary, stickyGroupHeaders, tableContainerProps, virtualize, className, ...props }: DataTableProps<TData>): React.JSX.Element;
|
|
235
|
+
export declare function DataTable<TData extends RowData>({ columns, data, fetchRows, searchKey, searchPlaceholder: searchPlaceholderProp, searchable, pageSize, pageSizeOptions, selectable, onRowSelectionChange, getRowId, columnToggle, dense, variant, fit, initialSorting, locale: localeProp, initialColumnVisibility, emptyMessage: emptyMessageProp, labels, toolbar, caption, label, groupBy, groupSummary, stickyGroupHeaders, tableContainerProps, virtualize, className, ...props }: DataTableProps<TData>): React.JSX.Element;
|