@bwp-web/components 1.2.0 → 1.3.0

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.js CHANGED
@@ -909,7 +909,9 @@ import {
909
909
  DropdownChevronDownIcon,
910
910
  DropdownChevronUpIcon
911
911
  } from "@bwp-web/assets";
912
- import { flexRender } from "@tanstack/react-table";
912
+ import {
913
+ flexRender
914
+ } from "@tanstack/react-table";
913
915
  import React2, { useRef as useRef3 } from "react";
914
916
 
915
917
  // src/BiampTable/BiampTableEmptyState.tsx
@@ -1043,6 +1045,15 @@ function useLoadingDelay(loading, { delay = 150, minDuration = 500 } = {}) {
1043
1045
  return status === "loading" || status === "ending";
1044
1046
  }
1045
1047
 
1048
+ // src/BiampTable/slotProps.ts
1049
+ function resolveSlot(slot, ctx) {
1050
+ if (!slot) return void 0;
1051
+ return typeof slot === "function" ? slot(ctx) : slot;
1052
+ }
1053
+ function mergeSx(...inputs) {
1054
+ return inputs.filter((v) => Boolean(v)).flatMap((v) => Array.isArray(v) ? v : [v]);
1055
+ }
1056
+
1046
1057
  // src/BiampTable/BiampTable.tsx
1047
1058
  import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
