@equinor/apollo-components 3.5.1 → 3.5.2-beta.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,13 +1,13 @@
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, RowSelectionState, ExpandedState, ColumnPinningState, VisibilityState, HeaderContext, Column } from '@tanstack/react-table';
4
+ import { CellContext, Cell, Header, Table, Row, SortingState, OnChangeFn, ColumnDef, ColumnResizeMode, RowSelectionState, ExpandedState, ColumnPinningState, VisibilityState, HeaderContext, Column } from '@tanstack/react-table';
5
+ export { Cell, CellContext, ColumnDef, ColumnPinningState, ColumnResizeMode, ColumnSort, ExpandedState, HeaderContext, OnChangeFn, Row, RowSelectionState, SortingState, Table, VisibilityState, createColumnHelper } from '@tanstack/react-table';
5
6
  import * as styled_components from 'styled-components';
6
7
  import * as _equinor_eds_core_react from '@equinor/eds-core-react';
7
8
  import { CellProps, TypographyProps as TypographyProps$1 } from '@equinor/eds-core-react';
8
9
  import { ColumnDef as ColumnDef$1 } from '@tanstack/table-core';
9
10
  import { SetRequired } from 'type-fest';
10
- import { TableOptions } from '@tanstack/table-core/build/lib/types';
11
11
  import { Variants } from '@equinor/eds-core-react/dist/types/components/types';
12
12
  import { FieldError } from 'react-hook-form';
13
13
 
@@ -27,12 +27,12 @@ declare const ChipsCell: (props: {
27
27
  values?: string[];
28
28
  }) => JSX.Element;
29
29
 
