@equinor/eds-data-grid-react 0.1.0-beta.3 → 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,57 +1,111 @@
1
- import { useMemo } from 'react';
1
+ import { useState, useRef, useMemo } from 'react';
2
2
  import { DebouncedInput } from './DebouncedInput.js';
3
- import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { Button, Icon, Popover } from '@equinor/eds-core-react';
4
+ import { filter_alt_active, filter_alt } from '@equinor/eds-icons';
5
+ import styled from 'styled-components';
6
+ import { tokens } from '@equinor/eds-tokens';
7
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
4
8
 
5
9
  /* istanbul ignore file */
6
10
 
7
- function Filter(_ref) {
8
- 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;
9
- var column = _ref.column,
10
- table = _ref.table;
11
- var firstValue = (_table$getPreFiltered = table.getPreFilteredRowModel().flatRows[0]) === null || _table$getPreFiltered === void 0 ? void 0 : _table$getPreFiltered.getValue(column.id);
12
- var columnFilterValue = column.getFilterValue();
13
- var sortedUniqueValues = useMemo(function () {
14
- return typeof firstValue === 'number' ? [] : Array.from(column.getFacetedUniqueValues().keys()).sort().map(function (v) {
15
- return v !== null && v !== void 0 ? v : 'NULL_OR_UNDEFINED';
16
- });
17
- },
11
+ const NumberContainer = styled.div.withConfig({
12
+ displayName: "Filter__NumberContainer",
13
+ componentId: "sc-ytpdpw-0"
14
+ })(["display:grid;grid-template-columns:80px 80px;grid-column-gap:32px;"]);
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 => {
23
+ event.stopPropagation();
24
+ setOpen(!open);
25
+ };
26
+ const columnText = useMemo(() => {
27
+ let header;
28
+ try {
29
+ if (typeof column.columnDef.header === 'function') {
30
+ const obj = column.columnDef.header(
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-argument
32
+ {});
33
+ header = obj.props.children;
34
+ } else {
35
+ header = column.columnDef.header;
36
+ }
37
+ } catch {
38
+ /*em all*/
39
+ }
40
+ return header;
41
+ }, [column.columnDef]);
42
+ const columnFilterValue = column.getFilterValue();
43
+ const sortedUniqueValues = useMemo(() => typeof firstValue === 'number' ? [] : Array.from(column.getFacetedUniqueValues().keys()).sort().map(v => v ?? 'NULL_OR_UNDEFINED'),
18
44
  // eslint-disable-next-line react-hooks/exhaustive-deps
19
45
  [column.getFacetedUniqueValues()]);
20
- return typeof firstValue === 'number' ? /*#__PURE__*/jsxs("div", {
21
- children: [/*#__PURE__*/jsx(DebouncedInput, {
22
- type: "number",
23
- values: sortedUniqueValues,
24
- 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 : ''),
25
- 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 : ''),
26
- value: (_ = columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue[0]) !== null && _ !== void 0 ? _ : '',
27
- onChange: function onChange(value) {
28
- return column.setFilterValue(function (old) {
29
- return [value, old === null || old === void 0 ? void 0 : old[1]];
30
- });
46
+ const hasActiveFilters = value => {
47
+ if (Array.isArray(value)) {
48
+ if (typeof firstValue === 'number') {
49
+ return value.some(v => !isNaN(v) && !!v);
50
+ } else {
51
+ return value.filter(v => !!v).length > 0;
52
+ }
53
+ }
54
+ return value;
55
+ };
56
+ return /*#__PURE__*/jsxs(Fragment, {
57
+ children: [/*#__PURE__*/jsx(Button, {
58
+ "aria-haspopup": true,
59
+ "aria-expanded": open,
60
+ "data-testid": 'open-filters',
61
+ ref: filterIconRef,
62
+ onClick: togglePopover,
63
+ variant: 'ghost_icon',
64
+ children: /*#__PURE__*/jsx(Icon, {
65
+ color: tokens.colors.text.static_icons__default.hex,
66
+ data: hasActiveFilters(columnFilterValue) ? filter_alt_active : filter_alt
67
+ })
68
+ }), /*#__PURE__*/jsx(Popover, {
69
+ style: {
70
+ width: typeof firstValue === 'number' ? '220px' : '340px'
31
71
  },
32
- 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], ")") : '')
33
- }), /*#__PURE__*/jsx(DebouncedInput, {
34
- type: "number",
35
- values: sortedUniqueValues,
36
- 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 : ''),
37
- 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 : ''),
38
- value: (_2 = columnFilterValue === null || columnFilterValue === void 0 ? void 0 : columnFilterValue[1]) !== null && _2 !== void 0 ? _2 : '',
39
- onChange: function onChange(value) {
40
- return column.setFilterValue(function (old) {
41
- return [old === null || old === void 0 ? void 0 : old[0], value];
42
- });
43
- },
44
- 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], ")") : '')
72
+ anchorEl: filterIconRef.current,
73
+ open: open,
74
+ onClose: () => setOpen(false),
75
+ children: /*#__PURE__*/jsx(Popover.Content, {
76
+ style: {
77
+ width: typeof firstValue === 'number' ? '180px' : '310px'
78
+ },
79
+ children: typeof firstValue === 'number' ? /*#__PURE__*/jsxs(NumberContainer, {
80
+ children: [/*#__PURE__*/jsx(DebouncedInput, {
81
+ type: "number",
82
+ values: sortedUniqueValues,
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]})` : ''}`
88
+ }), /*#__PURE__*/jsx(DebouncedInput, {
89
+ type: "number",
90
+ values: sortedUniqueValues,
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]})` : ''}`
96
+ })]
97
+ }) : /*#__PURE__*/jsx(DebouncedInput, {
98
+ type: "text",
99
+ label: columnText,
100
+ values: sortedUniqueValues,
101
+ debounce: 100,
102
+ value: columnFilterValue ?? [],
103
+ onChange: value => column.setFilterValue(value),
104
+ placeholder: `${(columnFilterValue ?? []).length} / ${column.getFacetedUniqueValues().size} selected`,
105
+ list: column.id + 'list'
106
+ })
107
+ })
45
108
  })]
