@equinor/eds-data-grid-react 0.2.0 → 0.3.0-rc

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.
@@ -1,4 +1,3 @@
1
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
1
  import { useState, useRef, useMemo } from 'react';
3
2
  import { DebouncedInput } from './DebouncedInput.js';
4
3
  import { Button, Icon, Popover } from '@equinor/eds-core-react';
@@ -7,58 +6,49 @@ import styled from 'styled-components';
7
6
  import { tokens } from '@equinor/eds-tokens';
8
7
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
9
8
 
10
- var NumberContainer = styled.div.withConfig({
9
+ /* istanbul ignore file */
10
+
11
+ const NumberContainer = styled.div.withConfig({
11
12
  displayName: "Filter__NumberContainer",
12
13
  componentId: "sc-ytpdpw-0"
13
14
  })(["display:grid;grid-template-columns:80px 80px;grid-column-gap:32px;"]);
14
- function Filter(_ref) {
15
- var _table$getPreFiltered, _column$getFacetedMin, _column$getFacetedMin2, _column$getFacetedMin3, _column$getFacetedMin4, _, _column$getFacetedMin5, _column$getFacetedMin6, _column$getFacetedMin7, _column$getFacetedMin8, _column$getFacetedMin9, _column$getFacetedMin10, _2, _column$getFacetedMin11, _column$getFacetedMin12;
16
- var column = _ref.column,
17
- table = _ref.table;
18
- var firstValue = (_table$getPreFiltered = table.getPreFilteredRowModel().flatRows[0]) === null || _table$getPreFiltered === void 0 ? void 0 : _table$getPreFiltered.getValue(column.id);
19
- var _useState = useState(false),
20
- _useState2 = _slicedToArray(_useState, 2),
21
- open = _useState2[0],
22
- setOpen = _useState2[1];
23
- var filterIconRef = useRef();
24
- var togglePopover = function togglePopover(event) {
15
+ function Filter({
16
+ column,
17
+ table
18
+ }) {
19
+ const firstValue = table.getPreFilteredRowModel().flatRows[0]?.getValue(column.id);
20
+ const [open, setOpen] = useState(false);
21
+ const filterIconRef = useRef();
22
+ const togglePopover = event => {
25
23
  event.stopPropagation();
26
24
  setOpen(!open);
27
25
  };
28
- var columnText = useMemo(function () {
29
- var header;
26
+ const columnText = useMemo(() => {
27
+ let header;
30
28
  try {
31
29
  if (typeof column.columnDef.header === 'function') {
32
- var obj = column.columnDef.header(
30
+ const obj = column.columnDef.header(
33
31
  // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-argument
34
32
  {});
35
33
  header = obj.props.children;
36
34
  } else {
37
35
  header = column.columnDef.header;
38
36
  }
39
- } catch (_unused) {
37
+ } catch {
40
38
  /*em all*/
41
39
  }
42
40
  return header;
43
41
  }, [column.columnDef]);
44
- var columnFilterValue = column.getFilterValue();
45
- var sortedUniqueValues = useMemo(function () {
46
- return typeof firstValue === 'number' ? [] : Array.from(column.getFacetedUniqueValues().keys()).sort().map(function (v) {
47
- return v !== null && v !== void 0 ? v : 'NULL_OR_UNDEFINED';
48
- });
49
- },
42
+ const columnFilterValue = column.getFilterValue();
43
+ const sortedUniqueValues = useMemo(() => typeof firstValue === 'number' ? [] : Array.from(column.getFacetedUniqueValues().keys()).sort().map(v => v ?? 'NULL_OR_UNDEFINED'),
50
44
  // eslint-disable-next-line react-hooks/exhaustive-deps
51
45
  [column.getFacetedUniqueValues()]);
52
- var hasActiveFilters = function hasActiveFilters(value) {
46
+ const hasActiveFilters = value => {
53
47
  if (Array.isArray(value)) {
54
48
  if (typeof firstValue === 'number') {
55
- return value.some(function (v) {
56
- return !isNaN(v) && !!v;
57
- });
49
+ return value.some(v => !isNaN(v) && !!v);
58
50
  } else {
59
- return value.filter(function (v) {
60
- return !!v;
61
- }).length > 0;
51
+ return value.filter(v => !!v).length > 0;
62
52
  }
63
53
  }
64
54
  return value;
@@ -81,9 +71,7 @@ function Filter(_ref) {
81
71
  },
82
72
  anchorEl: filterIconRef.current,
83
73
  open: open,
84
- onClose: function onClose() {
85
- return setOpen(false);
86
- },
74
+ onClose: () => setOpen(false),
87
75
  children: /*#__PURE__*/jsx(Popover.Content, {
88
76
  style: {
89
77
  width: typeof firstValue === 'number' ? '180px' : '310px'
@@ -92,38 +80,28 @@ function Filter(_ref) {
92
80
  children: [/*#__PURE__*/jsx(DebouncedInput, {
93
81
  type: "number",
94
82
  values: sortedUniqueValues,
95
- min: Number((_column$getFacetedMin = (_column$getFacetedMin2 = column.getFacetedMinMaxValues()) === null || _column$getFacetedMin2 === void 0 ? void 0 : _column$getFacetedMin2[0]) !== null && _column$getFacetedMin !== void 0 ? _column$getFacetedMin : ''),
96
- max: Number((_column$getFacetedMin3 = (_column$getFacetedMin4 = column.getFacetedMinMaxValues()) === null || _column$getFacetedMin4 === void 0 ? void 0 : _column$getFacetedMin4[1]) !== null && _column$getFacetedMin3 !== void 0 ? _column$getFacetedMin3 : ''),
97
- value: (_ = columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue[0]) !== null && _ !== void 0 ? _ : '',
98
- onChange: function onChange(value) {
99
- return column.setFilterValue(function (old) {
100
- return [value, old === null || old === void 0 ? void 0 : old[1]];
101
- });
102
- },
103
- placeholder: "Min ".concat((_column$getFacetedMin5 = column.getFacetedMinMaxValues()) !== null && _column$getFacetedMin5 !== void 0 && _column$getFacetedMin5[0] ? "(".concat((_column$getFacetedMin6 = column.getFacetedMinMaxValues()) === null || _column$getFacetedMin6 === void 0 ? void 0 : _column$getFacetedMin6[0], ")") : '')
83
+ min: Number(column.getFacetedMinMaxValues()?.[0] ?? ''),
84
+ max: Number(column.getFacetedMinMaxValues()?.[1] ?? ''),
85
+ value: columnFilterValue?.[0] ?? '',
86
+ onChange: value => column.setFilterValue(old => [value, old?.[1]]),
87
+ placeholder: `Min ${column.getFacetedMinMaxValues()?.[0] ? `(${column.getFacetedMinMaxValues()?.[0]})` : ''}`
104
88
  }), /*#__PURE__*/jsx(DebouncedInput, {
105
89
  type: "number",
106
90
  values: sortedUniqueValues,
107
- min: Number((_column$getFacetedMin7 = (_column$getFacetedMin8 = column.getFacetedMinMaxValues()) === null || _column$getFacetedMin8 === void 0 ? void 0 : _column$getFacetedMin8[0]) !== null && _column$getFacetedMin7 !== void 0 ? _column$getFacetedMin7 : ''),
108
- max: Number((_column$getFacetedMin9 = (_column$getFacetedMin10 = column.getFacetedMinMaxValues()) === null || _column$getFacetedMin10 === void 0 ? void 0 : _column$getFacetedMin10[1]) !== null && _column$getFacetedMin9 !== void 0 ? _column$getFacetedMin9 : ''),
109
- value: (_2 = columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue[1]) !== null && _2 !== void 0 ? _2 : '',
110
- onChange: function onChange(value) {
111
- return column.setFilterValue(function (old) {
112
- return [old === null || old === void 0 ? void 0 : old[0], value];
113
- });
114
- },
115
- placeholder: "Max ".concat((_column$getFacetedMin11 = column.getFacetedMinMaxValues()) !== null && _column$getFacetedMin11 !== void 0 && _column$getFacetedMin11[1] ? "(".concat((_column$getFacetedMin12 = column.getFacetedMinMaxValues()) === null || _column$getFacetedMin12 === void 0 ? void 0 : _column$getFacetedMin12[1], ")") : '')
91
+ min: Number(column.getFacetedMinMaxValues()?.[0] ?? ''),
92
+ max: Number(column.getFacetedMinMaxValues()?.[1] ?? ''),
93
+ value: columnFilterValue?.[1] ?? '',
94
+ onChange: value => column.setFilterValue(old => [old?.[0], value]),
95
+ placeholder: `Max ${column.getFacetedMinMaxValues()?.[1] ? `(${column.getFacetedMinMaxValues()?.[1]})` : ''}`
116
96
  })]
117
97
  }) : /*#__PURE__*/jsx(DebouncedInput, {
118
98
  type: "text",
119
99
  label: columnText,
120
100
  values: sortedUniqueValues,
121
101
  debounce: 100,
122
- value: columnFilterValue !== null && columnFilterValue !== void 0 ? columnFilterValue : [],
123
- onChange: function onChange(value) {
124
- return column.setFilterValue(value);
125
- },
126
- placeholder: "".concat((columnFilterValue !== null && columnFilterValue !== void 0 ? columnFilterValue : []).length, " / ").concat(column.getFacetedUniqueValues().size, " selected"),
102
+ value: columnFilterValue ?? [],
103
+ onChange: value => column.setFilterValue(value),
104
+ placeholder: `${(columnFilterValue ?? []).length} / ${column.getFacetedUniqueValues().size} selected`,
127
105
  list: column.id + 'list'
128
106
  })
129
107
  })
@@ -1,42 +1,33 @@
1
- import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
1
  import { flexRender } from '@tanstack/react-table';
3
- import { Table, Typography } from '@equinor/eds-core-react';
2
+ import { Table } from '@equinor/eds-core-react';
4
3
  import { useTableContext } from '../EdsDataGridContext.js';
5
4
  import { useMemo } from 'react';
6
- import { tokens } from '@equinor/eds-tokens';
7
5
  import styled from 'styled-components';
8
6
  import { jsx } from 'react/jsx-runtime';
9
7
 
10
- var StyledCell = styled(Table.Cell).withConfig({
8
+ const StyledCell = styled(Table.Cell).withConfig({
11
9
  displayName: "TableBodyCell__StyledCell",
12
10
  componentId: "sc-1gsd2k4-0"
13
- })(["position:", ";", " z-index:", ";background-color:", ";overflow:hidden;white-space:nowrap;text-overflow:ellipsis;"], function (p) {
14
- return p.$pinned ? 'sticky' : 'relative';
15
- }, function (p) {
11
+ })(["position:", ";", " z-index:", ";background-color:inherit;"], p => p.$pinned ? 'sticky' : 'relative', p => {
16
12
  if (p.$pinned) {
17
- return "".concat(p.$pinned, ": ").concat(p.$offset, "px;");
13
+ return `${p.$pinned}: ${p.$offset}px;`;
18
14
  }
19
15
  return '';
20
- }, function (p) {
21
- return p.$pinned ? 11 : 'auto';
22
- }, function (p) {
23
- return p.$pinned ? tokens.colors.ui.background__default.hex : 'inherit';
24
- });
25
- function TableBodyCell(_ref) {
26
- var _cellStyle;
27
- var cell = _ref.cell;
28
- var _useTableContext = useTableContext(),
29
- cellClass = _useTableContext.cellClass,
30
- cellStyle = _useTableContext.cellStyle,
31
- table = _useTableContext.table;
32
- var pinned = cell.column.getIsPinned();
33
- var pinnedOffset = useMemo(function () {
16
+ }, p => p.$pinned ? 11 : 'auto');
17
+ function TableBodyCell({
18
+ cell
19
+ }) {
20
+ const {
21
+ cellClass,
22
+ cellStyle,
23
+ table
24
+ } = useTableContext();
25
+ const pinned = cell.column.getIsPinned();
26
+ const pinnedOffset = useMemo(() => {
34
27
  if (!pinned) {
35
28
  return 0;
36
29
  }
37
- var header = table.getFlatHeaders().find(function (h) {
38
- return h.id === cell.column.id;
39
- });
30
+ const header = table.getFlatHeaders().find(h => h.id === cell.column.id);
40
31
  return pinned === 'left' ? header.getStart() : table.getTotalSize() - header.getStart() - cell.column.getSize();
41
32
  }, [pinned, cell.column, table]);
42
33
  return /*#__PURE__*/jsx(StyledCell, {
@@ -44,16 +35,12 @@ function TableBodyCell(_ref) {
44
35
  $offset: pinnedOffset,
45
36
  className: cellClass ? cellClass(cell.row, cell.column.id) : '',
46
37
  key: cell.id,
47
- style: _objectSpread({
38
+ style: {
48
39
  width: cell.column.getSize(),
49
- maxWidth: cell.column.getSize()
50
- }, (_cellStyle = cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle(cell.row, cell.column.id)) !== null && _cellStyle !== void 0 ? _cellStyle : {}),
51
- children: /*#__PURE__*/jsx(Typography, {
52
- as: "span",
53
- group: "table",
54
- variant: "cell_text",
55
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
56
- })
40
+ maxWidth: cell.column.getSize(),
41
+ ...(cellStyle?.(cell.row, cell.column.id) ?? {})
42
+ },
43
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
57
44
  });
58
45
  }
59
46
 
@@ -1,4 +1,3 @@
1
- import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
1
  import { flexRender } from '@tanstack/react-table';
3
2
  import { Table, Icon } from '@equinor/eds-core-react';
4
3
  import { arrow_up, arrow_down } from '@equinor/eds-icons';
@@ -9,47 +8,40 @@ import { tokens } from '@equinor/eds-tokens';
9
8
  import { useMemo } from 'react';
10
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
11
10
 
12
- var getSortLabel = function getSortLabel(sorted) {
11
+ const getSortLabel = sorted => {
13
12
  if (sorted) {
14
- return "".concat(sorted, "ending");
13
+ return `${sorted}ending`;
15
14
  }
16
15
  return 'none';
17
16
  };
18
- var ResizeInner = styled.div.withConfig({
17
+ const ResizeInner = styled.div.withConfig({
19
18
  displayName: "TableHeaderCell__ResizeInner",
20
19
  componentId: "sc-1n0j3v0-0"
21
20
  })(["width:2px;opacity:0;height:100%;"]);
22
- var Resizer = styled.div.withConfig({
21
+ const Resizer = styled.div.withConfig({
23
22
  displayName: "TableHeaderCell__Resizer",
24
23
  componentId: "sc-1n0j3v0-1"
25
- })(["transform:", ";", "{opacity:", ";}position:absolute;right:0;top:0;height:100%;width:5px;cursor:col-resize;user-select:none;touch-action:none;display:flex;justify-content:flex-end;"], function (props) {
26
- return props.$columnResizeMode === 'onEnd' ? 'translateX(0px)' : 'none';
27
- }, ResizeInner, function (props) {
28
- return props.$isResizing ? 1 : 0;
29
- });
30
- var Cell = styled(Table.Cell).withConfig({
24
+ })(["transform:", ";", "{opacity:", ";}position:absolute;right:0;top:0;height:100%;width:5px;cursor:col-resize;user-select:none;touch-action:none;display:flex;justify-content:flex-end;"], props => props.$columnResizeMode === 'onEnd' ? 'translateX(0px)' : 'none', ResizeInner, props => props.$isResizing ? 1 : 0);
25
+ const Cell = styled(Table.Cell).withConfig({
31
26
  displayName: "TableHeaderCell__Cell",
32
27
  componentId: "sc-1n0j3v0-2"
33
- })(["font-weight:bold;height:30px;position:", ";top:0;", " z-index:", ";&:hover ", "{background:", ";opacity:1;}"], function (p) {
34
- return p.$sticky || p.$pinned ? 'sticky' : 'relative';
35
- }, function (p) {
28
+ })(["font-weight:bold;height:30px;position:", ";top:0;", " ", ";&:hover ", "{background:", ";opacity:1;}"], p => p.$sticky || p.$pinned ? 'sticky' : 'relative', p => {
36
29
  if (p.$pinned) {
37
- return "".concat(p.$pinned, ": ").concat(p.$offset, "px;");
30
+ return `${p.$pinned}: ${p.$offset}px;`;
38
31
  }
39
32
  return '';
40
- }, function (p) {
41
- if (p.$sticky && p.$pinned) return 13;
42
- if (p.$sticky || p.$pinned) return 12;
43
- return 'auto';
33
+ }, p => {
34
+ if (p.$sticky && p.$pinned) return 'z-index: 13';
35
+ if (p.$sticky || p.$pinned) return 'z-index: 12';
44
36
  }, ResizeInner, tokens.colors.interactive.primary__hover.rgba);
45
- function TableHeaderCell(_ref) {
46
- var _asc$desc;
47
- var header = _ref.header,
48
- columnResizeMode = _ref.columnResizeMode;
49
- var ctx = useTableContext();
50
- var table = ctx.table;
51
- var pinned = header.column.getIsPinned();
52
- var offset = useMemo(function () {
37
+ function TableHeaderCell({
38
+ header,
39
+ columnResizeMode
40
+ }) {
41
+ const ctx = useTableContext();
42
+ const table = ctx.table;
43
+ const pinned = header.column.getIsPinned();
44
+ const offset = useMemo(() => {
53
45
  if (!pinned) {
54
46
  return null;
55
47
  }
@@ -60,7 +52,9 @@ function TableHeaderCell(_ref) {
60
52
  $offset: offset,
61
53
  $pinned: pinned,
62
54
  className: ctx.headerClass ? ctx.headerClass(header.column) : '',
63
- style: _objectSpread({}, ctx.headerStyle ? ctx.headerStyle(header.column) : {}),
55
+ style: {
56
+ ...(ctx.headerStyle ? ctx.headerStyle(header.column) : {})
57
+ },
64
58
  "aria-hidden": true
65
59
  }) : /*#__PURE__*/jsxs(Cell, {
66
60
  $sticky: ctx.stickyHeader,
@@ -71,10 +65,11 @@ function TableHeaderCell(_ref) {
71
65
  onClick: header.column.getToggleSortingHandler(),
72
66
  key: header.id,
73
67
  colSpan: header.colSpan,
74
- style: _objectSpread({
68
+ style: {
75
69
  width: header.getSize(),
76
- verticalAlign: ctx.enableColumnFiltering ? 'top' : 'middle'
77
- }, ctx.headerStyle ? ctx.headerStyle(header.column) : {}),
70
+ verticalAlign: ctx.enableColumnFiltering ? 'top' : 'middle',
71
+ ...(ctx.headerStyle ? ctx.headerStyle(header.column) : {})
72
+ },
78
73
  children: [/*#__PURE__*/jsxs(Fragment, {
79
74
  children: [/*#__PURE__*/jsx("div", {
80
75
  style: {
@@ -85,30 +80,26 @@ function TableHeaderCell(_ref) {
85
80
  className: "table-header-cell-label",
86
81
  children: flexRender(header.column.columnDef.header, header.getContext())
87
82
  })
88
- }), (_asc$desc = {
83
+ }), {
89
84
  asc: /*#__PURE__*/jsx(Icon, {
90
85
  data: arrow_up
91
86
  }),
92
87
  desc: /*#__PURE__*/jsx(Icon, {
93
88
  data: arrow_down
94
89
  })
95
- }[header.column.getIsSorted()]) !== null && _asc$desc !== void 0 ? _asc$desc : null, header.column.getCanFilter() ?
90
+ }[header.column.getIsSorted()] ?? null, header.column.getCanFilter() ?
96
91
 
97
92
  // Supressing this warning - div is not interactive, but prevents propagation of events to avoid unintended sorting
98
93
  // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
99
94
  jsx("div", {
100
- onClick: function onClick(e) {
101
- return e.stopPropagation();
102
- },
95
+ onClick: e => e.stopPropagation(),
103
96
  children: /*#__PURE__*/jsx(Filter, {
104
97
  column: header.column,
105
98
  table: table
106
99
  })
107
100
  }) : null]
108
101
  }), columnResizeMode && /*#__PURE__*/jsx(Resizer, {
109
- onClick: function onClick(e) {
110
- return e.stopPropagation();
111
- },
102
+ onClick: e => e.stopPropagation(),
112
103
  onMouseDown: header.getResizeHandler(),
113
104
  onTouchStart: header.getResizeHandler(),
114
105
  $isResizing: header.column.getIsResizing(),
@@ -2,20 +2,19 @@ import { Table } from '@equinor/eds-core-react';
2
2
  import { TableHeaderCell } from './TableHeaderCell.js';
3
3
  import { jsx } from 'react/jsx-runtime';
4
4
 
5
- function TableHeaderRow(_ref) {
6
- var headerGroup = _ref.headerGroup,
7
- columnResizeMode = _ref.columnResizeMode,
8
- deltaOffset = _ref.deltaOffset,
9
- table = _ref.table;
5
+ function TableHeaderRow({
6
+ headerGroup,
7
+ columnResizeMode,
8
+ deltaOffset,
9
+ table
10
+ }) {
10
11
  return /*#__PURE__*/jsx(Table.Row, {
11
- children: headerGroup.headers.map(function (header) {
12
- return /*#__PURE__*/jsx(TableHeaderCell, {
13
- header: header,
14
- table: table,
15
- columnResizeMode: columnResizeMode,
16
- deltaOffset: deltaOffset
17
- }, header.id);
18
- })
12
+ children: headerGroup.headers.map(header => /*#__PURE__*/jsx(TableHeaderCell, {
13
+ header: header,
14
+ table: table,
15
+ columnResizeMode: columnResizeMode,
16
+ deltaOffset: deltaOffset
17
+ }, header.id))
19
18
  });
20
19
  }
21
20
 
@@ -1,29 +1,33 @@
1
- import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
1
  import { Table } from '@equinor/eds-core-react';
3
2
  import { TableBodyCell } from './TableBodyCell.js';
4
3
  import { useTableContext } from '../EdsDataGridContext.js';
4
+ import styled from 'styled-components';
5
5
  import { jsx } from 'react/jsx-runtime';
6
6
 
7
- function TableRow(_ref) {
8
- var _rowStyle;
9
- var row = _ref.row;
10
- var _useTableContext = useTableContext(),
11
- rowClass = _useTableContext.rowClass,
12
- rowStyle = _useTableContext.rowStyle;
13
- return /*#__PURE__*/jsx(Table.Row, {
14
- style: _objectSpread({
15
- cursor: row.getCanSelect() ? 'pointer' : 'inherit'
16
- }, (_rowStyle = rowStyle === null || rowStyle === void 0 ? void 0 : rowStyle(row)) !== null && _rowStyle !== void 0 ? _rowStyle : {}),
17
- className: "".concat(row.getIsSelected() ? 'selected' : '', " ").concat(rowClass === null || rowClass === void 0 ? void 0 : rowClass(row)),
18
- onClick: function onClick() {
19
- return row.getCanSelect() ? row.toggleSelected() : null;
7
+ function TableRow({
8
+ row
9
+ }) {
10
+ const {
11
+ rowClass,
12
+ rowStyle
13
+ } = useTableContext();
14
+ return /*#__PURE__*/jsx(StyledTableRow, {
15
+ style: {
16
+ cursor: row.getCanSelect() ? 'pointer' : 'inherit',
17
+ ...(rowStyle?.(row) ?? {})
20
18
  },
21
- children: row.getVisibleCells().map(function (cell) {
22
- return /*#__PURE__*/jsx(TableBodyCell, {
23
- cell: cell
24
- }, cell.id);
25
- })
19
+ className: `${row.getIsSelected() ? 'selected' : ''} ${rowClass?.(row)}`,
20
+ onClick: () => row.getCanSelect() ? row.toggleSelected() : null,
21
+ children: row.getVisibleCells().map(cell => /*#__PURE__*/jsx(TableBodyCell, {
22
+ cell: cell
23
+ }, cell.id))
26
24
  });
27
25
  }
28
26
 
27
+ // Neccessary to have this attribute as class to prevent overriding hover color
28
+ const StyledTableRow = styled(Table.Row).withConfig({
29
+ displayName: "TableRow__StyledTableRow",
30
+ componentId: "sc-1vjfq5p-0"
31
+ })(["background-color:inherit;"]);
32
+
29
33
  export { TableRow };
@@ -1,2 +1,2 @@
1
1
  import { EdsDataGridProps } from './EdsDataGridProps';
2
- export declare function EdsDataGrid<T>({ rows, columns, columnResizeMode, pageSize, rowSelection, selectedRows, enableColumnFiltering, debug, enablePagination, enableSorting, stickyHeader, onSelectRow, caption, enableVirtual, virtualHeight, columnVisibility, columnVisibilityChange, emptyMessage, columnOrder, cellClass, cellStyle, rowClass, rowStyle, headerClass, headerStyle, externalPaginator, onSortingChange, manualSorting, sortingState, columnPinState, scrollbarHorizontal, width, height, }: EdsDataGridProps<T>): import("react/jsx-runtime").JSX.Element;
2
+ export declare function EdsDataGrid<T>({ rows, columns, columnResizeMode, pageSize, rowSelection, selectedRows, enableColumnFiltering, debug, enablePagination, enableSorting, stickyHeader, onSelectRow, caption, enableVirtual, virtualHeight, columnVisibility, columnVisibilityChange, emptyMessage, columnOrder, cellClass, cellStyle, rowClass, rowStyle, headerClass, headerStyle, externalPaginator, onSortingChange, manualSorting, sortingState, columnPinState, scrollbarHorizontal, width, minWidth, height, getRowId, rowVirtualizerInstanceRef, }: EdsDataGridProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +1,6 @@
1
- import { Column, ColumnDef, ColumnPinningState, ColumnResizeMode, OnChangeFn, Row, RowSelectionState, SortingState } from '@tanstack/react-table';
2
- import { CSSProperties, ReactElement } from 'react';
1
+ import { Column, ColumnDef, ColumnPinningState, ColumnResizeMode, OnChangeFn, Row, RowSelectionState, SortingState, TableOptions } from '@tanstack/react-table';
2
+ import { Virtualizer } from '@tanstack/react-virtual';
3
+ import { CSSProperties, MutableRefObject, ReactElement } from 'react';
3
4
  type BaseProps<T> = {
4
5
  /**
5
6
  * The rows to display in the table
@@ -57,14 +58,32 @@ type BaseProps<T> = {
57
58
  scrollbarHorizontal?: boolean;
58
59
  /**
59
60
  * Width of the table. Only takes effect if {@link scrollbarHorizontal} is true.
61
+ *
62
+ * No suffix (like `px` or `rem`) equals to `px`.
60
63
  * @default 800
61
64
  */
62
- width?: number;
65
+ width?: string | number;
66
+ /**
67
+ * Min width of the table element.
68
+ *
69
+ * @example minWidth: 800
70
+ * @default none
71
+ */
72
+ minWidth?: string | number;
63
73
  /**
64
74
  * Height of the table.
75
+ *
76
+ * No suffix (like `px` or `rem`) equals to `px`.
65
77
  * @default none
66
78
  */
67
- height?: number;
79
+ height?: string | number;
80
+ /**
81
+ * This optional function is used to derive a unique ID for any given row. If not provided the rows index is used (nested rows join together with `.` using their grandparents' index eg. `index.index.index`). If you need to identify individual rows that are originating from any server-side operations, it's suggested you use this function to return an ID that makes sense regardless of network IO/ambiguity eg. a userId, taskId, database ID field, etc.
82
+ * @example getRowId: row => row.userId
83
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/table#getrowid)
84
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/tables)
85
+ */
86
+ getRowId?: TableOptions<T>['getRowId'];
68
87
  };
69
88
  type StyleProps<T> = {
70
89
  /**
@@ -163,7 +182,10 @@ type SortProps = {
163
182
  type ColumnProps = {
164
183
  columnPinState?: ColumnPinningState;
165
184
  };
166
- export type EdsDataGridProps<T> = BaseProps<T> & StyleProps<T> & SortProps & FilterProps & PagingProps & ColumnProps & VirtualProps & {
185
+ type RefProps = {
186
+ rowVirtualizerInstanceRef?: MutableRefObject<Virtualizer<HTMLDivElement, Element> | null>;
187
+ };
188
+ export type EdsDataGridProps<T> = BaseProps<T> & StyleProps<T> & SortProps & FilterProps & PagingProps & ColumnProps & VirtualProps & RefProps & {
167
189
  /**
168
190
  * Which columns are visible. If not set, all columns are visible. undefined means that the column is visible.
169
191
  * @default undefined
@@ -1,2 +1,3 @@
1
1
  export * from './EdsDataGrid';
2
2
  export * from './EdsDataGridProps';
3
+ export * from './types';
@@ -0,0 +1,3 @@
1
+ import type { Cell, CellContext, ColumnDef, ColumnPinningState, ColumnResizeMode, ColumnSort, ExpandedState, HeaderContext, OnChangeFn, Row, RowSelectionState, SortingState, Table, VisibilityState } from '@tanstack/react-table';
2
+ import type { Virtualizer } from '@tanstack/react-virtual';
3
+ export type { Cell, CellContext, ColumnDef, ColumnPinningState, ColumnResizeMode, ColumnSort, ExpandedState, HeaderContext, OnChangeFn, Row, RowSelectionState, SortingState, Table, VisibilityState, Virtualizer, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/eds-data-grid-react",
3
- "version": "0.2.0",
3
+ "version": "0.3.0-rc",
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",
@@ -16,15 +16,15 @@
16
16
  "peerDependencies": {
17
17
  "react": ">=16.8",
18
18
  "react-dom": ">=16.8",
19
- "styled-components": ">=4.2"
19
+ "styled-components": ">=4.2",
20
+ "@equinor/eds-core-react": "^0.35.1"
20
21
  },
21
22
  "dependencies": {
22
23
  "@tanstack/react-table": "^8.10.7",
23
- "@tanstack/react-virtual": "^3.0.0-beta.54",
24
- "@equinor/eds-core-react": "^0.35.0",
25
- "@equinor/eds-icons": "^0.20.0",
26
- "@equinor/eds-utils": "^0.8.3",
27
- "@equinor/eds-tokens": "0.9.2"
24
+ "@tanstack/react-virtual": "^3.0.1",
25
+ "@equinor/eds-icons": "^0.21.0",
26
+ "@equinor/eds-tokens": "0.9.2",
27
+ "@equinor/eds-utils": "^0.8.3"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@mdx-js/react": "2.3.0",
@@ -92,7 +92,6 @@
92
92
  "pnpm": ">=4",
93
93
  "node": ">=10.0.0"
94
94
  },
95
- "browserslist": "defaults, not IE 11",
96
95
  "scripts": {
97
96
  "build": "rollup -c --bundleConfigAsCjs && tsc -p tsconfig.build.json",
98
97
  "test": "tsc -p tsconfig.spec.json && jest",