@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.
Files changed (200) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/accordion.js +1 -1
  4. package/dist/components/alert-dialog.js +1 -1
  5. package/dist/components/ascii-field.d.ts +1 -1
  6. package/dist/components/ascii-field.js +2 -1
  7. package/dist/components/bottom-nav.d.ts +86 -0
  8. package/dist/components/bottom-nav.js +175 -0
  9. package/dist/components/breadcrumb.d.ts +9 -0
  10. package/dist/components/breadcrumb.js +6 -1
  11. package/dist/components/button-group.d.ts +1 -1
  12. package/dist/components/button-group.js +2 -2
  13. package/dist/components/button.js +1 -1
  14. package/dist/components/calendar.d.ts +1 -1
  15. package/dist/components/calendar.js +18 -3
  16. package/dist/components/carousel.d.ts +22 -3
  17. package/dist/components/carousel.js +25 -7
  18. package/dist/components/chart.d.ts +20 -0
  19. package/dist/components/chart.js +52 -3
  20. package/dist/components/code-block.d.ts +20 -10
  21. package/dist/components/code-block.js +54 -12
  22. package/dist/components/collapsible.js +3 -3
  23. package/dist/components/color-picker.d.ts +30 -8
  24. package/dist/components/color-picker.js +48 -27
  25. package/dist/components/combobox.d.ts +21 -3
  26. package/dist/components/combobox.js +79 -7
  27. package/dist/components/command.d.ts +23 -3
  28. package/dist/components/command.js +63 -18
  29. package/dist/components/conversation.d.ts +10 -1
  30. package/dist/components/conversation.js +24 -7
  31. package/dist/components/copy-button.d.ts +15 -6
  32. package/dist/components/copy-button.js +27 -10
  33. package/dist/components/data-table.d.ts +66 -6
  34. package/dist/components/data-table.js +376 -23
  35. package/dist/components/date-picker.d.ts +73 -4
  36. package/dist/components/date-picker.js +138 -7
  37. package/dist/components/dialog.d.ts +10 -1
  38. package/dist/components/dialog.js +6 -3
  39. package/dist/components/drawer.d.ts +10 -1
  40. package/dist/components/drawer.js +6 -3
  41. package/dist/components/feature-list.js +2 -2
  42. package/dist/components/field.d.ts +27 -8
  43. package/dist/components/field.js +49 -4
  44. package/dist/components/file-drop.d.ts +26 -4
  45. package/dist/components/file-drop.js +125 -64
  46. package/dist/components/filter-bar.d.ts +50 -3
  47. package/dist/components/filter-bar.js +71 -33
  48. package/dist/components/form.d.ts +4 -2
  49. package/dist/components/form.js +24 -2
  50. package/dist/components/graph.d.ts +41 -0
  51. package/dist/components/graph.js +106 -50
  52. package/dist/components/illustration.js +51 -4
  53. package/dist/components/input-group.d.ts +18 -7
  54. package/dist/components/input-group.js +41 -19
  55. package/dist/components/input.d.ts +2 -2
  56. package/dist/components/input.js +3 -3
  57. package/dist/components/kbd.d.ts +17 -0
  58. package/dist/components/kbd.js +8 -1
  59. package/dist/components/layout.d.ts +2 -1
  60. package/dist/components/layout.js +55 -11
  61. package/dist/components/lightbox.d.ts +100 -0
  62. package/dist/components/lightbox.js +457 -0
  63. package/dist/components/locale.d.ts +44 -0
  64. package/dist/components/locale.js +37 -0
  65. package/dist/components/logo.js +1 -1
  66. package/dist/components/menu.js +3 -1
  67. package/dist/components/menubar.js +60 -13
  68. package/dist/components/message.d.ts +3 -3
  69. package/dist/components/message.js +12 -8
  70. package/dist/components/meter.js +3 -1
  71. package/dist/components/money-input.d.ts +80 -0
  72. package/dist/components/money-input.js +253 -0
  73. package/dist/components/navigation-menu.js +4 -2
  74. package/dist/components/number-field.d.ts +21 -2
  75. package/dist/components/number-field.js +53 -28
  76. package/dist/components/otp-field.d.ts +14 -1
  77. package/dist/components/otp-field.js +10 -2
  78. package/dist/components/pagination.d.ts +13 -7
  79. package/dist/components/pagination.js +18 -7
  80. package/dist/components/pdf-viewer.d.ts +67 -2
  81. package/dist/components/pdf-viewer.js +88 -21
  82. package/dist/components/phone-input.d.ts +79 -0
  83. package/dist/components/phone-input.js +282 -0
  84. package/dist/components/popover.js +1 -1
  85. package/dist/components/progress.js +3 -1
  86. package/dist/components/prompt-input.d.ts +34 -9
  87. package/dist/components/prompt-input.js +37 -17
  88. package/dist/components/radio-group.js +7 -2
  89. package/dist/components/rating.d.ts +73 -0
  90. package/dist/components/rating.js +124 -0
  91. package/dist/components/reasoning.d.ts +16 -1
  92. package/dist/components/reasoning.js +10 -7
  93. package/dist/components/resizable.d.ts +10 -1
  94. package/dist/components/resizable.js +4 -1
  95. package/dist/components/response.d.ts +17 -5
  96. package/dist/components/response.js +58 -18
  97. package/dist/components/scroll-area.d.ts +1 -1
  98. package/dist/components/select.js +14 -3
  99. package/dist/components/separator.js +1 -1
  100. package/dist/components/sidebar.d.ts +20 -4
  101. package/dist/components/sidebar.js +70 -35
  102. package/dist/components/site-header.d.ts +46 -12
  103. package/dist/components/site-header.js +78 -19
  104. package/dist/components/skeleton.d.ts +1 -1
  105. package/dist/components/skeleton.js +1 -1
  106. package/dist/components/slider.js +3 -1
  107. package/dist/components/sortable.d.ts +178 -0
  108. package/dist/components/sortable.js +1282 -0
  109. package/dist/components/sources.d.ts +17 -2
  110. package/dist/components/sources.js +11 -4
  111. package/dist/components/spinner.d.ts +13 -1
  112. package/dist/components/spinner.js +5 -2
  113. package/dist/components/stat.d.ts +91 -0
  114. package/dist/components/stat.js +141 -0
  115. package/dist/components/stepper.d.ts +71 -0
  116. package/dist/components/stepper.js +101 -0
  117. package/dist/components/switch.d.ts +2 -2
  118. package/dist/components/switch.js +2 -2
  119. package/dist/components/table.d.ts +13 -3
  120. package/dist/components/table.js +231 -41
  121. package/dist/components/tabs.js +8 -4
  122. package/dist/components/tags-input.d.ts +18 -2
  123. package/dist/components/tags-input.js +66 -34
  124. package/dist/components/theme.d.ts +16 -2
  125. package/dist/components/theme.js +34 -8
  126. package/dist/components/time-field.d.ts +24 -4
  127. package/dist/components/time-field.js +32 -9
  128. package/dist/components/timeline.d.ts +18 -2
  129. package/dist/components/timeline.js +13 -4
  130. package/dist/components/tippy.d.ts +48 -0
  131. package/dist/components/tippy.js +648 -0
  132. package/dist/components/toast.d.ts +18 -2
  133. package/dist/components/toast.js +12 -3
  134. package/dist/components/toggle-group.js +1 -0
  135. package/dist/components/tool-call.d.ts +19 -8
  136. package/dist/components/tool-call.js +23 -7
  137. package/dist/components/toolbar.d.ts +1 -1
  138. package/dist/components/toolbar.js +10 -2
  139. package/dist/components/tooltip.d.ts +4 -2
  140. package/dist/components/tooltip.js +10 -4
  141. package/dist/components/tour.d.ts +127 -0
  142. package/dist/components/tour.js +673 -0
  143. package/dist/components/tree.js +45 -9
  144. package/dist/components/video-player.d.ts +10 -2
  145. package/dist/components/video-player.js +134 -38
  146. package/dist/illustration.d.ts +2 -0
  147. package/dist/illustration.js +7 -0
  148. package/dist/index.d.ts +11 -3
  149. package/dist/index.js +11 -3
  150. package/dist/lib/code-highlight.d.ts +3 -16
  151. package/dist/lib/code-highlight.js +160 -10
  152. package/dist/lib/code-theme.js +3 -3
  153. package/dist/lib/digit-roll.js +8 -8
  154. package/dist/lib/field-errors.d.ts +28 -0
  155. package/dist/lib/field-errors.js +24 -0
  156. package/dist/lib/field-value.d.ts +13 -0
  157. package/dist/lib/field-value.js +44 -0
  158. package/dist/lib/glide.d.ts +5 -4
  159. package/dist/lib/glide.js +5 -4
  160. package/dist/lib/graph-layout.js +11 -2
  161. package/dist/lib/money.d.ts +73 -0
  162. package/dist/lib/money.js +343 -0
  163. package/dist/lib/phone-countries.d.ts +1 -0
  164. package/dist/lib/phone-countries.js +281 -0
  165. package/dist/lib/phone.d.ts +90 -0
  166. package/dist/lib/phone.js +286 -0
  167. package/dist/lib/platform.d.ts +8 -3
  168. package/dist/lib/platform.js +13 -6
  169. package/dist/lib/row-index.d.ts +15 -0
  170. package/dist/lib/row-index.js +136 -0
  171. package/dist/lib/table-fit.d.ts +3 -2
  172. package/dist/lib/table-fit.js +52 -23
  173. package/dist/lib/theme-script.d.ts +15 -2
  174. package/dist/lib/theme-script.js +23 -3
  175. package/dist/lib/tippy/pixels.d.ts +47 -0
  176. package/dist/lib/tippy/pixels.js +187 -0
  177. package/dist/lib/tippy/sprite.d.ts +86 -0
  178. package/dist/lib/tippy/sprite.js +753 -0
  179. package/dist/messages/de.d.ts +12 -0
  180. package/dist/messages/de.js +326 -0
  181. package/dist/styles/expressive.css +60 -26
  182. package/dist/styles/index.css +11 -2
  183. package/dist/styles/material.css +47 -23
  184. package/dist/styles/parts/ai.css +4 -2
  185. package/dist/styles/parts/controls.css +85 -32
  186. package/dist/styles/parts/data.css +33 -5
  187. package/dist/styles/parts/feedback.css +110 -13
  188. package/dist/styles/parts/foundations.css +1 -1
  189. package/dist/styles/parts/navigation.css +230 -5
  190. package/dist/styles/parts/overlays.css +98 -11
  191. package/dist/styles/parts/pdf.css +13 -7
  192. package/dist/styles/tokens.css +28 -4
  193. package/dist/vite.d.ts +0 -50
  194. package/dist/vite.js +0 -100
  195. package/package.json +28 -33
  196. package/dist/components/code-highlight.d.ts +0 -13
  197. package/dist/components/code-highlight.js +0 -107
  198. package/dist/components/whiteboard.d.ts +0 -80
  199. package/dist/components/whiteboard.js +0 -389
  200. 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
- el.scrollTo({ top: el.scrollHeight, behavior: reducedMotion() ? "auto" : behavior });
94
- }, [setStuck]);
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) || node.scrollHeight <= node.clientHeight + 1)
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)] [scroll-behavior:auto] overflow-y-auto overscroll-contain focus-ring", children: parts.filter((child) => !isButton(child)) }), parts.filter(isButton)] }) }));
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 = "Scroll to the latest message", className, onClick, ...props }) {
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
- "absolute bottom-4 left-1/2 -translate-x-1/2 transition-[opacity,translate] duration-(--duration) ease-(--ease)",
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. They cross-fade
39
- and swap scale on --duration (0 under reduced motion), so the button never changes size. */
40
- const face = "col-start-1 row-start-1 place-self-center transition-[opacity,scale] duration-(--duration) ease-(--ease)";
41
- const shown = "scale-100 opacity-100";
42
- const hidden = "scale-50 opacity-0";
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 copyLabel = labels?.copy ?? "Copy";
93
- const copiedLabel = labels?.copied ?? "Copied";
94
- const failedLabel = labels?.failed ?? "Couldn't copy";
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
- "aria-label": labelled ? undefined : announcement || copyLabel,
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: ReadonlyArray<TData>;
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 browser.
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;