@mirror-physics/fractal-ui 0.2.0-next.67 → 0.2.0-next.69
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/dist/index.cjs +10 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -258,8 +258,13 @@ interface SortableTableRowAction<T> {
|
|
|
258
258
|
interface SortableTableSelection<T> {
|
|
259
259
|
/** Returns whether a row is selected. Selection is controlled by the consumer. */
|
|
260
260
|
isSelected: (row: T) => boolean;
|
|
261
|
-
/** Called when an individual row
|
|
261
|
+
/** Called when an individual row changes selection. */
|
|
262
262
|
onSelectedChange: (row: T, selected: boolean) => void;
|
|
263
|
+
/**
|
|
264
|
+
* Handles the complete selectable row set in one update when the header
|
|
265
|
+
* checkbox changes. Falls back to `onSelectedChange` for each row when omitted.
|
|
266
|
+
*/
|
|
267
|
+
onSelectAllChange?: (rows: T[], selected: boolean) => void;
|
|
263
268
|
/** Accessible name for an individual row's checkbox. */
|
|
264
269
|
getRowLabel: (row: T) => string;
|
|
265
270
|
/** Accessible name for the header checkbox. */
|
package/dist/index.d.ts
CHANGED
|
@@ -258,8 +258,13 @@ interface SortableTableRowAction<T> {
|
|
|
258
258
|
interface SortableTableSelection<T> {
|
|
259
259
|
/** Returns whether a row is selected. Selection is controlled by the consumer. */
|
|
260
260
|
isSelected: (row: T) => boolean;
|
|
261
|
-
/** Called when an individual row
|
|
261
|
+
/** Called when an individual row changes selection. */
|
|
262
262
|
onSelectedChange: (row: T, selected: boolean) => void;
|
|
263
|
+
/**
|
|
264
|
+
* Handles the complete selectable row set in one update when the header
|
|
265
|
+
* checkbox changes. Falls back to `onSelectedChange` for each row when omitted.
|
|
266
|
+
*/
|
|
267
|
+
onSelectAllChange?: (rows: T[], selected: boolean) => void;
|
|
263
268
|
/** Accessible name for an individual row's checkbox. */
|
|
264
269
|
getRowLabel: (row: T) => string;
|
|
265
270
|
/** Accessible name for the header checkbox. */
|
package/dist/index.js
CHANGED
|
@@ -1420,10 +1420,11 @@ function SortableTable({
|
|
|
1420
1420
|
const startIndex = (page - 1) * pageSize;
|
|
1421
1421
|
return sorted.slice(startIndex, startIndex + pageSize);
|
|
1422
1422
|
}, [pagination, sorted]);
|
|
1423
|
-
const
|
|
1423
|
+
const selectedRows = selection ? sorted.filter(selection.isSelected) : [];
|
|
1424
|
+
const selectableRows = selection ? sorted.filter((row) => !isRowDisabled?.(row) && !isRowSelectionDisabled?.(row)) : [];
|
|
1424
1425
|
const selectedRowCount = selection ? selectableRows.filter(selection.isSelected).length : 0;
|
|
1425
1426
|
const allRowsSelected = selectableRows.length > 0 && selectedRowCount === selectableRows.length;
|
|
1426
|
-
const someRowsSelected =
|
|
1427
|
+
const someRowsSelected = selectedRows.length > 0 && !allRowsSelected;
|
|
1427
1428
|
const handleSortClick = (key) => {
|
|
1428
1429
|
let nextDirection;
|
|
1429
1430
|
if (!activeKey || !activeDirection) {
|
|
@@ -1460,10 +1461,15 @@ function SortableTable({
|
|
|
1460
1461
|
{
|
|
1461
1462
|
"aria-label": selection.selectAllLabel ?? "Select all rows",
|
|
1462
1463
|
checked: allRowsSelected,
|
|
1463
|
-
disabled: selectableRows.length === 0,
|
|
1464
|
+
disabled: selectableRows.length === 0 && selectedRows.length === 0,
|
|
1464
1465
|
indeterminate: someRowsSelected,
|
|
1465
1466
|
onCheckedChange: (checked) => {
|
|
1466
|
-
selectableRows
|
|
1467
|
+
const rows = checked ? selectableRows : selectedRows;
|
|
1468
|
+
if (selection.onSelectAllChange) {
|
|
1469
|
+
selection.onSelectAllChange(rows, checked);
|
|
1470
|
+
return;
|
|
1471
|
+
}
|
|
1472
|
+
rows.forEach((row) => {
|
|
1467
1473
|
if (selection.isSelected(row) !== checked) {
|
|
1468
1474
|
selection.onSelectedChange(row, checked);
|
|
1469
1475
|
}
|