@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.
- package/dist/eds-data-grid-react.cjs +319 -405
- package/dist/esm/EdsDataGrid.js +163 -186
- package/dist/esm/EdsDataGridContext.js +6 -9
- package/dist/esm/components/DebouncedInput.js +33 -55
- package/dist/esm/components/Filter.js +34 -56
- package/dist/esm/components/TableBodyCell.js +21 -34
- package/dist/esm/components/TableHeaderCell.js +30 -39
- package/dist/esm/components/TableHeaderRow.js +12 -13
- package/dist/esm/components/TableRow.js +23 -19
- package/dist/types/EdsDataGrid.d.ts +1 -1
- package/dist/types/EdsDataGridProps.d.ts +27 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types.d.ts +3 -0
- package/package.json +7 -8
|
@@ -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
|
-
|
|
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(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
29
|
-
|
|
26
|
+
const columnText = useMemo(() => {
|
|
27
|
+
let header;
|
|
30
28
|
try {
|
|
31
29
|
if (typeof column.columnDef.header === 'function') {
|
|
32
|
-
|
|
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
|
|
37
|
+
} catch {
|
|
40
38
|
/*em all*/
|
|
41
39
|
}
|
|
42
40
|
return header;
|
|
43
41
|
}, [column.columnDef]);
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
46
|
+
const hasActiveFilters = value => {
|
|
53
47
|
if (Array.isArray(value)) {
|
|
54
48
|
if (typeof firstValue === 'number') {
|
|
55
|
-
return value.some(
|
|
56
|
-
return !isNaN(v) && !!v;
|
|
57
|
-
});
|
|
49
|
+
return value.some(v => !isNaN(v) && !!v);
|
|
58
50
|
} else {
|
|
59
|
-
return value.filter(
|
|
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:
|
|
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(
|
|
96
|
-
max: Number(
|
|
97
|
-
value:
|
|
98
|
-
onChange:
|
|
99
|
-
|
|
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(
|
|
108
|
-
max: Number(
|
|
109
|
-
value:
|
|
110
|
-
onChange:
|
|
111
|
-
|
|
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
|
|
123
|
-
onChange:
|
|
124
|
-
|
|
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
|
|
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
|
-
|
|
8
|
+
const StyledCell = styled(Table.Cell).withConfig({
|
|
11
9
|
displayName: "TableBodyCell__StyledCell",
|
|
12
10
|
componentId: "sc-1gsd2k4-0"
|
|
13
|
-
})(["position:", ";", " z-index:", ";background-color:
|
|
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
|
|
13
|
+
return `${p.$pinned}: ${p.$offset}px;`;
|
|
18
14
|
}
|
|
19
15
|
return '';
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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:
|
|
38
|
+
style: {
|
|
48
39
|
width: cell.column.getSize(),
|
|
49
|
-
maxWidth: cell.column.getSize()
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
11
|
+
const getSortLabel = sorted => {
|
|
13
12
|
if (sorted) {
|
|
14
|
-
return
|
|
13
|
+
return `${sorted}ending`;
|
|
15
14
|
}
|
|
16
15
|
return 'none';
|
|
17
16
|
};
|
|
18
|
-
|
|
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
|
-
|
|
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;"],
|
|
26
|
-
|
|
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;", "
|
|
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
|
|
30
|
+
return `${p.$pinned}: ${p.$offset}px;`;
|
|
38
31
|
}
|
|
39
32
|
return '';
|
|
40
|
-
},
|
|
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(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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:
|
|
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:
|
|
68
|
+
style: {
|
|
75
69
|
width: header.getSize(),
|
|
76
|
-
verticalAlign: ctx.enableColumnFiltering ? 'top' : 'middle'
|
|
77
|
-
|
|
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
|
-
}),
|
|
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()]
|
|
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:
|
|
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:
|
|
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(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
function TableHeaderRow({
|
|
6
|
+
headerGroup,
|
|
7
|
+
columnResizeMode,
|
|
8
|
+
deltaOffset,
|
|
9
|
+
table
|
|
10
|
+
}) {
|
|
10
11
|
return /*#__PURE__*/jsx(Table.Row, {
|
|
11
|
-
children: headerGroup.headers.map(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
rowClass
|
|
12
|
-
rowStyle
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
24
|
-
"@equinor/eds-
|
|
25
|
-
"@equinor/eds-
|
|
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",
|