@equinor/apollo-components 3.6.0 → 3.7.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,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,42 +27,11 @@ 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>;
32
+ columnSelectPlaceholder?: string;
64
33
  }
65
- declare function ColumnSelect<T>({ table }: ColumnSelectProps<T>): JSX.Element;
34
+ declare function ColumnSelect<T>({ table, columnSelectPlaceholder }: ColumnSelectProps<T>): JSX.Element;
66
35
 
67
36
  interface TableHeaderProps<T> {
68
37
  table: Table<T>;
@@ -108,6 +77,13 @@ interface CellConfig<T> {
108
77
  * ***Note**: This only applies to default cells. Custom cells need custom implementation.*
109
78
  */
110
79
  truncateMode?: TruncateMode | ((cell: Cell<T, unknown>) => TruncateMode);
80
+ /**
81
+ * Manually set the cell background color. Prioritized over highlight color.
82
+ *
83
+ * @param cell
84
+ * @returns color in hex, rgb or rgba, undefined to use default
85
+ */
86
+ getCellColor?: (cell: Cell<T, unknown>) => string | undefined;
111
87
  }
112
88
  type RowSelectionMode = 'single' | 'multiple';
113
89
  type TableLayout = 'auto' | 'fixed';
@@ -169,6 +145,7 @@ interface DataTableProps<T> {
169
145
  enableColumnSelect?: boolean;
170
146
  enableGlobalFilterInput?: boolean;
171
147
  globalFilterPlaceholder?: string;
148
+ columnSelectPlaceholder?: string;
172
149
  filterFromLeafRows?: boolean;
173
150
  /**
174
151
  * @deprecated Use `customActionsLeft` instead
@@ -222,6 +199,36 @@ declare function prependSelectColumn<T>(columns: ColumnDef<T>[], config?: DataTa
222
199
  /** Useful in cases where you either have a value, function or undefined. */
223
200
  declare function getFunctionValueOrDefault<T extends boolean | string | number, P>(valueOrFn: ((props: P) => T) | T | undefined, fnProps: P, defaultValue: T): T;
224
201
 
202
+ type TableCellProps<T> = {
203
+ cell: Cell<T, unknown>;
204
+ cellConfig?: CellConfig<T>;
205
+ };
206
+ type StyledStickyCellProps = {
207
+ backgroundColor?: string;
208
+ };
209
+ declare const StyledStickyCell: styled_components.StyledComponent<react.ForwardRefExoticComponent<_equinor_eds_core_react.CellProps & react.RefAttributes<HTMLTableCellElement>>, any, ({} & _equinor_eds_core_react.CellProps) & StyledStickyCellProps, never>;
210
+ declare function DynamicCell<T>({ cell, cellConfig }: TableCellProps<T>): JSX.Element;
211
+
212
+ interface HeaderCellProps<TData, TValue> {
213
+ header: Header<TData, TValue>;
214
+ /** Needed for column resizing */
215
+ table: Table<TData>;
216
+ }
217
+ declare const HeaderCell: <TData, TValue>({ header, table }: HeaderCellProps<TData, TValue>) => JSX.Element;
218
+
219
+ type HierarchyCellOptions = {
220
+ getRowDepth?: () => number;
221
+ getDisplayName?: () => string;
222
+ };
223
+ declare function HierarchyCell<T>(cell: CellContext<T, any>, options?: HierarchyCellOptions): JSX.Element;
224
+
225
+ interface PopoverCellProps {
226
+ id: string;
227
+ value: string;
228
+ title?: string | JSX.Element | ReactNode;
229
+ }
230
+ declare function PopoverCell(props: PopoverCellProps): JSX.Element;
231
+
225
232
  declare function SelectColumnDef<T>(props: SetRequired<DataTableProps<T>, 'rowSelection'>['rowSelection']): ColumnDef$1<T, any>;
226
233
 
227
234
  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
@@ -3008,24 +3010,34 @@ var ActionsWrapper = import_styled_components10.default.div`
3008
3010
  justify-content: flex-end;
3009
3011
  gap: 0.5rem;
3010
3012
  `;
3011
- function ColumnSelect({ table }) {
3013
+ function ColumnSelect({ table, columnSelectPlaceholder }) {
3012
3014
  const [isOpen, setIsOpen] = (0, import_react3.useState)(false);
3013
3015
  const referenceElement = (0, import_react3.useRef)(null);
3014
3016
  const selectableColumns = table.getAllLeafColumns().filter((column) => column.id !== "select");
3015
3017
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
3016
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_eds_core_react10.Tooltip, { title: "Select columns", placement: "left", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3017
- import_eds_core_react10.Button,
3018
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3019
+ import_eds_core_react10.Tooltip,
3018
3020
  {
3019
- "aria-haspopup": true,
3020
- id: "column-select-anchor",
3021
- "aria-controls": "column-select-popover",
3022
- "aria-expanded": isOpen,
3023
- ref: referenceElement,
3024
- variant: "ghost_icon",
3025
- onClick: () => setIsOpen(true),
3026
- children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_eds_core_react10.Icon, { name: "view_column", data: import_eds_icons5.view_column })
3021
+ title: columnSelectPlaceholder ? "" : "Select columns",
3022
+ placement: "left",
3023
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3024
+ import_eds_core_react10.Button,
3025
+ {
3026
+ "aria-haspopup": true,
3027
+ id: "column-select-anchor",
3028
+ "aria-controls": "column-select-popover",
3029
+ "aria-expanded": isOpen,
3030
+ ref: referenceElement,
3031
+ variant: columnSelectPlaceholder ? "ghost" : "ghost_icon",
3032
+ onClick: () => setIsOpen(true),
3033
+ children: [
3034
+ columnSelectPlaceholder,
3035
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_eds_core_react10.Icon, { name: "view_column", data: import_eds_icons5.view_column })
3036
+ ]
3037
+ }
3038
+ )
3027
3039
  }
3028
- ) }),
3040
+ ),
3029
3041
  /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3030
