@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.
- package/dist/eds-data-grid-react.cjs +458 -353
- package/dist/esm/EdsDataGrid.js +172 -159
- package/dist/esm/EdsDataGridContext.js +6 -9
- package/dist/esm/components/DebouncedInput.js +59 -47
- package/dist/esm/components/Filter.js +100 -46
- package/dist/esm/components/TableBodyCell.js +35 -20
- package/dist/esm/components/TableHeaderCell.js +65 -48
- package/dist/esm/components/TableHeaderRow.js +12 -13
- package/dist/esm/components/TableRow.js +23 -19
- package/dist/types/EdsDataGrid.d.ts +2 -133
- package/dist/types/EdsDataGridContext.d.ts +1 -1
- package/dist/types/EdsDataGridProps.d.ts +204 -0
- package/dist/types/components/DebouncedInput.d.ts +3 -2
- package/dist/types/components/Filter.d.ts +1 -1
- package/dist/types/components/TableBodyCell.d.ts +1 -1
- package/dist/types/components/TableHeaderCell.d.ts +1 -1
- package/dist/types/components/TableHeaderRow.d.ts +1 -1
- package/dist/types/components/TableRow.d.ts +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/types.d.ts +3 -0
- package/package.json +43 -45
|
@@ -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 {
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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:
|
|
38
|
+
style: {
|
|
17
39
|
width: cell.column.getSize(),
|
|
18
40
|
maxWidth: cell.column.getSize(),
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
11
|
+
const getSortLabel = sorted => {
|
|
12
12
|
if (sorted) {
|
|
13
|
-
return
|
|
13
|
+
return `${sorted}ending`;
|
|
14
14
|
}
|
|
15
15
|
return 'none';
|
|
16
16
|
};
|
|
17
|
-
|
|
18
|
-
displayName: "
|
|
17
|
+
const ResizeInner = styled.div.withConfig({
|
|
18
|
+
displayName: "TableHeaderCell__ResizeInner",
|
|
19
19
|
componentId: "sc-1n0j3v0-0"
|
|
20
|
-
})(["
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
})(["
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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:
|
|
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:
|
|
68
|
+
style: {
|
|
50
69
|
width: header.getSize(),
|
|
51
|
-
verticalAlign: ctx.enableColumnFiltering ? '
|
|
52
|
-
|
|
70
|
+
verticalAlign: ctx.enableColumnFiltering ? 'top' : 'middle',
|
|
71
|
+
...(ctx.headerStyle ? ctx.headerStyle(header.column) : {})
|
|
72
|
+
},
|
|
53
73
|
children: [/*#__PURE__*/jsxs(Fragment, {
|
|
54
|
-
children: [/*#__PURE__*/
|
|
74
|
+
children: [/*#__PURE__*/jsx("div", {
|
|
55
75
|
style: {
|
|
56
76
|
display: 'flex',
|
|
57
77
|
flexDirection: 'column'
|
|
58
78
|
},
|
|
59
|
-
children:
|
|
79
|
+
children: /*#__PURE__*/jsx("span", {
|
|
60
80
|
className: "table-header-cell-label",
|
|
61
81
|
children: flexRender(header.column.columnDef.header, header.getContext())
|
|
62
|
-
})
|
|
63
|
-
|
|
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()]
|
|
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:
|
|
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(
|
|
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,133 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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 {};
|