@equinor/apollo-components 1.4.0 → 1.5.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 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, RowSelectionState, SortingState } from '@tanstack/react-table';
4
+ import { Cell, CellContext, ColumnDef, Row, RowSelectionState, SortingState } 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';
@@ -28,7 +28,11 @@ declare type TableCellProps<T> = {
28
28
  };
29
29
  declare function DynamicCell<T>({ cell, highlight }: TableCellProps<T>): JSX.Element;
30
30
 
31
- declare function HierarchyCell<T>(cell: CellContext<T, any>): JSX.Element;
31
+ declare type HierarchyCellOptions = {
32
+ getRowDepth?: () => number;
33
+ getDisplayName?: () => string;
34
+ };
35
+ declare function HierarchyCell<T>(cell: CellContext<T, any>, options?: HierarchyCellOptions): JSX.Element;
32
36
 
33
37
  interface HeaderConfig {
34
38
  captionPadding?: string;
@@ -48,6 +52,7 @@ declare type DataTableConfig<T> = {
48
52
  width?: string;
49
53
  selectColumn?: 'default' | ((options?: Record<string, any>) => ColumnDef<T, any>);
50
54
  getSubRows?: (originalRow: T) => T[] | undefined;
55
+ onRowClick?: (row: Row<T>) => void;
51
56
  } & ExpansionConfig;
52
57
  interface ExpansionConfig {
53
58
  expandAllByDefault?: boolean;
package/dist/index.js CHANGED
@@ -324,15 +324,16 @@ var CellWrapper = (0, import_styled_components8.default)(TypographyCustom)`
324
324
  }
325
325
  `}
326
326
  `;
327
- function HierarchyCell(cell) {
327
+ function HierarchyCell(cell, options = {}) {
328
+ var _a, _b;
328
329
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(CellWrapper, {
329
- depth: cell.row.depth,
330
+ depth: ((_a = options.getRowDepth) == null ? void 0 : _a.call(options)) ?? cell.row.depth,
330
331
  expanded: cell.row.getIsExpanded(),
331
332
  children: [
332
333
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", {
333
334
  className: "--divider"
334
335
  }),
335
- cell.getValue()
336
+ ((_b = options.getDisplayName) == null ? void 0 : _b.call(options)) ?? cell.getValue()
336
337
  ]
337
338
  });
338
339
  }
@@ -347,6 +348,7 @@ var CellWrapper2 = import_styled_components9.default.div`
347
348
  align-items: center;
348
349
  width: 48px;
349
350
  margin-left: -16px;
351
+ z-index: 2;
350
352
  `;
351
353
  function SelectColumnDef(selectionMode) {
352
354
  return {
@@ -369,18 +371,27 @@ function SelectColumnDef(selectionMode) {
369
371
  selectionMode === "single" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_eds_core_react6.Radio, {
370
372
  checked: row.getIsSelected(),
371
373
  "aria-label": `Select row ${row.id}`,
372
- onChange: row.getToggleSelectedHandler()
374
+ onChange: (e) => {
375
+ e.stopPropagation();
376
+ row.getToggleSelectedHandler()(e);
377
+ }
373
378
  }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_eds_core_react6.Checkbox, {
374
379
  checked: row.getIsSelected(),
375
380
  indeterminate: row.getIsSomeSelected(),
376
381
  "aria-label": `Select row ${row.id}`,
377
- onChange: row.getToggleSelectedHandler()
382
+ onChange: (e) => {
383
+ e.stopPropagation();
384
+ row.getToggleSelectedHandler()(e);
385
+ }
378
386
  }),
379
387
  row.getCanExpand() && table.options.enableExpanding && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_eds_core_react6.Button, {
380
388
  variant: "ghost_icon",
381
389
  color: "secondary",
382
390
  "aria-label": row.getIsExpanded() ? "Close group" : "Expand group",
383
- onClick: row.getToggleExpandedHandler(),
391
+ onClick: (e) => {
392
+ e.stopPropagation();
393
+ row.getToggleExpandedHandler()();
394
+ },
384
395
  style: { cursor: "pointer" },
385
396
  children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_eds_core_react6.Icon, {
386
397
  data: row.getIsExpanded() ? import_eds_icons3.chevron_up : import_eds_icons3.chevron_down
@@ -500,7 +511,7 @@ var TableHeader = ({ table, sticky }) => /* @__PURE__ */ (0, import_jsx_runtime1
500
511
 
501
512
  // src/DataTable/components/BasicTable.tsx
502
513
  var import_jsx_runtime11 = require("react/jsx-runtime");
503
- function BasicTable({ table, stickyHeader, isLoading }) {
514
+ function BasicTable({ table, config, stickyHeader, isLoading }) {
504
515
  const tableRows = table.getRowModel().rows;
505
516
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_eds_core_react10.Table, {
506
517
  children: [
@@ -510,6 +521,10 @@ function BasicTable({ table, stickyHeader, isLoading }) {
510
521
  }),
511
522
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_eds_core_react10.Table.Body, {
512
523
  children: tableRows.length ? tableRows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_eds_core_react10.Table.Row, {
524
+ onClick: () => {
525
+ var _a;
526
+ return (_a = config == null ? void 0 : config.onRowClick) == null ? void 0 : _a.call(config, row);
527
+ },
513
528
  children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_eds_core_react10.Table.Cell, {
514
529
  children: (0, import_react_table3.flexRender)(cell.column.columnDef.cell, cell.getContext())
515
530
  }, cell.id))
@@ -765,7 +780,7 @@ var PaddingRow = (props) => {
765
780
 
766
781
  // src/DataTable/components/VirtualTable.tsx
767
782
  var import_jsx_runtime16 = require("react/jsx-runtime");
768
- function VirtualTable({ table, containerRef, ...props }) {
783
+ function VirtualTable({ table, config, containerRef, ...props }) {
769
784
  var _a, _b;
770
785
  const { rows } = table.getRowModel();
771
786
  const rowVirtualizer = (0, import_react_virtual.useVirtualizer)({
@@ -791,6 +806,10 @@ function VirtualTable({ table, containerRef, ...props }) {
791
806
  const row = rows[virtualRow.index];
792
807
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_eds_core_react15.Table.Row, {
793
808
  active: row.getIsSelected(),
809
+ onClick: () => {
810
+ var _a2;
811
+ return (_a2 = config == null ? void 0 : config.onRowClick) == null ? void 0 : _a2.call(config, row);
812
+ },
794
813
  children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_eds_core_react15.Table.Cell, {
795
814
  children: (0, import_react_table4.flexRender)(cell.column.columnDef.cell, cell.getContext())
796
815
  }, cell.id))
@@ -897,10 +916,12 @@ function DataTable({
897
916
  children: (config == null ? void 0 : config.virtual) ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(VirtualTable, {
898
917
  containerRef: tableContainerRef,
899
918
  table,
919
+ config,
900
920
  isLoading,
901
921
  stickyHeader: header == null ? void 0 : header.stickyHeader
902
922
  }) : /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(BasicTable, {
903
923
  table,
924
+ config,
904
925
  isLoading,
905
926
  stickyHeader: header == null ? void 0 : header.stickyHeader
906
927
  })
package/dist/index.mjs CHANGED
@@ -282,15 +282,16 @@ var CellWrapper = styled7(TypographyCustom)`
282
282
  }
