@seekalfred/primitives 0.7.3 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -1
- package/dist/alert/alert.d.ts +2 -2
- package/dist/alert-dialog/alert-dialog.d.ts +14 -0
- package/dist/alert-dialog/alert-dialog.js +51 -26
- package/dist/alert-dialog/alert-dialog.js.map +1 -1
- package/dist/announcement-bar/announcement-bar.d.ts +15 -4
- package/dist/announcement-bar/announcement-bar.js +31 -6
- package/dist/announcement-bar/announcement-bar.js.map +1 -1
- package/dist/avatar/avatar.d.ts +7 -0
- package/dist/avatar/avatar.js +33 -12
- package/dist/avatar/avatar.js.map +1 -1
- package/dist/badge/badge.d.ts +1 -1
- package/dist/bar-chart/bar-chart-series.d.ts +75 -0
- package/dist/bar-chart/bar-chart-series.js +401 -0
- package/dist/bar-chart/bar-chart-series.js.map +1 -0
- package/dist/bar-chart/bar-chart.d.ts +25 -1
- package/dist/bar-chart/bar-chart.js +26 -1
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/index.d.ts +2 -1
- package/dist/button/button.d.ts +2 -2
- package/dist/chip-group/chip-group.d.ts +11 -0
- package/dist/chip-group/chip-group.js +50 -34
- package/dist/chip-group/chip-group.js.map +1 -1
- package/dist/chip-group/index.d.ts +2 -2
- package/dist/copy-button/copy-button.d.ts +19 -3
- package/dist/copy-button/copy-button.js +7 -4
- package/dist/copy-button/copy-button.js.map +1 -1
- package/dist/file-drop-zone/file-drop-zone.d.ts +29 -3
- package/dist/file-drop-zone/file-drop-zone.js +26 -8
- package/dist/file-drop-zone/file-drop-zone.js.map +1 -1
- package/dist/gauge/gauge.d.ts +18 -1
- package/dist/gauge/gauge.js +35 -21
- package/dist/gauge/gauge.js.map +1 -1
- package/dist/gauge/index.d.ts +2 -2
- package/dist/index.d.ts +8 -7
- package/dist/index.js +4 -4
- package/dist/input/input.d.ts +7 -0
- package/dist/input/input.js +3 -1
- package/dist/input/input.js.map +1 -1
- package/dist/lib/field-shell.js +2 -6
- package/dist/lib/field-shell.js.map +1 -1
- package/dist/lib/required-marker.js +20 -0
- package/dist/lib/required-marker.js.map +1 -0
- package/dist/line-chart/index.d.ts +2 -2
- package/dist/line-chart/line-chart.d.ts +105 -3
- package/dist/line-chart/line-chart.js +183 -44
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/money-input/index.d.ts +2 -2
- package/dist/money-input/money-input.d.ts +14 -0
- package/dist/money-input/money-input.js +17 -7
- package/dist/money-input/money-input.js.map +1 -1
- package/dist/morph-select/morph-select.d.ts +8 -1
- package/dist/morph-select/morph-select.js +8 -5
- package/dist/morph-select/morph-select.js.map +1 -1
- package/dist/multi-select/multi-select.d.ts +31 -0
- package/dist/multi-select/multi-select.js +122 -5
- package/dist/multi-select/multi-select.js.map +1 -1
- package/dist/progress/index.d.ts +2 -2
- package/dist/progress/index.js +2 -2
- package/dist/progress/progress.d.ts +53 -2
- package/dist/progress/progress.js +146 -36
- package/dist/progress/progress.js.map +1 -1
- package/dist/radio-group/radio-group.d.ts +1 -1
- package/dist/scrub-input/scrub-input.d.ts +11 -1
- package/dist/scrub-input/scrub-input.js +22 -10
- package/dist/scrub-input/scrub-input.js.map +1 -1
- package/dist/select/select.d.ts +9 -0
- package/dist/select/select.js +3 -2
- package/dist/select/select.js.map +1 -1
- package/dist/sparkline/sparkline.d.ts +27 -2
- package/dist/sparkline/sparkline.js +115 -18
- package/dist/sparkline/sparkline.js.map +1 -1
- package/dist/stat-card/index.d.ts +2 -2
- package/dist/stat-card/index.js +2 -2
- package/dist/stat-card/stat-card.d.ts +32 -1
- package/dist/stat-card/stat-card.js +52 -9
- package/dist/stat-card/stat-card.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/table/index.d.ts +2 -2
- package/dist/table/index.js +2 -2
- package/dist/table/table.d.ts +114 -4
- package/dist/table/table.js +374 -94
- package/dist/table/table.js.map +1 -1
- package/dist/text-shimmer/text-shimmer.d.ts +18 -2
- package/dist/text-shimmer/text-shimmer.js +5 -2
- package/dist/text-shimmer/text-shimmer.js.map +1 -1
- package/dist/textarea/textarea.d.ts +7 -0
- package/dist/textarea/textarea.js +3 -1
- package/dist/textarea/textarea.js.map +1 -1
- package/dist/toast/toast.d.ts +2 -2
- package/package.json +3 -3
package/dist/table/table.js
CHANGED
|
@@ -6,8 +6,8 @@ import { useFlip } from "../lib/flip.js";
|
|
|
6
6
|
import { Checkbox as Checkbox$1 } from "../checkbox/checkbox.js";
|
|
7
7
|
import { Select as Select$1, SelectItem } from "../select/select.js";
|
|
8
8
|
import { cva } from "class-variance-authority";
|
|
9
|
-
import { forwardRef, useEffect, useMemo, useRef, useState } from "react";
|
|
10
|
-
import { Cell, Column, Row, Table, TableBody, TableFooter, TableHeader } from "react-aria-components";
|
|
9
|
+
import { forwardRef, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
10
|
+
import { Button, Cell, Column, Row, Table, TableBody, TableFooter, TableHeader } from "react-aria-components";
|
|
11
11
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
import { flushSync } from "react-dom";
|
|
13
13
|
//#region src/table/table.tsx
|
|
@@ -118,7 +118,13 @@ const tableVariants = cva([
|
|
|
118
118
|
"w-full border-collapse box-border",
|
|
119
119
|
"font-sans text-base leading-(--leading-normal)",
|
|
120
120
|
"bg-surface text-foreground"
|
|
121
|
-
]
|
|
121
|
+
], {
|
|
122
|
+
variants: { density: {
|
|
123
|
+
default: "",
|
|
124
|
+
compact: "text-sm"
|
|
125
|
+
} },
|
|
126
|
+
defaultVariants: { density: "default" }
|
|
127
|
+
});
|
|
122
128
|
/**
|
|
123
129
|
* The header is near-white, not a grey band.
|
|
124
130
|
*
|
|
@@ -182,16 +188,70 @@ const tableColumnVariants = cva([
|
|
|
182
188
|
center: "text-center",
|
|
183
189
|
end: "text-end"
|
|
184
190
|
},
|
|
191
|
+
density: {
|
|
192
|
+
default: "",
|
|
193
|
+
compact: "py-2"
|
|
194
|
+
},
|
|
195
|
+
hidden: {
|
|
196
|
+
true: "group/column py-0 data-[focus-visible]:py-(--density-row-pad-y)",
|
|
197
|
+
false: ""
|
|
198
|
+
},
|
|
185
199
|
headerType: {
|
|
186
200
|
sentence: "text-sm leading-none",
|
|
187
201
|
caps: "text-xs uppercase tracking-wide leading-none"
|
|
188
202
|
}
|
|
189
203
|
},
|
|
204
|
+
compoundVariants: [{
|
|
205
|
+
density: "compact",
|
|
206
|
+
hidden: true,
|
|
207
|
+
class: "data-[focus-visible]:py-2"
|
|
208
|
+
}],
|
|
190
209
|
defaultVariants: {
|
|
191
210
|
align: "start",
|
|
192
|
-
headerType: "sentence"
|
|
211
|
+
headerType: "sentence",
|
|
212
|
+
density: "default",
|
|
213
|
+
hidden: false
|
|
193
214
|
}
|
|
194
215
|
});
|
|
216
|
+
/**
|
|
217
|
+
* The disclosure button that opens a row's sub-rows (`getSubRows`).
|
|
218
|
+
*
|
|
219
|
+
* A real button in the first cell, named by that cell's own content and
|
|
220
|
+
* carrying `aria-expanded`, so a reader hears "Meta, button, collapsed"
|
|
221
|
+
* without the library inventing copy. 24px square: the WCAG 2.2 target-size
|
|
222
|
+
* floor (2.5.8), and the step each level of sub-rows is indented by, so a
|
|
223
|
+
* child's text lines up one button-width in from its parent's. The chevron
|
|
224
|
+
* turns a quarter when the row opens; with reduced motion it simply flips.
|
|
225
|
+
*/
|
|
226
|
+
const tableExpandButtonVariants = cva([
|
|
227
|
+
"inline-flex size-6 shrink-0 items-center justify-center rounded-sm cursor-pointer",
|
|
228
|
+
"text-muted-foreground data-[hovered]:bg-muted data-[hovered]:text-foreground",
|
|
229
|
+
"[&_svg]:motion-safe:transition-transform [&_svg]:motion-safe:duration-(--duration-snappy) [&_svg]:motion-safe:ease-snappy",
|
|
230
|
+
"data-[expanded]:[&_svg]:rotate-90 rtl:data-[expanded]:[&_svg]:-rotate-90",
|
|
231
|
+
...FOCUS_RING
|
|
232
|
+
]);
|
|
233
|
+
/**
|
|
234
|
+
* A group header row (`isGroupRow`): one cell spanning the row, naming the rows
|
|
235
|
+
* under it ("Mobile" / "Desktop"). The header band's fill and label type, so it
|
|
236
|
+
* reads as a heading of the rows that follow rather than as one of them.
|
|
237
|
+
*/
|
|
238
|
+
const tableGroupRowVariants = cva(["bg-header-fill hover:bg-header-fill", "[&>td]:text-sm [&>td]:font-semibold [&>td]:text-muted-foreground"]);
|
|
239
|
+
/**
|
|
240
|
+
* The sort control of a column header in a plain table (`keyboardModel="table"`).
|
|
241
|
+
*
|
|
242
|
+
* In the grid the header cell is the control; in a plain table a cell cannot
|
|
243
|
+
* take focus, so the label sits in a real button that Tab reaches. It wears
|
|
244
|
+
* the header's own type and colour, and is at least 24px tall so a compact
|
|
245
|
+
* header still clears the WCAG 2.2 target size (2.5.8).
|
|
246
|
+
*/
|
|
247
|
+
const tableSortButtonVariants = cva([
|
|
248
|
+
"inline-flex min-h-6 items-center cursor-pointer",
|
|
249
|
+
"bg-transparent p-0 border-0 font-[inherit] text-[length:inherit] leading-[inherit] text-inherit",
|
|
250
|
+
"outline-none focus-visible:outline-solid",
|
|
251
|
+
"focus-visible:outline-(length:--focus-ring-width)",
|
|
252
|
+
"focus-visible:outline-offset-(--focus-ring-offset)",
|
|
253
|
+
"focus-visible:outline-(--color-ring)"
|
|
254
|
+
]);
|
|
195
255
|
const tableRowVariants = cva([
|
|
196
256
|
"group/row box-border bg-surface",
|
|
197
257
|
"motion-safe:transition-colors motion-safe:duration-(--duration-fast) motion-safe:ease-standard",
|
|
@@ -230,11 +290,16 @@ const tableCellVariants = cva([
|
|
|
230
290
|
numeric: {
|
|
231
291
|
true: "tabular-nums whitespace-nowrap",
|
|
232
292
|
false: ""
|
|
293
|
+
},
|
|
294
|
+
density: {
|
|
295
|
+
default: "",
|
|
296
|
+
compact: "py-2"
|
|
233
297
|
}
|
|
234
298
|
},
|
|
235
299
|
defaultVariants: {
|
|
236
300
|
align: "start",
|
|
237
|
-
numeric: false
|
|
301
|
+
numeric: false,
|
|
302
|
+
density: "default"
|
|
238
303
|
}
|
|
239
304
|
});
|
|
240
305
|
/**
|
|
@@ -375,6 +440,20 @@ function RowChevronGlyph() {
|
|
|
375
440
|
})
|
|
376
441
|
});
|
|
377
442
|
}
|
|
443
|
+
function ExpandChevronGlyph() {
|
|
444
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
445
|
+
"data-slot": "table-row-expand-chevron",
|
|
446
|
+
"aria-hidden": "true",
|
|
447
|
+
viewBox: "0 0 16 16",
|
|
448
|
+
fill: "none",
|
|
449
|
+
stroke: "currentColor",
|
|
450
|
+
strokeWidth: "1.5",
|
|
451
|
+
strokeLinecap: "round",
|
|
452
|
+
strokeLinejoin: "round",
|
|
453
|
+
className: "size-(--icon-sm) rtl:-scale-x-100",
|
|
454
|
+
children: /* @__PURE__ */ jsx("path", { d: "m6 3 5 5-5 5" })
|
|
455
|
+
});
|
|
456
|
+
}
|
|
378
457
|
function SortCaretGlyph({ direction }) {
|
|
379
458
|
return /* @__PURE__ */ jsxs("svg", {
|
|
380
459
|
"data-slot": "table-sort-caret",
|
|
@@ -456,9 +535,10 @@ function createColumns() {
|
|
|
456
535
|
/**
|
|
457
536
|
* A data table.
|
|
458
537
|
*
|
|
459
|
-
* Maturity: **beta**.
|
|
460
|
-
*
|
|
461
|
-
*
|
|
538
|
+
* Maturity: **beta**. Filtering is deliberately absent -- it had one consumer
|
|
539
|
+
* or none across the six legacy tables, and it belongs to DataGrid. Rows can
|
|
540
|
+
* open onto sub-rows (`getSubRows`) and head a group (`isGroupRow`), which the
|
|
541
|
+
* product's usage and page-speed reports needed. Sorting glides: when a sort reorders the
|
|
462
542
|
* rows, each slides to its new place instead of jumping (the lib/flip helper).
|
|
463
543
|
* Selection is opt-in with `selectionMode="multiple"`.
|
|
464
544
|
*
|
|
@@ -496,17 +576,20 @@ function compareKeys(a, b) {
|
|
|
496
576
|
if (typeof a === "number" && typeof b === "number") return a - b;
|
|
497
577
|
return String(a).localeCompare(String(b));
|
|
498
578
|
}
|
|
499
|
-
|
|
579
|
+
/** `level` in the order `sort` asks for; unchanged when there is none or its column is gone. */
|
|
580
|
+
function sortRows(level, columns, sort) {
|
|
581
|
+
if (!sort) return level;
|
|
582
|
+
const sorted = columns.find((column) => column.id === sort.column);
|
|
583
|
+
if (!sorted) return level;
|
|
584
|
+
const direction = sort.direction === "descending" ? -1 : 1;
|
|
585
|
+
return [...level].sort((a, b) => direction * compareKeys(sortKey(sorted, a), sortKey(sorted, b)));
|
|
586
|
+
}
|
|
587
|
+
const Table$1 = forwardRef(function Table$2({ data, columns, getRowId, variant, sortDescriptor, defaultSortDescriptor, onSortChange, onRowAction, isRowHighlighted, rowClassName, selectionMode, selectedKeys, defaultSelectedKeys, onSelectionChange, selectionLabels, frame, headerType, headerFill, striped, totalRow, empty, minWidth, stickyFirstColumn, pageSize, pageSizeOptions, onPageSizeChange, pageLabels, getSubRows, expandedKeys, defaultExpandedKeys, onExpandedChange, isGroupRow, density, headerHidden, keyboardModel, className, ...props }, ref) {
|
|
500
588
|
const isControlled = sortDescriptor !== void 0;
|
|
501
589
|
const [uncontrolledSort, setUncontrolledSort] = useState(defaultSortDescriptor);
|
|
502
590
|
const activeSort = isControlled ? sortDescriptor : uncontrolledSort;
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
const sorted = columns.find((column) => column.id === activeSort.column);
|
|
506
|
-
if (!sorted) return data;
|
|
507
|
-
const direction = activeSort.direction === "descending" ? -1 : 1;
|
|
508
|
-
return [...data].sort((a, b) => direction * compareKeys(sortKey(sorted, a), sortKey(sorted, b)));
|
|
509
|
-
}, [
|
|
591
|
+
const sortLevel = (level) => isControlled ? level : sortRows(level, columns, activeSort);
|
|
592
|
+
const rows = useMemo(() => isControlled ? data : sortRows(data, columns, activeSort), [
|
|
510
593
|
data,
|
|
511
594
|
columns,
|
|
512
595
|
activeSort,
|
|
@@ -526,15 +609,65 @@ const Table$1 = forwardRef(function Table$2({ data, columns, getRowId, variant,
|
|
|
526
609
|
perPage: pageLabels?.perPage ?? ((size) => `${size} per page`),
|
|
527
610
|
rowsPerPage: pageLabels?.rowsPerPage ?? "Rows per page"
|
|
528
611
|
};
|
|
529
|
-
const
|
|
530
|
-
const
|
|
612
|
+
const [uncontrolledExpanded, setUncontrolledExpanded] = useState(() => new Set(defaultExpandedKeys ?? []));
|
|
613
|
+
const expanded = expandedKeys === void 0 ? uncontrolledExpanded : new Set(expandedKeys);
|
|
614
|
+
const toggleExpanded = (key) => {
|
|
615
|
+
const next = new Set(expanded);
|
|
616
|
+
if (next.has(key)) next.delete(key);
|
|
617
|
+
else next.add(key);
|
|
618
|
+
if (expandedKeys === void 0) setUncontrolledExpanded(next);
|
|
619
|
+
onExpandedChange?.(next);
|
|
620
|
+
};
|
|
621
|
+
const expandable = getSubRows !== void 0;
|
|
622
|
+
const { rowsByKey, subRowsByRow } = useMemo(() => {
|
|
623
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
624
|
+
const subRows = /* @__PURE__ */ new Map();
|
|
625
|
+
const index = (level) => {
|
|
626
|
+
for (const row of level) {
|
|
627
|
+
byKey.set(getRowId(row), row);
|
|
628
|
+
const children = getSubRows?.(row) ?? [];
|
|
629
|
+
subRows.set(row, children);
|
|
630
|
+
index(children);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
index(data);
|
|
634
|
+
return {
|
|
635
|
+
rowsByKey: byKey,
|
|
636
|
+
subRowsByRow: subRows
|
|
637
|
+
};
|
|
638
|
+
}, [
|
|
639
|
+
data,
|
|
640
|
+
getSubRows,
|
|
641
|
+
getRowId
|
|
642
|
+
]);
|
|
643
|
+
const subRowsOf = (row) => subRowsByRow.get(row) ?? [];
|
|
644
|
+
const shownRows = [];
|
|
645
|
+
const walk = (level, depth) => {
|
|
646
|
+
for (const [index, row] of level.entries()) {
|
|
647
|
+
const subRows = subRowsOf(row);
|
|
648
|
+
const isExpanded = subRows.length > 0 && expanded.has(getRowId(row));
|
|
649
|
+
shownRows.push({
|
|
650
|
+
row,
|
|
651
|
+
depth,
|
|
652
|
+
index,
|
|
653
|
+
hasSubRows: subRows.length > 0,
|
|
654
|
+
isExpanded
|
|
655
|
+
});
|
|
656
|
+
if (isExpanded) walk(sortLevel(subRows), depth + 1);
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
walk(visibleRows, 0);
|
|
660
|
+
const idBase = useId();
|
|
661
|
+
const plain = keyboardModel === "table";
|
|
662
|
+
const selectable = selectionMode === "multiple" && !plain;
|
|
663
|
+
const rowAction = plain ? void 0 : onRowAction;
|
|
531
664
|
const [uncontrolledSelection, setUncontrolledSelection] = useState(defaultSelectedKeys ?? /* @__PURE__ */ new Set());
|
|
532
665
|
const selection = selectedKeys ?? uncontrolledSelection;
|
|
533
666
|
const commitSelection = (keys) => {
|
|
534
667
|
if (selectedKeys === void 0) setUncontrolledSelection(keys);
|
|
535
668
|
onSelectionChange?.(keys);
|
|
536
669
|
};
|
|
537
|
-
const selectedCount = selection === "all" ?
|
|
670
|
+
const selectedCount = selection === "all" ? shownRows.length : [...selection].filter((key) => rowsByKey.has(key)).length;
|
|
538
671
|
const selectLabels = {
|
|
539
672
|
item: selectionLabels?.item ?? {
|
|
540
673
|
one: "row",
|
|
@@ -574,6 +707,73 @@ const Table$1 = forwardRef(function Table$2({ data, columns, getRowId, variant,
|
|
|
574
707
|
part,
|
|
575
708
|
striped: part === "body" && !!striped
|
|
576
709
|
});
|
|
710
|
+
const headerPart = headerFill === "none" ? "bare" : "header";
|
|
711
|
+
const alignOf = (column) => column.align ?? (column.numeric ? "end" : void 0);
|
|
712
|
+
const stickyFirst = (column, part) => [stickyFirstColumn && column === columns[0] && stickyCell(part), stickyFirstColumn && selectable && column === columns[0] && "start-11"];
|
|
713
|
+
const columnClass = (column) => cnAll(tableColumnVariants({
|
|
714
|
+
align: alignOf(column),
|
|
715
|
+
headerType,
|
|
716
|
+
density,
|
|
717
|
+
hidden: headerHidden
|
|
718
|
+
}), stickyFirst(column, headerPart));
|
|
719
|
+
const cellClass = (column, part) => cnAll(tableCellVariants({
|
|
720
|
+
align: alignOf(column),
|
|
721
|
+
numeric: column.numeric,
|
|
722
|
+
density
|
|
723
|
+
}), stickyFirst(column, part));
|
|
724
|
+
const rowClass = (row, isGroup) => cn(cnAll(tableRowVariants({
|
|
725
|
+
variant,
|
|
726
|
+
striped
|
|
727
|
+
}), isGroup && tableGroupRowVariants(), rowAction && !isGroup && "cursor-pointer", headerHidden && "first:border-t-0"), rowClassName?.(row));
|
|
728
|
+
const isSortable = (column) => !headerHidden && !!column.sortable;
|
|
729
|
+
const headerLabel = (column) => {
|
|
730
|
+
const label = /* @__PURE__ */ jsxs(Fragment$1, { children: [column.header, isSortable(column) ? /* @__PURE__ */ jsx(SortCaretGlyph, { direction: activeSort?.column === column.id ? activeSort.direction : "none" }) : null] });
|
|
731
|
+
return headerHidden ? /* @__PURE__ */ jsx("span", {
|
|
732
|
+
"data-slot": "table-column-label",
|
|
733
|
+
className: "sr-only group-data-[focus-visible]/column:not-sr-only",
|
|
734
|
+
children: label
|
|
735
|
+
}) : label;
|
|
736
|
+
};
|
|
737
|
+
const changeSort = (descriptor) => {
|
|
738
|
+
if (!isControlled) setUncontrolledSort(descriptor);
|
|
739
|
+
setPage(1);
|
|
740
|
+
onSortChange?.(descriptor);
|
|
741
|
+
};
|
|
742
|
+
const cellContent = (column, row, index) => {
|
|
743
|
+
const value = column.accessor(row);
|
|
744
|
+
return column.cell ? column.cell({
|
|
745
|
+
value,
|
|
746
|
+
row,
|
|
747
|
+
index
|
|
748
|
+
}) : renderValue(column, value, row);
|
|
749
|
+
};
|
|
750
|
+
const indentClass = (column) => expandable && column === columns[0] && "ps-[calc(var(--density-row-pad-x)+var(--table-row-depth)*--spacing(7))]";
|
|
751
|
+
const depthStyle = (column, depth) => expandable && column === columns[0] ? { "--table-row-depth": depth } : void 0;
|
|
752
|
+
const firstCellContent = (column, content, { row, hasSubRows, isExpanded }, labelId) => expandable && column === columns[0] ? /* @__PURE__ */ jsxs("span", {
|
|
753
|
+
className: "flex items-center gap-1",
|
|
754
|
+
children: [hasSubRows ? /* @__PURE__ */ jsx(Button, {
|
|
755
|
+
"data-slot": "table-row-expand",
|
|
756
|
+
"aria-expanded": isExpanded,
|
|
757
|
+
"aria-labelledby": labelId,
|
|
758
|
+
className: cnAll(tableExpandButtonVariants()),
|
|
759
|
+
onPress: () => toggleExpanded(getRowId(row)),
|
|
760
|
+
children: /* @__PURE__ */ jsx(ExpandChevronGlyph, {})
|
|
761
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
762
|
+
"aria-hidden": "true",
|
|
763
|
+
className: "size-6 shrink-0"
|
|
764
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
765
|
+
id: labelId,
|
|
766
|
+
"data-slot": "table-row-label",
|
|
767
|
+
className: "min-w-0",
|
|
768
|
+
children: content
|
|
769
|
+
})]
|
|
770
|
+
}) : content;
|
|
771
|
+
const columnStyle = (column) => column.width === void 0 ? void 0 : { width: column.width };
|
|
772
|
+
const emptyState = empty === void 0 ? void 0 : /* @__PURE__ */ jsx("div", {
|
|
773
|
+
"data-slot": "table-empty",
|
|
774
|
+
className: cnAll(tableEmptyVariants()),
|
|
775
|
+
children: empty
|
|
776
|
+
});
|
|
577
777
|
return /* @__PURE__ */ jsxs("div", {
|
|
578
778
|
"data-slot": "table-card",
|
|
579
779
|
"data-overflow-start": edges.start || void 0,
|
|
@@ -585,24 +785,104 @@ const Table$1 = forwardRef(function Table$2({ data, columns, getRowId, variant,
|
|
|
585
785
|
ref: scrollRef,
|
|
586
786
|
"data-slot": "table-scroll",
|
|
587
787
|
className: cnAll(tableScrollVariants()),
|
|
588
|
-
children: /* @__PURE__ */ jsxs(
|
|
788
|
+
children: plain ? /* @__PURE__ */ jsxs("table", {
|
|
789
|
+
ref,
|
|
790
|
+
...props,
|
|
791
|
+
"data-slot": "table",
|
|
792
|
+
"data-keyboard-model": "table",
|
|
793
|
+
className: cn(tableVariants({ density }), className),
|
|
794
|
+
style: tableStyle,
|
|
795
|
+
children: [
|
|
796
|
+
/* @__PURE__ */ jsx("thead", {
|
|
797
|
+
"data-slot": "table-header",
|
|
798
|
+
className: cnAll(tableHeaderVariants({ headerFill })),
|
|
799
|
+
children: /* @__PURE__ */ jsx("tr", { children: columns.map((column) => {
|
|
800
|
+
const sorted = activeSort?.column === column.id ? activeSort.direction : void 0;
|
|
801
|
+
return /* @__PURE__ */ jsx("th", {
|
|
802
|
+
scope: "col",
|
|
803
|
+
"data-slot": "table-column",
|
|
804
|
+
"data-sorted": sortedColumn === column.id || void 0,
|
|
805
|
+
"aria-sort": isSortable(column) ? sorted ?? "none" : void 0,
|
|
806
|
+
className: columnClass(column),
|
|
807
|
+
style: columnStyle(column),
|
|
808
|
+
children: isSortable(column) ? /* @__PURE__ */ jsx("button", {
|
|
809
|
+
type: "button",
|
|
810
|
+
"data-slot": "table-sort-button",
|
|
811
|
+
className: cnAll(tableSortButtonVariants()),
|
|
812
|
+
onClick: () => changeSort({
|
|
813
|
+
column: column.id,
|
|
814
|
+
direction: sorted === "ascending" ? "descending" : "ascending"
|
|
815
|
+
}),
|
|
816
|
+
children: headerLabel(column)
|
|
817
|
+
}) : headerLabel(column)
|
|
818
|
+
}, column.id);
|
|
819
|
+
}) })
|
|
820
|
+
}),
|
|
821
|
+
/* @__PURE__ */ jsx("tbody", {
|
|
822
|
+
"data-slot": "table-body",
|
|
823
|
+
children: shownRows.length === 0 && emptyState ? /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", {
|
|
824
|
+
colSpan: columns.length,
|
|
825
|
+
children: emptyState
|
|
826
|
+
}) }) : shownRows.map((shown, position) => {
|
|
827
|
+
const { row, depth, index } = shown;
|
|
828
|
+
const key = getRowId(row);
|
|
829
|
+
const isGroup = isGroupRow?.(row) ?? false;
|
|
830
|
+
const shownColumns = isGroup ? columns.slice(0, 1) : columns;
|
|
831
|
+
const labelId = `${idBase}-row-${String(position)}`;
|
|
832
|
+
return /* @__PURE__ */ jsx("tr", {
|
|
833
|
+
"data-slot": "table-row",
|
|
834
|
+
"data-flip": String(key),
|
|
835
|
+
"data-highlighted": isRowHighlighted?.(row) || void 0,
|
|
836
|
+
"data-depth": expandable ? depth : void 0,
|
|
837
|
+
"data-open": shown.isExpanded || void 0,
|
|
838
|
+
"data-group": isGroup || void 0,
|
|
839
|
+
className: rowClass(row, isGroup),
|
|
840
|
+
children: shownColumns.map((column) => {
|
|
841
|
+
const content = firstCellContent(column, cellContent(column, row, index), shown, labelId);
|
|
842
|
+
const cellProps = {
|
|
843
|
+
"data-slot": "table-cell",
|
|
844
|
+
"data-sorted": sortedColumn === column.id || void 0,
|
|
845
|
+
colSpan: isGroup ? columns.length : void 0,
|
|
846
|
+
style: depthStyle(column, depth)
|
|
847
|
+
};
|
|
848
|
+
return column === columns[0] ? /* @__PURE__ */ jsx("th", {
|
|
849
|
+
scope: "row",
|
|
850
|
+
...cellProps,
|
|
851
|
+
className: cnAll(cellClass(column, "body"), indentClass(column), "font-normal"),
|
|
852
|
+
children: content
|
|
853
|
+
}, column.id) : /* @__PURE__ */ jsx("td", {
|
|
854
|
+
...cellProps,
|
|
855
|
+
className: cellClass(column, "body"),
|
|
856
|
+
children: content
|
|
857
|
+
}, column.id);
|
|
858
|
+
})
|
|
859
|
+
}, String(key));
|
|
860
|
+
})
|
|
861
|
+
}),
|
|
862
|
+
totalRow ? /* @__PURE__ */ jsx("tfoot", {
|
|
863
|
+
"data-slot": "table-footer",
|
|
864
|
+
className: cnAll(tableFooterVariants()),
|
|
865
|
+
children: /* @__PURE__ */ jsx("tr", { children: columns.map((column) => /* @__PURE__ */ jsx("td", {
|
|
866
|
+
"data-slot": "table-cell",
|
|
867
|
+
className: cellClass(column, "bare"),
|
|
868
|
+
children: totalRow(column)
|
|
869
|
+
}, column.id)) })
|
|
870
|
+
}) : null
|
|
871
|
+
]
|
|
872
|
+
}) : /* @__PURE__ */ jsxs(Table, {
|
|
589
873
|
ref,
|
|
590
874
|
...props,
|
|
591
875
|
"data-slot": "table",
|
|
592
|
-
className: cn(tableVariants(), className),
|
|
876
|
+
className: cn(tableVariants({ density }), className),
|
|
593
877
|
style: tableStyle,
|
|
594
878
|
selectionMode: selectable ? "multiple" : void 0,
|
|
595
879
|
selectedKeys: selectable ? selection : void 0,
|
|
596
880
|
onSelectionChange: selectable ? commitSelection : void 0,
|
|
597
881
|
sortDescriptor: activeSort,
|
|
598
|
-
onSortChange:
|
|
599
|
-
|
|
600
|
-
setPage(1);
|
|
601
|
-
onSortChange?.(descriptor);
|
|
602
|
-
},
|
|
603
|
-
onRowAction: onRowAction ? (key) => {
|
|
882
|
+
onSortChange: changeSort,
|
|
883
|
+
onRowAction: rowAction ? (key) => {
|
|
604
884
|
const row = rowsByKey.get(key);
|
|
605
|
-
if (row !== void 0)
|
|
885
|
+
if (row !== void 0 && !isGroupRow?.(row)) rowAction(row);
|
|
606
886
|
} : void 0,
|
|
607
887
|
children: [
|
|
608
888
|
/* @__PURE__ */ jsxs(TableHeader, {
|
|
@@ -612,81 +892,84 @@ const Table$1 = forwardRef(function Table$2({ data, columns, getRowId, variant,
|
|
|
612
892
|
selectable ? /* @__PURE__ */ jsx(Column, {
|
|
613
893
|
id: SELECT_COLUMN_ID,
|
|
614
894
|
"data-slot": "table-column",
|
|
615
|
-
className: cnAll(tableColumnVariants({
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
895
|
+
className: cnAll(tableColumnVariants({
|
|
896
|
+
headerType,
|
|
897
|
+
density,
|
|
898
|
+
hidden: headerHidden
|
|
899
|
+
}), SELECT_CELL, stickyFirstColumn && stickyCell(headerPart), stickyFirstColumn && "border-e-0"),
|
|
900
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
901
|
+
className: headerHidden ? "sr-only group-data-[focus-visible]/column:not-sr-only" : void 0,
|
|
902
|
+
children: /* @__PURE__ */ jsx(Checkbox$1, {
|
|
903
|
+
slot: "selection",
|
|
904
|
+
"aria-label": selectionLabels?.selectAll
|
|
905
|
+
})
|
|
619
906
|
})
|
|
620
907
|
}) : null,
|
|
621
|
-
columns.map((column) => /* @__PURE__ */
|
|
908
|
+
columns.map((column) => /* @__PURE__ */ jsx(Column, {
|
|
622
909
|
id: column.id,
|
|
623
910
|
isRowHeader: column === columns[0],
|
|
624
|
-
allowsSorting: column
|
|
911
|
+
allowsSorting: isSortable(column),
|
|
625
912
|
"data-slot": "table-column",
|
|
626
913
|
"data-sorted": sortedColumn === column.id || void 0,
|
|
627
|
-
className:
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}), stickyFirstColumn && column === columns[0] && stickyCell(headerFill === "none" ? "bare" : "header"), stickyFirstColumn && selectable && column === columns[0] && "start-11"),
|
|
631
|
-
style: column.width === void 0 ? void 0 : { width: column.width },
|
|
632
|
-
children: [column.header, column.sortable ? /* @__PURE__ */ jsx(SortCaretGlyph, { direction: activeSort?.column === column.id ? activeSort.direction : "none" }) : null]
|
|
914
|
+
className: columnClass(column),
|
|
915
|
+
style: columnStyle(column),
|
|
916
|
+
children: headerLabel(column)
|
|
633
917
|
}, column.id)),
|
|
634
|
-
|
|
918
|
+
rowAction ? /* @__PURE__ */ jsx(Column, {
|
|
635
919
|
id: CHEVRON_COLUMN_ID,
|
|
636
920
|
"data-slot": "table-column",
|
|
637
|
-
className: cnAll(tableColumnVariants({
|
|
921
|
+
className: cnAll(tableColumnVariants({
|
|
922
|
+
headerType,
|
|
923
|
+
density,
|
|
924
|
+
hidden: headerHidden
|
|
925
|
+
}), CHEVRON_CELL),
|
|
638
926
|
children: ""
|
|
639
927
|
}) : null
|
|
640
928
|
]
|
|
641
929
|
}),
|
|
642
930
|
/* @__PURE__ */ jsx(TableBody, {
|
|
643
931
|
"data-slot": "table-body",
|
|
644
|
-
renderEmptyState:
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
932
|
+
renderEmptyState: emptyState === void 0 ? void 0 : () => emptyState,
|
|
933
|
+
children: shownRows.map((shown, position) => {
|
|
934
|
+
const { row, depth, index } = shown;
|
|
935
|
+
const key = getRowId(row);
|
|
936
|
+
const isGroup = isGroupRow?.(row) ?? false;
|
|
937
|
+
const shownColumns = isGroup ? columns.slice(0, 1) : columns;
|
|
938
|
+
const labelId = `${idBase}-row-${String(position)}`;
|
|
939
|
+
return /* @__PURE__ */ jsxs(Row, {
|
|
940
|
+
id: key,
|
|
941
|
+
"data-slot": "table-row",
|
|
942
|
+
"data-flip": String(key),
|
|
943
|
+
"data-highlighted": isRowHighlighted?.(row) || void 0,
|
|
944
|
+
"data-depth": expandable ? depth : void 0,
|
|
945
|
+
"data-open": shown.isExpanded || void 0,
|
|
946
|
+
"data-group": isGroup || void 0,
|
|
947
|
+
className: rowClass(row, isGroup),
|
|
948
|
+
children: [
|
|
949
|
+
selectable ? /* @__PURE__ */ jsx(Cell, {
|
|
950
|
+
"data-slot": "table-cell",
|
|
951
|
+
className: cnAll(tableCellVariants({ density }), SELECT_CELL, stickyFirstColumn && stickyCell("body"), stickyFirstColumn && "border-e-0"),
|
|
952
|
+
children: /* @__PURE__ */ jsx(Checkbox$1, {
|
|
953
|
+
slot: "selection",
|
|
954
|
+
"aria-label": selectionLabels?.selectRow
|
|
955
|
+
})
|
|
956
|
+
}) : null,
|
|
957
|
+
shownColumns.map((column) => /* @__PURE__ */ jsx(Cell, {
|
|
670
958
|
"data-slot": "table-cell",
|
|
671
959
|
"data-sorted": sortedColumn === column.id || void 0,
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
className: cnAll(tableCellVariants(), CHEVRON_CELL),
|
|
686
|
-
children: /* @__PURE__ */ jsx(RowChevronGlyph, {})
|
|
687
|
-
}) : null
|
|
688
|
-
]
|
|
689
|
-
}, String(getRowId(row))))
|
|
960
|
+
colSpan: isGroup ? columns.length + (rowAction ? 1 : 0) : void 0,
|
|
961
|
+
className: cnAll(cellClass(column, "body"), indentClass(column)),
|
|
962
|
+
style: depthStyle(column, depth),
|
|
963
|
+
children: firstCellContent(column, cellContent(column, row, index), shown, labelId)
|
|
964
|
+
}, column.id)),
|
|
965
|
+
rowAction && !isGroup ? /* @__PURE__ */ jsx(Cell, {
|
|
966
|
+
"data-slot": "table-cell",
|
|
967
|
+
className: cnAll(tableCellVariants({ density }), CHEVRON_CELL),
|
|
968
|
+
children: /* @__PURE__ */ jsx(RowChevronGlyph, {})
|
|
969
|
+
}) : null
|
|
970
|
+
]
|
|
971
|
+
}, String(key));
|
|
972
|
+
})
|
|
690
973
|
}),
|
|
691
974
|
totalRow ? /* @__PURE__ */ jsx(TableFooter, {
|
|
692
975
|
"data-slot": "table-footer",
|
|
@@ -696,20 +979,17 @@ const Table$1 = forwardRef(function Table$2({ data, columns, getRowId, variant,
|
|
|
696
979
|
children: [
|
|
697
980
|
selectable ? /* @__PURE__ */ jsx(Cell, {
|
|
698
981
|
"data-slot": "table-cell",
|
|
699
|
-
className: cnAll(tableCellVariants(), SELECT_CELL, stickyFirstColumn && stickyCell("bare"), stickyFirstColumn && "border-e-0"),
|
|
982
|
+
className: cnAll(tableCellVariants({ density }), SELECT_CELL, stickyFirstColumn && stickyCell("bare"), stickyFirstColumn && "border-e-0"),
|
|
700
983
|
children: ""
|
|
701
984
|
}) : null,
|
|
702
985
|
columns.map((col) => /* @__PURE__ */ jsx(Cell, {
|
|
703
986
|
"data-slot": "table-cell",
|
|
704
|
-
className:
|
|
705
|
-
align: col.align ?? (col.numeric ? "end" : void 0),
|
|
706
|
-
numeric: col.numeric
|
|
707
|
-
}), stickyFirstColumn && col === columns[0] && stickyCell("bare"), stickyFirstColumn && selectable && col === columns[0] && "start-11"),
|
|
987
|
+
className: cellClass(col, "bare"),
|
|
708
988
|
children: totalRow(col)
|
|
709
989
|
}, col.id)),
|
|
710
|
-
|
|
990
|
+
rowAction ? /* @__PURE__ */ jsx(Cell, {
|
|
711
991
|
"data-slot": "table-cell",
|
|
712
|
-
className: cnAll(tableCellVariants(), CHEVRON_CELL),
|
|
992
|
+
className: cnAll(tableCellVariants({ density }), CHEVRON_CELL),
|
|
713
993
|
children: ""
|
|
714
994
|
}) : null
|
|
715
995
|
]
|
|
@@ -785,6 +1065,6 @@ const Table$1 = forwardRef(function Table$2({ data, columns, getRowId, variant,
|
|
|
785
1065
|
});
|
|
786
1066
|
});
|
|
787
1067
|
//#endregion
|
|
788
|
-
export { Table$1 as Table, createColumns, tableCardVariants, tableCellVariants, tableColumnVariants, tableEmptyVariants, tableFooterVariants, tableHeaderVariants, tablePaginationVariants, tableRowVariants, tableScrollVariants, tableSelectionBarVariants, tableStickyCellVariants, tableVariants };
|
|
1068
|
+
export { Table$1 as Table, createColumns, tableCardVariants, tableCellVariants, tableColumnVariants, tableEmptyVariants, tableExpandButtonVariants, tableFooterVariants, tableGroupRowVariants, tableHeaderVariants, tablePaginationVariants, tableRowVariants, tableScrollVariants, tableSelectionBarVariants, tableSortButtonVariants, tableStickyCellVariants, tableVariants };
|
|
789
1069
|
|
|
790
1070
|
//# sourceMappingURL=table.js.map
|