30
- declare type TableCellProps<T> = {
30
+ type TableCellProps<T> = {
31
31
  cell: Cell<T, unknown>;
32
32
  highlight?: boolean;
33
33
  getStickyCellColor?: (cell: Cell<T, unknown>) => string;
34
34
  };
35
- declare type StyledStickyCellProps = {
35
+ type StyledStickyCellProps = {
36
36
  highlight?: boolean;
37
37
  backgroundColor?: string;
38
38
  };
@@ -46,7 +46,7 @@ interface HeaderCellProps<TData, TValue> {
46
46
  }
47
47
  declare const HeaderCell: <TData, TValue>({ header, table }: HeaderCellProps<TData, TValue>) => JSX.Element;
48
48
 
49
- declare type HierarchyCellOptions = {
49
+ type HierarchyCellOptions = {
50
50
  getRowDepth?: () => number;
51
51
  getDisplayName?: () => string;
52
52
  };
@@ -86,9 +86,13 @@ interface RowConfig<T> {
86
86
  onClick?: (row: Row<T>) => void;
87
87
  onMouseEnter?: (row: Row<T>) => void;
88
88
  onMouseLeave?: (row: Row<T>) => void;
89
+ /**
90
+ * Whatever is returned from this function will be added as a data-id attribute on the tr in the dom.
91
+ */
92
+ getDataIdAttribute?: (row: Row<T>) => string | undefined;
89
93
  }
90
- declare type TruncateMode = 'wrap' | 'hover';
91
- declare type SortConfig = {
94
+ type TruncateMode = 'wrap' | 'hover';
95
+ type SortConfig = {
92
96
  enableSorting?: boolean;
93
97
  manualSorting?: boolean;
94
98
  sorting?: SortingState;
@@ -105,8 +109,8 @@ interface CellConfig<T> {
105
109
  */
106
110
  truncateMode?: TruncateMode | ((cell: Cell<T, unknown>) => TruncateMode);
107
111
  }
108
- declare type RowSelectionMode = 'single' | 'multiple';
109
- declare type TableLayout = 'auto' | 'fixed';
112
+ type RowSelectionMode = 'single' | 'multiple';
113
+ type TableLayout = 'auto' | 'fixed';
110
114
  interface HTMLPropsRef<T extends HTMLElement> extends HTMLProps<T> {
111
115
  ref?: MutableRefObject<T | null> | null;
112
116
  }
@@ -138,7 +142,7 @@ interface DataTableProps<T> {
138
142
  virtual?: boolean;
139
143
  getRowId?: (originalRow: T, index: number, parent: Row<T> | undefined) => string;
140
144
  getSubRows?: (originalRow: T) => T[] | undefined;
141
- columnResizing?: boolean | TableOptions<T>['columnResizeMode'];
145
+ columnResizing?: boolean | ColumnResizeMode;
142
146
  rowSelection?: Partial<ControlledState<RowSelectionState>> & {
143
147
  mode?: RowSelectionMode;
144
148
  selectColumn?: 'default' | ((options?: Record<string, any>) => ColumnDef<T, any>);
@@ -181,7 +185,7 @@ interface DataTableProps<T> {
181
185
  tableContainerProps?: HTMLPropsRef<HTMLDivElement>;
182
186
  infiniteScroll?: InfiniteScrollConfig;
183
187
  }
184
- declare type ControlledState<T> = {
188
+ type ControlledState<T> = {
185
189
  state?: T;
186
190
  /** Callback when state chagnes. Using this requires the state to be fully controlled. */
187
191
  onChange?: Dispatch<SetStateAction<T>>;
@@ -197,8 +201,26 @@ declare function DataTable<T>(props: DataTableProps<T>): JSX.Element;
197
201
  * @returns A capitalized header
198
202
  */
199
203
  declare function capitalizeHeader<T>(context: HeaderContext<T, any>): string;
204
+ /**
205
+ * Used to conditionally return any given value.
206
+ *
207
+ * @param enabled - A bool whether the value should be enabled or not
208
+ * @param value - Any given value.
209
+ * @returns Value or undefined
210
+ */
211
+ declare function enableOrUndefined<T>(enabled: boolean | undefined, value: T): T | undefined;
212
+ /**
213
+ * Get column header if set
214
+ * @param column
215
+ * @returns Column label
216
+ */
217
+ declare function getColumnHeader<T>(column: Column<T, any>): string;
218
+ /** Prepend a column definition array with a select column if enabled in the config. */
219
+ declare function prependSelectColumnIfEnabled<T>(columns: ColumnDef<T, any>[], config?: DataTableProps<T>['rowSelection']): ColumnDef<T, any>[];
200
220
  /** Prepend a column definition array with a select column. */
201
- declare function prependSelectColumn<T>(columns: ColumnDef<T>[], config?: DataTableProps<T>['rowSelection']): ColumnDef<T, unknown>[];
221
+ declare function prependSelectColumn<T>(columns: ColumnDef<T>[], config?: DataTableProps<T>['rowSelection']): ColumnDef<T>[];
222
+ /** Useful in cases where you either have a value, function or undefined. */
223
+ declare function getFunctionValueOrDefault<T extends boolean | string | number, P>(valueOrFn: ((props: P) => T) | T | undefined, fnProps: P, defaultValue: T): T;
202
224
 
203
225
  declare function SelectColumnDef<T>(props: SetRequired<DataTableProps<T>, 'rowSelection'>['rowSelection']): ColumnDef$1<T, any>;
204
226
 
@@ -206,7 +228,7 @@ declare const leftCellShadow: styled_components.FlattenSimpleInterpolation;
206
228
  declare const StickyCell: styled_components.StyledComponent<react.ForwardRefExoticComponent<CellProps & react.RefAttributes<HTMLTableCellElement>>, any, {} & CellProps, never>;
207
229
  declare const StickyHeaderCell: styled_components.StyledComponent<react.ForwardRefExoticComponent<CellProps & react.RefAttributes<HTMLTableCellElement>>, any, ({} & CellProps) & CellProps, never>;
208
230
 
209
- declare type TypographyProps = {
231
+ type TypographyProps = {
210
232
  truncate?: boolean;
211
233
  enableShowAllOnHover?: boolean;
212
234
  } & TypographyProps$1;
@@ -226,12 +248,12 @@ declare function getTotalRight<TData>(table: Table<TData>, column: Column<TData>
226
248
  declare function getIsFirstRightPinnedColumn<TData>(column: Column<TData>): boolean;
227
249
  declare function getIsLastLeftPinnedColumn<TData>(table: Table<TData>, column: Column<TData>): boolean;
228
250
 
229
- declare type FormMeta = {
251
+ type FormMeta = {
230
252
  _isNew?: boolean;
231
253
  _editMode?: boolean;
232
254
  _hasRemoteChange?: boolean;
233
255
  };
234
- declare type WithoutFormMeta<T extends FormMeta> = Omit<T, keyof FormMeta>;
256
+ type WithoutFormMeta<T extends FormMeta> = Omit<T, keyof FormMeta>;
235
257
 
236
258
  /**
237
259
  * Subscribes to the `_editMode` field in a `react-hook-form` context.
@@ -310,4 +332,4 @@ declare function EditableTextFieldCell<T extends FormMeta>({ error: errorFromPro
310
332
  declare const WARNING_PREFIX = "WARNING";
311
333
  declare function getHelperTextProps({ error, warning, helperText, }: GetHelperTextPropsProps): GetHelperTextProps;
312
334
 
313
- export { AppShell, AppSidebar, CellConfig, CheckboxCell, ChipsCell, ColumnSelect, DataTable, DataTableProps, DynamicCell, EditableCellBaseProps, EditableCheckboxCell, EditableDateCell, EditableDateCellProps, EditableDropdownSingleCell, EditableDropdownSingleCellProps, EditableNumberCell, EditableTextAreaCell, EditableTextFieldCell, FormMeta, GetHelperTextProps, GetHelperTextPropsProps, HTMLPropsRef, HeaderCell, HierarchyCell, InfiniteScrollConfig, Option, PopoverCell, RowConfig, RowSelectionMode, SelectColumnDef, SortConfig, StickyCell, StickyHeaderCell, StyledStickyCell, TableHeader, TableLayout, TableRowWrapper, TableRowWrapperProps, TruncateMode, TypographyCustom, TypographyProps, WARNING_PREFIX, WithoutFormMeta, addFormMeta, capitalizeHeader, getHelperTextProps, getIsFirstRightPinnedColumn, getIsLastLeftPinnedColumn, getTotalRight, leftCellShadow, prependSelectColumn, removeFormMeta, stopPropagation, stringToHslColor, useEditMode, useGetIsNew, useHasRemoteChange, useSetFormMeta };
335
+ export { AppShell, AppSidebar, CellConfig, CheckboxCell, ChipsCell, ColumnSelect, DataTable, DataTableProps, DynamicCell, EditableCellBaseProps, EditableCheckboxCell, EditableDateCell, EditableDateCellProps, EditableDropdownSingleCell, EditableDropdownSingleCellProps, EditableNumberCell, EditableTextAreaCell, EditableTextFieldCell, FormMeta, GetHelperTextProps, GetHelperTextPropsProps, HTMLPropsRef, HeaderCell, HierarchyCell, InfiniteScrollConfig, Option, PopoverCell, RowConfig, RowSelectionMode, SelectColumnDef, SortConfig, StickyCell, StickyHeaderCell, StyledStickyCell, TableHeader, TableLayout, TableRowWrapper, TableRowWrapperProps, TruncateMode, TypographyCustom, TypographyProps, WARNING_PREFIX, WithoutFormMeta, addFormMeta, capitalizeHeader, enableOrUndefined, getColumnHeader, getFunctionValueOrDefault, getHelperTextProps, getIsFirstRightPinnedColumn, getIsLastLeftPinnedColumn, getTotalRight, leftCellShadow, prependSelectColumn, prependSelectColumnIfEnabled, removeFormMeta, stopPropagation, stringToHslColor, useEditMode, useGetIsNew, useHasRemoteChange, useSetFormMeta };
package/dist/index.js CHANGED
@@ -2397,12 +2397,17 @@ __export(src_exports, {
2397
2397
  WARNING_PREFIX: () => WARNING_PREFIX,
2398
2398
  addFormMeta: () => addFormMeta,
2399
2399
  capitalizeHeader: () => capitalizeHeader,
2400
+ createColumnHelper: () => import_react_table3.createColumnHelper,
2401
+ enableOrUndefined: () => enableOrUndefined,
2402
+ getColumnHeader: () => getColumnHeader,
2403
+ getFunctionValueOrDefault: () => getFunctionValueOrDefault,
2400
2404
  getHelperTextProps: () => getHelperTextProps,
2401
2405
  getIsFirstRightPinnedColumn: () => getIsFirstRightPinnedColumn,
2402
2406
  getIsLastLeftPinnedColumn: () => getIsLastLeftPinnedColumn,
2403
2407
  getTotalRight: () => getTotalRight,
2404
2408
  leftCellShadow: () => leftCellShadow,
2405
2409
  prependSelectColumn: () => prependSelectColumn,
2410
+ prependSelectColumnIfEnabled: () => prependSelectColumnIfEnabled,
2406
2411
  removeFormMeta: () => removeFormMeta,
2407
2412
  stopPropagation: () => stopPropagation,
2408
2413
  stringToHslColor: () => stringToHslColor,
@@ -2954,6 +2959,7 @@ var import_react3 = require("react");
2954
2959
  var import_styled_components10 = __toESM(require("styled-components"));
2955
2960
 
2956
2961
  // src/DataTable/utils.tsx
2962
+ var import_react_table3 = require("@tanstack/react-table");
2957
2963
  function capitalizeHeader(context) {
2958
2964
  const header = context.header.id;
2959
2965
  return header.charAt(0).toUpperCase() + header.slice(1);
@@ -2967,6 +2973,13 @@ function getColumnHeader(column) {
2967
2973
  return column.id;
2968
2974
  return typeof columnHeader === "string" ? columnHeader : column.id;
2969
2975
  }
2976
+ function prependSelectColumnIfEnabled(columns, config) {
2977
+ if (!config)
2978
+ return columns;
2979
+ if (!Boolean(config == null ? void 0 : config.mode))
2980
+ return columns;
2981
+ return prependSelectColumn(columns, config);
2982
+ }
2970
2983
  function prependSelectColumn(columns, config) {
2971
2984
  if (!(config == null ? void 0 : config.selectColumn))
2972
2985
  return columns;
@@ -3072,7 +3085,7 @@ function TableHeader({ table, sticky }) {
3072
3085
  }
3073
3086
 
3074
3087
  // src/DataTable/DataTable.tsx
3075
- var import_react_table3 = require("@tanstack/react-table");
3088
+ var import_react_table4 = require("@tanstack/react-table");
3076
3089
  var import_react7 = require("react");
3077
3090
  var import_styled_components16 = __toESM(require("styled-components"));
3078
3091
 
@@ -3111,17 +3124,19 @@ function TableRow({
3111
3124
  measureElement,
3112
3125
  index
3113
3126
  }) {
3114
- var _a;
3127
+ var _a, _b;
3115
3128
  const rowWrapper = rowConfig == null ? void 0 : rowConfig.rowWrapper;
3129
+ const dataIdValue = (_a = rowConfig == null ? void 0 : rowConfig.getDataIdAttribute) == null ? void 0 : _a.call(rowConfig, row);
3116
3130
  const tableRowContent = /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3117
3131
  StyledTableRow,
3118
3132
  {
3119
3133
  active: row.getIsSelected(),
3120
3134
  "data-index": index,
3135
+ "data-id": dataIdValue,
3121
3136
  ref: measureElement,
3122
3137
  style: {
3123
3138
  cursor: (rowConfig == null ? void 0 : rowConfig.onClick) ? "pointer" : "initial",
3124
- backgroundColor: (_a = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _a.call(rowConfig, row)
3139
+ backgroundColor: (_b = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _b.call(rowConfig, row)
3125
3140
  },
3126
3141
  onClick: () => {
3127
3142
  var _a2;
@@ -3462,7 +3477,7 @@ function DataTable(props) {
3462
3477
  typeof props.columnPinning === "object" && props.columnPinning.state ? props.columnPinning.state : internalColumnPinning,
3463
3478
  typeof props.columnPinning === "object" && props.columnPinning.onChange ? props.columnPinning.onChange : setInternalColumnPinning
3464
3479
  ];
3465
- const table = (0, import_react_table3.useReactTable)({
3480
+ const table = (0, import_react_table4.useReactTable)({
3466
3481
  columns: prependSelectColumn(columns, props.rowSelection),
3467
3482
  data,
3468
3483
  globalFilterFn: enableGlobalFilter(fuzzyFilter),
@@ -3489,10 +3504,10 @@ function DataTable(props) {
3489
3504
  enableSubRowSelection: ((_z = props.rowSelection) == null ? void 0 : _z.mode) !== "single",
3490
3505
  filterFromLeafRows: bannerConfig == null ? void 0 : bannerConfig.filterFromLeafRows,
3491
3506
  enablePinning: props.columnPinning !== void 0 && (typeof props.columnPinning === "boolean" ? props.columnPinning : props.columnPinning.enable),
3492
- getFilteredRowModel: enableGlobalFilter((0, import_react_table3.getFilteredRowModel)()),
3493
- getCoreRowModel: (0, import_react_table3.getCoreRowModel)(),
3494
- getExpandedRowModel: (0, import_react_table3.getExpandedRowModel)(),
3495
- getSortedRowModel: (0, import_react_table3.getSortedRowModel)(),
3507
+ getFilteredRowModel: enableGlobalFilter((0, import_react_table4.getFilteredRowModel)()),
3508
+ getCoreRowModel: (0, import_react_table4.getCoreRowModel)(),
3509
+ getExpandedRowModel: (0, import_react_table4.getExpandedRowModel)(),
3510
+ getSortedRowModel: (0, import_react_table4.getSortedRowModel)(),
3496
3511
  onExpandedChange: setExpandedState,
3497
3512
  onRowSelectionChange: setRowSelectionState,
3498
3513
  onColumnPinningChange: setColumnPinning,
@@ -4143,12 +4158,17 @@ var InlineTextField3 = (0, import_styled_components20.default)(import_eds_core_r
4143
4158
  WARNING_PREFIX,
4144
4159
  addFormMeta,
4145
4160
  capitalizeHeader,
4161
+ createColumnHelper,
4162
+ enableOrUndefined,
4163
+ getColumnHeader,
4164
+ getFunctionValueOrDefault,
4146
4165
  getHelperTextProps,
4147
4166
  getIsFirstRightPinnedColumn,
4148
4167
  getIsLastLeftPinnedColumn,
4149
4168
  getTotalRight,
4150
4169
  leftCellShadow,
4151
4170
  prependSelectColumn,
4171
+ prependSelectColumnIfEnabled,
4152
4172
  removeFormMeta,
4153
4173
  stopPropagation,
4154
4174
  stringToHslColor,
package/dist/index.mjs CHANGED
@@ -2906,6 +2906,7 @@ import { useRef as useRef2, useState as useState3 } from "react";
2906
2906
  import styled10 from "styled-components";
2907
2907
 
2908
2908
  // src/DataTable/utils.tsx
2909
+ import { createColumnHelper } from "@tanstack/react-table";
2909
2910
  function capitalizeHeader(context) {
2910
2911
  const header = context.header.id;
2911
2912
  return header.charAt(0).toUpperCase() + header.slice(1);
@@ -2919,6 +2920,13 @@ function getColumnHeader(column) {
2919
2920
  return column.id;
2920
2921
  return typeof columnHeader === "string" ? columnHeader : column.id;
2921
2922
  }
2923
+ function prependSelectColumnIfEnabled(columns, config) {
2924
+ if (!config)
2925
+ return columns;
2926
+ if (!Boolean(config == null ? void 0 : config.mode))
2927
+ return columns;
2928
+ return prependSelectColumn(columns, config);
2929
+ }
2922
2930
  function prependSelectColumn(columns, config) {
2923
2931
  if (!(config == null ? void 0 : config.selectColumn))
2924
2932
  return columns;
@@ -3069,17 +3077,19 @@ function TableRow({
3069
3077
  measureElement,
3070
3078
  index
3071
3079
  }) {
3072
- var _a;
3080
+ var _a, _b;
3073
3081
  const rowWrapper = rowConfig == null ? void 0 : rowConfig.rowWrapper;
3082
+ const dataIdValue = (_a = rowConfig == null ? void 0 : rowConfig.getDataIdAttribute) == null ? void 0 : _a.call(rowConfig, row);
3074
3083
  const tableRowContent = /* @__PURE__ */ jsx14(
3075
3084
  StyledTableRow,
3076
3085
  {
3077
3086
  active: row.getIsSelected(),
3078
3087
  "data-index": index,
3088
+ "data-id": dataIdValue,
3079
3089
  ref: measureElement,
3080
3090
  style: {
3081
3091
  cursor: (rowConfig == null ? void 0 : rowConfig.onClick) ? "pointer" : "initial",
3082
- backgroundColor: (_a = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _a.call(rowConfig, row)
3092
+ backgroundColor: (_b = rowConfig == null ? void 0 : rowConfig.getRowBackground) == null ? void 0 : _b.call(rowConfig, row)
3083
3093
  },
3084
3094
  onClick: () => {
3085
3095
  var _a2;
@@ -4100,12 +4110,17 @@ export {
4100
4110
  WARNING_PREFIX,
4101
4111
  addFormMeta,
4102
4112
  capitalizeHeader,
4113
+ createColumnHelper,
4114
+ enableOrUndefined,
4115
+ getColumnHeader,
4116
+ getFunctionValueOrDefault,
4103
4117
  getHelperTextProps,
4104
4118
  getIsFirstRightPinnedColumn,
4105
4119
  getIsLastLeftPinnedColumn,
4106
4120
  getTotalRight,
4107
4121
  leftCellShadow,
4108
4122
  prependSelectColumn,
4123
+ prependSelectColumnIfEnabled,
4109
4124
  removeFormMeta,
4110
4125
  stopPropagation,
4111
4126
  stringToHslColor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/apollo-components",
3
- "version": "3.5.1",
3
+ "version": "3.5.2-beta.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -46,7 +46,7 @@
46
46
  "eslint-config-custom": "*",
47
47
  "storybook": "^7.0.0-alpha.38",
48
48
  "tsconfig": "*",
49
- "typescript": "^4.5.2"
49
+ "typescript": "^5.2.2"
50
50
  },
51
51
  "publishConfig": {
52
52
  "access": "public"