@equinor/apollo-components 1.7.1 → 1.8.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.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { IconData } from '@equinor/eds-icons';
2
2
  import * as react from 'react';
3
- import { ReactNode, ComponentProps } from 'react';
3
+ import { ReactNode, ReactElement, ComponentProps } from 'react';
4
4
  import { Cell, CellContext, Table, Row, ColumnDef, RowSelectionState, SortingState, HeaderContext } from '@tanstack/react-table';
5
5
  import { ColumnDef as ColumnDef$1 } from '@tanstack/table-core';
6
6
  import * as styled_components from 'styled-components';
@@ -47,7 +47,18 @@ interface FilterConfig {
47
47
  filterFromLeafRows?: boolean;
48
48
  filterActions?: <T>(table: Table<T>) => ReactNode;
49
49
  }
50
+ interface TableRowWrapper<T> {
51
+ (props: TableRowWrapperProps<T>): ReactElement;
52
+ }
53
+ interface TableRowWrapperProps<T> {
54
+ row: Row<T>;
55
+ children: ReactNode;
56
+ }
50
57
  interface RowConfig<T> {
58
+ /**
59
+ * ! Unstable - Row Wrapper has not been tested for compatibility with virtualization. Use with caution.
60
+ */
61
+ rowWrapper?: TableRowWrapper<T>;
51
62
  getRowBackground?: (row: Row<T>) => string | undefined;
52
63
  onClick?: (row: Row<T>) => void;
53
64
  onMouseEnter?: (row: Row<T>) => void;
@@ -55,6 +66,7 @@ interface RowConfig<T> {
55
66
  }
56
67
  interface CellConfig<T> {
57
68
  getStickyCellColor?: (cell: Cell<T, unknown>) => string;
69
+ getShouldHighlight?: (cell: Cell<T, unknown>) => boolean;
58
70
  }
59
71
  declare type RowSelectionMode = 'single' | 'multiple';
60
72
  declare type DataTableConfig<T> = {
@@ -83,7 +95,7 @@ interface DataTableProps<T> {
83
95
  filters?: FilterConfig;
84
96
  header?: HeaderConfig;
85
97
  }
86
- declare function DataTable$1<T>({ columns, data, isLoading, header, filters, config, rowConfig, }: DataTableProps<T>): JSX.Element;
98
+ declare function DataTable$1<T>({ columns, data, isLoading, header, filters, config, cellConfig, rowConfig, }: DataTableProps<T>): JSX.Element;
87
99
 
88
100
  declare type DataTableProviderProps = ComponentProps<typeof Provider>;
89
101
  declare function DataTableProvider({ children, ...props }: DataTableProviderProps): JSX.Element;
@@ -140,4 +152,4 @@ declare type TypographyProps = {
140
152
  */
141
153
  declare const TypographyCustom: (props: TypographyProps) => JSX.Element;
142
154
 
143
- export { AppShell, AppSidebar, CellConfig, ChipsCell, ColumnSelect, DataTable, DataTableConfig, DynamicCell, FilterConfig, HeaderConfig, HierarchyCell, RowConfig, RowSelectionMode, SelectColumnDef, StickyCell, TableHeader, TypographyCustom, capitalizeHeader, globalFilterAtom, prependSelectColumn, rowSelectionAtom, tableSortingAtom };
155
+ export { AppShell, AppSidebar, CellConfig, ChipsCell, ColumnSelect, DataTable, DataTableConfig, DynamicCell, FilterConfig, HeaderConfig, HierarchyCell, RowConfig, RowSelectionMode, SelectColumnDef, StickyCell, TableHeader, TableRowWrapper, TableRowWrapperProps, TypographyCustom, capitalizeHeader, globalFilterAtom, prependSelectColumn, rowSelectionAtom, tableSortingAtom };
package/dist/index.js CHANGED
@@ -539,20 +539,30 @@ function TableHeader({ table, sticky }) {
539
539
  var import_eds_core_react10 = require("@equinor/eds-core-react");
540
540
  var import_jsx_runtime11 = require("react/jsx-runtime");
541
541
  function TableRow({ row, rowConfig, cellConfig }) {
542
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_eds_core_react10.Table.Row, {
542
+ var _a;
543
+ const rowWrapper = rowConfig == null ? void 0 : rowConfig.rowWrapper;
544
+ const tableRowContent = /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_eds_core_react10.Table.Row, {
543
545
  active: row.getIsSelected(),
544
- style: { cursor: (rowConfig == null ? void 0 : rowConfig.onClick) ? "pointer" : "initial" },
546
+ style: {
547
+ cursor: (rowConfig == null ? void 0 : rowConfig.onClick) ? "pointer" : "initial",
548
+ backgroundColor: (_a = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _a.call(rowConfig, row)
549
+ },
545
550
  onClick: () => {
546
- var _a;
547
- return (_a = rowConfig == null ? void 0 : rowConfig.onClick) == null ? void 0 : _a.call(rowConfig, row);
551
+ var _a2;
552
+ return (_a2 = rowConfig == null ? void 0 : rowConfig.onClick) == null ? void 0 : _a2.call(rowConfig, row);
548
553
  },
549
554
  onMouseEnter: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseEnter),
550
555
  onMouseLeave: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseLeave),
551
- children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(DynamicCell, {
552
- cell,
553
- getStickyCellColor: cellConfig == null ? void 0 : cellConfig.getStickyCellColor
554
- }, cell.id))
556
+ children: row.getVisibleCells().map((cell) => {
557
+ var _a2;
558
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(DynamicCell, {
559
+ cell,
560
+ getStickyCellColor: cellConfig == null ? void 0 : cellConfig.getStickyCellColor,
561
+ highlight: (_a2 = cellConfig == null ? void 0 : cellConfig.getShouldHighlight) == null ? void 0 : _a2.call(cellConfig, cell)
562
+ }, cell.id);
563
+ })
555
564
  });
565
+ return rowWrapper ? rowWrapper({ row, children: tableRowContent }) : tableRowContent;
556
566
  }
557
567
  function handleRowEvent(row, handler) {
558
568
  if (!handler)
@@ -914,6 +924,7 @@ function DataTable({
914
924
  header,
915
925
  filters,
916
926
  config,
927
+ cellConfig,
917
928
  rowConfig
918
929
  }) {
919
930
  const [columnVisibility, setColumnVisibility] = (0, import_jotai3.useAtom)(columnVisibilityAtom);
@@ -982,11 +993,13 @@ function DataTable({
982
993
  containerRef: tableContainerRef,
983
994
  table,
984
995
  rowConfig,
996
+ cellConfig,
985
997
  isLoading,
986
998
  stickyHeader: header == null ? void 0 : header.stickyHeader
987
999
  }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(BasicTable, {
988
1000
  table,
989
1001
  rowConfig,
1002
+ cellConfig,
990
1003
  isLoading,
991
1004
  stickyHeader: header == null ? void 0 : header.stickyHeader
992
1005
  })
package/dist/index.mjs CHANGED
@@ -500,20 +500,30 @@ function TableHeader({ table, sticky }) {
500
500
  import { Table as Table6 } from "@equinor/eds-core-react";
501
501
  import { jsx as jsx11 } from "react/jsx-runtime";
502
502
  function TableRow({ row, rowConfig, cellConfig }) {
503
- return /* @__PURE__ */ jsx11(Table6.Row, {
503
+ var _a;
504
+ const rowWrapper = rowConfig == null ? void 0 : rowConfig.rowWrapper;
505
+ const tableRowContent = /* @__PURE__ */ jsx11(Table6.Row, {
504
506
  active: row.getIsSelected(),
505
- style: { cursor: (rowConfig == null ? void 0 : rowConfig.onClick) ? "pointer" : "initial" },
507
+ style: {
508
+ cursor: (rowConfig == null ? void 0 : rowConfig.onClick) ? "pointer" : "initial",
509
+ backgroundColor: (_a = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _a.call(rowConfig, row)
510
+ },
506
511
  onClick: () => {
507
- var _a;
508
- return (_a = rowConfig == null ? void 0 : rowConfig.onClick) == null ? void 0 : _a.call(rowConfig, row);
512
+ var _a2;
513
+ return (_a2 = rowConfig == null ? void 0 : rowConfig.onClick) == null ? void 0 : _a2.call(rowConfig, row);
509
514
  },
510
515
  onMouseEnter: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseEnter),
511
516
  onMouseLeave: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseLeave),
512
- children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx11(DynamicCell, {
513
- cell,
514
- getStickyCellColor: cellConfig == null ? void 0 : cellConfig.getStickyCellColor
515
- }, cell.id))
517
+ children: row.getVisibleCells().map((cell) => {
518
+ var _a2;
519
+ return /* @__PURE__ */ jsx11(DynamicCell, {
520
+ cell,
521
+ getStickyCellColor: cellConfig == null ? void 0 : cellConfig.getStickyCellColor,
522
+ highlight: (_a2 = cellConfig == null ? void 0 : cellConfig.getShouldHighlight) == null ? void 0 : _a2.call(cellConfig, cell)
523
+ }, cell.id);
524
+ })
516
525
  });
526
+ return rowWrapper ? rowWrapper({ row, children: tableRowContent }) : tableRowContent;
517
527
  }
518
528
  function handleRowEvent(row, handler) {
519
529
  if (!handler)
@@ -875,6 +885,7 @@ function DataTable({
875
885
  header,
876
886
  filters,
877
887
  config,
888
+ cellConfig,
878
889
  rowConfig
879
890
  }) {
880
891
  const [columnVisibility, setColumnVisibility] = useAtom2(columnVisibilityAtom);
@@ -943,11 +954,13 @@ function DataTable({
943
954
  containerRef: tableContainerRef,
944
955
  table,
945
956
  rowConfig,
957
+ cellConfig,
946
958
  isLoading,
947
959
  stickyHeader: header == null ? void 0 : header.stickyHeader
948
960
  }) : /* @__PURE__ */ jsx18(BasicTable, {
949
961
  table,
950
962
  rowConfig,
963
+ cellConfig,
951
964
  isLoading,
952
965
  stickyHeader: header == null ? void 0 : header.stickyHeader
953
966
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/apollo-components",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",