@ctlyst.id/internal-ui 5.0.4 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +59 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -31
- 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;
|
@@ -260,11 +260,14 @@ interface DataTableProps<T> {
|
|
260
260
|
disabledRow?: (row: T) => boolean;
|
261
261
|
highlightedRow?: (row: T) => boolean;
|
262
262
|
highlightRowColor?: BackgroundProps['bg'];
|
263
|
+
/** paddingRowX in px */
|
264
|
+
paddingRowX?: number;
|
263
265
|
}
|
264
266
|
declare const isCellDisabled: (row: DisabledRowData, cellId: string) => boolean;
|
265
267
|
type DataTableRefs<T> = Pick<RowSelectionInstance<T>, 'toggleAllRowsSelected'>;
|
266
268
|
declare const useDataTable: <T>({ columns, dataSource, withSelectedRow, onSelectedRow, onSort, sortDescFirst, sortingState, manualSorting, selectedRow, disabledRow, onRowSelectionChange, columnPinning, }: DataTableProps<T>) => {
|
267
269
|
table: _tanstack_react_table.Table<T>;
|
270
|
+
action: React$1.MutableRefObject<string>;
|
268
271
|
toggleAllRowsSelected: (value?: boolean | undefined) => void;
|
269
272
|
generateColumn: () => ColumnDef<T>[];
|
270
273
|
};
|
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;
|
@@ -260,11 +260,14 @@ interface DataTableProps<T> {
|
|
260
260
|
disabledRow?: (row: T) => boolean;
|
261
261
|
highlightedRow?: (row: T) => boolean;
|
262
262
|
highlightRowColor?: BackgroundProps['bg'];
|
263
|
+
/** paddingRowX in px */
|
264
|
+
paddingRowX?: number;
|
263
265
|
}
|
264
266
|
declare const isCellDisabled: (row: DisabledRowData, cellId: string) => boolean;
|
265
267
|
type DataTableRefs<T> = Pick<RowSelectionInstance<T>, 'toggleAllRowsSelected'>;
|
266
268
|
declare const useDataTable: <T>({ columns, dataSource, withSelectedRow, onSelectedRow, onSort, sortDescFirst, sortingState, manualSorting, selectedRow, disabledRow, onRowSelectionChange, columnPinning, }: DataTableProps<T>) => {
|
267
269
|
table: _tanstack_react_table.Table<T>;
|
270
|
+
action: React$1.MutableRefObject<string>;
|
268
271
|
toggleAllRowsSelected: (value?: boolean | undefined) => void;
|
269
272
|
generateColumn: () => ColumnDef<T>[];
|
270
273
|
};
|
package/dist/index.js
CHANGED
@@ -1355,23 +1355,23 @@ var isCellDisabled = (row, cellId) => {
|
|
1355
1355
|
}
|
1356
1356
|
return false;
|
1357
1357
|
};
|
1358
|
-
var getCommonPinningStyles = (column) => {
|
1358
|
+
var getCommonPinningStyles = (column, paddingRowX) => {
|
1359
1359
|
const isPinned = column.getIsPinned();
|
1360
1360
|
const isFirstLeftPinnedColumn = isPinned === "left" && column.getIsFirstColumn("left");
|
1361
1361
|
const isLastLeftPinnedColumn = isPinned === "left" && column.getIsLastColumn("left");
|
1362
1362
|
const isFirstRightPinnedColumn = isPinned === "right" && column.getIsFirstColumn("right");
|
1363
1363
|
const isLastRightPinnedColumn = isPinned === "right" && column.getIsLastColumn("right");
|
1364
1364
|
return {
|
1365
|
-
left: isPinned === "left" ? `${column.getStart("left") + (!isFirstLeftPinnedColumn ?
|
1366
|
-
right: isPinned === "right" ? `${column.getAfter("right") + (!isLastRightPinnedColumn ?
|
1365
|
+
left: isPinned === "left" ? `${column.getStart("left") + (!isFirstLeftPinnedColumn ? paddingRowX : 0)}px` : void 0,
|
1366
|
+
right: isPinned === "right" ? `${column.getAfter("right") + (!isLastRightPinnedColumn ? paddingRowX : 0)}px` : void 0,
|
1367
1367
|
position: isPinned ? "sticky" : "relative",
|
1368
1368
|
zIndex: isPinned ? 1 : 0,
|
1369
1369
|
...isFirstLeftPinnedColumn ? {
|
1370
|
-
pl:
|
1371
|
-
} : {
|
1370
|
+
pl: `${paddingRowX + 8}px`
|
1371
|
+
} : {},
|
1372
1372
|
...isLastRightPinnedColumn ? {
|
1373
|
-
pr:
|
1374
|
-
} : {
|
1373
|
+
pr: `${paddingRowX + 8}px`
|
1374
|
+
} : {},
|
1375
1375
|
...isLastLeftPinnedColumn ? {
|
1376
1376
|
py: "16px",
|
1377
1377
|
pr: "8px",
|
@@ -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,9 +1439,10 @@ 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
1447
|
table2.toggleAllRowsSelected();
|
1446
1448
|
} else if (disabledRow) {
|
@@ -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,12 +1522,13 @@ var useDataTable = ({
|
|
1519
1522
|
}, []);
|
1520
1523
|
return {
|
1521
1524
|
table,
|
1525
|
+
action,
|
1522
1526
|
toggleAllRowsSelected,
|
1523
1527
|
generateColumn
|
1524
1528
|
};
|
1525
1529
|
};
|
1526
1530
|
var DataTable = React5.forwardRef((props, ref) => {
|
1527
|
-
var _a, _b, _c, _d, _e
|
1531
|
+
var _a, _b, _c, _d, _e;
|
1528
1532
|
const {
|
1529
1533
|
isLoading,
|
1530
1534
|
styles,
|
@@ -1536,10 +1540,11 @@ var DataTable = React5.forwardRef((props, ref) => {
|
|
1536
1540
|
highlightedRow,
|
1537
1541
|
withSelectedRow,
|
1538
1542
|
highlightRowColor,
|
1539
|
-
cellLineClamp = 2
|
1543
|
+
cellLineClamp = 2,
|
1544
|
+
paddingRowX = 8
|
1540
1545
|
} = props;
|
1541
1546
|
const { clickOrDragged, getDragOrClickProps } = useDragOrClick();
|
1542
|
-
const { table, toggleAllRowsSelected, generateColumn } = useDataTable(props);
|
1547
|
+
const { table, action, toggleAllRowsSelected, generateColumn } = useDataTable(props);
|
1543
1548
|
const refTable = React5.useRef(null);
|
1544
1549
|
React5.useImperativeHandle(ref, () => ({
|
1545
1550
|
toggleAllRowsSelected
|
@@ -1583,18 +1588,28 @@ var DataTable = React5.forwardRef((props, ref) => {
|
|
1583
1588
|
};
|
1584
1589
|
}, []);
|
1585
1590
|
const hasScroll = ((_a = refTable == null ? void 0 : refTable.current) == null ? void 0 : _a.offsetWidth) && ((_b = refTable == null ? void 0 : refTable.current) == null ? void 0 : _b.scrollWidth) && ((_c = refTable == null ? void 0 : refTable.current) == null ? void 0 : _c.offsetWidth) < ((_d = refTable == null ? void 0 : refTable.current) == null ? void 0 : _d.scrollWidth);
|
1591
|
+
const getTableHeaderSize = (header, index, totalColumn) => {
|
1592
|
+
if (header.column.getIsFirstColumn("left") || header.column.getIsLastColumn("right")) {
|
1593
|
+
return { width: `${header.getSize() + paddingRowX}px` };
|
1594
|
+
}
|
1595
|
+
if (index === 0) {
|
1596
|
+
return { width: `${header.getSize() + paddingRowX}px`, paddingLeft: `${8 + paddingRowX}` };
|
1597
|
+
}
|
1598
|
+
if (index === totalColumn - 1) {
|
1599
|
+
return { width: `${header.getSize() + paddingRowX}px`, paddingRight: `${8 + paddingRowX}` };
|
1600
|
+
}
|
1601
|
+
return { width: `${header.getSize()}px` };
|
1602
|
+
};
|
1586
1603
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
1587
1604
|
import_react29.Box,
|
1588
1605
|
{
|
1589
1606
|
overflowX: "auto",
|
1590
1607
|
overflowY: "hidden",
|
1591
1608
|
position: "relative",
|
1592
|
-
pl: ((_e = columnPinning == null ? void 0 : columnPinning.left) == null ? void 0 : _e.length) ? 0 : 2,
|
1593
|
-
pr: ((_f = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _f.length) ? 0 : 2,
|
1594
1609
|
maxW: "100%",
|
1595
1610
|
w: "full",
|
1596
1611
|
ref: refTable,
|
1597
|
-
...((
|
1612
|
+
...((_e = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _e.length) && hasScroll ? { "data-pin-right": true } : {},
|
1598
1613
|
...container,
|
1599
1614
|
children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_react29.Table, { ...styles == null ? void 0 : styles.table, "data-loading": "true", children: [
|
1600
1615
|
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react29.Thead, { ...(styles == null ? void 0 : styles.tableHead, headerSticky ? { position: "sticky", top: 0, bg: "white", zIndex: 1 } : {}), children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react29.Tr, { mx: "2", ...styles == null ? void 0 : styles.tableRow, children: headerGroup.headers.map((header, index) => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
@@ -1632,8 +1647,10 @@ var DataTable = React5.forwardRef((props, ref) => {
|
|
1632
1647
|
import_react29.Th,
|
1633
1648
|
{
|
1634
1649
|
colSpan: header.colSpan,
|
1635
|
-
|
1636
|
-
|
1650
|
+
_first: { paddingLeft: `${paddingRowX + 8}px` },
|
1651
|
+
_last: { paddingRight: `${paddingRowX + 8}px` },
|
1652
|
+
sx: getCommonPinningStyles(header.column, paddingRowX),
|
1653
|
+
...getTableHeaderSize(header, index, headerGroup.headers.length),
|
1637
1654
|
...styles == null ? void 0 : styles.tableColumnHeader,
|
1638
1655
|
children: /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
|
1639
1656
|
import_react29.Flex,
|
@@ -1669,7 +1686,7 @@ var DataTable = React5.forwardRef((props, ref) => {
|
|
1669
1686
|
}) }, headerGroup.id))
|
1670
1687
|
}
|
1671
1688
|
),
|
1672
|
-
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react29.Tbody, { ...styles == null ? void 0 : styles.tableBody, children: table.getRowModel().rows.map((row) => {
|
1689
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react29.Tbody, { ...styles == null ? void 0 : styles.tableBody, children: table.getRowModel().rows.map((row, index) => {
|
1673
1690
|
const isDisabledRow = disabledRow && disabledRow(row.original);
|
1674
1691
|
const isHighlightedRow = highlightedRow && highlightedRow(row.original);
|
1675
1692
|
return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
@@ -1700,6 +1717,7 @@ var DataTable = React5.forwardRef((props, ref) => {
|
|
1700
1717
|
(_a2 = e.currentTarget) == null ? void 0 : _a2.removeAttribute("data-active");
|
1701
1718
|
},
|
1702
1719
|
onClick: () => {
|
1720
|
+
action.current = "selectRow";
|
1703
1721
|
if (withSelectedRow) row.toggleSelected();
|
1704
1722
|
if (onRowClick) {
|
1705
1723
|
if (isDisabledRow) return;
|
@@ -1717,8 +1735,10 @@ var DataTable = React5.forwardRef((props, ref) => {
|
|
1717
1735
|
{
|
1718
1736
|
"data-test-id": `CT_Component_TableCell_${cell.id}`,
|
1719
1737
|
fontSize: "text.sm",
|
1738
|
+
_first: { paddingLeft: `${paddingRowX + 8}px` },
|
1739
|
+
_last: { paddingRight: `${paddingRowX + 8}px` },
|
1720
1740
|
sx: {
|
1721
|
-
...getCommonPinningStyles(cell.column)
|
1741
|
+
...getCommonPinningStyles(cell.column, paddingRowX)
|
1722
1742
|
},
|
1723
1743
|
...styles == null ? void 0 : styles.tableCell,
|
1724
1744
|
children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
@@ -1730,14 +1750,22 @@ var DataTable = React5.forwardRef((props, ref) => {
|
|
1730
1750
|
align: "center",
|
1731
1751
|
"data-test-id": `CT_Component_TableCell_Content-${cell.id}`,
|
1732
1752
|
opacity: isDisabled ? 0.5 : 1,
|
1733
|
-
...cellLineClamp > 0 ? {
|
1734
|
-
noOfLines: cellLineClamp,
|
1735
|
-
sx: {
|
1736
|
-
display: "-webkit-inline-box"
|
1737
|
-
}
|
1738
|
-
} : {},
|
1739
1753
|
sx: { ...meta && meta.columnStyles ? meta.columnStyles : {} },
|
1740
|
-
children: (0,
|
1754
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
|
1755
|
+
import_react29.Box,
|
1756
|
+
{
|
1757
|
+
onMouseUp: (e) => {
|
1758
|
+
e.stopPropagation();
|
1759
|
+
},
|
1760
|
+
...cellLineClamp > 0 ? {
|
1761
|
+
noOfLines: cellLineClamp,
|
1762
|
+
sx: {
|
1763
|
+
display: "-webkit-inline-box"
|
1764
|
+
}
|
1765
|
+
} : {},
|
1766
|
+
children: (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext())
|
1767
|
+
}
|
1768
|
+
)
|
1741
1769
|
}
|
1742
1770
|
)
|
1743
1771
|
},
|