@equinor/apollo-components 1.8.1 → 1.9.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
@@ -84,10 +84,7 @@ interface ExpansionConfig {
84
84
  expandAllByDefault?: boolean;
85
85
  hideExpandControls?: boolean;
86
86
  }
87
-
88
- interface DataTableProps<T> {
89
- data: T[];
90
- columns: ColumnDef<T, any>[];
87
+ interface DataTableCommonProps<T> {
91
88
  isLoading?: boolean;
92
89
  className?: string;
93
90
  config?: DataTableConfig<T>;
@@ -96,7 +93,15 @@ interface DataTableProps<T> {
96
93
  filters?: FilterConfig;
97
94
  header?: HeaderConfig;
98
95
  }
99
- declare function DataTable$1<T>({ columns, data, isLoading, header, filters, config, cellConfig, rowConfig, }: DataTableProps<T>): JSX.Element;
96
+ interface DataTableProps<T> extends DataTableCommonProps<T> {
97
+ data: T[];
98
+ columns: ColumnDef<T, any>[];
99
+ }
100
+ interface DataTableRawProps<T> extends DataTableCommonProps<T> {
101
+ table: Table<T>;
102
+ }
103
+
104
+ declare function DataTable$1<T>(props: DataTableProps<T>): JSX.Element;
100
105
 
101
106
  declare type DataTableProviderProps = ComponentProps<typeof Provider>;
102
107
  declare function DataTableProvider({ children, ...props }: DataTableProviderProps): JSX.Element;
@@ -153,4 +158,4 @@ declare type TypographyProps = {
153
158
  */
154
159
  declare const TypographyCustom: (props: TypographyProps) => JSX.Element;
155
160
 
156
- export { AppShell, AppSidebar, CellConfig, ChipsCell, ColumnSelect, DataTable, DataTableConfig, DynamicCell, FilterConfig, HeaderConfig, HierarchyCell, RowConfig, RowSelectionMode, SelectColumnDef, StickyCell, TableHeader, TableRowWrapper, TableRowWrapperProps, TypographyCustom, capitalizeHeader, globalFilterAtom, prependSelectColumn, rowSelectionAtom, tableSortingAtom };
161
+ export { AppShell, AppSidebar, CellConfig, ChipsCell, ColumnSelect, DataTable, DataTableCommonProps, DataTableConfig, DataTableProps, DataTableRawProps, DynamicCell, FilterConfig, HeaderConfig, HierarchyCell, RowConfig, RowSelectionMode, SelectColumnDef, StickyCell, TableHeader, TableRowWrapper, TableRowWrapperProps, TypographyCustom, capitalizeHeader, globalFilterAtom, prependSelectColumn, rowSelectionAtom, tableSortingAtom };
package/dist/index.js CHANGED
@@ -403,20 +403,10 @@ function SelectColumnDef(selectionMode) {
403
403
  };
404
404
  }
405
405
 
406
- // src/DataTable/DataTable.tsx
407
- var import_react_table3 = require("@tanstack/react-table");
408
- var import_jotai3 = require("jotai");
406
+ // src/DataTable/DataTableRaw.tsx
409
407
  var import_react4 = require("react");
410
408
  var import_styled_components14 = __toESM(require("styled-components"));
411
409
 
412
- // src/DataTable/atoms.ts
413
- var import_jotai = require("jotai");
414
- var columnVisibilityAtom = (0, import_jotai.atom)({});
415
- var globalFilterAtom = (0, import_jotai.atom)("");
416
- var rowSelectionAtom = (0, import_jotai.atom)({});
417
- var tableSortingAtom = (0, import_jotai.atom)([]);
418
- var expandedRowsAtom = (0, import_jotai.atom)({});
419
-
420
410
  // src/DataTable/components/BasicTable.tsx
421
411
  var import_eds_core_react11 = require("@equinor/eds-core-react");
422
412
 
@@ -469,13 +459,14 @@ var HeaderCell = ({ header }) => {
469
459
  onClick: header.column.getToggleSortingHandler(),
470
460
  colSpan: header.colSpan
471
461
  };
472
- if ((_a = header.column.columnDef.meta) == null ? void 0 : _a.sticky)
462
+ if ((_a = header.column.columnDef.meta) == null ? void 0 : _a.sticky) {
473
463
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(StickyHeaderCell, {
474
464
  ...cellProps,
475
465
  children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(HeaderContent, {
476
466
  header
477
467
  })
478
468
  }, header.id);
469
+ }
479
470
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_eds_core_react8.Table.Cell, {
480
471
  ...cellProps,
481
472
  children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(HeaderContent, {
@@ -601,6 +592,14 @@ var import_eds_icons7 = require("@equinor/eds-icons");
601
592
  var import_jotai2 = require("jotai");
602
593
  var import_styled_components13 = __toESM(require("styled-components"));
603
594
 
595
+ // src/DataTable/atoms.ts
596
+ var import_jotai = require("jotai");
597
+ var columnVisibilityAtom = (0, import_jotai.atom)({});
598
+ var globalFilterAtom = (0, import_jotai.atom)("");
599
+ var rowSelectionAtom = (0, import_jotai.atom)({});
600
+ var tableSortingAtom = (0, import_jotai.atom)([]);
601
+ var expandedRowsAtom = (0, import_jotai.atom)({});
602
+
604
603
  // src/DataTable/filters/DebouncedInput.tsx
605
604
  var import_eds_core_react12 = require("@equinor/eds-core-react");
606
605
  var import_eds_icons5 = require("@equinor/eds-icons");
@@ -895,7 +894,7 @@ function VirtualTable({
895
894
  });
896
895
  }
897
896
 
898
- // src/DataTable/DataTable.tsx
897
+ // src/DataTable/DataTableRaw.tsx
899
898
  var import_jsx_runtime18 = require("react/jsx-runtime");
900
899
  var DataTableWrapper = import_styled_components14.default.div`
901
900
  width: ${(props) => props.width ?? "100%"};
@@ -906,23 +905,52 @@ var DataTableWrapper = import_styled_components14.default.div`
906
905
  overflow: auto;
907
906
 
908
907
  table {
909
- width: ${(props) => props.width ?? "100%"};
910
- height: ${(props) => props.height ?? "100%"};
911
- table-layout: ${(props) => props.tableLayout ?? "fixed"};
912
- border-collapse: collapse;
908
+ width: 100%;
909
+ table-layout: auto;
913
910
  }
914
911
  }
915
912
  `;
916
- function DataTable({
917
- columns,
918
- data,
919
- isLoading,
920
- header,
921
- filters,
922
- config,
923
- cellConfig,
924
- rowConfig
925
- }) {
913
+ function DataTableRaw(props) {
914
+ const { isLoading, header, filters, config, rowConfig, table } = props;
915
+ const tableContainerRef = (0, import_react4.useRef)(null);
916
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(DataTableWrapper, {
917
+ captionPadding: header == null ? void 0 : header.captionPadding,
918
+ height: config == null ? void 0 : config.height,
919
+ width: config == null ? void 0 : config.width,
920
+ children: [
921
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(DataTableHeader, {
922
+ tableCaption: header == null ? void 0 : header.tableCaption,
923
+ captionPadding: header == null ? void 0 : header.captionPadding,
924
+ table,
925
+ config: filters
926
+ }),
927
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", {
928
+ ref: tableContainerRef,
929
+ className: "--table-container",
930
+ children: (config == null ? void 0 : config.virtual) ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(VirtualTable, {
931
+ containerRef: tableContainerRef,
932
+ table,
933
+ rowConfig,
934
+ isLoading,
935
+ stickyHeader: header == null ? void 0 : header.stickyHeader
936
+ }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(BasicTable, {
937
+ table,
938
+ rowConfig,
939
+ isLoading,
940
+ stickyHeader: header == null ? void 0 : header.stickyHeader
941
+ })
942
+ })
943
+ ]
944
+ });
945
+ }
946
+
947
+ // src/DataTable/useDataTable.tsx
948
+ var import_react_table3 = require("@tanstack/react-table");
949
+ var import_jotai3 = require("jotai");
950
+ var import_react5 = require("react");
951
+ var import_jsx_runtime19 = require("react/jsx-runtime");
952
+ function useDataTable(props) {
953
+ const { columns, data, filters, config, meta } = props;
926
954
  const [columnVisibility, setColumnVisibility] = (0, import_jotai3.useAtom)(columnVisibilityAtom);
927
955
  const [globalFilter, setGlobalFilter] = (0, import_jotai3.useAtom)(globalFilterAtom);
928
956
  const [sorting, setSorting] = (0, import_jotai3.useAtom)(tableSortingAtom);
@@ -943,11 +971,12 @@ function DataTable({
943
971
  columnVisibility
944
972
  },
945
973
  defaultColumn: {
946
- cell: (cell) => /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TypographyCustom, {
974
+ cell: (cell) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(TypographyCustom, {
947
975
  noWrap: true,
948
976
  children: cell.getValue()
949
977
  })
950
978
  },
979
+ meta,
951
980
  enableSorting: config == null ? void 0 : config.sortable,
952
981
  enableExpanding: !(config == null ? void 0 : config.hideExpandControls),
953
982
  enableMultiRowSelection: (config == null ? void 0 : config.rowSelectionMode) === "multiple",
@@ -965,50 +994,29 @@ function DataTable({
965
994
  getSubRows: config == null ? void 0 : config.getSubRows,
966
995
  getRowId: config == null ? void 0 : config.getRowId
967
996
  });
968
- (0, import_react4.useEffect)(() => {
997
+ (0, import_react5.useEffect)(() => {
969
998
  if (config && config.expandAllByDefault) {
970
999
  table.toggleAllRowsExpanded();
971
1000
  }
972
1001
  }, [table, config == null ? void 0 : config.expandAllByDefault]);
973
- const tableContainerRef = (0, import_react4.useRef)(null);
974
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(DataTableWrapper, {
975
- height: config == null ? void 0 : config.height,
976
- width: config == null ? void 0 : config.width,
977
- tableLayout: config == null ? void 0 : config.tableLayout,
978
- children: [
979
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(DataTableHeader, {
980
- tableCaption: header == null ? void 0 : header.tableCaption,
981
- captionPadding: header == null ? void 0 : header.captionPadding,
982
- table,
983
- config: filters
984
- }),
985
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", {
986
- ref: tableContainerRef,
987
- className: "--table-container",
988
- children: (config == null ? void 0 : config.virtual) ? /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(VirtualTable, {
989
- containerRef: tableContainerRef,
990
- table,
991
- rowConfig,
992
- cellConfig,
993
- isLoading,
994
- stickyHeader: header == null ? void 0 : header.stickyHeader
995
- }) : /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(BasicTable, {
996
- table,
997
- rowConfig,
998
- cellConfig,
999
- isLoading,
1000
- stickyHeader: header == null ? void 0 : header.stickyHeader
1001
- })
1002
- })
1003
- ]
1002
+ return table;
1003
+ }
1004
+
1005
+ // src/DataTable/DataTable.tsx
1006
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1007
+ function DataTable(props) {
1008
+ const table = useDataTable(props);
1009
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(DataTableRaw, {
1010
+ table,
1011
+ ...props
1004
1012
  });
1005
1013
  }
1006
1014
 
1007
1015
  // src/DataTable/Provider.tsx
1008
1016
  var import_jotai4 = require("jotai");
1009
- var import_jsx_runtime19 = require("react/jsx-runtime");
1017
+ var import_jsx_runtime21 = require("react/jsx-runtime");
1010
1018
  function DataTableProvider({ children, ...props }) {
1011
- return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_jotai4.Provider, {
1019
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_jotai4.Provider, {
1012
1020
  ...props,
1013
1021
  children
1014
1022
  });
package/dist/index.mjs CHANGED
@@ -358,26 +358,10 @@ function SelectColumnDef(selectionMode) {
358
358
  };
359
359
  }
360
360
 
361
- // src/DataTable/DataTable.tsx
362
- import {
363
- getCoreRowModel,
364
- getExpandedRowModel,
365
- getFilteredRowModel,
366
- getSortedRowModel,
367
- useReactTable
368
- } from "@tanstack/react-table";
369
- import { useAtom as useAtom2 } from "jotai";
370
- import { useEffect as useEffect2, useRef as useRef2 } from "react";
361
+ // src/DataTable/DataTableRaw.tsx
362
+ import { useRef as useRef2 } from "react";
371
363
  import styled14 from "styled-components";
372
364
 
373
- // src/DataTable/atoms.ts
374
- import { atom } from "jotai";
375
- var columnVisibilityAtom = atom({});
376
- var globalFilterAtom = atom("");
377
- var rowSelectionAtom = atom({});
378
- var tableSortingAtom = atom([]);
379
- var expandedRowsAtom = atom({});
380
-
381
365
  // src/DataTable/components/BasicTable.tsx
382
366
  import { Table as EdsTable } from "@equinor/eds-core-react";
383
367
 
@@ -430,13 +414,14 @@ var HeaderCell = ({ header }) => {
430
414
  onClick: header.column.getToggleSortingHandler(),
431
415
  colSpan: header.colSpan
432
416
  };
433
- if ((_a = header.column.columnDef.meta) == null ? void 0 : _a.sticky)
417
+ if ((_a = header.column.columnDef.meta) == null ? void 0 : _a.sticky) {
434
418
  return /* @__PURE__ */ jsx9(StickyHeaderCell, {
435
419
  ...cellProps,
436
420
  children: /* @__PURE__ */ jsx9(HeaderContent, {
437
421
  header
438
422
  })
439
423
  }, header.id);
424
+ }
440
425
  return /* @__PURE__ */ jsx9(Table4.Cell, {
441
426
  ...cellProps,
442
427
  children: /* @__PURE__ */ jsx9(HeaderContent, {
@@ -562,6 +547,14 @@ import { search } from "@equinor/eds-icons";
562
547
  import { useAtom } from "jotai";
563
548
  import styled13 from "styled-components";
564
549
 
550
+ // src/DataTable/atoms.ts
551
+ import { atom } from "jotai";
552
+ var columnVisibilityAtom = atom({});
553
+ var globalFilterAtom = atom("");
554
+ var rowSelectionAtom = atom({});
555
+ var tableSortingAtom = atom([]);
556
+ var expandedRowsAtom = atom({});
557
+
565
558
  // src/DataTable/filters/DebouncedInput.tsx
566
559
  import { Button as Button3, Icon as Icon5, Input, Tooltip } from "@equinor/eds-core-react";
567
560
  import { close } from "@equinor/eds-icons";
@@ -856,7 +849,7 @@ function VirtualTable({
856
849
  });
857
850
  }
858
851
 
859
- // src/DataTable/DataTable.tsx
852
+ // src/DataTable/DataTableRaw.tsx
860
853
  import { jsx as jsx18, jsxs as jsxs11 } from "react/jsx-runtime";
861
854
  var DataTableWrapper = styled14.div`
862
855
  width: ${(props) => props.width ?? "100%"};
@@ -867,23 +860,58 @@ var DataTableWrapper = styled14.div`
867
860
  overflow: auto;
868
861
 
869
862
  table {
870
- width: ${(props) => props.width ?? "100%"};
871
- height: ${(props) => props.height ?? "100%"};
872
- table-layout: ${(props) => props.tableLayout ?? "fixed"};
873
- border-collapse: collapse;
863
+ width: 100%;
864
+ table-layout: auto;
874
865
  }
875
866
  }
876
867
  `;
877
- function DataTable({
878
- columns,
879
- data,
880
- isLoading,
881
- header,
882
- filters,
883
- config,
884
- cellConfig,
885
- rowConfig
886
- }) {
868
+ function DataTableRaw(props) {
869
+ const { isLoading, header, filters, config, rowConfig, table } = props;
870
+ const tableContainerRef = useRef2(null);
871
+ return /* @__PURE__ */ jsxs11(DataTableWrapper, {
872
+ captionPadding: header == null ? void 0 : header.captionPadding,
873
+ height: config == null ? void 0 : config.height,
874
+ width: config == null ? void 0 : config.width,
875
+ children: [
876
+ /* @__PURE__ */ jsx18(DataTableHeader, {
877
+ tableCaption: header == null ? void 0 : header.tableCaption,
878
+ captionPadding: header == null ? void 0 : header.captionPadding,
879
+ table,
880
+ config: filters
881
+ }),
882
+ /* @__PURE__ */ jsx18("div", {
883
+ ref: tableContainerRef,
884
+ className: "--table-container",
885
+ children: (config == null ? void 0 : config.virtual) ? /* @__PURE__ */ jsx18(VirtualTable, {
886
+ containerRef: tableContainerRef,
887
+ table,
888
+ rowConfig,
889
+ isLoading,
890
+ stickyHeader: header == null ? void 0 : header.stickyHeader
891
+ }) : /* @__PURE__ */ jsx18(BasicTable, {
892
+ table,
893
+ rowConfig,
894
+ isLoading,
895
+ stickyHeader: header == null ? void 0 : header.stickyHeader
896
+ })
897
+ })
898
+ ]
899
+ });
900
+ }
901
+
902
+ // src/DataTable/useDataTable.tsx
903
+ import {
904
+ getCoreRowModel,
905
+ getExpandedRowModel,
906
+ getFilteredRowModel,
907
+ getSortedRowModel,
908
+ useReactTable
909
+ } from "@tanstack/react-table";
910
+ import { useAtom as useAtom2 } from "jotai";
911
+ import { useEffect as useEffect2 } from "react";
912
+ import { jsx as jsx19 } from "react/jsx-runtime";
913
+ function useDataTable(props) {
914
+ const { columns, data, filters, config, meta } = props;
887
915
  const [columnVisibility, setColumnVisibility] = useAtom2(columnVisibilityAtom);
888
916
  const [globalFilter, setGlobalFilter] = useAtom2(globalFilterAtom);
889
917
  const [sorting, setSorting] = useAtom2(tableSortingAtom);
@@ -904,11 +932,12 @@ function DataTable({
904
932
  columnVisibility
905
933
  },
906
934
  defaultColumn: {
907
- cell: (cell) => /* @__PURE__ */ jsx18(TypographyCustom, {
935
+ cell: (cell) => /* @__PURE__ */ jsx19(TypographyCustom, {
908
936
  noWrap: true,
909
937
  children: cell.getValue()
910
938
  })
911
939
  },
940
+ meta,
912
941
  enableSorting: config == null ? void 0 : config.sortable,
913
942
  enableExpanding: !(config == null ? void 0 : config.hideExpandControls),
914
943
  enableMultiRowSelection: (config == null ? void 0 : config.rowSelectionMode) === "multiple",
@@ -931,45 +960,24 @@ function DataTable({
931
960
  table.toggleAllRowsExpanded();
932
961
  }
933
962
  }, [table, config == null ? void 0 : config.expandAllByDefault]);
934
- const tableContainerRef = useRef2(null);
935
- return /* @__PURE__ */ jsxs11(DataTableWrapper, {
936
- height: config == null ? void 0 : config.height,
937
- width: config == null ? void 0 : config.width,
938
- tableLayout: config == null ? void 0 : config.tableLayout,
939
- children: [
940
- /* @__PURE__ */ jsx18(DataTableHeader, {
941
- tableCaption: header == null ? void 0 : header.tableCaption,
942
- captionPadding: header == null ? void 0 : header.captionPadding,
943
- table,
944
- config: filters
945
- }),
946
- /* @__PURE__ */ jsx18("div", {
947
- ref: tableContainerRef,
948
- className: "--table-container",
949
- children: (config == null ? void 0 : config.virtual) ? /* @__PURE__ */ jsx18(VirtualTable, {
950
- containerRef: tableContainerRef,
951
- table,
952
- rowConfig,
953
- cellConfig,
954
- isLoading,
955
- stickyHeader: header == null ? void 0 : header.stickyHeader
956
- }) : /* @__PURE__ */ jsx18(BasicTable, {
957
- table,
958
- rowConfig,
959
- cellConfig,
960
- isLoading,
961
- stickyHeader: header == null ? void 0 : header.stickyHeader
962
- })
963
- })
964
- ]
963
+ return table;
964
+ }
965
+
966
+ // src/DataTable/DataTable.tsx
967
+ import { jsx as jsx20 } from "react/jsx-runtime";
968
+ function DataTable(props) {
969
+ const table = useDataTable(props);
970
+ return /* @__PURE__ */ jsx20(DataTableRaw, {
971
+ table,
972
+ ...props
965
973
  });
966
974
  }
967
975
 
968
976
  // src/DataTable/Provider.tsx
969
977
  import { Provider } from "jotai";
970
- import { jsx as jsx19 } from "react/jsx-runtime";
978
+ import { jsx as jsx21 } from "react/jsx-runtime";
971
979
  function DataTableProvider({ children, ...props }) {
972
- return /* @__PURE__ */ jsx19(Provider, {
980
+ return /* @__PURE__ */ jsx21(Provider, {
973
981
  ...props,
974
982
  children
975
983
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/apollo-components",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",