@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
package/dist/components/table.js
CHANGED
|
@@ -6,6 +6,7 @@ import * as React from "react";
|
|
|
6
6
|
import { flushSync } from "react-dom";
|
|
7
7
|
import { cn } from "../lib/cn.js";
|
|
8
8
|
import { mergeRefs } from "../lib/merge-refs.js";
|
|
9
|
+
import { cssDuration } from "../lib/motion.js";
|
|
9
10
|
import { Flip, drawOrder, fitStep, layoutFor, measureMetrics, reducedMotion, removalOrder, titleRoom, widestRows, } from "../lib/table-fit.js";
|
|
10
11
|
const TableDenseContext = React.createContext(false);
|
|
11
12
|
const TableFitContext = React.createContext(null);
|
|
@@ -68,8 +69,21 @@ function StaticTable({ dense = false, variant = "card", containerProps, classNam
|
|
|
68
69
|
const scrolls = useScrolls(containerRef);
|
|
69
70
|
return (_jsx(TableDenseContext.Provider, { value: dense, children: _jsx("div", { "data-slot": "table-container", "data-variant": variant, tabIndex: scrolls ? 0 : undefined, role: scrolls ? "region" : undefined, "aria-label": scrolls ? props["aria-label"] : undefined, "aria-labelledby": scrolls ? props["aria-labelledby"] : undefined, ...containerProps, ref: containerRefs, className: cn("relative w-full overflow-x-auto focus-ring", variant === "card" && "surface-card [--card-padding:0] [--scrollbar-inset:var(--radius-card)]", containerProps?.className), children: _jsx("table", { "data-slot": "table", "data-dense": dense ? "" : undefined, "data-variant": variant, className: cn("w-full caption-bottom border-collapse text-start font-body text-sm", className), ...props }) }) }));
|
|
70
71
|
}
|
|
71
|
-
/**
|
|
72
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Card padding, carried by the rows in a fitting table: 16px, 24px from a 40rem container; and the
|
|
74
|
+
* gap between columns, 12–28px with the container's width. The fit sets both as it measures the
|
|
75
|
+
* width (`fitSpacing`). Not a container query and `cqi`: WebKit restyles every cell of a size
|
|
76
|
+
* container on each resize, which made a fitting table drag as Safari resized it.
|
|
77
|
+
*/
|
|
78
|
+
const FIT_SPACING = "[--table-pad:--spacing(4)] in-data-wide:[--table-pad:--spacing(6)] gap-x-(--fit-gap,0.75rem)";
|
|
79
|
+
/** The container's padding (`data-wide`) and column gap (`--fit-gap`) at its current width. */
|
|
80
|
+
function fitSpacing(container, body, rem) {
|
|
81
|
+
const width = container.clientWidth;
|
|
82
|
+
container.toggleAttribute("data-wide", width >= 40 * rem);
|
|
83
|
+
const gap = Math.min(Math.max(0.046 * width - 0.45 * rem, 0.75 * rem), 1.75 * rem);
|
|
84
|
+
body.style.setProperty("--fit-gap", `${gap}px`);
|
|
85
|
+
return gap;
|
|
86
|
+
}
|
|
73
87
|
/**
|
|
74
88
|
* A table that fits its columns to its container. It is one table at every width — `role="table"`
|
|
75
89
|
* on a CSS grid whose groups and rows are subgrids — so a column is as wide as its widest cell
|
|
@@ -140,9 +154,9 @@ function FitTable({ dense = false, variant = "card", containerProps, className,
|
|
|
140
154
|
if (!metrics)
|
|
141
155
|
return;
|
|
142
156
|
const { step, order, columns, drawn, title } = latest.current;
|
|
157
|
+
const gap = fitSpacing(container, body, rem());
|
|
143
158
|
const row = body.querySelector("[data-slot=table-row]");
|
|
144
159
|
const edge = row ? parseFloat(getComputedStyle(row).paddingInlineStart) : 16;
|
|
145
|
-
const gap = parseFloat(getComputedStyle(body).columnGap) || 0;
|
|
146
160
|
const available = body.clientWidth;
|
|
147
161
|
const next = fitStep({
|
|
148
162
|
available,
|
|
@@ -273,7 +287,7 @@ function FitTable({ dense = false, variant = "card", containerProps, className,
|
|
|
273
287
|
const containerRefs = React.useMemo(() => mergeRefs(containerRef, containerProps?.ref), [containerProps?.ref]);
|
|
274
288
|
const bodyRefs = React.useMemo(() => mergeRefs(bodyRef, ref), [ref]);
|
|
275
289
|
const scrolls = useScrolls(bodyRef);
|
|
276
|
-
return (_jsx(TableFitContext.Provider, { value: value, children: _jsx(TableDenseContext.Provider, { value: dense, children: _jsxs("div", { "data-slot": "table-container", "data-variant": variant, "data-fit": "", "data-tier": order.length - layout.step, "data-final": layout.final ? "" : undefined, ...containerProps, ref: containerRefs, className: cn("
|
|
290
|
+
return (_jsx(TableFitContext.Provider, { value: value, children: _jsx(TableDenseContext.Provider, { value: dense, children: _jsxs("div", { "data-slot": "table-container", "data-variant": variant, "data-fit": "", "data-tier": order.length - layout.step, "data-final": layout.final ? "" : undefined, ...containerProps, ref: containerRefs, className: cn("relative flex w-full max-w-full min-w-0 flex-col overflow-hidden", variant === "card" && "surface-card [--card-padding:0] [--scrollbar-inset:var(--radius-card)]", containerProps?.className), children: [_jsx("div", { tabIndex: scrolls ? 0 : undefined, ...props, ref: bodyRefs, role: "table", "data-slot": "table", "data-fit": "", "data-dense": dense ? "" : undefined, "data-variant": variant, className: cn("relative grid min-h-0 flex-1 content-start overflow-auto text-start font-body text-sm focus-visible:outline-none", FIT_SPACING, className), style: { gridTemplateColumns: template, ...style }, children: children }), _jsx("div", { ref: layerRef, "aria-hidden": true, "data-slot": "table-ghosts", className: "pointer-events-none absolute inset-0 z-3 overflow-hidden font-body text-sm" })] }) }) }));
|
|
277
291
|
}
|
|
278
292
|
/* ── Sections ──────────────────────────────────────────────────────────────── */
|
|
279
293
|
export function TableHeader({ className, ...props }) {
|
|
@@ -349,7 +363,9 @@ function FitCell({ place, fit, kind, className, style, children, colSpan, scope:
|
|
|
349
363
|
return (_jsx("div", { role: role, className: cn("min-w-0", (colSpan ?? 1) > 1 && "col-span-full", className), style: style, ...props, children: children }));
|
|
350
364
|
if (index === fit.title) {
|
|
351
365
|
const inline = fit.inlined && !head;
|
|
352
|
-
return (_jsx("div", { role: role, "data-title": "", className: cn(inline
|
|
366
|
+
return (_jsx("div", { role: role, "data-title": "", className: cn(inline
|
|
367
|
+
? "inline"
|
|
368
|
+
: cn("flex min-w-0", head ? "items-center" : "min-h-(--control-h-sm) items-start py-1"), className), style: inline ? style : { gridColumn: fit.track.get(index), ...style }, ...props, children: _jsx("span", { "data-slot": "table-title-text", className: fit.final && !head ? "min-w-0 text-pretty break-words" : "whitespace-nowrap", children: children }) }));
|
|
353
369
|
}
|
|
354
370
|
const end = fit.align[index] === "end";
|
|
355
371
|
const column = fit.modes[index] ?? "column";
|
|
@@ -358,18 +374,24 @@ function FitCell({ place, fit, kind, className, style, children, colSpan, scope:
|
|
|
358
374
|
return (_jsx("div", { role: role, "data-column": index, "data-head": head ? "" : undefined, "data-mode": mode, "data-align": end ? "end" : "start", "data-flip": "piece", "data-flip-key": `${rowKey}:${index}`, className: cn("min-w-0 items-center whitespace-nowrap", mode === "column" && "flex",
|
|
359
375
|
// Cells are 30px, the height of a dense control, so a button sits in a 46px row; text
|
|
360
376
|
// centres on the title's first line.
|
|
361
|
-
mode === "column" && !head && "min-h-
|
|
377
|
+
mode === "column" && !head && "min-h-(--control-h-sm)", mode === "column" && (end ? "justify-self-end text-end" : "justify-self-start"),
|
|
362
378
|
// Inline cells flow right after the title's last word, and wrap like words.
|
|
363
379
|
mode === "inline" && "inline-flex min-h-5.5 align-top",
|
|
364
380
|
// In the final layout, where titles wrap, one longer than the line (a link) wraps inside
|
|
365
381
|
// the title cell too, instead of running out of the table.
|
|
366
382
|
mode === "inline" && fit.final && "max-w-full wrap-anywhere whitespace-normal", mode === "hidden" && "sr-only", className), style: mode === "column" ? { gridColumn: fit.track.get(index), ...style } : style, ...props, children: children }));
|
|
367
383
|
}
|
|
368
|
-
/**
|
|
384
|
+
/**
|
|
385
|
+
* A header cell. In the `TableHeader` it is a column header, set as an eyebrow: 12px mono,
|
|
386
|
+
* uppercase, 0.18em tracking, muted. In a body or footer row it is that row's header — a
|
|
387
|
+
* `<th scope="row">` set like a cell in the foreground ink, not as an eyebrow: use it for the
|
|
388
|
+
* cell that names the row (a feature in a comparison, a month in a report).
|
|
389
|
+
*/
|
|
369
390
|
export function TableHead({ numeric = false, align, width, priority, inline, minWidth, titleColumn, className, style, ...props }) {
|
|
370
391
|
const dense = React.useContext(TableDenseContext);
|
|
371
392
|
const fit = React.useContext(TableFitContext);
|
|
372
393
|
const slot = React.useContext(TableCellSlotContext);
|
|
394
|
+
const row = React.useContext(TableSectionContext) === "body";
|
|
373
395
|
const end = (align ?? (numeric ? "end" : "start")) === "end";
|
|
374
396
|
const register = fit?.register;
|
|
375
397
|
const index = slot?.head ? slot.index : -1;
|
|
@@ -380,6 +402,8 @@ export function TableHead({ numeric = false, align, width, priority, inline, min
|
|
|
380
402
|
}, [register, index, priority, inline, minWidth, width, titleColumn, end]);
|
|
381
403
|
if (fit && slot)
|
|
382
404
|
return (_jsx(FitCell, { place: slot, fit: fit, kind: "head", "data-slot": "table-head", className: cn(slot.head ? "eyebrow font-normal" : "text-start font-normal text-foreground", className), style: style, ...props }));
|
|
405
|
+
if (row)
|
|
406
|
+
return (_jsx("th", { "data-slot": "table-head", scope: "row", className: cn("px-4 text-start align-middle font-normal text-foreground first:ps-6 last:pe-6", dense ? "h-(--control-h-sm) py-1 text-[13px]" : "h-(--control-h-lg) py-2", end && "text-end", numeric && "font-mono text-[13px] whitespace-nowrap tabular-nums", className), style: width ? { width, ...style } : style, ...props }));
|
|
383
407
|
return (_jsx("th", { "data-slot": "table-head", scope: "col", className: cn("px-4 text-start align-middle eyebrow font-normal whitespace-nowrap first:ps-6 last:pe-6", dense ? "h-(--control-h-sm)" : "h-(--control-h)", end && "text-end", className), style: width ? { width, ...style } : style, ...props }));
|
|
384
408
|
}
|
|
385
409
|
export function TableCell({ numeric = false, className, ...props }) {
|
|
@@ -393,6 +417,55 @@ export function TableCell({ numeric = false, className, ...props }) {
|
|
|
393
417
|
return (_jsx("td", { "data-slot": "table-cell", className: cn("px-4 align-middle text-foreground-soft first:ps-6 last:pe-6", dense ? "h-(--control-h-sm) py-1 text-[13px]" : "h-(--control-h-lg) py-2", numeric && "text-end font-mono text-[13px] whitespace-nowrap tabular-nums", className), ...props }));
|
|
394
418
|
}
|
|
395
419
|
const TableGroupContext = React.createContext(null);
|
|
420
|
+
/** The rows after the header that a group reveals, at most this many of them staggered. */
|
|
421
|
+
const REVEAL_STAGGER_ROWS = 6;
|
|
422
|
+
const REVEAL_STAGGER_MS = 15;
|
|
423
|
+
/** `--duration-fade` in ms (kept under reduced motion), in either unit a build may write. */
|
|
424
|
+
function fadeMs(el) {
|
|
425
|
+
const value = getComputedStyle(el).getPropertyValue("--duration-fade").trim();
|
|
426
|
+
const n = parseFloat(value);
|
|
427
|
+
if (!Number.isFinite(n))
|
|
428
|
+
return 0;
|
|
429
|
+
return value.endsWith("ms") ? n : value.endsWith("s") ? n * 1000 : n;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* A group that opens shows its rows at once (they are not drawn while it is closed), then fades
|
|
433
|
+
* them in, each rising 4px, the first few a beat apart: --duration and 5 × 15ms, within 300ms.
|
|
434
|
+
* Under reduced motion they only fade, on --duration-fade. Closing stays instant: the rows go
|
|
435
|
+
* as they were asked to. The first render reveals nothing.
|
|
436
|
+
*/
|
|
437
|
+
function useRevealRows(group, open) {
|
|
438
|
+
const was = React.useRef(open);
|
|
439
|
+
React.useLayoutEffect(() => {
|
|
440
|
+
const opened = open && !was.current;
|
|
441
|
+
was.current = open;
|
|
442
|
+
const el = group.current;
|
|
443
|
+
if (!opened || !el || typeof el.animate !== "function")
|
|
444
|
+
return;
|
|
445
|
+
const rows = el.querySelectorAll(':scope > [data-slot="table-row"]');
|
|
446
|
+
const move = cssDuration(el);
|
|
447
|
+
const fade = move ? 0 : fadeMs(el);
|
|
448
|
+
const easing = getComputedStyle(el).getPropertyValue("--ease").trim() || "ease-out";
|
|
449
|
+
const running = [];
|
|
450
|
+
rows.forEach((row, i) => {
|
|
451
|
+
running.push(row.animate(move
|
|
452
|
+
? [
|
|
453
|
+
{ opacity: 0, translate: "0 -4px" },
|
|
454
|
+
{ opacity: 1, translate: "0 0" },
|
|
455
|
+
]
|
|
456
|
+
: [{ opacity: 0 }, { opacity: 1 }], {
|
|
457
|
+
duration: move || fade,
|
|
458
|
+
delay: move ? Math.min(i, REVEAL_STAGGER_ROWS - 1) * REVEAL_STAGGER_MS : 0,
|
|
459
|
+
easing,
|
|
460
|
+
fill: "backwards",
|
|
461
|
+
}));
|
|
462
|
+
});
|
|
463
|
+
return () => {
|
|
464
|
+
for (const a of running)
|
|
465
|
+
a.cancel();
|
|
466
|
+
};
|
|
467
|
+
}, [group, open]);
|
|
468
|
+
}
|
|
396
469
|
/**
|
|
397
470
|
* TableGroup — one group of rows: a `<tbody>` that starts with a `TableGroupHeader` and holds
|
|
398
471
|
* ordinary `TableRow`s. Use several in place of a single `TableBody`.
|
|
@@ -401,8 +474,10 @@ const TableGroupContext = React.createContext(null);
|
|
|
401
474
|
* break: grouping by something every row shares, or into groups of one. If most groups would
|
|
402
475
|
* hold a single row, sort the column instead.
|
|
403
476
|
*/
|
|
404
|
-
export function TableGroup({ open: openProp, defaultOpen = true, onOpenChange, collapsible = true, className, ...props }) {
|
|
477
|
+
export function TableGroup({ open: openProp, defaultOpen = true, onOpenChange, collapsible = true, className, ref, ...props }) {
|
|
405
478
|
const fit = React.useContext(TableFitContext);
|
|
479
|
+
const own = React.useRef(null);
|
|
480
|
+
const refs = React.useMemo(() => mergeRefs(own, ref), [ref]);
|
|
406
481
|
const [uncontrolled, setUncontrolled] = React.useState(defaultOpen);
|
|
407
482
|
const open = openProp ?? uncontrolled;
|
|
408
483
|
const onOpenChangeRef = React.useRef(onOpenChange);
|
|
@@ -414,7 +489,8 @@ export function TableGroup({ open: openProp, defaultOpen = true, onOpenChange, c
|
|
|
414
489
|
}, [openProp]);
|
|
415
490
|
const value = React.useMemo(() => ({ open, setOpen, collapsible }), [open, setOpen, collapsible]);
|
|
416
491
|
const state = { "data-open": open ? "" : undefined, "data-closed": open ? undefined : "" };
|
|
417
|
-
|
|
492
|
+
useRevealRows(own, open);
|
|
493
|
+
return (_jsx(TableGroupContext.Provider, { value: value, children: fit ? (_jsx("div", { ref: refs, role: "rowgroup", "data-slot": "table-group", ...state, className: cn(SUBGRID, className), ...props })) : (_jsx("tbody", { ref: refs, "data-slot": "table-group", ...state, className: className, ...props })) }));
|
|
418
494
|
}
|
|
419
495
|
/**
|
|
420
496
|
* The first row of a `TableGroup`: a full-width band with the label, a mono count and an
|
|
@@ -454,6 +530,10 @@ function useVirtualRow(ref) {
|
|
|
454
530
|
const FIRST_ROWS = 40;
|
|
455
531
|
/** The height of the view assumed until the scroller is measured. */
|
|
456
532
|
const FIRST_VIEW = 1000;
|
|
533
|
+
/** The most a virtual body is drawn tall, under every browser's limit: more rows share it. */
|
|
534
|
+
const MAX_HEIGHT = 15_000_000;
|
|
535
|
+
/** A compressed body keeps the scroll position as rows are measured: a pixel there isn't one here. */
|
|
536
|
+
const noAdjust = () => false;
|
|
457
537
|
const isWindow = (value) => typeof window !== "undefined" && value === window;
|
|
458
538
|
/**
|
|
459
539
|
* The nearest ancestor that scrolls vertically — the table's own box when it has a height, a
|
|
@@ -492,7 +572,7 @@ const VirtualRow = React.memo(function VirtualRow({ index, rowIndex, measure, ro
|
|
|
492
572
|
* Use it from a few hundred rows on. The rule people break: reaching for it for a page of rows —
|
|
493
573
|
* rows that are not rendered can't be found with the browser's search or printed.
|
|
494
574
|
*/
|
|
495
|
-
export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows, overscan = 8, scrollResetKey, }) {
|
|
575
|
+
export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows, overscan = 8, scrollResetKey, onRangeChange, }) {
|
|
496
576
|
const fit = React.useContext(TableFitContext);
|
|
497
577
|
const dense = React.useContext(TableDenseContext);
|
|
498
578
|
/** The sizer rows' group, of no height: the rows start at its top. */
|
|
@@ -515,12 +595,24 @@ export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows,
|
|
|
515
595
|
group.rows.forEach((row, at) => items.push({ header: false, key: `r:${String(group.key)}:${keyOf(row, at)}`, group: g, row, at }));
|
|
516
596
|
spans.push({ start, end: items.length, open });
|
|
517
597
|
});
|
|
518
|
-
else
|
|
519
|
-
rows?.forEach((row, at) => items.push({ header: false, key: `r:${keyOf(row, at)}`, group: -1, row, at }));
|
|
520
598
|
return { items, spans };
|
|
521
|
-
}, [
|
|
599
|
+
}, [groups, toggled]);
|
|
600
|
+
// Without groups, each row is an entry of its own, made when it is asked for: a million rows
|
|
601
|
+
// need no list of a million entries, and rows filled in where they were (a server's, as they
|
|
602
|
+
// load) are read as they are now.
|
|
603
|
+
const count = groups ? items.length : (rows?.length ?? 0);
|
|
604
|
+
const itemAt = React.useCallback((i) => {
|
|
605
|
+
if (groups)
|
|
606
|
+
return items[i];
|
|
607
|
+
if (!rows || i < 0 || i >= rows.length)
|
|
608
|
+
return undefined;
|
|
609
|
+
const row = rows[i];
|
|
610
|
+
return { header: false, key: `r:${String(keyRef.current?.(row, i) ?? i)}`, group: -1, row, at: i };
|
|
611
|
+
}, [groups, items, rows]);
|
|
522
612
|
// The rows that size the columns, with their index (renderRow's second argument).
|
|
523
613
|
const sized = React.useMemo(() => {
|
|
614
|
+
if (!groups && rows && !sizeRows)
|
|
615
|
+
return widestRows(rows, fieldsOf).map((at) => ({ row: rows[at], at }));
|
|
524
616
|
const all = [];
|
|
525
617
|
if (groups)
|
|
526
618
|
for (const group of groups)
|
|
@@ -532,25 +624,37 @@ export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows,
|
|
|
532
624
|
const index = new Map(all.map((entry) => [entry.row, entry.at]));
|
|
533
625
|
return sizeRows.map((row) => ({ row, at: index.get(row) ?? -1 }));
|
|
534
626
|
}, [rows, groups, sizeRows]);
|
|
535
|
-
// Rows are 46px (30px dense) and group headers 38px until they are drawn
|
|
536
|
-
|
|
537
|
-
|
|
627
|
+
// Rows are 46px (30px dense) and group headers 38px until they are drawn; from then on, as tall
|
|
628
|
+
// as most of the drawn ones (`drawn`, below). An estimate off by a pixel makes every row drawn
|
|
629
|
+
// move every row after it, which with a million rows is most of each frame.
|
|
630
|
+
const [drawnSize, setDrawnSize] = React.useState(null);
|
|
631
|
+
const estimate = React.useCallback((i) => groups && items[i]?.header
|
|
632
|
+
? (drawnSize?.header ?? (dense ? 30 : 38))
|
|
633
|
+
: (drawnSize?.row ?? (dense ? 30 : 46)), [items, dense, drawnSize]);
|
|
634
|
+
const getItemKey = React.useCallback((i) => itemAt(i)?.key ?? i, [itemAt]);
|
|
538
635
|
// The last row to take the focus stays rendered wherever it scrolls, with the rows on either side,
|
|
539
636
|
// so Tab and Shift+Tab carry on from it to the next row, and a menu it opened can give the focus
|
|
540
637
|
// back to it.
|
|
541
638
|
const [focusKey, setFocusKey] = React.useState(null);
|
|
542
|
-
const focusIndex = React.useMemo(() =>
|
|
639
|
+
const focusIndex = React.useMemo(() => {
|
|
640
|
+
if (focusKey == null)
|
|
641
|
+
return -1;
|
|
642
|
+
for (let i = 0; i < count; i++)
|
|
643
|
+
if (itemAt(i).key === focusKey)
|
|
644
|
+
return i;
|
|
645
|
+
return -1;
|
|
646
|
+
}, [focusKey, itemAt, count]);
|
|
543
647
|
const rangeExtractor = React.useCallback((range) => {
|
|
544
648
|
const shown = new Set(defaultRangeExtractor(range));
|
|
545
649
|
// The group of the first row in view keeps its header, so a sticky one stays at the top.
|
|
546
|
-
const first = items[range.startIndex];
|
|
650
|
+
const first = groups ? items[range.startIndex] : undefined;
|
|
547
651
|
if (first && first.group >= 0)
|
|
548
652
|
shown.add(spans[first.group].start);
|
|
549
653
|
if (focusIndex >= 0)
|
|
550
654
|
for (let i = Math.max(0, focusIndex - 1); i <= Math.min(range.count - 1, focusIndex + 1); i++)
|
|
551
655
|
shown.add(i);
|
|
552
656
|
return [...shown].sort((a, b) => a - b);
|
|
553
|
-
}, [items, spans, focusIndex]);
|
|
657
|
+
}, [groups, items, spans, focusIndex]);
|
|
554
658
|
// What scrolls the rows — the table's own box, an ancestor or the window — and where in it they
|
|
555
659
|
// start. Both are known only once the table is in the page: before that (on the server, and in
|
|
556
660
|
// the first render here) the first rows are drawn, the same on both.
|
|
@@ -558,8 +662,15 @@ export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows,
|
|
|
558
662
|
const scrollerRef = React.useRef(null);
|
|
559
663
|
const [margin, setMargin] = React.useState(0);
|
|
560
664
|
const live = scroller != null;
|
|
665
|
+
// Set at each render, read as the scroller moves (see `compress`).
|
|
666
|
+
const realOffsetRef = React.useRef(0);
|
|
667
|
+
const compressRef = React.useRef(1);
|
|
668
|
+
const marginRef = React.useRef(0);
|
|
669
|
+
const toRows = (offset) => offset <= marginRef.current
|
|
670
|
+
? offset
|
|
671
|
+
: marginRef.current + (offset - marginRef.current) * compressRef.current;
|
|
561
672
|
const virtualizer = useVirtualizer({
|
|
562
|
-
count
|
|
673
|
+
count,
|
|
563
674
|
enabled: live,
|
|
564
675
|
getScrollElement: () => scroller,
|
|
565
676
|
estimateSize: estimate,
|
|
@@ -568,14 +679,30 @@ export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows,
|
|
|
568
679
|
scrollMargin: margin,
|
|
569
680
|
rangeExtractor,
|
|
570
681
|
initialRect: { width: 0, height: FIRST_VIEW },
|
|
571
|
-
initialOffset: () => (!scroller ? 0 : isWindow(scroller) ? scroller.scrollY : scroller.scrollTop),
|
|
682
|
+
initialOffset: () => toRows(!scroller ? 0 : isWindow(scroller) ? scroller.scrollY : scroller.scrollTop),
|
|
572
683
|
observeElementRect: (instance, cb) => isWindow(instance.scrollElement)
|
|
573
684
|
? observeWindowRect(instance, cb)
|
|
574
685
|
: observeElementRect(instance, cb),
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
686
|
+
// The scroller's offset, in the rows' own space: past where they start, `compress` times as far.
|
|
687
|
+
observeElementOffset: (instance, cb) => {
|
|
688
|
+
const report = (offset, scrolling) => {
|
|
689
|
+
realOffsetRef.current = offset;
|
|
690
|
+
cb(toRows(offset), scrolling);
|
|
691
|
+
};
|
|
692
|
+
return isWindow(instance.scrollElement)
|
|
693
|
+
? observeWindowOffset(instance, report)
|
|
694
|
+
: observeElementOffset(instance, report);
|
|
695
|
+
},
|
|
578
696
|
});
|
|
697
|
+
// Rows taller in all than a browser can draw (about 33M px in Chrome and Safari, 17M in Firefox)
|
|
698
|
+
// are drawn in at most MAX_HEIGHT: the space between them shrinks, and the rows in view sit
|
|
699
|
+
// where they would, at their own height.
|
|
700
|
+
const viewHeight = virtualizer.scrollRect?.height ?? FIRST_VIEW;
|
|
701
|
+
const virtualTotal = virtualizer.getTotalSize();
|
|
702
|
+
const compress = live && virtualTotal > MAX_HEIGHT ? (virtualTotal - viewHeight) / (MAX_HEIGHT - viewHeight) : 1;
|
|
703
|
+
compressRef.current = compress;
|
|
704
|
+
marginRef.current = margin;
|
|
705
|
+
virtualizer.shouldAdjustScrollPositionOnItemSizeChange = compress > 1 ? noAdjust : undefined;
|
|
579
706
|
/** Looks for the scroller again: when the rows change, or the table or the window resize. */
|
|
580
707
|
const findScroller = React.useCallback(() => {
|
|
581
708
|
const anchor = anchorRef.current;
|
|
@@ -600,7 +727,7 @@ export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows,
|
|
|
600
727
|
React.useLayoutEffect(() => {
|
|
601
728
|
findScroller();
|
|
602
729
|
measureMargin();
|
|
603
|
-
}, [findScroller, measureMargin,
|
|
730
|
+
}, [findScroller, measureMargin, count]);
|
|
604
731
|
React.useEffect(() => {
|
|
605
732
|
const anchor = anchorRef.current;
|
|
606
733
|
if (!anchor)
|
|
@@ -636,14 +763,14 @@ export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows,
|
|
|
636
763
|
];
|
|
637
764
|
setHeadRows(heads.length);
|
|
638
765
|
heads.forEach((row, i) => row.setAttribute("aria-rowindex", String(i + 1)));
|
|
639
|
-
table.setAttribute("aria-rowcount", String(heads.length +
|
|
766
|
+
table.setAttribute("aria-rowcount", String(heads.length + count));
|
|
640
767
|
return () => {
|
|
641
768
|
table.removeAttribute("aria-rowcount");
|
|
642
769
|
heads.forEach((row) => row.removeAttribute("aria-rowindex"));
|
|
643
770
|
};
|
|
644
|
-
}, [
|
|
645
|
-
const itemsRef = React.useRef(
|
|
646
|
-
itemsRef.current =
|
|
771
|
+
}, [count]);
|
|
772
|
+
const itemsRef = React.useRef(itemAt);
|
|
773
|
+
itemsRef.current = itemAt;
|
|
647
774
|
React.useEffect(() => {
|
|
648
775
|
const table = anchorRef.current?.closest("table, [role=table]");
|
|
649
776
|
if (!table)
|
|
@@ -654,7 +781,7 @@ export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows,
|
|
|
654
781
|
: null;
|
|
655
782
|
if (!row || row.closest("table, [role=table]") !== table)
|
|
656
783
|
return;
|
|
657
|
-
const entry = itemsRef.current
|
|
784
|
+
const entry = itemsRef.current(Number(row.getAttribute("data-index")));
|
|
658
785
|
if (entry)
|
|
659
786
|
setFocusKey(entry.key);
|
|
660
787
|
};
|
|
@@ -683,37 +810,100 @@ export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows,
|
|
|
683
810
|
const measure = virtualizer.measureElement;
|
|
684
811
|
const shown = live
|
|
685
812
|
? virtualizer.getVirtualIndexes()
|
|
686
|
-
: Array.from({ length: Math.min(FIRST_ROWS,
|
|
813
|
+
: Array.from({ length: Math.min(FIRST_ROWS, count) }, (_, i) => i);
|
|
687
814
|
let starts = null;
|
|
688
815
|
if (!live) {
|
|
689
|
-
starts = new Float64Array(
|
|
690
|
-
for (let i = 0; i <
|
|
816
|
+
starts = new Float64Array(count + 1);
|
|
817
|
+
for (let i = 0; i < count; i++)
|
|
691
818
|
starts[i + 1] = starts[i] + estimate(i);
|
|
692
819
|
}
|
|
693
820
|
const startOf = (i) => (starts ? starts[i] : virtualizer.measurementsCache[i].start - margin);
|
|
694
821
|
const endOf = (i) => (starts ? starts[i + 1] : virtualizer.measurementsCache[i].end - margin);
|
|
695
|
-
const total = starts ? starts[
|
|
822
|
+
const total = starts ? starts[count] : compress > 1 ? MAX_HEIGHT : virtualTotal;
|
|
823
|
+
// Where a point of the rows is drawn. Compressed, the view's top (`seen`, the rows' own space)
|
|
824
|
+
// is drawn where the scroller is (`at`), the rows around it at their height, and the rest of the
|
|
825
|
+
// rows shrink into the space on either side.
|
|
826
|
+
let place = (y) => y;
|
|
827
|
+
if (compress > 1) {
|
|
828
|
+
const at = realOffsetRef.current - margin;
|
|
829
|
+
const seen = at > 0 ? at * compress : at;
|
|
830
|
+
const near = viewHeight * 2;
|
|
831
|
+
const from = Math.max(0, seen - Math.min(near, Math.max(0, at)));
|
|
832
|
+
const to = Math.min(virtualTotal, seen + Math.min(near, Math.max(0, total - at)));
|
|
833
|
+
const fromAt = at - (seen - from);
|
|
834
|
+
const toAt = at + (to - seen);
|
|
835
|
+
place = (y) => y < from
|
|
836
|
+
? from > 0
|
|
837
|
+
? (y / from) * fromAt
|
|
838
|
+
: 0
|
|
839
|
+
: y > to
|
|
840
|
+
? toAt + ((y - to) / Math.max(1, virtualTotal - to)) * (total - toAt)
|
|
841
|
+
: at + (y - seen);
|
|
842
|
+
}
|
|
843
|
+
// The estimate follows the rows drawn: most of them are one height (and a theme can change it).
|
|
844
|
+
React.useLayoutEffect(() => {
|
|
845
|
+
const table = anchorRef.current?.closest("table, [role=table]");
|
|
846
|
+
if (!live || !table)
|
|
847
|
+
return;
|
|
848
|
+
const common = (selector) => {
|
|
849
|
+
const count = new Map();
|
|
850
|
+
for (const el of table.querySelectorAll(selector)) {
|
|
851
|
+
const h = Math.round(el.getBoundingClientRect().height * 2) / 2;
|
|
852
|
+
if (h > 0)
|
|
853
|
+
count.set(h, (count.get(h) ?? 0) + 1);
|
|
854
|
+
}
|
|
855
|
+
let best;
|
|
856
|
+
for (const [h, n] of count)
|
|
857
|
+
if (best === undefined || n > count.get(best))
|
|
858
|
+
best = h;
|
|
859
|
+
return best;
|
|
860
|
+
};
|
|
861
|
+
const row = common(":scope [data-slot=table-row][data-index]");
|
|
862
|
+
const header = common(":scope [data-slot=table-group-header][data-index]");
|
|
863
|
+
setDrawnSize((old) => {
|
|
864
|
+
const next = {
|
|
865
|
+
row: row ?? old?.row ?? (dense ? 30 : 46),
|
|
866
|
+
header: header ?? old?.header ?? (dense ? 30 : 38),
|
|
867
|
+
};
|
|
868
|
+
return old && old.row === next.row && old.header === next.header ? old : next;
|
|
869
|
+
});
|
|
870
|
+
});
|
|
696
871
|
const spacer = (key, height, outer = false) => fit ? (_jsx("div", { "aria-hidden": true, "data-slot": "table-spacer", className: "col-span-full", style: { height } }, key)) : outer ? (_jsx("tbody", { "aria-hidden": true, "data-slot": "table-spacer", children: _jsx("tr", { children: _jsx("td", { style: { height, padding: 0 } }) }) }, key)) : (_jsx("tr", { "aria-hidden": true, "data-slot": "table-spacer", children: _jsx("td", { style: { height, padding: 0 } }) }, key));
|
|
697
872
|
const entry = (i) => {
|
|
698
|
-
const item =
|
|
873
|
+
const item = itemAt(i);
|
|
699
874
|
const rowIndex = headRows + i + 1;
|
|
700
875
|
if (item.header)
|
|
701
876
|
return (_jsx(VirtualRow, { index: i, rowIndex: rowIndex, measure: measure, row: groups[item.group].header, at: -1, render: renderHeader }, item.key));
|
|
702
877
|
return (_jsx(VirtualRow, { index: i, rowIndex: rowIndex, measure: measure, row: item.row, at: item.at, render: renderRow }, item.key));
|
|
703
878
|
};
|
|
879
|
+
// The rows rendered, for a body that loads them as they come into view.
|
|
880
|
+
// The rows in view and `overscan` beyond — not a far-off row kept for the focus.
|
|
881
|
+
const range = live ? virtualizer.range : null;
|
|
882
|
+
const firstRow = groups || !range ? -1 : Math.max(0, range.startIndex - overscan);
|
|
883
|
+
const lastRow = groups || !range ? -1 : Math.min(count - 1, range.endIndex + overscan);
|
|
884
|
+
const rangeRef = React.useRef(onRangeChange);
|
|
885
|
+
rangeRef.current = onRangeChange;
|
|
886
|
+
React.useEffect(() => {
|
|
887
|
+
if (lastRow >= 0)
|
|
888
|
+
rangeRef.current?.(firstRow, lastRow + 1);
|
|
889
|
+
}, [firstRow, lastRow]);
|
|
890
|
+
/** Where the last `run` ended. */
|
|
891
|
+
let runEnd = 0;
|
|
704
892
|
/** The shown entries `from` up to `to`, spaced out between `top` and `bottom`. */
|
|
705
893
|
const run = (from, to, top, bottom) => {
|
|
706
894
|
const out = [];
|
|
707
895
|
let y = top;
|
|
708
896
|
for (let j = from; j < to; j++) {
|
|
709
897
|
const i = shown[j];
|
|
710
|
-
|
|
711
|
-
|
|
898
|
+
const start = place(startOf(i));
|
|
899
|
+
if (start > y + 0.5)
|
|
900
|
+
out.push(spacer(`gap-${i}`, start - y));
|
|
712
901
|
out.push(entry(i));
|
|
713
|
-
y = endOf(i);
|
|
902
|
+
y = Math.max(y, start) + endOf(i) - startOf(i);
|
|
714
903
|
}
|
|
715
904
|
if (bottom > y + 0.5)
|
|
716
905
|
out.push(spacer("end", bottom - y));
|
|
906
|
+
runEnd = Math.max(y, bottom);
|
|
717
907
|
return out;
|
|
718
908
|
};
|
|
719
909
|
// Rendered once per change of the rows, not as the table scrolls.
|
|
@@ -728,8 +918,8 @@ export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows,
|
|
|
728
918
|
for (let j = 0; j < shown.length;) {
|
|
729
919
|
const g = items[shown[j]].group;
|
|
730
920
|
const { start: first, end, open } = spans[g];
|
|
731
|
-
const top = startOf(first);
|
|
732
|
-
const bottom = endOf(end - 1);
|
|
921
|
+
const top = Math.max(y, place(startOf(first)));
|
|
922
|
+
const bottom = place(endOf(end - 1));
|
|
733
923
|
let k = j;
|
|
734
924
|
while (k < shown.length && items[shown[k]].group === g)
|
|
735
925
|
k++;
|
|
@@ -741,7 +931,7 @@ export function TableVirtualBody({ rows, groups, renderRow, getRowKey, sizeRows,
|
|
|
741
931
|
setToggled((map) => new Map(map).set(group.key, next));
|
|
742
932
|
group.onOpenChange?.(next);
|
|
743
933
|
}, collapsible: group.collapsible, children: run(j, k, top, bottom) }, `g:${String(group.key)}`));
|
|
744
|
-
y =
|
|
934
|
+
y = runEnd;
|
|
745
935
|
j = k;
|
|
746
936
|
}
|
|
747
937
|
if (total > y + 0.5)
|
package/dist/components/tabs.js
CHANGED
|
@@ -48,12 +48,12 @@ const indicatorVariants = {
|
|
|
48
48
|
segmented: [
|
|
49
49
|
"pointer-events-none absolute top-0 left-0 -z-10 h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top) rounded-item",
|
|
50
50
|
"bg-control-surface bg-linear-to-b from-control-inner-edge to-transparent shadow-raised",
|
|
51
|
-
"transition-[translate,width,height] duration-(--duration) ease-(--ease)",
|
|
51
|
+
"transition-[translate,width,height] duration-(--duration-glide) ease-(--ease-glide)",
|
|
52
52
|
].join(" "),
|
|
53
53
|
underline: [
|
|
54
54
|
"pointer-events-none absolute bottom-0 left-0 h-px w-(--active-tab-width) translate-x-(--active-tab-left) bg-foreground forced-colors:bg-[color:Highlight] forced-colors:forced-color-adjust-none",
|
|
55
55
|
"data-[orientation=vertical]:top-0 data-[orientation=vertical]:bottom-auto data-[orientation=vertical]:-start-px data-[orientation=vertical]:h-(--active-tab-height) data-[orientation=vertical]:w-px data-[orientation=vertical]:translate-x-0 data-[orientation=vertical]:translate-y-(--active-tab-top)",
|
|
56
|
-
"transition-[translate,width,height] duration-(--duration) ease-(--ease)",
|
|
56
|
+
"transition-[translate,width,height] duration-(--duration-glide) ease-(--ease-glide)",
|
|
57
57
|
].join(" "),
|
|
58
58
|
};
|
|
59
59
|
/**
|
|
@@ -149,7 +149,7 @@ export function TabsTab({ className, ...props }) {
|
|
|
149
149
|
const variant = React.useContext(TabsVariantContext);
|
|
150
150
|
return (_jsx(BaseTabs.Tab, { "data-slot": "tabs-tab", className: sx([
|
|
151
151
|
"relative inline-flex shrink-0 cursor-pointer items-center leading-none whitespace-nowrap focus-ring select-none",
|
|
152
|
-
"transition-colors duration-(--duration) ease-(--ease)",
|
|
152
|
+
"transition-colors duration-(--duration-fade) ease-(--ease)",
|
|
153
153
|
// A disabled tab stays focusable (Base UI) and still takes hover, so a tooltip can say why.
|
|
154
154
|
"disabled:pointer-events-none data-disabled:cursor-not-allowed data-disabled:opacity-50",
|
|
155
155
|
"[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
@@ -158,5 +158,9 @@ export function TabsTab({ className, ...props }) {
|
|
|
158
158
|
}
|
|
159
159
|
/** The content for one tab. Only the active panel is mounted unless `keepMounted` is set. */
|
|
160
160
|
export function TabsPanel({ className, ...props }) {
|
|
161
|
-
return (_jsx(BaseTabs.Panel, { "data-slot": "tabs-panel",
|
|
161
|
+
return (_jsx(BaseTabs.Panel, { "data-slot": "tabs-panel",
|
|
162
|
+
// Base UI keeps the panel that is leaving for a frame, for an exit animation, beside the one
|
|
163
|
+
// arriving: both at once would double the height for that frame, and the page jump under
|
|
164
|
+
// the pointer. A panel has no exit animation here, so the leaving one goes at once.
|
|
165
|
+
className: sx("min-w-0 flex-1 focus-ring data-ending-style:hidden", className), ...props }));
|
|
162
166
|
}
|
|
@@ -3,6 +3,17 @@ declare const groupSizes: {
|
|
|
3
3
|
readonly sm: "min-h-(--control-h-sm) p-0.5";
|
|
4
4
|
readonly default: "min-h-(--control-h) p-[3px]";
|
|
5
5
|
};
|
|
6
|
+
export interface TagsInputMessages {
|
|
7
|
+
/** Each chip's remove button. */
|
|
8
|
+
remove: (tag: string) => string;
|
|
9
|
+
/** Read after a tag that `validate` turned down. */
|
|
10
|
+
invalid: string;
|
|
11
|
+
}
|
|
12
|
+
declare module "./locale" {
|
|
13
|
+
interface Messages {
|
|
14
|
+
tagsInput: TagsInputMessages;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
6
17
|
export interface TagsInputProps extends Omit<React.ComponentProps<"input">, "value" | "defaultValue" | "onChange" | "size" | "max" | "type" | "className"> {
|
|
7
18
|
value?: string[];
|
|
8
19
|
defaultValue?: string[];
|
|
@@ -21,8 +32,13 @@ export interface TagsInputProps extends Omit<React.ComponentProps<"input">, "val
|
|
|
21
32
|
* and marks the `Field` invalid.
|
|
22
33
|
*/
|
|
23
34
|
required?: boolean;
|
|
24
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* The remove button's name. Default: "Remove {tag}".
|
|
37
|
+
* @deprecated Use `labels.remove`.
|
|
38
|
+
*/
|
|
25
39
|
removeLabel?: (tag: string) => string;
|
|
40
|
+
/** What screen readers hear on the chips; a LocaleProvider sets it for every TagsInput. */
|
|
41
|
+
labels?: Partial<TagsInputMessages>;
|
|
26
42
|
/** Classes for the visible field, not the bare `<input>`. */
|
|
27
43
|
className?: string;
|
|
28
44
|
}
|
|
@@ -36,5 +52,5 @@ export interface TagsInputProps extends Omit<React.ComponentProps<"input">, "val
|
|
|
36
52
|
* (letter case aside). Pass `validate` to mark the tags that don't fit, and say why under the
|
|
37
53
|
* field. The rule people break: colouring tags by kind — they are raised secondary surfaces.
|
|
38
54
|
*/
|
|
39
|
-
export declare function TagsInput({ value: valueProp, defaultValue, onValueChange, size, validate, max, name, removeLabel, className, placeholder, disabled, readOnly, required, id, ref, onKeyDown, onPaste, onFocus, onBlur, ...props }: TagsInputProps): React.JSX.Element;
|
|
55
|
+
export declare function TagsInput({ value: valueProp, defaultValue, onValueChange, size, validate, max, name, removeLabel, labels, className, placeholder, disabled, readOnly, required, id, ref, onKeyDown, onPaste, onFocus, onBlur, ...props }: TagsInputProps): React.JSX.Element;
|
|
40
56
|
export {};
|