@equinor/apollo-components 3.5.2 → 3.6.0-beta.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.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { IconData } from '@equinor/eds-icons';
2
2
  import * as react from 'react';
3
3
  import { ReactNode, ReactElement, HTMLProps, MutableRefObject, Dispatch, SetStateAction, SyntheticEvent } from 'react';
4
- import { CellContext, Cell, Header, Table, Row, SortingState, OnChangeFn, ColumnDef, ColumnResizeMode, RowSelectionState, ExpandedState, ColumnPinningState, VisibilityState, HeaderContext, Column } from '@tanstack/react-table';
4
+ import { CellContext, Table, Row, SortingState, OnChangeFn, Cell, ColumnDef, ColumnResizeMode, RowSelectionState, ExpandedState, ColumnPinningState, VisibilityState, HeaderContext, Column, Header } from '@tanstack/react-table';
5
5
  export { Cell, CellContext, ColumnDef, ColumnPinningState, ColumnResizeMode, ColumnSort, ExpandedState, HeaderContext, OnChangeFn, Row, RowSelectionState, SortingState, Table, VisibilityState, createColumnHelper } from '@tanstack/react-table';
6
6
  import * as styled_components from 'styled-components';
7
7
  import * as _equinor_eds_core_react from '@equinor/eds-core-react';
@@ -27,38 +27,6 @@ declare const ChipsCell: (props: {
27
27
  values?: string[];
28
28
  }) => JSX.Element;
29
29
 
30
- type TableCellProps<T> = {
31
- cell: Cell<T, unknown>;
32
- highlight?: boolean;
33
- getStickyCellColor?: (cell: Cell<T, unknown>) => string;
34
- };
35
- type StyledStickyCellProps = {
36
- highlight?: boolean;
37
- backgroundColor?: string;
38
- };
39
- declare const StyledStickyCell: styled_components.StyledComponent<react.ForwardRefExoticComponent<_equinor_eds_core_react.CellProps & react.RefAttributes<HTMLTableCellElement>>, any, ({} & _equinor_eds_core_react.CellProps) & StyledStickyCellProps, never>;
40
- declare function DynamicCell<T>({ cell, highlight, getStickyCellColor }: TableCellProps<T>): JSX.Element;
41
-
42
- interface HeaderCellProps<TData, TValue> {
43
- header: Header<TData, TValue>;
44
- /** Needed for column resizing */
45
- table: Table<TData>;
46
- }
47
- declare const HeaderCell: <TData, TValue>({ header, table }: HeaderCellProps<TData, TValue>) => JSX.Element;
48
-
49
- type HierarchyCellOptions = {
50
- getRowDepth?: () => number;
51
- getDisplayName?: () => string;
52
- };
53
- declare function HierarchyCell<T>(cell: CellContext<T, any>, options?: HierarchyCellOptions): JSX.Element;
54
-
55
- interface PopoverCellProps {
56
- id: string;
57
- value: string;
58
- title?: string | JSX.Element | ReactNode;
59
- }
60
- declare function PopoverCell(props: PopoverCellProps): JSX.Element;
61
-
62
30
  interface ColumnSelectProps<T> {
63
31
  table: Table<T>;
64
32
  }
@@ -86,6 +54,10 @@ interface RowConfig<T> {
86
54
  onClick?: (row: Row<T>) => void;
87
55
  onMouseEnter?: (row: Row<T>) => void;
88
56
  onMouseLeave?: (row: Row<T>) => void;
57
+ /**
58
+ * Whatever is returned from this function will be added as a data-id attribute on the tr in the dom.
59
+ */
60
+ getDataIdAttribute?: (row: Row<T>) => string | undefined;
89
61
  }
90
62
  type TruncateMode = 'wrap' | 'hover';
