@bwp-web/components 1.2.0 → 1.3.1

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,42 +1124,71 @@ function BiampTableRowInner({
1113
1124
  enableExpanding,
1114
1125
  selectChildrenWithParent,
1115
1126
  getRowLabel,
1116
- hasExpandableRows
1127
+ hasExpandableRows,
1128
+ customColor,
1129
+ rowSlotProps,
1130
+ cellSlotProps
1117
1131
  }) {
1118
1132
  const clickable = onRowClick ? isRowClickable ? isRowClickable(row.original) : true : false;
1133
+ const resolvedRow = resolveSlot(rowSlotProps, { row });
1134
+ const {
1135
+ sx: userRowSx,
1136
+ onClick: userRowOnClick,
1137
+ onKeyDown: userRowOnKeyDown,
1138
+ ...restRowProps
1139
+ } = resolvedRow ?? {};
1119
1140
  return /* @__PURE__ */ jsxs5(
1120
1141
  TableRow,
1121
1142
  {
1143
+ ...restRowProps,
1122
1144
  hover: clickable,
1123
1145
  selected: enableRowSelection ? isSelected : void 0,
1124
1146
  role: clickable ? "button" : void 0,
1125
1147
  tabIndex: clickable ? 0 : void 0,
1126
- sx: clickable ? rowCursorPointerSx : void 0,
1127
- onClick: clickable && onRowClick ? () => onRowClick(row.original) : void 0,
1148
+ sx: mergeSx(
1149
+ clickable && rowCursorPointerSx,
1150
+ customColor ? { backgroundColor: customColor } : void 0,
1151
+ userRowSx
1152
+ ),
1153
+ onClick: clickable && onRowClick ? (e) => {
1154
+ onRowClick(row.original);
1155
+ userRowOnClick?.(e);
1156
+ } : userRowOnClick,
1128
1157
  onKeyDown: clickable && onRowClick ? (e) => {
1129
1158
  if (e.key === "Enter" || e.key === " ") {
1130
1159
  e.preventDefault();
1131
1160
  onRowClick(row.original);
1132
1161
  }
1133
- } : void 0,
1162
+ userRowOnKeyDown?.(e);
1163
+ } : userRowOnKeyDown,
1134
1164
  children: [
1135
- enableRowSelection && /* @__PURE__ */ jsx8(TableCell, { padding: "checkbox", sx: selectionCellSx, children: /* @__PURE__ */ jsx8(
1136
- Checkbox,
1165
+ enableRowSelection && /* @__PURE__ */ jsx8(
1166
+ TableCell,
1137
1167
  {
1138
- checked: isSelected,
1139
- disabled: !row.getCanSelect(),
1140
- onChange: (e) => row.toggleSelected(e.target.checked, {
1141
- selectChildren: selectChildrenWithParent
1142
- }),
1143
- onClick: (e) => e.stopPropagation(),
1144
- sx: !row.getCanSelect() ? checkboxHiddenSx : void 0,
1145
- slotProps: {
1146
- input: {
1147
- "aria-label": getRowLabel ? `Select ${getRowLabel(row.original)}` : `Select row ${row.index + 1}`
1168
+ padding: "checkbox",
1169
+ sx: mergeSx(
1170
+ selectionCellSx,
1171
+ customColor ? { backgroundColor: customColor } : void 0
1172
+ ),
1173
+ children: /* @__PURE__ */ jsx8(
1174
+ Checkbox,
1175
+ {
1176
+ checked: isSelected,
1177
+ disabled: !row.getCanSelect(),
1178
+ onChange: (e) => row.toggleSelected(e.target.checked, {
1179
+ selectChildren: selectChildrenWithParent
1180
+ }),
1181
+ onClick: (e) => e.stopPropagation(),
1182
+ sx: !row.getCanSelect() ? checkboxHiddenSx : void 0,
1183
+ slotProps: {
1184
+ input: {
1185
+ "aria-label": getRowLabel ? `Select ${getRowLabel(row.original)}` : `Select row ${row.index + 1}`
1186
+ }
1187
+ }
1148
1188
  }
1149
- }
1189
+ )
1150
1190
  }
1151
- ) }),
1191
+ ),
1152
1192
  row.getVisibleCells().map((cell, cellIndex, cells) => {
1153
1193
  const sticky = cell.column.columnDef.meta?.sticky;
1154
1194
  const isExpandCell = enableExpanding && !sticky && cellIndex === cells.findIndex((c) => !c.column.columnDef.meta?.sticky);
@@ -1156,14 +1196,19 @@ function BiampTableRowInner({
1156
1196
  cell.column.columnDef.cell,
1157
1197
  cell.getContext()
1158
1198
  );
1199
+ const resolvedCell = resolveSlot(cellSlotProps, { cell });
1200
+ const { sx: userCellSx, ...restCellProps } = resolvedCell ?? {};
1159
1201
  return /* @__PURE__ */ jsx8(
1160
1202
  TableCell,
1161
1203
  {
1204
+ ...restCellProps,
1162
1205
  "data-sticky": sticky || void 0,
1163
- sx: {
1164
- ...cellSx(sticky, cell.column.columnDef.meta?.minWidth, 2),
1165
- pl: isExpandCell ? "6px" : "12px"
1166
- },
1206
+ sx: mergeSx(
1207
+ cellSx(sticky, cell.column.columnDef.meta?.minWidth, 2),
1208
+ { pl: isExpandCell ? "6px" : "12px" },
1209
+ sticky && customColor ? { backgroundColor: customColor } : void 0,
1210
+ userCellSx
1211
+ ),
1167
1212
  children: (() => {
1168
1213
  if (sticky) return content;
1169
1214
  const truncate = cell.column.columnDef.meta?.truncate ?? true;
@@ -1219,7 +1264,7 @@ function BiampTableRowInner({
1219
1264
  );
1220
1265
  }
1221
1266
  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;
1267
+ 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.customColor === next.customColor && prev.rowSlotProps === next.rowSlotProps && prev.cellSlotProps === next.cellSlotProps;
1223
1268
  }
1224
1269
  var BiampTableRow = React2.memo(
1225
1270
  BiampTableRowInner,
@@ -1237,9 +1282,15 @@ function BiampTable({
1237
1282
  hideSelectAll,
1238
1283
  selectChildrenWithParent = false,
1239
1284
  getRowLabel,
1285
+ setRowColor,
1286
+ slotProps,
1240
1287
  sx,
1241
1288
  ...boxProps
1242
1289
  }) {
1290
+ const { sx: userTableSx, ...restTableSlotProps } = slotProps?.table ?? {};
1291
+ const { sx: userHeadSx, ...restHeadSlotProps } = slotProps?.head ?? {};
1292
+ const { sx: userBodySx, ...restBodySlotProps } = slotProps?.body ?? {};
1293
+ const { sx: userHeaderRowSx, ...restHeaderRowSlotProps } = slotProps?.headerRow ?? {};
1243
1294
  const tableMinWidth = table.getVisibleLeafColumns().reduce(
1244
1295
  (sum, col) => {
1245
1296
  const mw = col.columnDef.meta?.minWidth;
@@ -1271,73 +1322,99 @@ function BiampTable({
1271
1322
  MuiTable,
1272
1323
  {
1273
1324
  "aria-busy": showLoading || void 0,
1274
- sx: { minWidth: tableMinWidth, tableLayout: "auto" },
1325
+ ...restTableSlotProps,
1326
+ sx: mergeSx(
1327
+ { minWidth: tableMinWidth, tableLayout: "auto" },
1328
+ userTableSx
1329
+ ),
1275
1330
  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,
1331
+ /* @__PURE__ */ jsx8(TableHead, { ...restHeadSlotProps, sx: mergeSx(userHeadSx), children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsxs5(
1332
+ TableRow,
1333
+ {
1334
+ ...restHeaderRowSlotProps,
1335
+ sx: mergeSx(userHeaderRowSx),
1336
+ children: [
1337
+ enableRowSelection && /* @__PURE__ */ jsx8(TableCell, { padding: "checkbox", sx: headerSelectionCellSx, children: !hideSelectAll && /* @__PURE__ */ jsx8(
1338
+ Checkbox,
1339
+ {
1340
+ checked: table.getIsAllPageRowsSelected(),
1341
+ indeterminate: table.getIsSomePageRowsSelected(),
1342
+ onChange: table.getToggleAllPageRowsSelectedHandler(),
1343
+ sx: rows.length === 0 ? checkboxHiddenHeaderSx : void 0,
1344
+ slotProps: { input: { "aria-label": "Select all rows" } }
1345
+ }
1346
+ ) }),
1347
+ headerGroup.headers.map((header) => {
1348
+ const sticky = header.column.columnDef.meta?.sticky;
1349
+ const resolvedHeaderCell = resolveSlot(slotProps?.headerCell, {
1350
+ header
1351
+ });
1352
+ const { sx: userHeaderCellSx, ...restHeaderCellProps } = resolvedHeaderCell ?? {};
1353
+ return /* @__PURE__ */ jsx8(
1354
+ TableCell,
1304
1355
  {
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
1356
+ ...restHeaderCellProps,
1357
+ "data-sticky": sticky || void 0,
1358
+ sortDirection: header.column.getIsSorted() || false,
1359
+ ...header.column.getCanSort() && {
1360
+ "aria-sort": header.column.getIsSorted() ? header.column.getIsSorted() === "asc" ? "ascending" : "descending" : "none"
1310
1361
  },
1311
- children: flexRender(
1362
+ sx: mergeSx(
1363
+ cellSx(sticky, header.column.columnDef.meta?.minWidth, 3),
1364
+ userHeaderCellSx
1365
+ ),
1366
+ children: header.isPlaceholder ? null : header.column.getCanSort() ? /* @__PURE__ */ jsx8(
1367
+ TableSortLabel,
1368
+ {
1369
+ active: !!header.column.getIsSorted(),
1370
+ direction: header.column.getIsSorted() || "asc",
1371
+ onClick: header.column.getToggleSortingHandler(),
1372
+ ...header.column.getIsSorted() && {
1373
+ IconComponent: header.column.getIsSorted() === "asc" ? DropdownChevronUpIcon : DropdownChevronDownIcon
1374
+ },
1375
+ children: flexRender(
1376
+ header.column.columnDef.header,
1377
+ header.getContext()
1378
+ )
1379
+ }
1380
+ ) : flexRender(
1312
1381
  header.column.columnDef.header,
1313
1382
  header.getContext()
1314
1383
  )
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
1384
+ },
1385
+ header.id
1386
+ );
1387
+ })
1388
+ ]
1338
1389
  },
1339
- row.id
1340
- )) })
1390
+ headerGroup.id
1391
+ )) }),
1392
+ /* @__PURE__ */ jsx8(
1393
+ TableBody,
1394
+ {
1395
+ ...restBodySlotProps,
1396
+ sx: mergeSx({ opacity: showLoading ? 0.3 : 1 }, userBodySx),
1397
+ children: !showError && rows.map((row) => /* @__PURE__ */ jsx8(
1398
+ BiampTableRow,
1399
+ {
1400
+ row,
1401
+ isExpanded: row.getIsExpanded(),
1402
+ isSelected: row.getIsSelected(),
1403
+ onRowClick,
1404
+ isRowClickable,
1405
+ enableRowSelection,
1406
+ enableExpanding,
1407
+ selectChildrenWithParent,
1408
+ getRowLabel,
1409
+ hasExpandableRows,
1410
+ customColor: setRowColor?.(row.original),
1411
+ rowSlotProps: slotProps?.row,
1412
+ cellSlotProps: slotProps?.cell
1413
+ },
1414
+ row.id
1415
+ ))
1416
+ }
1417
+ )
1341
1418
  ]
1342
1419
  }
1343
1420
  ),