@equinor/apollo-components 1.5.1 → 1.6.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/index.d.ts +19 -3
- package/dist/index.js +51 -16
- package/dist/index.mjs +49 -16
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IconData } from '@equinor/eds-icons';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { ReactNode, ComponentProps } from 'react';
|
|
4
|
-
import { Cell, CellContext, ColumnDef, Row, RowSelectionState, SortingState } from '@tanstack/react-table';
|
|
4
|
+
import { Cell, CellContext, ColumnDef, Row, RowSelectionState, SortingState, Table, HeaderContext } from '@tanstack/react-table';
|
|
5
5
|
import { ColumnDef as ColumnDef$1 } from '@tanstack/table-core';
|
|
6
6
|
import * as styled_components from 'styled-components';
|
|
7
7
|
import { CellProps, TypographyProps as TypographyProps$1 } from '@equinor/eds-core-react';
|
|
@@ -25,8 +25,9 @@ declare const ChipsCell: (props: {
|
|
|
25
25
|
declare type TableCellProps<T> = {
|
|
26
26
|
cell: Cell<T, unknown>;
|
|
27
27
|
highlight?: boolean;
|
|
28
|
+
getStickyCellColor?: (cell: Cell<T, unknown>) => string;
|
|
28
29
|
};
|
|
29
|
-
declare function DynamicCell<T>({ cell, highlight }: TableCellProps<T>): JSX.Element;
|
|
30
|
+
declare function DynamicCell<T>({ cell, highlight, getStickyCellColor }: TableCellProps<T>): JSX.Element;
|
|
30
31
|
|
|
31
32
|
declare type HierarchyCellOptions = {
|
|
32
33
|
getRowDepth?: () => number;
|
|
@@ -42,6 +43,7 @@ interface HeaderConfig {
|
|
|
42
43
|
interface FilterConfig {
|
|
43
44
|
globalFilter?: boolean;
|
|
44
45
|
globalFilterPlaceholder?: string;
|
|
46
|
+
filterFromLeafRows?: boolean;
|
|
45
47
|
}
|
|
46
48
|
declare type RowSelectionMode = 'single' | 'multiple';
|
|
47
49
|
declare type DataTableConfig<T> = {
|
|
@@ -84,6 +86,20 @@ declare const tableSortingAtom: jotai.PrimitiveAtom<SortingState> & {
|
|
|
84
86
|
init: SortingState;
|
|
85
87
|
};
|
|
86
88
|
|
|
89
|
+
interface TableHeaderProps<T> {
|
|
90
|
+
table: Table<T>;
|
|
91
|
+
sticky?: boolean;
|
|
92
|
+
}
|
|
93
|
+
declare function TableHeader<T>({ table, sticky }: TableHeaderProps<T>): JSX.Element;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Capitalize the table header.
|
|
97
|
+
*
|
|
98
|
+
* React table utility function.
|
|
99
|
+
* @param context
|
|
100
|
+
* @returns A capitalized header
|
|
101
|
+
*/
|
|
102
|
+
declare function capitalizeHeader<T>(context: HeaderContext<T, any>): string;
|
|
87
103
|
/** Prepend a column definition array with a select column. */
|
|
88
104
|
declare function prependSelectColumn<T>(columns: ColumnDef<T>[], config?: DataTableConfig<T>): ColumnDef<T, unknown>[];
|
|
89
105
|
|
|
@@ -107,4 +123,4 @@ declare type TypographyProps = {
|
|
|
107
123
|
*/
|
|
108
124
|
declare const TypographyCustom: (props: TypographyProps) => JSX.Element;
|
|
109
125
|
|
|
110
|
-
export { AppShell, AppSidebar, ChipsCell, DataTable, DataTableConfig, DynamicCell, FilterConfig, HeaderConfig, HierarchyCell, RowSelectionMode, SelectColumnDef, StickyCell, TypographyCustom, globalFilterAtom, prependSelectColumn, rowSelectionAtom, tableSortingAtom };
|
|
126
|
+
export { AppShell, AppSidebar, ChipsCell, DataTable, DataTableConfig, DynamicCell, FilterConfig, HeaderConfig, HierarchyCell, RowSelectionMode, SelectColumnDef, StickyCell, TableHeader, TypographyCustom, capitalizeHeader, globalFilterAtom, prependSelectColumn, rowSelectionAtom, tableSortingAtom };
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,9 @@ __export(src_exports, {
|
|
|
34
34
|
HierarchyCell: () => HierarchyCell,
|
|
35
35
|
SelectColumnDef: () => SelectColumnDef,
|
|
36
36
|
StickyCell: () => StickyCell,
|
|
37
|
+
TableHeader: () => TableHeader,
|
|
37
38
|
TypographyCustom: () => TypographyCustom,
|
|
39
|
+
capitalizeHeader: () => capitalizeHeader,
|
|
38
40
|
globalFilterAtom: () => globalFilterAtom,
|
|
39
41
|
prependSelectColumn: () => prependSelectColumn,
|
|
40
42
|
rowSelectionAtom: () => rowSelectionAtom,
|
|
@@ -222,13 +224,14 @@ var StyledStickyCell = (0, import_styled_components6.default)(StickyCell)`
|
|
|
222
224
|
${leftCellShadow}
|
|
223
225
|
`;
|
|
224
226
|
var StyledCell = (0, import_styled_components6.default)(import_eds_core_react4.Table.Cell)`
|
|
225
|
-
|
|
227
|
+
${(props) => props.backgroundColor ? `background-color: ${props.backgroundColor} !important;` : ``}
|
|
226
228
|
`;
|
|
227
|
-
function DynamicCell({ cell, highlight }) {
|
|
229
|
+
function DynamicCell({ cell, highlight, getStickyCellColor }) {
|
|
228
230
|
var _a;
|
|
229
231
|
const cellContent = (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext());
|
|
230
232
|
if ((_a = cell.column.columnDef.meta) == null ? void 0 : _a.sticky) {
|
|
231
233
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(StyledStickyCell, {
|
|
234
|
+
backgroundColor: getStickyCellColor == null ? void 0 : getStickyCellColor(cell),
|
|
232
235
|
"data-column": cell.column.id,
|
|
233
236
|
children: cellContent
|
|
234
237
|
});
|
|
@@ -458,22 +461,31 @@ var HeaderDiv = import_styled_components11.default.div`
|
|
|
458
461
|
display: flex;
|
|
459
462
|
align-items: center;
|
|
460
463
|
gap: 0.25rem;
|
|
464
|
+
z-index: 5;
|
|
461
465
|
`;
|
|
462
466
|
var StyledStickyCell2 = (0, import_styled_components11.default)(StickyCell)`
|
|
463
|
-
z-index: 5;
|
|
464
467
|
${leftCellShadow}
|
|
465
468
|
`;
|
|
466
469
|
var HeaderCell = ({ header }) => {
|
|
467
470
|
var _a;
|
|
471
|
+
const style = {
|
|
472
|
+
width: header.column.getSize() === -1 ? "auto" : header.column.getSize()
|
|
473
|
+
};
|
|
474
|
+
const cellProps = {
|
|
475
|
+
style,
|
|
476
|
+
sort: getSort(header),
|
|
477
|
+
onClick: header.column.getToggleSortingHandler(),
|
|
478
|
+
colSpan: header.colSpan
|
|
479
|
+
};
|
|
468
480
|
if ((_a = header.column.columnDef.meta) == null ? void 0 : _a.sticky)
|
|
469
481
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(StyledStickyCell2, {
|
|
470
|
-
|
|
482
|
+
...cellProps,
|
|
471
483
|
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(HeaderContent, {
|
|
472
484
|
header
|
|
473
485
|
})
|
|
474
486
|
}, header.id);
|
|
475
487
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_eds_core_react8.Table.Cell, {
|
|
476
|
-
|
|
488
|
+
...cellProps,
|
|
477
489
|
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(HeaderContent, {
|
|
478
490
|
header
|
|
479
491
|
})
|
|
@@ -483,31 +495,47 @@ function HeaderContent({ header }) {
|
|
|
483
495
|
if (header.isPlaceholder)
|
|
484
496
|
return null;
|
|
485
497
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(HeaderDiv, {
|
|
486
|
-
onClick: header.column.getToggleSortingHandler(),
|
|
487
498
|
children: [
|
|
488
499
|
(0, import_react_table2.flexRender)(header.column.columnDef.header, header.getContext()),
|
|
489
500
|
{
|
|
490
501
|
asc: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_eds_core_react8.Icon, {
|
|
491
|
-
data: import_eds_icons4.
|
|
502
|
+
data: import_eds_icons4.arrow_drop_up
|
|
492
503
|
}),
|
|
493
504
|
desc: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_eds_core_react8.Icon, {
|
|
494
|
-
data: import_eds_icons4.
|
|
505
|
+
data: import_eds_icons4.arrow_drop_down
|
|
506
|
+
}),
|
|
507
|
+
none: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_eds_core_react8.Icon, {
|
|
508
|
+
data: import_eds_icons4.arrow_drop_down
|
|
495
509
|
})
|
|
496
510
|
}[header.column.getIsSorted()] ?? null
|
|
497
511
|
]
|
|
498
512
|
});
|
|
499
513
|
}
|
|
514
|
+
function getSort({ column }) {
|
|
515
|
+
if (!column.getCanSort())
|
|
516
|
+
return void 0;
|
|
517
|
+
switch (column.getIsSorted()) {
|
|
518
|
+
case "asc":
|
|
519
|
+
return "ascending";
|
|
520
|
+
case "desc":
|
|
521
|
+
return "descending";
|
|
522
|
+
default:
|
|
523
|
+
return "none";
|
|
524
|
+
}
|
|
525
|
+
}
|
|
500
526
|
|
|
501
527
|
// src/DataTable/components/TableHeader.tsx
|
|
502
528
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
children:
|
|
507
|
-
header
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
})
|
|
529
|
+
function TableHeader({ table, sticky }) {
|
|
530
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_eds_core_react9.Table.Head, {
|
|
531
|
+
sticky,
|
|
532
|
+
children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_eds_core_react9.Table.Row, {
|
|
533
|
+
children: headerGroup.headers.map((header) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(HeaderCell, {
|
|
534
|
+
header
|
|
535
|
+
}, header.id))
|
|
536
|
+
}, headerGroup.id))
|
|
537
|
+
});
|
|
538
|
+
}
|
|
511
539
|
|
|
512
540
|
// src/DataTable/components/BasicTable.tsx
|
|
513
541
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
@@ -543,6 +571,10 @@ var import_react2 = require("react");
|
|
|
543
571
|
var import_styled_components12 = __toESM(require("styled-components"));
|
|
544
572
|
|
|
545
573
|
// src/DataTable/utils.tsx
|
|
574
|
+
function capitalizeHeader(context) {
|
|
575
|
+
const header = context.header.id;
|
|
576
|
+
return header.charAt(0).toUpperCase() + header.slice(1);
|
|
577
|
+
}
|
|
546
578
|
function enableOrUndefined(enabled, value) {
|
|
547
579
|
return Boolean(enabled) ? value : void 0;
|
|
548
580
|
}
|
|
@@ -879,6 +911,7 @@ function DataTable({
|
|
|
879
911
|
enableExpanding: !(config == null ? void 0 : config.hideExpandControls),
|
|
880
912
|
enableMultiRowSelection: (config == null ? void 0 : config.rowSelectionMode) === "multiple",
|
|
881
913
|
enableSubRowSelection: (config == null ? void 0 : config.rowSelectionMode) !== "single",
|
|
914
|
+
filterFromLeafRows: filters == null ? void 0 : filters.filterFromLeafRows,
|
|
882
915
|
getFilteredRowModel: enableGlobalFilter((0, import_react_table5.getFilteredRowModel)()),
|
|
883
916
|
getCoreRowModel: (0, import_react_table5.getCoreRowModel)(),
|
|
884
917
|
getExpandedRowModel: (0, import_react_table5.getExpandedRowModel)(),
|
|
@@ -954,7 +987,9 @@ DataTable2.Provider = DataTableProvider;
|
|
|
954
987
|
HierarchyCell,
|
|
955
988
|
SelectColumnDef,
|
|
956
989
|
StickyCell,
|
|
990
|
+
TableHeader,
|
|
957
991
|
TypographyCustom,
|
|
992
|
+
capitalizeHeader,
|
|
958
993
|
globalFilterAtom,
|
|
959
994
|
prependSelectColumn,
|
|
960
995
|
rowSelectionAtom,
|
package/dist/index.mjs
CHANGED
|
@@ -178,13 +178,14 @@ var StyledStickyCell = styled5(StickyCell)`
|
|
|
178
178
|
${leftCellShadow}
|
|
179
179
|
`;
|
|
180
180
|
var StyledCell = styled5(Table2.Cell)`
|
|
181
|
-
|
|
181
|
+
${(props) => props.backgroundColor ? `background-color: ${props.backgroundColor} !important;` : ``}
|
|
182
182
|
`;
|
|
183
|
-
function DynamicCell({ cell, highlight }) {
|
|
183
|
+
function DynamicCell({ cell, highlight, getStickyCellColor }) {
|
|
184
184
|
var _a;
|
|
185
185
|
const cellContent = flexRender(cell.column.columnDef.cell, cell.getContext());
|
|
186
186
|
if ((_a = cell.column.columnDef.meta) == null ? void 0 : _a.sticky) {
|
|
187
187
|
return /* @__PURE__ */ jsx4(StyledStickyCell, {
|
|
188
|
+
backgroundColor: getStickyCellColor == null ? void 0 : getStickyCellColor(cell),
|
|
188
189
|
"data-column": cell.column.id,
|
|
189
190
|
children: cellContent
|
|
190
191
|
});
|
|
@@ -422,22 +423,31 @@ var HeaderDiv = styled10.div`
|
|
|
422
423
|
display: flex;
|
|
423
424
|
align-items: center;
|
|
424
425
|
gap: 0.25rem;
|
|
426
|
+
z-index: 5;
|
|
425
427
|
`;
|
|
426
428
|
var StyledStickyCell2 = styled10(StickyCell)`
|
|
427
|
-
z-index: 5;
|
|
428
429
|
${leftCellShadow}
|
|
429
430
|
`;
|
|
430
431
|
var HeaderCell = ({ header }) => {
|
|
431
432
|
var _a;
|
|
433
|
+
const style = {
|
|
434
|
+
width: header.column.getSize() === -1 ? "auto" : header.column.getSize()
|
|
435
|
+
};
|
|
436
|
+
const cellProps = {
|
|
437
|
+
style,
|
|
438
|
+
sort: getSort(header),
|
|
439
|
+
onClick: header.column.getToggleSortingHandler(),
|
|
440
|
+
colSpan: header.colSpan
|
|
441
|
+
};
|
|
432
442
|
if ((_a = header.column.columnDef.meta) == null ? void 0 : _a.sticky)
|
|
433
443
|
return /* @__PURE__ */ jsx9(StyledStickyCell2, {
|
|
434
|
-
|
|
444
|
+
...cellProps,
|
|
435
445
|
children: /* @__PURE__ */ jsx9(HeaderContent, {
|
|
436
446
|
header
|
|
437
447
|
})
|
|
438
448
|
}, header.id);
|
|
439
449
|
return /* @__PURE__ */ jsx9(Table4.Cell, {
|
|
440
|
-
|
|
450
|
+
...cellProps,
|
|
441
451
|
children: /* @__PURE__ */ jsx9(HeaderContent, {
|
|
442
452
|
header
|
|
443
453
|
})
|
|
@@ -447,31 +457,47 @@ function HeaderContent({ header }) {
|
|
|
447
457
|
if (header.isPlaceholder)
|
|
448
458
|
return null;
|
|
449
459
|
return /* @__PURE__ */ jsxs6(HeaderDiv, {
|
|
450
|
-
onClick: header.column.getToggleSortingHandler(),
|
|
451
460
|
children: [
|
|
452
461
|
flexRender2(header.column.columnDef.header, header.getContext()),
|
|
453
462
|
{
|
|
454
463
|
asc: /* @__PURE__ */ jsx9(Icon4, {
|
|
455
|
-
data:
|
|
464
|
+
data: arrow_drop_up
|
|
456
465
|
}),
|
|
457
466
|
desc: /* @__PURE__ */ jsx9(Icon4, {
|
|
458
|
-
data:
|
|
467
|
+
data: arrow_drop_down
|
|
468
|
+
}),
|
|
469
|
+
none: /* @__PURE__ */ jsx9(Icon4, {
|
|
470
|
+
data: arrow_drop_down
|
|
459
471
|
})
|
|
460
472
|
}[header.column.getIsSorted()] ?? null
|
|
461
473
|
]
|
|
462
474
|
});
|
|
463
475
|
}
|
|
476
|
+
function getSort({ column }) {
|
|
477
|
+
if (!column.getCanSort())
|
|
478
|
+
return void 0;
|
|
479
|
+
switch (column.getIsSorted()) {
|
|
480
|
+
case "asc":
|
|
481
|
+
return "ascending";
|
|
482
|
+
case "desc":
|
|
483
|
+
return "descending";
|
|
484
|
+
default:
|
|
485
|
+
return "none";
|
|
486
|
+
}
|
|
487
|
+
}
|
|
464
488
|
|
|
465
489
|
// src/DataTable/components/TableHeader.tsx
|
|
466
490
|
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
children:
|
|
471
|
-
header
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
})
|
|
491
|
+
function TableHeader({ table, sticky }) {
|
|
492
|
+
return /* @__PURE__ */ jsx10(Table5.Head, {
|
|
493
|
+
sticky,
|
|
494
|
+
children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx10(Table5.Row, {
|
|
495
|
+
children: headerGroup.headers.map((header) => /* @__PURE__ */ jsx10(HeaderCell, {
|
|
496
|
+
header
|
|
497
|
+
}, header.id))
|
|
498
|
+
}, headerGroup.id))
|
|
499
|
+
});
|
|
500
|
+
}
|
|
475
501
|
|
|
476
502
|
// src/DataTable/components/BasicTable.tsx
|
|
477
503
|
import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
@@ -507,6 +533,10 @@ import { useRef, useState as useState2 } from "react";
|
|
|
507
533
|
import styled11 from "styled-components";
|
|
508
534
|
|
|
509
535
|
// src/DataTable/utils.tsx
|
|
536
|
+
function capitalizeHeader(context) {
|
|
537
|
+
const header = context.header.id;
|
|
538
|
+
return header.charAt(0).toUpperCase() + header.slice(1);
|
|
539
|
+
}
|
|
510
540
|
function enableOrUndefined(enabled, value) {
|
|
511
541
|
return Boolean(enabled) ? value : void 0;
|
|
512
542
|
}
|
|
@@ -843,6 +873,7 @@ function DataTable({
|
|
|
843
873
|
enableExpanding: !(config == null ? void 0 : config.hideExpandControls),
|
|
844
874
|
enableMultiRowSelection: (config == null ? void 0 : config.rowSelectionMode) === "multiple",
|
|
845
875
|
enableSubRowSelection: (config == null ? void 0 : config.rowSelectionMode) !== "single",
|
|
876
|
+
filterFromLeafRows: filters == null ? void 0 : filters.filterFromLeafRows,
|
|
846
877
|
getFilteredRowModel: enableGlobalFilter(getFilteredRowModel()),
|
|
847
878
|
getCoreRowModel: getCoreRowModel(),
|
|
848
879
|
getExpandedRowModel: getExpandedRowModel(),
|
|
@@ -917,7 +948,9 @@ export {
|
|
|
917
948
|
HierarchyCell,
|
|
918
949
|
SelectColumnDef,
|
|
919
950
|
StickyCell,
|
|
951
|
+
TableHeader,
|
|
920
952
|
TypographyCustom,
|
|
953
|
+
capitalizeHeader,
|
|
921
954
|
globalFilterAtom,
|
|
922
955
|
prependSelectColumn,
|
|
923
956
|
rowSelectionAtom,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equinor/apollo-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"@equinor/eds-core-react": "^0.27.0",
|
|
21
21
|
"@equinor/eds-icons": "^0.15.0",
|
|
22
22
|
"@equinor/eds-tokens": "^0.9.0",
|
|
23
|
-
"@tanstack/match-sorter-utils": "^8.
|
|
24
|
-
"@tanstack/react-table": "^8.
|
|
23
|
+
"@tanstack/match-sorter-utils": "^8.7.6",
|
|
24
|
+
"@tanstack/react-table": "^8.7.6",
|
|
25
25
|
"@tanstack/react-virtual": "^3.0.0-beta.23",
|
|
26
26
|
"jotai": "^1.10.0",
|
|
27
27
|
"styled-components": "^5.3.6",
|