46
- }) : /*#__PURE__*/jsx(DebouncedInput, {
47
- type: "text",
48
- values: sortedUniqueValues,
49
- value: columnFilterValue !== null && columnFilterValue !== void 0 ? columnFilterValue : '',
50
- onChange: function onChange(value) {
51
- return column.setFilterValue(value);
52
- },
53
- placeholder: "Search (".concat(column.getFacetedUniqueValues().size, ")"),
54
- list: column.id + 'list'
55
109
  });
56
110
  }
57
111
 
@@ -1,31 +1,46 @@
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';
4
+ import { useMemo } from 'react';
5
+ import styled from 'styled-components';
5
6
  import { jsx } from 'react/jsx-runtime';
6
7
 
7
- function TableBodyCell(_ref) {
8
- var _cellStyle;
9
- var cell = _ref.cell;
10
- var _useTableContext = useTableContext(),
11
- cellClass = _useTableContext.cellClass,
12
- cellStyle = _useTableContext.cellStyle;
13
- return /*#__PURE__*/jsx(Table.Cell, {
8
+ const StyledCell = styled(Table.Cell).withConfig({
9
+ displayName: "TableBodyCell__StyledCell",
10
+ componentId: "sc-1gsd2k4-0"
11
+ })(["position:", ";", " z-index:", ";background-color:inherit;"], p => p.$pinned ? 'sticky' : 'relative', p => {
12
+ if (p.$pinned) {
13
+ return `${p.$pinned}: ${p.$offset}px;`;
14
+ }
15
+ return '';
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(() => {
27
+ if (!pinned) {
28
+ return 0;
29
+ }
30
+ const header = table.getFlatHeaders().find(h => h.id === cell.column.id);
31
+ return pinned === 'left' ? header.getStart() : table.getTotalSize() - header.getStart() - cell.column.getSize();
32
+ }, [pinned, cell.column, table]);
33
+ return /*#__PURE__*/jsx(StyledCell, {
34
+ $pinned: pinned,
35
+ $offset: pinnedOffset,
14
36
  className: cellClass ? cellClass(cell.row, cell.column.id) : '',
15
37
  key: cell.id,
16
- style: _objectSpread({
38
+ style: {
17
39
  width: cell.column.getSize(),
18
40
  maxWidth: cell.column.getSize(),
19
- overflow: 'hidden',
20
- whiteSpace: 'nowrap',
21
- textOverflow: 'ellipsis'
22
- }, (_cellStyle = cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle(cell.row, cell.column.id)) !== null && _cellStyle !== void 0 ? _cellStyle : {}),
23
- children: /*#__PURE__*/jsx(Typography, {
24
- as: "span",
25
- group: "table",
26
- variant: "cell_text",
27
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
28
- })
41
+ ...(cellStyle?.(cell.row, cell.column.id) ?? {})
42
+ },
43
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
29
44
  });
30
45
  }
31
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';
@@ -6,90 +5,108 @@ import { useTableContext } from '../EdsDataGridContext.js';
6
5
  import { Filter } from './Filter.js';
7
6
  import styled from 'styled-components';
8
7
  import { tokens } from '@equinor/eds-tokens';
8
+ import { useMemo } from 'react';
9
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
 
11
- var getSortLabel = function getSortLabel(sorted) {
11
+ const getSortLabel = sorted => {
12
12
  if (sorted) {
13
- return "".concat(sorted, "ending");
13
+ return `${sorted}ending`;
14
14
  }
15
15
  return 'none';
16
16
  };
17
- var Resizer = styled.div.withConfig({
18
- displayName: "TableHeaderCell__Resizer",
17
+ const ResizeInner = styled.div.withConfig({
18
+ displayName: "TableHeaderCell__ResizeInner",
19
19
  componentId: "sc-1n0j3v0-0"
20
- })(["transform:", ";opacity:", ";position:absolute;right:0;top:0;height:100%;width:5px;cursor:col-resize;user-select:none;touch-action:none;"], function (props) {
21
- return props.$columnResizeMode === 'onEnd' ? 'translateX(0px)' : 'none';
22
- }, function (props) {
23
- return props.$isResizing ? 1 : 0;
24
- });
25
- var Cell = styled(Table.Cell).withConfig({
26
- displayName: "TableHeaderCell__Cell",
20
+ })(["width:2px;opacity:0;height:100%;"]);
21
+ const Resizer = styled.div.withConfig({
22
+ displayName: "TableHeaderCell__Resizer",
27
23
  componentId: "sc-1n0j3v0-1"
28
- })(["font-weight:bold;height:30px;position:", ";&:hover ", "{background:", ";opacity:1;}"], function (p) {
29
- return p.sticky ? 'sticky' : 'relative';
30
- }, Resizer, tokens.colors.interactive.primary__hover.rgba);
31
- function TableHeaderCell(_ref) {
32
- var _asc$desc;
33
- var header = _ref.header,
34
- columnResizeMode = _ref.columnResizeMode;
35
- var ctx = useTableContext();
36
- var table = ctx.table;
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({
26
+ displayName: "TableHeaderCell__Cell",
27
+ componentId: "sc-1n0j3v0-2"
28
+ })(["font-weight:bold;height:30px;position:", ";top:0;", " ", ";&:hover ", "{background:", ";opacity:1;}"], p => p.$sticky || p.$pinned ? 'sticky' : 'relative', p => {
29
+ if (p.$pinned) {
30
+ return `${p.$pinned}: ${p.$offset}px;`;
31
+ }
32
+ return '';
33
+ }, p => {
34
+ if (p.$sticky && p.$pinned) return 'z-index: 13';
35
+ if (p.$sticky || p.$pinned) return 'z-index: 12';
36
+ }, ResizeInner, tokens.colors.interactive.primary__hover.rgba);
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(() => {
45
+ if (!pinned) {
46
+ return null;
47
+ }
48
+ return pinned === 'left' ? header.getStart() : table.getTotalSize() - header.getStart() - header.getSize();
49
+ }, [pinned, header, table]);
37
50
  return header.isPlaceholder ? /*#__PURE__*/jsx(Cell, {
38
- sticky: ctx.stickyHeader,
51
+ $sticky: ctx.stickyHeader,
52
+ $offset: offset,
53
+ $pinned: pinned,
39
54
  className: ctx.headerClass ? ctx.headerClass(header.column) : '',
40
- style: ctx.headerStyle ? ctx.headerStyle(header.column) : {},
55
+ style: {
56
+ ...(ctx.headerStyle ? ctx.headerStyle(header.column) : {})
57
+ },
41
58
  "aria-hidden": true
42
59
  }) : /*#__PURE__*/jsxs(Cell, {
43
- sticky: ctx.stickyHeader,
60
+ $sticky: ctx.stickyHeader,
61
+ $offset: offset,
62
+ $pinned: pinned,
44
63
  className: ctx.headerClass ? ctx.headerClass(header.column) : '',
45
64
  "aria-sort": getSortLabel(header.column.getIsSorted()),
46
65
  onClick: header.column.getToggleSortingHandler(),
47
66
  key: header.id,
48
67
  colSpan: header.colSpan,
49
- style: _objectSpread({
68
+ style: {
50
69
  width: header.getSize(),
51
- verticalAlign: ctx.enableColumnFiltering ? 'baseline' : 'middle'
52
- }, ctx.headerStyle ? ctx.headerStyle(header.column) : {}),
70
+ verticalAlign: ctx.enableColumnFiltering ? 'top' : 'middle',
71
+ ...(ctx.headerStyle ? ctx.headerStyle(header.column) : {})
72
+ },
53
73
  children: [/*#__PURE__*/jsxs(Fragment, {
54
- children: [/*#__PURE__*/jsxs("div", {
74
+ children: [/*#__PURE__*/jsx("div", {
55
75
  style: {
56
76
  display: 'flex',
57
77
  flexDirection: 'column'
58
78
  },
59
- children: [/*#__PURE__*/jsx("span", {
79
+ children: /*#__PURE__*/jsx("span", {
60
80
  className: "table-header-cell-label",
61
81
  children: flexRender(header.column.columnDef.header, header.getContext())
62
- }), header.column.getCanFilter() ?
63
- /*#__PURE__*/
64
- // Supressing this warning - div is not interactive, but prevents propagation of events to avoid unintended sorting
65
- // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
66
- jsx("div", {
67
- onClick: function onClick(e) {
68
- return e.stopPropagation();
69
- },
70
- children: /*#__PURE__*/jsx(Filter, {
71
- column: header.column,
72
- table: table
73
- })
74
- }) : null]
75
- }), (_asc$desc = {
82
+ })
83
+ }), {
76
84
  asc: /*#__PURE__*/jsx(Icon, {
77
85
  data: arrow_up
78
86
  }),
79
87
  desc: /*#__PURE__*/jsx(Icon, {
80
88
  data: arrow_down
81
89
  })
82
- }[header.column.getIsSorted()]) !== null && _asc$desc !== void 0 ? _asc$desc : null]
90
+ }[header.column.getIsSorted()] ?? null, header.column.getCanFilter() ?
91
+
92
+ // Supressing this warning - div is not interactive, but prevents propagation of events to avoid unintended sorting
93
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
94
+ jsx("div", {
95
+ onClick: e => e.stopPropagation(),
96
+ children: /*#__PURE__*/jsx(Filter, {
97
+ column: header.column,
98
+ table: table
99
+ })
100
+ }) : null]
83
101
  }), columnResizeMode && /*#__PURE__*/jsx(Resizer, {
84
- onClick: function onClick(e) {
85
- return e.stopPropagation();
86
- },
102
+ onClick: e => e.stopPropagation(),
87
103
  onMouseDown: header.getResizeHandler(),
88
104
  onTouchStart: header.getResizeHandler(),
89
105
  $isResizing: header.column.getIsResizing(),
90
106
  $columnResizeMode: columnResizeMode,
91
107
  className: 'resize-handle',
92
- "data-testid": 'resize-handle'
108
+ "data-testid": 'resize-handle',
109
+ children: /*#__PURE__*/jsx(ResizeInner, {})
93
110
  })]
94
111
  });
95
112
  }
@@ -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,133 +1,2 @@
1
- import { Column, ColumnDef, ColumnResizeMode, OnChangeFn, Row, RowSelectionState } from '@tanstack/react-table';
2
- import { CSSProperties, ReactElement } from 'react';
3
- export type EdsDataGridProps<T> = {
4
- /**
5
- * The rows to display in the table
6
- */
7
- rows: Array<T>;
8
- /**
9
- * Definition of the columns to display in the table
10
- */
11
- columns: ColumnDef<T>[];
12
- /**
13
- * The mode of column resizing. If not set, column resizing is disabled.
14
- * Can be either 'onChange' or 'onEnd'
15
- * @default undefined
16
- */
17
- columnResizeMode?: ColumnResizeMode;
18
- /**
19
- * Set this to enable rowSelection. If a function is provided, it will be called for each row to determine if it is selectable.
20
- * @default false
21
- */
22
- rowSelection?: boolean | ((row: Row<T>) => boolean);
23
- /**
24
- * Callback for when row-selection changes
25
- */
26
- onSelectRow?: OnChangeFn<RowSelectionState>;
27
- /**
28
- * Enable debug mode. See https://tanstack.com/table/v8/docs/api/core/table#debugall
29
- * @default false
30
- */
31
- debug?: boolean;
32
- /**
33
- * Enable sorting.
34
- * @default false
35
- */
36
- enableSorting?: boolean;
37
- /**
38
- * Make the table header sticky
39
- * @default false
40
- */
41
- stickyHeader?: boolean;
42
- /**
43
- * Element to display in Table.Caption
44
- * @default undefined
45
- */
46
- caption?: ReactElement;
47
- /**
48
- * Whether to enable column filtering, adding inputs to the header cells
49
- * Individual columns can be configured to disable filtering
50
- * @default false
51
- */
52
- enableColumnFiltering?: boolean;
53
- /**
54
- * Whether pagination should be enabled.
55
- * @default false
56
- */
57
- enablePagination?: boolean;
58
- /**
59
- * The number of rows per page
60
- * Only used if enablePagination is true
61
- * @default 25
62
- */
63
- pageSize?: number;
64
- /**
65
- * The message to display when there are no rows
66
- * @default undefined
67
- */
68
- emptyMessage?: string;
69
- /**
70
- * The currently selected rows
71
- * @default {}
72
- */
73
- selectedRows?: Record<string | number, boolean>;
74
- /**
75
- * Whether to enable virtualization. This will render only the visible rows currently in view.
76
- * @default false
77
- */
78
- enableVirtual?: boolean;
79
- /**
80
- * The height of the virtualized table in pixels.
81
- * @default 500
82
- */
83
- virtualHeight?: number;
84
- /**
85
- * Which columns are visible. If not set, all columns are visible. undefined means that the column is visible.
86
- * @default undefined
87
- */
88
- columnVisibility?: Record<string, boolean>;
89
- /**
90
- * Callback for when column visibility changes. Only called if columnVisibility is set.
91
- * @param columnVisibility
92
- */
93
- columnVisibilityChange?: (columnVisibility: Record<string, boolean>) => void;
94
- /**
95
- * An array of the columnIds in the order they should be displayed.
96
- */
97
- columnOrder?: Array<string>;
98
- /**
99
- * Function that can be used to set custom css on a cell
100
- * @param row
101
- * @param columnId
102
- */
103
- cellStyle?: (row: Row<T>, columnId: string) => CSSProperties;
104
- /**
105
- * Function that can be used to set a custom class on a cell
106
- * @param row
107
- * @param columnId
108
- * @returns string with list of classes
109
- */
110
- cellClass?: (row: Row<T>, columnId: string) => string;
111
- /**
112
- * Function that can be used to set a custom class on a row
113
- * @param row
114
- * @returns string with list of classes
115
- */
116
- rowClass?: (row: Row<T>) => string;
117
- /**
118
- * Function that can be used to set custom css on a row
119
- * @param row
120
- */
121
- rowStyle?: (row: Row<T>) => CSSProperties;
122
- /**
123
- * Function that can be used to set custom classes on a header cell
124
- * @param column
125
- */
126
- headerClass?: (column: Column<T>) => string;
127
- /**
128
- * Function that can be used to set custom styles on a header cell
129
- * @param column
130
- */
131
- headerStyle?: (column: Column<T>) => CSSProperties;
132
- };
133
- 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, }: EdsDataGridProps<T>): JSX.Element;
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, minWidth, height, getRowId, rowVirtualizerInstanceRef, }: EdsDataGridProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -15,6 +15,6 @@ type Context<T> = {
15
15
  export declare const EdsDataGridContext: import("react").Context<Context<any>>;
16
16
  export declare function TableProvider<T>({ children, ...props }: Context<T> & {
17
17
  children: ReactElement | Array<ReactElement>;
18
- }): JSX.Element;
18
+ }): import("react/jsx-runtime").JSX.Element;
19
19
  export declare const useTableContext: () => Context<any>;
20
20
  export {};