3042
  import_eds_core_react10.Popover,
3031
3043
  {
@@ -3144,18 +3156,7 @@ function TableRow({
3144
3156
  },
3145
3157
  onMouseEnter: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseEnter),
3146
3158
  onMouseLeave: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseLeave),
3147
- children: row.getVisibleCells().map((cell) => {
3148
- var _a2;
3149
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3150
- DynamicCell,
3151
- {
3152
- cell,
3153
- getStickyCellColor: cellConfig == null ? void 0 : cellConfig.getStickyCellColor,
3154
- highlight: (_a2 = cellConfig == null ? void 0 : cellConfig.getShouldHighlight) == null ? void 0 : _a2.call(cellConfig, cell)
3155
- },
3156
- cell.id
3157
- );
3158
- })
3159
+ children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DynamicCell, { cell, cellConfig }, cell.id))
3159
3160
  }
3160
3161
  );
3161
3162
  return rowWrapper ? rowWrapper({ row, children: tableRowContent }) : tableRowContent;
@@ -3289,7 +3290,7 @@ function TableBanner({
3289
3290
  onChange: (value) => globalFilter.onChange(String(value))
3290
3291
  }
3291
3292
  ),
3292
- (bannerConfig == null ? void 0 : bannerConfig.enableColumnSelect) && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ColumnSelect, { table }),
3293
+ (bannerConfig == null ? void 0 : bannerConfig.enableColumnSelect) && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ColumnSelect, { table, columnSelectPlaceholder: bannerConfig.columnSelectPlaceholder }),
3293
3294
  (bannerConfig == null ? void 0 : bannerConfig.totalRowCount) && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { children: [
3294
3295
  table.options.data.length.toLocaleString(),
3295
3296
  " /",
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
@@ -2955,24 +2957,34 @@ var ActionsWrapper = styled10.div`
2955
2957
  justify-content: flex-end;
2956
2958
  gap: 0.5rem;
2957
2959
  `;
2958
- function ColumnSelect({ table }) {
2960
+ function ColumnSelect({ table, columnSelectPlaceholder }) {
2959
2961
  const [isOpen, setIsOpen] = useState3(false);
2960
2962
  const referenceElement = useRef2(null);
2961
2963
  const selectableColumns = table.getAllLeafColumns().filter((column) => column.id !== "select");
2962
2964
  return /* @__PURE__ */ jsxs7(Fragment2, { children: [
2963
- /* @__PURE__ */ jsx11(Tooltip, { title: "Select columns", placement: "left", children: /* @__PURE__ */ jsx11(
2964
- Button3,
2965
+ /* @__PURE__ */ jsx11(
2966
+ Tooltip,
2965
2967
  {
2966
- "aria-haspopup": true,
2967
- id: "column-select-anchor",
2968
- "aria-controls": "column-select-popover",
2969
- "aria-expanded": isOpen,
2970
- ref: referenceElement,
2971
- variant: "ghost_icon",
2972
- onClick: () => setIsOpen(true),
2973
- children: /* @__PURE__ */ jsx11(Icon5, { name: "view_column", data: view_column })
2968
+ title: columnSelectPlaceholder ? "" : "Select columns",
2969
+ placement: "left",
2970
+ children: /* @__PURE__ */ jsxs7(
2971
+ Button3,
2972
+ {
2973
+ "aria-haspopup": true,
2974
+ id: "column-select-anchor",
2975
+ "aria-controls": "column-select-popover",
2976
+ "aria-expanded": isOpen,
2977
+ ref: referenceElement,
2978
+ variant: columnSelectPlaceholder ? "ghost" : "ghost_icon",
2979
+ onClick: () => setIsOpen(true),
2980
+ children: [
2981
+ columnSelectPlaceholder,
2982
+ /* @__PURE__ */ jsx11(Icon5, { name: "view_column", data: view_column })
2983
+ ]
2984
+ }
2985
+ )
2974
2986
  }
2975
- ) }),
2987
+ ),
2976
2988
  /* @__PURE__ */ jsxs7(
2977
2989
  Popover2,
2978
2990
  {
@@ -3097,18 +3109,7 @@ function TableRow({
3097
3109
  },
3098
3110
  onMouseEnter: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseEnter),
3099
3111
  onMouseLeave: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseLeave),
3100
- children: row.getVisibleCells().map((cell) => {
3101
- var _a2;
3102
- return /* @__PURE__ */ jsx14(
3103
- DynamicCell,
3104
- {
3105
- cell,
3106
- getStickyCellColor: cellConfig == null ? void 0 : cellConfig.getStickyCellColor,
3107
- highlight: (_a2 = cellConfig == null ? void 0 : cellConfig.getShouldHighlight) == null ? void 0 : _a2.call(cellConfig, cell)
3108
- },
3109
- cell.id
3110
- );
3111
- })
3112
+ children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx14(DynamicCell, { cell, cellConfig }, cell.id))
3112
3113
  }
3113
3114
  );
3114
3115
  return rowWrapper ? rowWrapper({ row, children: tableRowContent }) : tableRowContent;
@@ -3242,7 +3243,7 @@ function TableBanner({
3242
3243
  onChange: (value) => globalFilter.onChange(String(value))
3243
3244
  }
3244
3245
  ),
3245
- (bannerConfig == null ? void 0 : bannerConfig.enableColumnSelect) && /* @__PURE__ */ jsx17(ColumnSelect, { table }),
3246
+ (bannerConfig == null ? void 0 : bannerConfig.enableColumnSelect) && /* @__PURE__ */ jsx17(ColumnSelect, { table, columnSelectPlaceholder: bannerConfig.columnSelectPlaceholder }),
3246
3247
  (bannerConfig == null ? void 0 : bannerConfig.totalRowCount) && /* @__PURE__ */ jsxs9("span", { children: [
3247
3248
  table.options.data.length.toLocaleString(),
3248
3249
  " /",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/apollo-components",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",