@ctlyst.id/internal-ui 5.0.3 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +15 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -248,7 +248,7 @@ interface DataTableProps<T> {
|
|
248
248
|
withSelectedRow?: boolean | undefined;
|
249
249
|
selectedRow?: RowSelectionState;
|
250
250
|
onRowSelectionChange?: OnChangeFn<RowSelectionState>;
|
251
|
-
onSelectedRow?: (data: T[]) => void;
|
251
|
+
onSelectedRow?: (data: T[], action: string) => void;
|
252
252
|
onSort?: (data: SortingState) => void;
|
253
253
|
manualSorting?: boolean;
|
254
254
|
sortingState?: SortingState;
|
@@ -265,6 +265,7 @@ declare const isCellDisabled: (row: DisabledRowData, cellId: string) => boolean;
|
|
265
265
|
type DataTableRefs<T> = Pick<RowSelectionInstance<T>, 'toggleAllRowsSelected'>;
|
266
266
|
declare const useDataTable: <T>({ columns, dataSource, withSelectedRow, onSelectedRow, onSort, sortDescFirst, sortingState, manualSorting, selectedRow, disabledRow, onRowSelectionChange, columnPinning, }: DataTableProps<T>) => {
|
267
267
|
table: _tanstack_react_table.Table<T>;
|
268
|
+
action: React$1.MutableRefObject<string>;
|
268
269
|
toggleAllRowsSelected: (value?: boolean | undefined) => void;
|
269
270
|
generateColumn: () => ColumnDef<T>[];
|
270
271
|
};
|
package/dist/index.d.ts
CHANGED
@@ -248,7 +248,7 @@ interface DataTableProps<T> {
|
|
248
248
|
withSelectedRow?: boolean | undefined;
|
249
249
|
selectedRow?: RowSelectionState;
|
250
250
|
onRowSelectionChange?: OnChangeFn<RowSelectionState>;
|
251
|
-
onSelectedRow?: (data: T[]) => void;
|
251
|
+
onSelectedRow?: (data: T[], action: string) => void;
|
252
252
|
onSort?: (data: SortingState) => void;
|
253
253
|
manualSorting?: boolean;
|
254
254
|
sortingState?: SortingState;
|
@@ -265,6 +265,7 @@ declare const isCellDisabled: (row: DisabledRowData, cellId: string) => boolean;
|
|
265
265
|
type DataTableRefs<T> = Pick<RowSelectionInstance<T>, 'toggleAllRowsSelected'>;
|
266
266
|
declare const useDataTable: <T>({ columns, dataSource, withSelectedRow, onSelectedRow, onSort, sortDescFirst, sortingState, manualSorting, selectedRow, disabledRow, onRowSelectionChange, columnPinning, }: DataTableProps<T>) => {
|
267
267
|
table: _tanstack_react_table.Table<T>;
|
268
|
+
action: React$1.MutableRefObject<string>;
|
268
269
|
toggleAllRowsSelected: (value?: boolean | undefined) => void;
|
269
270
|
generateColumn: () => ColumnDef<T>[];
|
270
271
|
};
|
package/dist/index.js
CHANGED
@@ -1427,6 +1427,7 @@ var useDataTable = ({
|
|
1427
1427
|
const [isFirstLoad, setIsFirstLoad] = React5.useState(true);
|
1428
1428
|
const [sorting, setSorting] = React5.useState(sortingState != null ? sortingState : []);
|
1429
1429
|
const dataColumns = React5.useMemo(() => columns, [columns]);
|
1430
|
+
const action = React5.useRef("");
|
1430
1431
|
const checkboxColumn = React5.useMemo(
|
1431
1432
|
() => [
|
1432
1433
|
{
|
@@ -1438,11 +1439,12 @@ var useDataTable = ({
|
|
1438
1439
|
"data-test-id": "select-header-data-table",
|
1439
1440
|
...{
|
1440
1441
|
isDisabled: table2.getPaginationRowModel().rows.filter((row) => !(disabledRow == null ? void 0 : disabledRow(row.original))).length === 0,
|
1441
|
-
isChecked: table2.
|
1442
|
-
isIndeterminate: table2.
|
1442
|
+
isChecked: table2.getIsAllPageRowsSelected(),
|
1443
|
+
isIndeterminate: table2.getIsSomePageRowsSelected(),
|
1443
1444
|
onChange: () => {
|
1445
|
+
action.current = "selectAll";
|
1444
1446
|
if (table2.getIsAllRowsSelected()) {
|
1445
|
-
table2.
|
1447
|
+
table2.toggleAllRowsSelected();
|
1446
1448
|
} else if (disabledRow) {
|
1447
1449
|
const prevSelected = table2.getFilteredSelectedRowModel().rows.length;
|
1448
1450
|
const rows = table2.getPaginationRowModel().rows.filter((row) => !disabledRow(row.original));
|
@@ -1452,7 +1454,7 @@ var useDataTable = ({
|
|
1452
1454
|
table2.setRowSelection(Object.fromEntries(rows.map((row) => [row.id, true])));
|
1453
1455
|
}
|
1454
1456
|
} else {
|
1455
|
-
table2.
|
1457
|
+
table2.toggleAllRowsSelected();
|
1456
1458
|
}
|
1457
1459
|
}
|
1458
1460
|
}
|
@@ -1470,7 +1472,7 @@ var useDataTable = ({
|
|
1470
1472
|
) })
|
1471
1473
|
}
|
1472
1474
|
],
|
1473
|
-
[]
|
1475
|
+
[dataSource]
|
1474
1476
|
);
|
1475
1477
|
const generateColumn = () => {
|
1476
1478
|
if (withSelectedRow) {
|
@@ -1500,15 +1502,16 @@ var useDataTable = ({
|
|
1500
1502
|
});
|
1501
1503
|
const { getSelectedRowModel, toggleAllRowsSelected } = table;
|
1502
1504
|
const { flatRows } = getSelectedRowModel();
|
1503
|
-
React5.useEffect(() => {
|
1504
|
-
table.setRowSelection(selectedRow != null ? selectedRow : {});
|
1505
|
-
}, [selectedRow]);
|
1506
1505
|
React5.useEffect(() => {
|
1507
1506
|
const rowData = flatRows.map((row) => row.original);
|
1508
1507
|
if (onSelectedRow) {
|
1509
|
-
onSelectedRow(rowData);
|
1508
|
+
onSelectedRow(rowData, action.current);
|
1510
1509
|
}
|
1511
1510
|
}, [flatRows]);
|
1511
|
+
React5.useEffect(() => {
|
1512
|
+
action.current = "newData";
|
1513
|
+
table.setRowSelection(selectedRow != null ? selectedRow : {});
|
1514
|
+
}, [selectedRow]);
|
1512
1515
|
React5.useEffect(() => {
|
1513
1516
|
if (onSort && !isFirstLoad) {
|
1514
1517
|
onSort(sorting);
|
@@ -1519,6 +1522,7 @@ var useDataTable = ({
|
|
1519
1522
|
}, []);
|
1520
1523
|
return {
|
1521
1524
|
table,
|
1525
|
+
action,
|
1522
1526
|
toggleAllRowsSelected,
|
1523
1527
|
generateColumn
|
1524
1528
|
};
|
@@ -1539,7 +1543,7 @@ var DataTable = React5.forwardRef((props, ref) => {
|
|
1539
1543
|
cellLineClamp = 2
|
1540
1544
|
} = props;
|
1541
1545
|
const { clickOrDragged, getDragOrClickProps } = useDragOrClick();
|
1542
|
-
const { table, toggleAllRowsSelected, generateColumn } = useDataTable(props);
|
1546
|
+
const { table, action, toggleAllRowsSelected, generateColumn } = useDataTable(props);
|
1543
1547
|
const refTable = React5.useRef(null);
|
1544
1548
|
React5.useImperativeHandle(ref, () => ({
|
1545
1549
|
toggleAllRowsSelected
|
@@ -1700,6 +1704,7 @@ var DataTable = React5.forwardRef((props, ref) => {
|
|
1700
1704
|
(_a2 = e.currentTarget) == null ? void 0 : _a2.removeAttribute("data-active");
|
1701
1705
|
},
|
1702
1706
|
onClick: () => {
|
1707
|
+
action.current = "selectRow";
|
1703
1708
|
if (withSelectedRow) row.toggleSelected();
|
1704
1709
|
if (onRowClick) {
|
1705
1710
|
if (isDisabledRow) return;
|