1048
1059
  var overlaySx = {
@@ -1113,24 +1124,38 @@ function BiampTableRowInner({
1113
1124
  enableExpanding,
1114
1125
  selectChildrenWithParent,
1115
1126
  getRowLabel,
1116
- hasExpandableRows
1127
+ hasExpandableRows,
1128
+ rowSlotProps,
1129
+ cellSlotProps
1117
1130
  }) {
1118
1131
  const clickable = onRowClick ? isRowClickable ? isRowClickable(row.original) : true : false;
1132
+ const resolvedRow = resolveSlot(rowSlotProps, { row });
1133
+ const {
1134
+ sx: userRowSx,
1135
+ onClick: userRowOnClick,
1136
+ onKeyDown: userRowOnKeyDown,
1137
+ ...restRowProps
1138
+ } = resolvedRow ?? {};
1119
1139
  return /* @__PURE__ */ jsxs5(
1120
1140
  TableRow,
1121
1141
  {
1142
+ ...restRowProps,
1122
1143
  hover: clickable,
1123
1144
  selected: enableRowSelection ? isSelected : void 0,
1124
1145
  role: clickable ? "button" : void 0,
1125
1146
  tabIndex: clickable ? 0 : void 0,
1126
- sx: clickable ? rowCursorPointerSx : void 0,
1127
- onClick: clickable && onRowClick ? () => onRowClick(row.original) : void 0,
1147
+ sx: mergeSx(clickable && rowCursorPointerSx, userRowSx),
1148
+ onClick: clickable && onRowClick ? (e) => {
1149
+ onRowClick(row.original);
1150
+ userRowOnClick?.(e);
1151
+ } : userRowOnClick,
1128
1152
  onKeyDown: clickable && onRowClick ? (e) => {
1129
1153
  if (e.key === "Enter" || e.key === " ") {
1130
1154
  e.preventDefault();
1131
1155
  onRowClick(row.original);
1132
1156
  }
1133
- } : void 0,
1157
+ userRowOnKeyDown?.(e);
1158
+ } : userRowOnKeyDown,
1134
1159
  children: [
1135
1160
  enableRowSelection && /* @__PURE__ */ jsx8(TableCell, { padding: "checkbox", sx: selectionCellSx, children: /* @__PURE__ */ jsx8(
1136
1161
  Checkbox,
@@ -1156,14 +1181,18 @@ function BiampTableRowInner({
1156
1181
  cell.column.columnDef.cell,
1157
1182
  cell.getContext()
1158
1183
  );
1184
+ const resolvedCell = resolveSlot(cellSlotProps, { cell });
1185
+ const { sx: userCellSx, ...restCellProps } = resolvedCell ?? {};
1159
1186
  return /* @__PURE__ */ jsx8(
1160
1187
  TableCell,
1161
1188
  {
1189
+ ...restCellProps,
1162
1190
  "data-sticky": sticky || void 0,
1163
- sx: {
1164
- ...cellSx(sticky, cell.column.columnDef.meta?.minWidth, 2),
1165
- pl: isExpandCell ? "6px" : "12px"
1166
- },
1191
+ sx: mergeSx(
1192
+ cellSx(sticky, cell.column.columnDef.meta?.minWidth, 2),
1193
+ { pl: isExpandCell ? "6px" : "12px" },
1194
+ userCellSx
1195
+ ),
1167
1196
  children: (() => {
1168
1197
  if (sticky) return content;
1169
1198
  const truncate = cell.column.columnDef.meta?.truncate ?? true;
@@ -1219,7 +1248,7 @@ function BiampTableRowInner({
1219
1248
  );
1220
1249
  }
1221
1250
  function biampTableRowPropsAreEqual(prev, next) {
1222
- return prev.row.id === next.row.id && prev.row.original === next.row.original && prev.isSelected === next.isSelected && prev.isExpanded === next.isExpanded && prev.row.getVisibleCells().length === next.row.getVisibleCells().length && prev.enableRowSelection === next.enableRowSelection && prev.enableExpanding === next.enableExpanding && prev.hasExpandableRows === next.hasExpandableRows && prev.selectChildrenWithParent === next.selectChildrenWithParent && prev.onRowClick === next.onRowClick && prev.isRowClickable === next.isRowClickable && prev.getRowLabel === next.getRowLabel;
1251
+ return prev.row.id === next.row.id && prev.row.original === next.row.original && prev.isSelected === next.isSelected && prev.isExpanded === next.isExpanded && prev.row.getVisibleCells().length === next.row.getVisibleCells().length && prev.enableRowSelection === next.enableRowSelection && prev.enableExpanding === next.enableExpanding && prev.hasExpandableRows === next.hasExpandableRows && prev.selectChildrenWithParent === next.selectChildrenWithParent && prev.onRowClick === next.onRowClick && prev.isRowClickable === next.isRowClickable && prev.getRowLabel === next.getRowLabel && prev.rowSlotProps === next.rowSlotProps && prev.cellSlotProps === next.cellSlotProps;
1223
1252
  }
1224
1253
  var BiampTableRow = React2.memo(
1225
1254
  BiampTableRowInner,
@@ -1237,9 +1266,14 @@ function BiampTable({
1237
1266
  hideSelectAll,
1238
1267
  selectChildrenWithParent = false,
1239
1268
  getRowLabel,
1269
+ slotProps,
1240
1270
  sx,
1241
1271
  ...boxProps
1242
1272
  }) {
1273
+ const { sx: userTableSx, ...restTableSlotProps } = slotProps?.table ?? {};
1274
+ const { sx: userHeadSx, ...restHeadSlotProps } = slotProps?.head ?? {};
1275
+ const { sx: userBodySx, ...restBodySlotProps } = slotProps?.body ?? {};
1276
+ const { sx: userHeaderRowSx, ...restHeaderRowSlotProps } = slotProps?.headerRow ?? {};
1243
1277
  const tableMinWidth = table.getVisibleLeafColumns().reduce(
1244
1278
  (sum, col) => {
1245
1279
  const mw = col.columnDef.meta?.minWidth;
@@ -1271,73 +1305,98 @@ function BiampTable({
1271
1305
  MuiTable,
1272
1306
  {
1273
1307
  "aria-busy": showLoading || void 0,
1274
- sx: { minWidth: tableMinWidth, tableLayout: "auto" },
1308
+ ...restTableSlotProps,
1309
+ sx: mergeSx(
1310
+ { minWidth: tableMinWidth, tableLayout: "auto" },
1311
+ userTableSx
1312
+ ),
1275
1313
  children: [
1276
- /* @__PURE__ */ jsx8(TableHead, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsxs5(TableRow, { children: [
1277
- enableRowSelection && /* @__PURE__ */ jsx8(TableCell, { padding: "checkbox", sx: headerSelectionCellSx, children: !hideSelectAll && /* @__PURE__ */ jsx8(
1278
- Checkbox,
1279
- {
1280
- checked: table.getIsAllPageRowsSelected(),
1281
- indeterminate: table.getIsSomePageRowsSelected(),
1282
- onChange: table.getToggleAllPageRowsSelectedHandler(),
1283
- sx: rows.length === 0 ? checkboxHiddenHeaderSx : void 0,
1284
- slotProps: { input: { "aria-label": "Select all rows" } }
1285
- }
1286
- ) }),
1287
- headerGroup.headers.map((header) => {
1288
- const sticky = header.column.columnDef.meta?.sticky;
1289
- return /* @__PURE__ */ jsx8(
1290
- TableCell,
1291
- {
1292
- "data-sticky": sticky || void 0,
1293
- sortDirection: header.column.getIsSorted() || false,
1294
- ...header.column.getCanSort() && {
1295
- "aria-sort": header.column.getIsSorted() ? header.column.getIsSorted() === "asc" ? "ascending" : "descending" : "none"
1296
- },
1297
- sx: cellSx(
1298
- sticky,
1299
- header.column.columnDef.meta?.minWidth,
1300
- 3
1301
- ),
1302
- children: header.isPlaceholder ? null : header.column.getCanSort() ? /* @__PURE__ */ jsx8(
1303
- TableSortLabel,
1314
+ /* @__PURE__ */ jsx8(TableHead, { ...restHeadSlotProps, sx: mergeSx(userHeadSx), children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsxs5(
1315
+ TableRow,
1316
+ {
1317
+ ...restHeaderRowSlotProps,
1318
+ sx: mergeSx(userHeaderRowSx),
1319
+ children: [
1320
+ enableRowSelection && /* @__PURE__ */ jsx8(TableCell, { padding: "checkbox", sx: headerSelectionCellSx, children: !hideSelectAll && /* @__PURE__ */ jsx8(
1321
+ Checkbox,
1322
+ {
1323
+ checked: table.getIsAllPageRowsSelected(),
1324
+ indeterminate: table.getIsSomePageRowsSelected(),
1325
+ onChange: table.getToggleAllPageRowsSelectedHandler(),
1326
+ sx: rows.length === 0 ? checkboxHiddenHeaderSx : void 0,
1327
+ slotProps: { input: { "aria-label": "Select all rows" } }
1328
+ }
1329
+ ) }),
1330
+ headerGroup.headers.map((header) => {
1331
+ const sticky = header.column.columnDef.meta?.sticky;
1332
+ const resolvedHeaderCell = resolveSlot(slotProps?.headerCell, {
1333
+ header
1334
+ });
1335
+ const { sx: userHeaderCellSx, ...restHeaderCellProps } = resolvedHeaderCell ?? {};
1336
+ return /* @__PURE__ */ jsx8(
1337
+ TableCell,
1304
1338
  {
1305
- active: !!header.column.getIsSorted(),
1306
- direction: header.column.getIsSorted() || "asc",
1307
- onClick: header.column.getToggleSortingHandler(),
1308
- ...header.column.getIsSorted() && {
1309
- IconComponent: header.column.getIsSorted() === "asc" ? DropdownChevronUpIcon : DropdownChevronDownIcon
1339
+ ...restHeaderCellProps,
1340
+ "data-sticky": sticky || void 0,
1341
+ sortDirection: header.column.getIsSorted() || false,
1342
+ ...header.column.getCanSort() && {
1343
+ "aria-sort": header.column.getIsSorted() ? header.column.getIsSorted() === "asc" ? "ascending" : "descending" : "none"
1310
1344
  },
1311
- children: flexRender(
1345
+ sx: mergeSx(
1346
+ cellSx(sticky, header.column.columnDef.meta?.minWidth, 3),
1347
+ userHeaderCellSx
1348
+ ),
1349
+ children: header.isPlaceholder ? null : header.column.getCanSort() ? /* @__PURE__ */ jsx8(
1350
+ TableSortLabel,
1351
+ {
1352
+ active: !!header.column.getIsSorted(),
1353
+ direction: header.column.getIsSorted() || "asc",
1354
+ onClick: header.column.getToggleSortingHandler(),
1355
+ ...header.column.getIsSorted() && {
1356
+ IconComponent: header.column.getIsSorted() === "asc" ? DropdownChevronUpIcon : DropdownChevronDownIcon
1357
+ },
1358
+ children: flexRender(
1359
+ header.column.columnDef.header,
1360
+ header.getContext()
1361
+ )
1362
+ }
1363
+ ) : flexRender(
1312
1364
  header.column.columnDef.header,
1313
1365
  header.getContext()
1314
1366
  )
1315
- }
1316
- ) : flexRender(
1317
- header.column.columnDef.header,
1318
- header.getContext()
1319
- )
1320
- },
1321
- header.id
1322
- );
1323
- })
1324
- ] }, headerGroup.id)) }),
1325
- /* @__PURE__ */ jsx8(TableBody, { sx: { opacity: showLoading ? 0.3 : 1 }, children: !showError && rows.map((row) => /* @__PURE__ */ jsx8(
1326
- BiampTableRow,
1327
- {
1328
- row,
1329
- isExpanded: row.getIsExpanded(),
1330
- isSelected: row.getIsSelected(),
1331
- onRowClick,
1332
- isRowClickable,
1333
- enableRowSelection,
1334
- enableExpanding,
1335
- selectChildrenWithParent,
1336
- getRowLabel,
1337
- hasExpandableRows
1367
+ },
1368
+ header.id
1369
+ );
1370
+ })
1371
+ ]
1338
1372
  },
1339
- row.id
1340
- )) })
1373
+ headerGroup.id
1374
+ )) }),
1375
+ /* @__PURE__ */ jsx8(
1376
+ TableBody,
1377
+ {
1378
+ ...restBodySlotProps,
1379
+ sx: mergeSx({ opacity: showLoading ? 0.3 : 1 }, userBodySx),
1380
+ children: !showError && rows.map((row) => /* @__PURE__ */ jsx8(
1381
+ BiampTableRow,
1382
+ {
1383
+ row,
1384
+ isExpanded: row.getIsExpanded(),
1385
+ isSelected: row.getIsSelected(),
1386
+ onRowClick,
1387
+ isRowClickable,
1388
+ enableRowSelection,
1389
+ enableExpanding,
1390
+ selectChildrenWithParent,
1391
+ getRowLabel,
1392
+ hasExpandableRows,
1393
+ rowSlotProps: slotProps?.row,
1394
+ cellSlotProps: slotProps?.cell
1395
+ },
1396
+ row.id
1397
+ ))
1398
+ }
1399
+ )
1341
1400
  ]
1342
1401
  }
1343
1402
  ),