283
283
  `}
284
284
  `;
285
- function HierarchyCell(cell) {
285
+ function HierarchyCell(cell, options = {}) {
286
+ var _a, _b;
286
287
  return /* @__PURE__ */ jsxs4(CellWrapper, {
287
- depth: cell.row.depth,
288
+ depth: ((_a = options.getRowDepth) == null ? void 0 : _a.call(options)) ?? cell.row.depth,
288
289
  expanded: cell.row.getIsExpanded(),
289
290
  children: [
290
291
  /* @__PURE__ */ jsx6("span", {
291
292
  className: "--divider"
292
293
  }),
293
- cell.getValue()
294
+ ((_b = options.getDisplayName) == null ? void 0 : _b.call(options)) ?? cell.getValue()
294
295
  ]
295
296
  });
296
297
  }
@@ -305,6 +306,7 @@ var CellWrapper2 = styled8.div`
305
306
  align-items: center;
306
307
  width: 48px;
307
308
  margin-left: -16px;
309
+ z-index: 2;
308
310
  `;
309
311
  function SelectColumnDef(selectionMode) {
310
312
  return {
@@ -327,18 +329,27 @@ function SelectColumnDef(selectionMode) {
327
329
  selectionMode === "single" ? /* @__PURE__ */ jsx7(Radio, {
328
330
  checked: row.getIsSelected(),
329
331
  "aria-label": `Select row ${row.id}`,
330
- onChange: row.getToggleSelectedHandler()
332
+ onChange: (e) => {
333
+ e.stopPropagation();
334
+ row.getToggleSelectedHandler()(e);
335
+ }
331
336
  }) : /* @__PURE__ */ jsx7(Checkbox, {
332
337
  checked: row.getIsSelected(),
333
338
  indeterminate: row.getIsSomeSelected(),
334
339
  "aria-label": `Select row ${row.id}`,
335
- onChange: row.getToggleSelectedHandler()
340
+ onChange: (e) => {
341
+ e.stopPropagation();
342
+ row.getToggleSelectedHandler()(e);
343
+ }
336
344
  }),
337
345
  row.getCanExpand() && table.options.enableExpanding && /* @__PURE__ */ jsx7(Button2, {
338
346
  variant: "ghost_icon",
339
347
  color: "secondary",
340
348
  "aria-label": row.getIsExpanded() ? "Close group" : "Expand group",
341
- onClick: row.getToggleExpandedHandler(),
349
+ onClick: (e) => {
350
+ e.stopPropagation();
351
+ row.getToggleExpandedHandler()();
352
+ },
342
353
  style: { cursor: "pointer" },
343
354
  children: /* @__PURE__ */ jsx7(Icon3, {
344
355
  data: row.getIsExpanded() ? chevron_up : chevron_down
@@ -464,7 +475,7 @@ var TableHeader = ({ table, sticky }) => /* @__PURE__ */ jsx10(Table5.Head, {
464
475
 
465
476
  // src/DataTable/components/BasicTable.tsx
466
477
  import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
467
- function BasicTable({ table, stickyHeader, isLoading }) {
478
+ function BasicTable({ table, config, stickyHeader, isLoading }) {
468
479
  const tableRows = table.getRowModel().rows;
469
480
  return /* @__PURE__ */ jsxs7(EdsTable, {
470
481
  children: [
@@ -474,6 +485,10 @@ function BasicTable({ table, stickyHeader, isLoading }) {
474
485
  }),
475
486
  /* @__PURE__ */ jsx11(EdsTable.Body, {
476
487
  children: tableRows.length ? tableRows.map((row) => /* @__PURE__ */ jsx11(EdsTable.Row, {
488
+ onClick: () => {
489
+ var _a;
490
+ return (_a = config == null ? void 0 : config.onRowClick) == null ? void 0 : _a.call(config, row);
491
+ },
477
492
  children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx11(EdsTable.Cell, {
478
493
  children: flexRender3(cell.column.columnDef.cell, cell.getContext())
479
494
  }, cell.id))
@@ -729,7 +744,7 @@ var PaddingRow = (props) => {
729
744
 
730
745
  // src/DataTable/components/VirtualTable.tsx
731
746
  import { jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
732
- function VirtualTable({ table, containerRef, ...props }) {
747
+ function VirtualTable({ table, config, containerRef, ...props }) {
733
748
  var _a, _b;
734
749
  const { rows } = table.getRowModel();
735
750
  const rowVirtualizer = useVirtualizer({
@@ -755,6 +770,10 @@ function VirtualTable({ table, containerRef, ...props }) {
755
770
  const row = rows[virtualRow.index];
756
771
  return /* @__PURE__ */ jsx16(Table8.Row, {
757
772
  active: row.getIsSelected(),
773
+ onClick: () => {
774
+ var _a2;
775
+ return (_a2 = config == null ? void 0 : config.onRowClick) == null ? void 0 : _a2.call(config, row);
776
+ },
758
777
  children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx16(Table8.Cell, {
759
778
  children: flexRender4(cell.column.columnDef.cell, cell.getContext())
760
779
  }, cell.id))
@@ -861,10 +880,12 @@ function DataTable({
861
880
  children: (config == null ? void 0 : config.virtual) ? /* @__PURE__ */ jsx17(VirtualTable, {
862
881
  containerRef: tableContainerRef,
863
882
  table,
883
+ config,
864
884
  isLoading,
865
885
  stickyHeader: header == null ? void 0 : header.stickyHeader
866
886
  }) : /* @__PURE__ */ jsx17(BasicTable, {
867
887
  table,
888
+ config,
868
889
  isLoading,
869
890
  stickyHeader: header == null ? void 0 : header.stickyHeader
870
891
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/apollo-components",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",