@ceed/ads 0.0.67 → 0.0.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.
@@ -11,6 +11,7 @@ type Column<T extends Record<string, V>, V = unknown> = {
11
11
  renderCell?: (params: {
12
12
  row: T;
13
13
  value?: V;
14
+ id: string;
14
15
  }) => ReactNode;
15
16
  };
16
17
  type DataTableProps<T extends Record<string, unknown>> = {
@@ -43,6 +44,12 @@ type DataTableProps<T extends Record<string, unknown>> = {
43
44
  */
44
45
  rowCount?: number;
45
46
  loading?: boolean;
47
+ getId?: (row: T) => string;
48
+ /**
49
+ * 기본적으로 Uncontrolled로 작동하지만, Controlled로 작동하게 하고 싶을 때 사용한다.
50
+ * 이 값이 true이면, 현재 페이지 이외에도 존재하는 모든 데이터가 선택된것으로 간주하고 동작한다.
51
+ */
52
+ isTotalSelected?: boolean;
46
53
  slots?: {
47
54
  checkbox?: React.ElementType;
48
55
  toolbar?: React.ElementType;
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  declare const Modal: import("framer-motion").CustomDomComponent<Pick<import("@mui/base").ModalOwnProps, "children" | "container" | "open" | "disablePortal" | "keepMounted" | "disableAutoFocus" | "disableEnforceFocus" | "disableRestoreFocus" | "disableEscapeKeyDown" | "disableScrollLock" | "hideBackdrop"> & {
3
- onClose?: ((event: {}, reason: "backdropClick" | "escapeKeyDown" | "closeClick") => void) | undefined;
3
+ onClose?: ((event: {}, reason: "escapeKeyDown" | "backdropClick" | "closeClick") => void) | undefined;
4
4
  sx?: import("@mui/joy/styles/types").SxProps | undefined;
5
5
  } & import("@mui/joy").ModalSlotsAndSlotProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
6
6
  ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
package/dist/index.js CHANGED
@@ -1312,10 +1312,16 @@ function useDataTableRenderer({
1312
1312
  paginationModel,
1313
1313
  onPaginationModelChange,
1314
1314
  selectionModel = [],
1315
- onSelectionModelChange
1315
+ onSelectionModelChange,
1316
+ getId: _getId,
1317
+ isTotalSelected: _isTotalSelected
1316
1318
  }) {
1317
1319
  const [page, setPage] = useState4(paginationModel?.page || 1);
1318
1320
  const pageSize = paginationModel?.pageSize || 20;
1321
+ const getId = useCallback3(
1322
+ (row, index) => _getId?.(row) ?? row?.id ?? `${(index || 0) + (page - 1) * pageSize}`,
1323
+ [_getId ?? page, pageSize]
1324
+ );
1319
1325
  const selectedModelSet = useMemo3(
1320
1326
  () => new Set(selectionModel),
1321
1327
  [selectionModel]
@@ -1325,15 +1331,13 @@ function useDataTableRenderer({
1325
1331
  [rows, page, pageSize, paginationMode]
1326
1332
  );
1327
1333
  const isAllSelected = useMemo3(
1328
- () => dataInPage.length > 0 && dataInPage.every(
1329
- (_, i) => selectedModelSet.has(`${i + (page - 1) * pageSize}`)
1330
- ),
1331
- [dataInPage, selectedModelSet, page, pageSize]
1334
+ () => dataInPage.length > 0 && dataInPage.every((row, i) => selectedModelSet.has(getId(row, i))),
1335
+ [dataInPage, selectedModelSet, page, pageSize, getId]
1332
1336
  );
1333
1337
  const rowCount = totalRowsProp || rows.length;
1334
1338
  const isTotalSelected = useMemo3(
1335
- () => rowCount > 0 && selectionModel.length === rowCount,
1336
- [selectionModel, rowCount]
1339
+ () => _isTotalSelected ?? (rowCount > 0 && selectionModel.length === rowCount),
1340
+ [_isTotalSelected, selectionModel, rowCount]
1337
1341
  );
1338
1342
  const handlePageChange = useCallback3(
1339
1343
  (newPage) => {
@@ -1358,6 +1362,7 @@ function useDataTableRenderer({
1358
1362
  page,
1359
1363
  pageSize,
1360
1364
  onPaginationModelChange: handlePageChange,
1365
+ getId,
1361
1366
  HeadCell,
1362
1367
  dataInPage,
1363
1368
  isAllSelected,
@@ -1368,9 +1373,7 @@ function useDataTableRenderer({
1368
1373
  [selectedModelSet]
1369
1374
  ),
1370
1375
  onAllCheckboxChange: useCallback3(() => {
1371
- onSelectionModelChange?.(
1372
- isAllSelected ? [] : dataInPage.map((_, i) => `${i + (page - 1) * pageSize}`)
1373
- );
1376
+ onSelectionModelChange?.(isAllSelected ? [] : dataInPage.map(getId));
1374
1377
  }, [isAllSelected, dataInPage, onSelectionModelChange]),
1375
1378
  onCheckboxChange: useCallback3(
1376
1379
  (event, selectedModel) => {
@@ -1395,8 +1398,8 @@ function useDataTableRenderer({
1395
1398
  ),
1396
1399
  onTotalSelect: useCallback3(() => {
1397
1400
  onSelectionModelChange?.(
1398
- isTotalSelected ? [] : rows.map((_, i) => `${i}`),
1399
- isTotalSelected
1401
+ isTotalSelected ? [] : rows.map(getId),
1402
+ !isTotalSelected
1400
1403
  );
1401
1404
  }, [isTotalSelected, rows, onSelectionModelChange])
1402
1405
  };
@@ -1436,6 +1439,7 @@ function DataTable(props) {
1436
1439
  isSelectedRow,
1437
1440
  onAllCheckboxChange,
1438
1441
  onCheckboxChange,
1442
+ getId,
1439
1443
  rowCount,
1440
1444
  page,
1441
1445
  pageSize,
@@ -1515,7 +1519,7 @@ function DataTable(props) {
1515
1519
  },
1516
1520
  /* @__PURE__ */ React12.createElement(LoadingOverlay, null)
1517
1521
  ))), /* @__PURE__ */ React12.createElement(OverlayWrapper, null), dataInPage.map((row, rowIndex) => {
1518
- const rowId = `${rowIndex + (page - 1) * pageSize}`;
1522
+ const rowId = getId(row, rowIndex);
1519
1523
  return /* @__PURE__ */ React12.createElement(
1520
1524
  "tr",
1521
1525
  {
@@ -1550,14 +1554,18 @@ function DataTable(props) {
1550
1554
  textAlign: column.type === "number" ? "end" : "start"
1551
1555
  }
1552
1556
  },
1553
- column.renderCell?.({ row, value: row[column.field] }) ?? row[column.field]
1557
+ column.renderCell?.({
1558
+ row,
1559
+ value: row[column.field],
1560
+ id: rowId
1561
+ }) ?? row[column.field]
1554
1562
  ))
1555
1563
  );
1556
1564
  })), Footer && /* @__PURE__ */ React12.createElement(Footer, null))
1557
1565
  ), /* @__PURE__ */ React12.createElement(
1558
1566
  TablePagination,
1559
1567
  {
1560
- paginationModel: { page, pageSize },
1568
+ paginationModel: useMemo3(() => ({ page, pageSize }), [page, pageSize]),
1561
1569
  rowCount,
1562
1570
  onPageChange: onPaginationModelChange
1563
1571
  }