@equinor/eds-data-grid-react 0.7.2 → 0.7.4

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.
@@ -8,6 +8,7 @@ var styled = require('styled-components');
8
8
  var jsxRuntime = require('react/jsx-runtime');
9
9
  var edsIcons = require('@equinor/eds-icons');
10
10
  var edsTokens = require('@equinor/eds-tokens');
11
+ var edsUtils = require('@equinor/eds-utils');
11
12
 
12
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
14
 
@@ -535,7 +536,7 @@ function logDevelopmentWarningOfPropUse(deprecatedProps) {
535
536
  }
536
537
 
537
538
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
538
- function EdsDataGrid({
539
+ function EdsDataGridInner({
539
540
  rows,
540
541
  columns,
541
542
  columnResizeMode,
@@ -580,6 +581,7 @@ function EdsDataGrid({
580
581
  height,
581
582
  getRowId,
582
583
  rowVirtualizerInstanceRef,
584
+ tableInstanceRef,
583
585
  columnSizing,
584
586
  onColumnResize,
585
587
  expansionState,
@@ -592,7 +594,7 @@ function EdsDataGrid({
592
594
  enableFooter,
593
595
  enableSortingRemoval,
594
596
  ...rest
595
- }) {
597
+ }, ref) {
596
598
  logDevelopmentWarningOfPropUse({
597
599
  virtualHeight: {
598
600
  value: virtualHeight,
@@ -806,6 +808,9 @@ function EdsDataGrid({
806
808
  }));
807
809
  }, [pageSize]);
808
810
  const table = reactTable.useReactTable(options);
811
+ if (tableInstanceRef) {
812
+ tableInstanceRef.current = table;
813
+ }
809
814
  let tableWrapperStyle = {};
810
815
 
811
816
  /**
@@ -820,6 +825,7 @@ function EdsDataGrid({
820
825
  };
821
826
  }
822
827
  const parentRef = react.useRef(null);
828
+ const combinedRef = react.useMemo(() => edsUtils.mergeRefs(parentRef, ref), [parentRef, ref]);
823
829
 
824
830
  /**
825
831
  * Virtualization setup
@@ -868,7 +874,7 @@ function EdsDataGrid({
868
874
  ...rest.style,
869
875
  ...tableWrapperStyle
870
876
  },
871
- ref: parentRef,
877
+ ref: combinedRef,
872
878
  $height: height,
873
879
  $width: width,
874
880
  $scrollbarHorizontal: scrollbarHorizontal,
@@ -978,6 +984,7 @@ const TableWrapper = styled__default.default.div.withConfig({
978
984
  $height,
979
985
  $width
980
986
  }) => Boolean($height) && Boolean($width) ? 'strict' : 'unset');
987
+ const EdsDataGrid = /*#__PURE__*/react.forwardRef(EdsDataGridInner);
981
988
 
982
989
  Object.defineProperty(exports, "createColumnHelper", {
983
990
  enumerable: true,
@@ -1,17 +1,18 @@
1
1
  import { Typography, useEds, Table, Pagination } from '@equinor/eds-core-react';
2
2
  import { getExpandedRowModel, getCoreRowModel, getSortedRowModel, getFacetedRowModel, getFacetedUniqueValues, getFacetedMinMaxValues, getFilteredRowModel, getPaginationRowModel, useReactTable } from '@tanstack/react-table';
3
3
  import { useVirtualizer } from '@tanstack/react-virtual';
4
- import { useState, useEffect, useMemo, useRef, useCallback } from 'react';
4
+ import { forwardRef, useState, useEffect, useMemo, useRef, useCallback } from 'react';
5
5
  import styled from 'styled-components';
6
6
  import { TableProvider } from './EdsDataGridContext.js';
7
7
  import { TableHeaderRow } from './components/TableHeaderRow.js';
8
8
  import { TableFooterRow } from './components/TableFooterRow.js';
9
9
  import { TableRow } from './components/TableRow.js';
10
10
  import { addPxSuffixIfInputHasNoPrefix, logDevelopmentWarningOfPropUse } from './utils.js';
11
+ import { mergeRefs } from '@equinor/eds-utils';
11
12
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
12
13
 
13
14
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
14
- function EdsDataGrid({
15
+ function EdsDataGridInner({
15
16
  rows,
16
17
  columns,
17
18
  columnResizeMode,
@@ -56,6 +57,7 @@ function EdsDataGrid({
56
57
  height,
57
58
  getRowId,
58
59
  rowVirtualizerInstanceRef,
60
+ tableInstanceRef,
59
61
  columnSizing,
60
62
  onColumnResize,
61
63
  expansionState,
@@ -68,7 +70,7 @@ function EdsDataGrid({
68
70
  enableFooter,
69
71
  enableSortingRemoval,
70
72
  ...rest
71
- }) {
73
+ }, ref) {
72
74
  logDevelopmentWarningOfPropUse({
73
75
  virtualHeight: {
74
76
  value: virtualHeight,
@@ -282,6 +284,9 @@ function EdsDataGrid({
282
284
  }));
283
285
  }, [pageSize]);
284
286
  const table = useReactTable(options);
287
+ if (tableInstanceRef) {
288
+ tableInstanceRef.current = table;
289
+ }
285
290
  let tableWrapperStyle = {};
286
291
 
287
292
  /**
@@ -296,6 +301,7 @@ function EdsDataGrid({
296
301
  };
297
302
  }
298
303
  const parentRef = useRef(null);
304
+ const combinedRef = useMemo(() => mergeRefs(parentRef, ref), [parentRef, ref]);
299
305
 
300
306
  /**
301
307
  * Virtualization setup
@@ -344,7 +350,7 @@ function EdsDataGrid({
344
350
  ...rest.style,
345
351
  ...tableWrapperStyle
346
352
  },
347
- ref: parentRef,
353
+ ref: combinedRef,
348
354
  $height: height,
349
355
  $width: width,
350
356
  $scrollbarHorizontal: scrollbarHorizontal,
@@ -454,5 +460,6 @@ const TableWrapper = styled.div.withConfig({
454
460
  $height,
455
461
  $width
456
462
  }) => Boolean($height) && Boolean($width) ? 'strict' : 'unset');
463
+ const EdsDataGrid = /*#__PURE__*/forwardRef(EdsDataGridInner);
457
464
 
458
465
  export { EdsDataGrid };
@@ -1,3 +1,7 @@
1
- import { HTMLAttributes } from 'react';
1
+ import { HTMLAttributes, ForwardedRef } from 'react';
2
2
  import { EdsDataGridProps } from './EdsDataGridProps';
3
- export declare function EdsDataGrid<T>({ rows, columns, columnResizeMode, pageSize, rowSelection, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, selectedRows, rowSelectionState, enableColumnFiltering, debug, enablePagination, enableSorting, stickyHeader, stickyFooter, onSelectRow, onRowSelectionChange, caption, enableVirtual, virtualHeight, columnVisibility, columnVisibilityChange, emptyMessage, columnOrder, cellClass, cellStyle, rowClass, rowStyle, headerClass, headerStyle, footerClass, footerStyle, externalPaginator, onSortingChange, manualSorting, sortingState, columnPinState, scrollbarHorizontal, width, minWidth, height, getRowId, rowVirtualizerInstanceRef, columnSizing, onColumnResize, expansionState, setExpansionState, getSubRows, defaultColumn, onRowContextMenu, onRowClick, onCellClick, enableFooter, enableSortingRemoval, ...rest }: EdsDataGridProps<T> & HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
3
+ declare function EdsDataGridInner<T>({ rows, columns, columnResizeMode, pageSize, rowSelection, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, selectedRows, rowSelectionState, enableColumnFiltering, debug, enablePagination, enableSorting, stickyHeader, stickyFooter, onSelectRow, onRowSelectionChange, caption, enableVirtual, virtualHeight, columnVisibility, columnVisibilityChange, emptyMessage, columnOrder, cellClass, cellStyle, rowClass, rowStyle, headerClass, headerStyle, footerClass, footerStyle, externalPaginator, onSortingChange, manualSorting, sortingState, columnPinState, scrollbarHorizontal, width, minWidth, height, getRowId, rowVirtualizerInstanceRef, tableInstanceRef, columnSizing, onColumnResize, expansionState, setExpansionState, getSubRows, defaultColumn, onRowContextMenu, onRowClick, onCellClick, enableFooter, enableSortingRemoval, ...rest }: EdsDataGridProps<T> & HTMLAttributes<HTMLDivElement>, ref: ForwardedRef<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
4
+ export declare const EdsDataGrid: <T>(props: EdsDataGridProps<T> & HTMLAttributes<HTMLDivElement> & {
5
+ ref?: ForwardedRef<HTMLDivElement>;
6
+ }) => ReturnType<typeof EdsDataGridInner>;
7
+ export {};
@@ -1,4 +1,4 @@
1
- import { Cell, Column, ColumnDef, ColumnPinningState, ColumnResizeMode, ColumnSizingState, ExpandedState, OnChangeFn, Row, RowSelectionState, SortingState, TableOptions } from '@tanstack/react-table';
1
+ import { Cell, Column, ColumnDef, ColumnPinningState, ColumnResizeMode, ColumnSizingState, ExpandedState, OnChangeFn, Row, RowSelectionState, SortingState, Table, TableOptions } from '@tanstack/react-table';
2
2
  import { Virtualizer } from '@tanstack/react-virtual';
3
3
  import { CSSProperties, MouseEvent, MutableRefObject, ReactElement } from 'react';
4
4
  type BaseProps<T> = {
@@ -272,15 +272,16 @@ type ColumnProps = {
272
272
  columnSizing?: ColumnSizingState;
273
273
  onColumnResize?: (e: ColumnSizingState) => void;
274
274
  };
275
- type RefProps = {
275
+ type RefProps<T> = {
276
276
  rowVirtualizerInstanceRef?: MutableRefObject<Virtualizer<HTMLDivElement, Element> | null>;
277
+ tableInstanceRef?: MutableRefObject<Table<T> | null>;
277
278
  };
278
279
  type ExpansionProps<T> = {
279
280
  expansionState?: ExpandedState;
280
281
  setExpansionState?: React.Dispatch<React.SetStateAction<ExpandedState>>;
281
282
  getSubRows?: (row: T, rowIndex: number) => Array<T>;
282
283
  };
283
- export type EdsDataGridProps<T> = BaseProps<T> & RowSelectionProps<T> & StyleProps<T> & HandlersProps<T> & SortProps & FilterProps & PagingProps & ColumnProps & VirtualProps & RefProps & ExpansionProps<T> & {
284
+ export type EdsDataGridProps<T> = BaseProps<T> & RowSelectionProps<T> & StyleProps<T> & HandlersProps<T> & SortProps & FilterProps & PagingProps & ColumnProps & VirtualProps & RefProps<T> & ExpansionProps<T> & {
284
285
  /**
285
286
  * Which columns are visible. If not set, all columns are visible. undefined means that the column is visible.
286
287
  * @default undefined
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/eds-data-grid-react",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "A feature-rich data-grid written in React, implementing the Equinor Design System",
5
5
  "license": "MIT",
6
6
  "types": "dist/types/index.d.ts",
@@ -23,8 +23,8 @@
23
23
  "@tanstack/react-table": "^8.20.1",
24
24
  "@tanstack/react-virtual": "^3.10.8",
25
25
  "@equinor/eds-icons": "^0.21.0",
26
- "@equinor/eds-tokens": "0.9.2",
27
- "@equinor/eds-utils": "^0.8.5"
26
+ "@equinor/eds-utils": "^0.8.5",
27
+ "@equinor/eds-tokens": "0.9.2"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@rollup/plugin-babel": "^6.0.4",