@equinor/eds-data-grid-react 0.2.0 → 0.3.0
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 +372 -408
- package/dist/esm/EdsDataGrid.js +192 -189
- 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/esm/utils.js +27 -0
- package/dist/types/EdsDataGrid.d.ts +1 -1
- package/dist/types/EdsDataGridProps.d.ts +29 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types.d.ts +3 -0
- package/dist/types/utils.d.ts +18 -0
- package/package.json +5 -6
|
@@ -1,34 +1,26 @@
|
|
|
1
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
3
1
|
import { useState, useEffect } from 'react';
|
|
4
2
|
import { InputWrapper, Input, Autocomplete, Chip } from '@equinor/eds-core-react';
|
|
5
3
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
/* istanbul ignore file */
|
|
8
6
|
// File ignored, as relevant actions are covered via Filter.test.tsx
|
|
9
|
-
function DebouncedInput(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
-
value = _useState2[0],
|
|
21
|
-
setValue = _useState2[1];
|
|
22
|
-
useEffect(function () {
|
|
7
|
+
function DebouncedInput({
|
|
8
|
+
value: initialValue,
|
|
9
|
+
values,
|
|
10
|
+
onChange,
|
|
11
|
+
debounce = 500,
|
|
12
|
+
label,
|
|
13
|
+
...props
|
|
14
|
+
}) {
|
|
15
|
+
const [value, setValue] = useState(initialValue);
|
|
16
|
+
useEffect(() => {
|
|
23
17
|
setValue(initialValue);
|
|
24
18
|
}, [initialValue]);
|
|
25
|
-
useEffect(
|
|
26
|
-
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const timeout = setTimeout(() => {
|
|
27
21
|
onChange(value);
|
|
28
22
|
}, debounce);
|
|
29
|
-
return
|
|
30
|
-
return clearTimeout(timeout);
|
|
31
|
-
};
|
|
23
|
+
return () => clearTimeout(timeout);
|
|
32
24
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
25
|
}, [value]);
|
|
34
26
|
return /*#__PURE__*/jsx(Fragment, {
|
|
@@ -38,55 +30,41 @@ function DebouncedInput(_ref) {
|
|
|
38
30
|
type: 'number',
|
|
39
31
|
placeholder: '0',
|
|
40
32
|
value: value,
|
|
41
|
-
onChange:
|
|
42
|
-
return setValue(e.target.valueAsNumber);
|
|
43
|
-
}
|
|
33
|
+
onChange: e => setValue(e.target.valueAsNumber)
|
|
44
34
|
})
|
|
45
35
|
}) : /*#__PURE__*/jsxs(Fragment, {
|
|
46
36
|
children: [/*#__PURE__*/jsx(Autocomplete, {
|
|
47
37
|
options: values,
|
|
48
38
|
autoWidth: true,
|
|
49
39
|
multiple: true,
|
|
50
|
-
optionComponent:
|
|
51
|
-
return opt === 'NULL_OR_UNDEFINED' ? '<Blank>' : opt;
|
|
52
|
-
},
|
|
40
|
+
optionComponent: opt => opt === 'NULL_OR_UNDEFINED' ? '<Blank>' : opt,
|
|
53
41
|
"data-testid": 'autocomplete'
|
|
54
42
|
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */,
|
|
55
|
-
label:
|
|
56
|
-
placeholder:
|
|
43
|
+
label: `Select ${label ?? ''}`,
|
|
44
|
+
placeholder: props.placeholder ?? 'Search',
|
|
57
45
|
disablePortal: false /*TODO: Check with Oddbjørn re. sizing/position*/,
|
|
58
|
-
|
|
59
46
|
selectedOptions: value,
|
|
60
|
-
onOptionsChange:
|
|
61
|
-
|
|
62
|
-
}
|
|
47
|
+
onOptionsChange: c => setValue(c.selectedItems),
|
|
48
|
+
multiline: true
|
|
63
49
|
}), /*#__PURE__*/jsx("div", {
|
|
64
50
|
style: {
|
|
65
51
|
display: 'flex',
|
|
66
52
|
flexWrap: 'wrap',
|
|
67
53
|
marginTop: '8px'
|
|
68
54
|
},
|
|
69
|
-
children: value.map(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
onDelete: function onDelete() {
|
|
83
|
-
return onChange(value.filter(function (item) {
|
|
84
|
-
return item !== v;
|
|
85
|
-
}));
|
|
86
|
-
},
|
|
87
|
-
children: [v.slice(0, 20), v.length > 20 ? '...' : '']
|
|
88
|
-
}, v);
|
|
89
|
-
})
|
|
55
|
+
children: value.map(v => /*#__PURE__*/jsxs(Chip, {
|
|
56
|
+
title: v,
|
|
57
|
+
onKeyDownCapture: event => {
|
|
58
|
+
if (['Backspace', 'Delete'].includes(event.key)) {
|
|
59
|
+
onChange(value.filter(item => item !== v));
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
style: {
|
|
63
|
+
margin: '4px'
|
|
64
|
+
},
|
|
65
|
+
onDelete: () => onChange(value.filter(item => item !== v)),
|
|
66
|
+
children: [v.slice(0, 20), v.length > 20 ? '...' : '']
|
|
67
|
+
}, v))
|
|
90
68
|
})]
|
|
91
69
|
})
|
|
92
70
|
});
|
|
@@ -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 };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function returning wether a string only contains number. Allows leading or trailing spaces.
|
|
3
|
+
*
|
|
4
|
+
* Examples:
|
|
5
|
+
*
|
|
6
|
+
* ```
|
|
7
|
+
* isNumberOnlyString("10") // true
|
|
8
|
+
* isNumberOnlyString("10.10") // true
|
|
9
|
+
* isNumberOnlyString("10px") // false
|
|
10
|
+
* isNumberOnlyString("10%") // false
|
|
11
|
+
* isNumberOnlyString("10 ") // true
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param number
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
function isNumberOnlyString(number) {
|
|
18
|
+
return !isNaN(Number(number)) && !isNaN(parseFloat(number));
|
|
19
|
+
}
|
|
20
|
+
function addPxSuffixIfInputHasNoPrefix(size) {
|
|
21
|
+
if (typeof size === 'number' || isNumberOnlyString(size)) {
|
|
22
|
+
return `${size}px`;
|
|
23
|
+
}
|
|
24
|
+
return size;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { addPxSuffixIfInputHasNoPrefix, isNumberOnlyString };
|
|
@@ -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, columnSizing, onColumnResize, }: EdsDataGridProps<T>): import("react/jsx-runtime").JSX.Element;
|