91
63
  type SortConfig = {
@@ -104,6 +76,13 @@ interface CellConfig<T> {
104
76
  * ***Note**: This only applies to default cells. Custom cells need custom implementation.*
105
77
  */
106
78
  truncateMode?: TruncateMode | ((cell: Cell<T, unknown>) => TruncateMode);
79
+ /**
80
+ * Manually set the cell background color. Prioritized over highlight color.
81
+ *
82
+ * @param cell
83
+ * @returns color in hex, rgb or rgba, undefined to use default
84
+ */
85
+ getCellColor?: (cell: Cell<T, unknown>) => string | undefined;
107
86
  }
108
87
  type RowSelectionMode = 'single' | 'multiple';
109
88
  type TableLayout = 'auto' | 'fixed';
@@ -218,6 +197,36 @@ declare function prependSelectColumn<T>(columns: ColumnDef<T>[], config?: DataTa
218
197
  /** Useful in cases where you either have a value, function or undefined. */
219
198
  declare function getFunctionValueOrDefault<T extends boolean | string | number, P>(valueOrFn: ((props: P) => T) | T | undefined, fnProps: P, defaultValue: T): T;
220
199
 
200
+ type TableCellProps<T> = {
201
+ cell: Cell<T, unknown>;
202
+ cellConfig?: CellConfig<T>;
203
+ };
204
+ type StyledStickyCellProps = {
205
+ backgroundColor?: string;
206
+ };
207
+ declare const StyledStickyCell: styled_components.StyledComponent<react.ForwardRefExoticComponent<_equinor_eds_core_react.CellProps & react.RefAttributes<HTMLTableCellElement>>, any, ({} & _equinor_eds_core_react.CellProps) & StyledStickyCellProps, never>;
208
+ declare function DynamicCell<T>({ cell, cellConfig }: TableCellProps<T>): JSX.Element;
209
+
210
+ interface HeaderCellProps<TData, TValue> {
211
+ header: Header<TData, TValue>;
212
+ /** Needed for column resizing */
213
+ table: Table<TData>;
214
+ }
215
+ declare const HeaderCell: <TData, TValue>({ header, table }: HeaderCellProps<TData, TValue>) => JSX.Element;
216
+
217
+ type HierarchyCellOptions = {
218
+ getRowDepth?: () => number;
219
+ getDisplayName?: () => string;
220
+ };
221
+ declare function HierarchyCell<T>(cell: CellContext<T, any>, options?: HierarchyCellOptions): JSX.Element;
222
+
223
+ interface PopoverCellProps {
224
+ id: string;
225
+ value: string;
226
+ title?: string | JSX.Element | ReactNode;
227
+ }
228
+ declare function PopoverCell(props: PopoverCellProps): JSX.Element;
229
+
221
230
  declare function SelectColumnDef<T>(props: SetRequired<DataTableProps<T>, 'rowSelection'>['rowSelection']): ColumnDef$1<T, any>;
222
231
 
223
232
  declare const leftCellShadow: styled_components.FlattenSimpleInterpolation;
package/dist/index.js CHANGED
@@ -2603,15 +2603,17 @@ var StickyHeaderCell = (0, import_styled_components4.default)(StickyCell)`
2603
2603
  // src/cells/DynamicCell.tsx
2604
2604
  var import_jsx_runtime5 = require("react/jsx-runtime");
2605
2605
  var StyledStickyCell = (0, import_styled_components5.default)(StickyCell)`
2606
- background-color: ${({ backgroundColor: bg }) => bg ? `${bg} !important` : `inherit`};
2606
+ background-color: ${({ backgroundColor }) => backgroundColor ? `${backgroundColor} !important` : `inherit`};
2607
2607
  `;
2608
2608
  var StyledCell = (0, import_styled_components5.default)(import_eds_core_react5.Table.Cell)`
2609
- background-color: ${({ backgroundColor: bg }) => bg ? `${bg} !important` : `inherit`};
2609
+ background-color: ${({ backgroundColor }) => backgroundColor ? `${backgroundColor} !important` : `inherit`};
2610
2610
  `;
2611
- function DynamicCell({ cell, highlight, getStickyCellColor }) {
2612
- var _a, _b;
2611
+ function DynamicCell({ cell, cellConfig }) {
2612
+ var _a, _b, _c, _d, _e;
2613
2613
  const cellContent = (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext());
2614
2614
  const columnPinningDirection = cell.column.getIsPinned();
2615
+ const stickyCellColor = (_a = cellConfig == null ? void 0 : cellConfig.getStickyCellColor) == null ? void 0 : _a.call(cellConfig, cell);
2616
+ const regularCellColor = (_d = (_b = cellConfig == null ? void 0 : cellConfig.getCellColor) == null ? void 0 : _b.call(cellConfig, cell)) != null ? _d : ((_c = cellConfig == null ? void 0 : cellConfig.getShouldHighlight) == null ? void 0 : _c.call(cellConfig, cell)) ? "#d5eaf4" : void 0;
2615
2617
  if (columnPinningDirection) {
2616
2618
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2617
2619
  import_eds_core_react5.Table.Cell,
@@ -2620,7 +2622,7 @@ function DynamicCell({ cell, highlight, getStickyCellColor }) {
2620
2622
  style: __spreadValues({
2621
2623
  position: "sticky",
2622
2624
  top: 0,
2623
- backgroundColor: (_a = getStickyCellColor == null ? void 0 : getStickyCellColor(cell)) != null ? _a : "inherit",
2625
+ backgroundColor: stickyCellColor != null ? stickyCellColor : "inherit",
2624
2626
  zIndex: 5,
2625
2627
  backgroundClip: "padding-box",
2626
2628
  display: "table-cell"
@@ -2635,10 +2637,10 @@ function DynamicCell({ cell, highlight, getStickyCellColor }) {
2635
2637
  }
2636
2638
  );
2637
2639
  }
2638
- if ((_b = cell.column.columnDef.meta) == null ? void 0 : _b.sticky) {
2639
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(StyledStickyCell, { backgroundColor: getStickyCellColor == null ? void 0 : getStickyCellColor(cell), "data-column": cell.column.id, children: cellContent });
2640
+ if ((_e = cell.column.columnDef.meta) == null ? void 0 : _e.sticky) {
2641
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(StyledStickyCell, { backgroundColor: stickyCellColor, "data-column": cell.column.id, children: cellContent });
2640
2642
  }
2641
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(StyledCell, { "data-column": cell.column.id, backgroundColor: highlight ? "#d5eaf4" : void 0, children: cellContent });
2643
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(StyledCell, { "data-column": cell.column.id, backgroundColor: regularCellColor, children: cellContent });
2642
2644
  }
2643
2645
 
2644
2646
  // src/cells/HeaderCell.tsx
@@ -3124,17 +3126,19 @@ function TableRow({
3124
3126
  measureElement,
3125
3127
  index
3126
3128
  }) {
3127
- var _a;
3129
+ var _a, _b;
3128
3130
  const rowWrapper = rowConfig == null ? void 0 : rowConfig.rowWrapper;
3131
+ const dataIdValue = (_a = rowConfig == null ? void 0 : rowConfig.getDataIdAttribute) == null ? void 0 : _a.call(rowConfig, row);
3129
3132
  const tableRowContent = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3130
3133
  StyledTableRow,
3131
3134
  {
3132
3135
  active: row.getIsSelected(),
3133
3136
  "data-index": index,
3137
+ "data-id": dataIdValue,
3134
3138
  ref: measureElement,
3135
3139
  style: {
3136
3140
  cursor: (rowConfig == null ? void 0 : rowConfig.onClick) ? "pointer" : "initial",
3137
- backgroundColor: (_a = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _a.call(rowConfig, row)
3141
+ backgroundColor: (_b = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _b.call(rowConfig, row)
3138
3142
  },
3139
3143
  onClick: () => {
3140
3144
  var _a2;
@@ -3142,18 +3146,7 @@ function TableRow({
3142
3146
  },
3143
3147
  onMouseEnter: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseEnter),
3144
3148
  onMouseLeave: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseLeave),
3145
- children: row.getVisibleCells().map((cell) => {
3146
- var _a2;
3147
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3148
- DynamicCell,
3149
- {
3150
- cell,
3151
- getStickyCellColor: cellConfig == null ? void 0 : cellConfig.getStickyCellColor,
3152
- highlight: (_a2 = cellConfig == null ? void 0 : cellConfig.getShouldHighlight) == null ? void 0 : _a2.call(cellConfig, cell)
3153
- },
3154
- cell.id
3155
- );
3156
- })
3149
+ children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DynamicCell, { cell, cellConfig }, cell.id))
3157
3150
  }
3158
3151
  );
3159
3152
  return rowWrapper ? rowWrapper({ row, children: tableRowContent }) : tableRowContent;
package/dist/index.mjs CHANGED
@@ -2548,15 +2548,17 @@ var StickyHeaderCell = styled4(StickyCell)`
2548
2548
  // src/cells/DynamicCell.tsx
2549
2549
  import { jsx as jsx5 } from "react/jsx-runtime";
2550
2550
  var StyledStickyCell = styled5(StickyCell)`
2551
- background-color: ${({ backgroundColor: bg }) => bg ? `${bg} !important` : `inherit`};
2551
+ background-color: ${({ backgroundColor }) => backgroundColor ? `${backgroundColor} !important` : `inherit`};
2552
2552
  `;
2553
2553
  var StyledCell = styled5(EdsTable.Cell)`
2554
- background-color: ${({ backgroundColor: bg }) => bg ? `${bg} !important` : `inherit`};
2554
+ background-color: ${({ backgroundColor }) => backgroundColor ? `${backgroundColor} !important` : `inherit`};
2555
2555
  `;
2556
- function DynamicCell({ cell, highlight, getStickyCellColor }) {
2557
- var _a, _b;
2556
+ function DynamicCell({ cell, cellConfig }) {
2557
+ var _a, _b, _c, _d, _e;
2558
2558
  const cellContent = flexRender(cell.column.columnDef.cell, cell.getContext());
2559
2559
  const columnPinningDirection = cell.column.getIsPinned();
2560
+ const stickyCellColor = (_a = cellConfig == null ? void 0 : cellConfig.getStickyCellColor) == null ? void 0 : _a.call(cellConfig, cell);
2561
+ const regularCellColor = (_d = (_b = cellConfig == null ? void 0 : cellConfig.getCellColor) == null ? void 0 : _b.call(cellConfig, cell)) != null ? _d : ((_c = cellConfig == null ? void 0 : cellConfig.getShouldHighlight) == null ? void 0 : _c.call(cellConfig, cell)) ? "#d5eaf4" : void 0;
2560
2562
  if (columnPinningDirection) {
2561
2563
  return /* @__PURE__ */ jsx5(
2562
2564
  EdsTable.Cell,
@@ -2565,7 +2567,7 @@ function DynamicCell({ cell, highlight, getStickyCellColor }) {
2565
2567
  style: __spreadValues({
2566
2568
  position: "sticky",
2567
2569
  top: 0,
2568
- backgroundColor: (_a = getStickyCellColor == null ? void 0 : getStickyCellColor(cell)) != null ? _a : "inherit",
2570
+ backgroundColor: stickyCellColor != null ? stickyCellColor : "inherit",
2569
2571
  zIndex: 5,
2570
2572
  backgroundClip: "padding-box",
2571
2573
  display: "table-cell"
@@ -2580,10 +2582,10 @@ function DynamicCell({ cell, highlight, getStickyCellColor }) {
2580
2582
  }
2581
2583
  );
2582
2584
  }
2583
- if ((_b = cell.column.columnDef.meta) == null ? void 0 : _b.sticky) {
2584
- return /* @__PURE__ */ jsx5(StyledStickyCell, { backgroundColor: getStickyCellColor == null ? void 0 : getStickyCellColor(cell), "data-column": cell.column.id, children: cellContent });
2585
+ if ((_e = cell.column.columnDef.meta) == null ? void 0 : _e.sticky) {
2586
+ return /* @__PURE__ */ jsx5(StyledStickyCell, { backgroundColor: stickyCellColor, "data-column": cell.column.id, children: cellContent });
2585
2587
  }
2586
- return /* @__PURE__ */ jsx5(StyledCell, { "data-column": cell.column.id, backgroundColor: highlight ? "#d5eaf4" : void 0, children: cellContent });
2588
+ return /* @__PURE__ */ jsx5(StyledCell, { "data-column": cell.column.id, backgroundColor: regularCellColor, children: cellContent });
2587
2589
  }
2588
2590
 
2589
2591
  // src/cells/HeaderCell.tsx
@@ -3077,17 +3079,19 @@ function TableRow({
3077
3079
  measureElement,
3078
3080
  index
3079
3081
  }) {
3080
- var _a;
3082
+ var _a, _b;
3081
3083
  const rowWrapper = rowConfig == null ? void 0 : rowConfig.rowWrapper;
3084
+ const dataIdValue = (_a = rowConfig == null ? void 0 : rowConfig.getDataIdAttribute) == null ? void 0 : _a.call(rowConfig, row);
3082
3085
  const tableRowContent = /* @__PURE__ */ jsx14(
3083
3086
  StyledTableRow,
3084
3087
  {
3085
3088
  active: row.getIsSelected(),
3086
3089
  "data-index": index,
3090
+ "data-id": dataIdValue,
3087
3091
  ref: measureElement,
3088
3092
  style: {
3089
3093
  cursor: (rowConfig == null ? void 0 : rowConfig.onClick) ? "pointer" : "initial",
3090
- backgroundColor: (_a = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _a.call(rowConfig, row)
3094
+ backgroundColor: (_b = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _b.call(rowConfig, row)
3091
3095
  },
3092
3096
  onClick: () => {
3093
3097
  var _a2;
@@ -3095,18 +3099,7 @@ function TableRow({
3095
3099
  },
3096
3100
  onMouseEnter: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseEnter),
3097
3101
  onMouseLeave: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseLeave),
3098
- children: row.getVisibleCells().map((cell) => {
3099
- var _a2;
3100
- return /* @__PURE__ */ jsx14(
3101
- DynamicCell,
3102
- {
3103
- cell,
3104
- getStickyCellColor: cellConfig == null ? void 0 : cellConfig.getStickyCellColor,
3105
- highlight: (_a2 = cellConfig == null ? void 0 : cellConfig.getShouldHighlight) == null ? void 0 : _a2.call(cellConfig, cell)
3106
- },
3107
- cell.id
3108
- );
3109
- })
3102
+ children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx14(DynamicCell, { cell, cellConfig }, cell.id))
3110
3103
  }
3111
3104
  );
3112
3105
  return rowWrapper ? rowWrapper({ row, children: tableRowContent }) : tableRowContent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/apollo-components",
3
- "version": "3.5.2",
3
+ "version": "3.6.0-beta.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",