@equinor/apollo-components 3.1.7 → 3.1.8-beta.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
@@ -4,9 +4,10 @@ import { ReactNode, ReactElement, HTMLProps, MutableRefObject, Dispatch, SetStat
4
4
  import * as styled_components from 'styled-components';
5
5
  import * as _equinor_eds_core_react from '@equinor/eds-core-react';
6
6
  import { CellProps, TypographyProps as TypographyProps$1 } from '@equinor/eds-core-react';
7
- import { Cell, Header, CellContext, Table, Row, SortingState, OnChangeFn, ColumnDef, RowSelectionState, ExpandedState, VisibilityState, HeaderContext } from '@tanstack/react-table';
7
+ import { Cell, Header, Table, CellContext, Row, SortingState, OnChangeFn, ColumnDef, RowSelectionState, ExpandedState, VisibilityState, HeaderContext } from '@tanstack/react-table';
8
8
  import { ColumnDef as ColumnDef$1 } from '@tanstack/table-core';
9
9
  import { SetRequired } from 'type-fest';
10
+ import { TableOptions } from '@tanstack/table-core/build/lib/types';
10
11
 
11
12
  interface AppShellProps {
12
13
  children?: ReactNode;
@@ -36,8 +37,9 @@ declare function DynamicCell<T>({ cell, highlight, getStickyCellColor }: TableCe
36
37
 
37
38
  interface HeaderCellProps<TData, TValue> {
38
39
  header: Header<TData, TValue>;
40
+ table: Table<TData>;
39
41
  }
40
- declare const HeaderCell: <TData, TValue>({ header }: HeaderCellProps<TData, TValue>) => JSX.Element;
42
+ declare const HeaderCell: <TData, TValue>({ header, table }: HeaderCellProps<TData, TValue>) => JSX.Element;
41
43
 
42
44
  declare type HierarchyCellOptions = {
43
45
  getRowDepth?: () => number;
@@ -131,6 +133,7 @@ interface DataTableProps<T> {
131
133
  virtual?: boolean;
132
134
  getRowId?: (originalRow: T, index: number, parent: Row<T> | undefined) => string;
133
135
  getSubRows?: (originalRow: T) => T[] | undefined;
136
+ columnResizing?: boolean | TableOptions<T>['columnResizeMode'];
134
137
  rowSelection?: Partial<ControlledState<RowSelectionState>> & {
135
138
  mode?: RowSelectionMode;
136
139
  selectColumn?: 'default' | ((options?: Record<string, any>) => ColumnDef<T, any>);
package/dist/index.js CHANGED
@@ -2580,16 +2580,40 @@ function DynamicCell({ cell, highlight, getStickyCellColor }) {
2580
2580
  // src/cells/HeaderCell.tsx
2581
2581
  var import_eds_core_react5 = require("@equinor/eds-core-react");
2582
2582
  var import_eds_icons3 = require("@equinor/eds-icons");
2583
+ var import_eds_tokens3 = require("@equinor/eds-tokens");
2583
2584
  var import_react_table2 = require("@tanstack/react-table");
2584
2585
  var import_styled_components6 = __toESM(require("styled-components"));
2585
2586
  var import_jsx_runtime5 = require("react/jsx-runtime");
2586
- var HeaderDiv = import_styled_components6.default.div`
2587
- display: flex;
2588
- align-items: center;
2589
- gap: 0.25rem;
2590
- z-index: 5;
2587
+ var resizeCellStyle = import_styled_components6.css`
2588
+ .resizer {
2589
+ position: absolute;
2590
+ right: 0;
2591
+ top: 0;
2592
+ height: 100%;
2593
+ width: 4px;
2594
+ opacity: 0;
2595
+ background: #aaa;
2596
+ cursor: col-resize;
2597
+ user-select: none;
2598
+ touch-action: none;
2599
+ }
2600
+
2601
+ .resizer.isResizing {
2602
+ background: ${import_eds_tokens3.tokens.colors.interactive.focus.hex};
2603
+ opacity: 1;
2604
+ }
2605
+
2606
+ &:hover .resizer {
2607
+ opacity: 1;
2608
+ }
2609
+ `;
2610
+ var StickyCell2 = (0, import_styled_components6.default)(StickyHeaderCell)`
2611
+ ${resizeCellStyle}
2591
2612
  `;
2592
- var HeaderCell = ({ header }) => {
2613
+ var Cell2 = (0, import_styled_components6.default)(import_eds_core_react5.Table.Cell)`
2614
+ ${resizeCellStyle}
2615
+ `;
2616
+ var HeaderCell = ({ header, table }) => {
2593
2617
  var _a;
2594
2618
  const style = {
2595
2619
  width: header.column.getSize(),
@@ -2602,21 +2626,29 @@ var HeaderCell = ({ header }) => {
2602
2626
  colSpan: header.colSpan
2603
2627
  };
2604
2628
  if ((_a = header.column.columnDef.meta) == null ? void 0 : _a.sticky) {
2605
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(StickyHeaderCell, {
2629
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(StickyCell2, {
2606
2630
  ...cellProps,
2607
2631
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(HeaderContent, {
2608
- header
2632
+ header,
2633
+ table
2609
2634
  })
2610
2635
  }, header.id);
2611
2636
  }
2612
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_eds_core_react5.Table.Cell, {
2637
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Cell2, {
2613
2638
  ...cellProps,
2614
2639
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(HeaderContent, {
2615
- header
2640
+ header,
2641
+ table
2616
2642
  })
2617
2643
  }, header.id);
2618
2644
  };
2619
- function HeaderContent({ header }) {
2645
+ var HeaderDiv = import_styled_components6.default.div`
2646
+ display: flex;
2647
+ align-items: center;
2648
+ gap: 0.25rem;
2649
+ z-index: 5;
2650
+ `;
2651
+ function HeaderContent({ header, table }) {
2620
2652
  if (header.isPlaceholder)
2621
2653
  return null;
2622
2654
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(HeaderDiv, {
@@ -2632,7 +2664,16 @@ function HeaderContent({ header }) {
2632
2664
  none: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_eds_core_react5.Icon, {
2633
2665
  data: import_eds_icons3.arrow_drop_down
2634
2666
  })
2635
- }[header.column.getIsSorted()] ?? null
2667
+ }[header.column.getIsSorted()] ?? null,
2668
+ table.options.enableColumnResizing && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", {
2669
+ onMouseDown: header.getResizeHandler(),
2670
+ onTouchStart: header.getResizeHandler(),
2671
+ onClick: (e) => e.stopPropagation(),
2672
+ className: `resizer ${header.column.getIsResizing() ? "isResizing" : ""}`,
2673
+ style: {
2674
+ transform: table.options.columnResizeMode === "onEnd" && header.column.getIsResizing() ? `translateX(${table.getState().columnSizingInfo.deltaOffset}px)` : ""
2675
+ }
2676
+ })
2636
2677
  ]
2637
2678
  });
2638
2679
  }
@@ -2650,12 +2691,12 @@ function getSort({ column }) {
2650
2691
  }
2651
2692
 
2652
2693
  // src/cells/HierarchyCell.tsx
2653
- var import_eds_tokens4 = require("@equinor/eds-tokens");
2694
+ var import_eds_tokens5 = require("@equinor/eds-tokens");
2654
2695
  var import_styled_components8 = __toESM(require("styled-components"));
2655
2696
 
2656
2697
  // src/cells/TypographyCustom.tsx
2657
2698
  var import_eds_core_react6 = require("@equinor/eds-core-react");
2658
- var import_eds_tokens3 = require("@equinor/eds-tokens");
2699
+ var import_eds_tokens4 = require("@equinor/eds-tokens");
2659
2700
  var import_styled_components7 = __toESM(require("styled-components"));
2660
2701
  var import_jsx_runtime6 = require("react/jsx-runtime");
2661
2702
  var truncateStyle = {
@@ -2689,7 +2730,7 @@ var TypographyCustom = (props) => {
2689
2730
  });
2690
2731
  };
2691
2732
  var HoverCapture = import_styled_components7.default.div`
2692
- height: ${import_eds_tokens3.tokens.typography.table.cell_text.lineHeight};
2733
+ height: ${import_eds_tokens4.tokens.typography.table.cell_text.lineHeight};
2693
2734
  background-color: inherit;
2694
2735
 
2695
2736
  position: relative;
@@ -2724,11 +2765,11 @@ var CellWrapper = (0, import_styled_components8.default)(TypographyCustom)`
2724
2765
  ${({ depth, expanded }) => expanded && depth === 0 && "font-weight: bold;"}
2725
2766
 
2726
2767
  ${({ depth }) => depth > 0 && import_styled_components8.css`
2727
- border-left: 3px solid ${import_eds_tokens4.tokens.colors.infographic.primary__moss_green_34.hex};
2768
+ border-left: 3px solid ${import_eds_tokens5.tokens.colors.infographic.primary__moss_green_34.hex};
2728
2769
  gap: 0.5rem;
2729
2770
  .--divider {
2730
2771
  width: ${depth * 32}px;
2731
- background-color: ${import_eds_tokens4.tokens.colors.infographic.primary__moss_green_34.hex};
2772
+ background-color: ${import_eds_tokens5.tokens.colors.infographic.primary__moss_green_34.hex};
2732
2773
  height: 3px;
2733
2774
  border-radius: 0 5px 5px 0;
2734
2775
  }
@@ -2984,7 +3025,8 @@ function TableHeader({ table, sticky }) {
2984
3025
  sticky,
2985
3026
  children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_eds_core_react10.Table.Row, {
2986
3027
  children: headerGroup.headers.map((header) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(HeaderCell, {
2987
- header
3028
+ header,
3029
+ table
2988
3030
  }, header.id))
2989
3031
  }, headerGroup.id))
2990
3032
  });
@@ -3367,7 +3409,7 @@ var import_jsx_runtime19 = require("react/jsx-runtime");
3367
3409
  function canUseContainStrict(height) {
3368
3410
  if (!height)
3369
3411
  return false;
3370
- const heightIsANumber = !isNaN(parseFloat(height));
3412
+ const heightIsANumber = !isNaN(Number(height)) && !isNaN(parseFloat(height));
3371
3413
  if (heightIsANumber)
3372
3414
  return false;
3373
3415
  const heightIsPercentage = height.endsWith("%");
@@ -3446,6 +3488,8 @@ function DataTable(props) {
3446
3488
  });
3447
3489
  }
3448
3490
  },
3491
+ enableColumnResizing: Boolean(props.columnResizing),
3492
+ columnResizeMode: typeof props.columnResizing === "boolean" ? "onChange" : props.columnResizing,
3449
3493
  enableSorting: sorting == null ? void 0 : sorting.enableSorting,
3450
3494
  manualSorting: sorting == null ? void 0 : sorting.manualSorting,
3451
3495
  enableExpanding: Boolean(props.expansion),
package/dist/index.mjs CHANGED
@@ -2534,18 +2534,42 @@ function DynamicCell({ cell, highlight, getStickyCellColor }) {
2534
2534
  }
2535
2535
 
2536
2536
  // src/cells/HeaderCell.tsx
2537
- import { Icon as Icon3, Table as Table3 } from "@equinor/eds-core-react";
2537
+ import { Icon as Icon3, Table as EdsTable } from "@equinor/eds-core-react";
2538
2538
  import { arrow_drop_down, arrow_drop_up } from "@equinor/eds-icons";
2539
+ import { tokens as tokens3 } from "@equinor/eds-tokens";
2539
2540
  import { flexRender as flexRender2 } from "@tanstack/react-table";
2540
- import styled6 from "styled-components";
2541
+ import styled6, { css as css3 } from "styled-components";
2541
2542
  import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
2542
- var HeaderDiv = styled6.div`
2543
- display: flex;
2544
- align-items: center;
2545
- gap: 0.25rem;
2546
- z-index: 5;
2543
+ var resizeCellStyle = css3`
2544
+ .resizer {
2545
+ position: absolute;
2546
+ right: 0;
2547
+ top: 0;
2548
+ height: 100%;
2549
+ width: 4px;
2550
+ opacity: 0;
2551
+ background: #aaa;
2552
+ cursor: col-resize;
2553
+ user-select: none;
2554
+ touch-action: none;
2555
+ }
2556
+
2557
+ .resizer.isResizing {
2558
+ background: ${tokens3.colors.interactive.focus.hex};
2559
+ opacity: 1;
2560
+ }
2561
+
2562
+ &:hover .resizer {
2563
+ opacity: 1;
2564
+ }
2565
+ `;
2566
+ var StickyCell2 = styled6(StickyHeaderCell)`
2567
+ ${resizeCellStyle}
2547
2568
  `;
2548
- var HeaderCell = ({ header }) => {
2569
+ var Cell2 = styled6(EdsTable.Cell)`
2570
+ ${resizeCellStyle}
2571
+ `;
2572
+ var HeaderCell = ({ header, table }) => {
2549
2573
  var _a;
2550
2574
  const style = {
2551
2575
  width: header.column.getSize(),
@@ -2558,21 +2582,29 @@ var HeaderCell = ({ header }) => {
2558
2582
  colSpan: header.colSpan
2559
2583
  };
2560
2584
  if ((_a = header.column.columnDef.meta) == null ? void 0 : _a.sticky) {
2561
- return /* @__PURE__ */ jsx5(StickyHeaderCell, {
2585
+ return /* @__PURE__ */ jsx5(StickyCell2, {
2562
2586
  ...cellProps,
2563
2587
  children: /* @__PURE__ */ jsx5(HeaderContent, {
2564
- header
2588
+ header,
2589
+ table
2565
2590
  })
2566
2591
  }, header.id);
2567
2592
  }
2568
- return /* @__PURE__ */ jsx5(Table3.Cell, {
2593
+ return /* @__PURE__ */ jsx5(Cell2, {
2569
2594
  ...cellProps,
2570
2595
  children: /* @__PURE__ */ jsx5(HeaderContent, {
2571
- header
2596
+ header,
2597
+ table
2572
2598
  })
2573
2599
  }, header.id);
2574
2600
  };
2575
- function HeaderContent({ header }) {
2601
+ var HeaderDiv = styled6.div`
2602
+ display: flex;
2603
+ align-items: center;
2604
+ gap: 0.25rem;
2605
+ z-index: 5;
2606
+ `;
2607
+ function HeaderContent({ header, table }) {
2576
2608
  if (header.isPlaceholder)
2577
2609
  return null;
2578
2610
  return /* @__PURE__ */ jsxs3(HeaderDiv, {
@@ -2588,7 +2620,16 @@ function HeaderContent({ header }) {
2588
2620
  none: /* @__PURE__ */ jsx5(Icon3, {
2589
2621
  data: arrow_drop_down
2590
2622
  })
2591
- }[header.column.getIsSorted()] ?? null
2623
+ }[header.column.getIsSorted()] ?? null,
2624
+ table.options.enableColumnResizing && /* @__PURE__ */ jsx5("div", {
2625
+ onMouseDown: header.getResizeHandler(),
2626
+ onTouchStart: header.getResizeHandler(),
2627
+ onClick: (e) => e.stopPropagation(),
2628
+ className: `resizer ${header.column.getIsResizing() ? "isResizing" : ""}`,
2629
+ style: {
2630
+ transform: table.options.columnResizeMode === "onEnd" && header.column.getIsResizing() ? `translateX(${table.getState().columnSizingInfo.deltaOffset}px)` : ""
2631
+ }
2632
+ })
2592
2633
  ]
2593
2634
  });
2594
2635
  }
@@ -2606,14 +2647,14 @@ function getSort({ column }) {
2606
2647
  }
2607
2648
 
2608
2649
  // src/cells/HierarchyCell.tsx
2609
- import { tokens as tokens4 } from "@equinor/eds-tokens";
2610
- import styled8, { css as css3 } from "styled-components";
2650
+ import { tokens as tokens5 } from "@equinor/eds-tokens";
2651
+ import styled8, { css as css4 } from "styled-components";
2611
2652
 
2612
2653
  // src/cells/TypographyCustom.tsx
2613
2654
  import {
2614
2655
  Typography as EdsTypography
2615
2656
  } from "@equinor/eds-core-react";
2616
- import { tokens as tokens3 } from "@equinor/eds-tokens";
2657
+ import { tokens as tokens4 } from "@equinor/eds-tokens";
2617
2658
  import styled7 from "styled-components";
2618
2659
  import { jsx as jsx6 } from "react/jsx-runtime";
2619
2660
  var truncateStyle = {
@@ -2647,7 +2688,7 @@ var TypographyCustom = (props) => {
2647
2688
  });
2648
2689
  };
2649
2690
  var HoverCapture = styled7.div`
2650
- height: ${tokens3.typography.table.cell_text.lineHeight};
2691
+ height: ${tokens4.typography.table.cell_text.lineHeight};
2651
2692
  background-color: inherit;
2652
2693
 
2653
2694
  position: relative;
@@ -2681,12 +2722,12 @@ var CellWrapper = styled8(TypographyCustom)`
2681
2722
 
2682
2723
  ${({ depth, expanded }) => expanded && depth === 0 && "font-weight: bold;"}
2683
2724
 
2684
- ${({ depth }) => depth > 0 && css3`
2685
- border-left: 3px solid ${tokens4.colors.infographic.primary__moss_green_34.hex};
2725
+ ${({ depth }) => depth > 0 && css4`
2726
+ border-left: 3px solid ${tokens5.colors.infographic.primary__moss_green_34.hex};
2686
2727
  gap: 0.5rem;
2687
2728
  .--divider {
2688
2729
  width: ${depth * 32}px;
2689
- background-color: ${tokens4.colors.infographic.primary__moss_green_34.hex};
2730
+ background-color: ${tokens5.colors.infographic.primary__moss_green_34.hex};
2690
2731
  height: 3px;
2691
2732
  border-radius: 0 5px 5px 0;
2692
2733
  }
@@ -2942,7 +2983,8 @@ function TableHeader({ table, sticky }) {
2942
2983
  sticky,
2943
2984
  children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx11(Table4.Row, {
2944
2985
  children: headerGroup.headers.map((header) => /* @__PURE__ */ jsx11(HeaderCell, {
2945
- header
2986
+ header,
2987
+ table
2946
2988
  }, header.id))
2947
2989
  }, headerGroup.id))
2948
2990
  });
@@ -2960,7 +3002,7 @@ import { useEffect as useEffect3, useRef as useRef3, useState as useState6 } fro
2960
3002
  import styled16 from "styled-components";
2961
3003
 
2962
3004
  // src/DataTable/components/BasicTable.tsx
2963
- import { Table as EdsTable } from "@equinor/eds-core-react";
3005
+ import { Table as EdsTable2 } from "@equinor/eds-core-react";
2964
3006
 
2965
3007
  // src/DataTable/components/PlaceholderRow.tsx
2966
3008
  import { DotProgress, Table as Table5, Typography as Typography2 } from "@equinor/eds-core-react";
@@ -3055,9 +3097,9 @@ function BasicTable({
3055
3097
  tableCaption
3056
3098
  }) {
3057
3099
  const tableRows = table.getRowModel().rows;
3058
- return /* @__PURE__ */ jsxs8(EdsTable, {
3100
+ return /* @__PURE__ */ jsxs8(EdsTable2, {
3059
3101
  children: [
3060
- /* @__PURE__ */ jsx14(EdsTable.Caption, {
3102
+ /* @__PURE__ */ jsx14(EdsTable2.Caption, {
3061
3103
  hidden: true,
3062
3104
  children: tableCaption
3063
3105
  }),
@@ -3331,7 +3373,7 @@ import { jsx as jsx19, jsxs as jsxs11 } from "react/jsx-runtime";
3331
3373
  function canUseContainStrict(height) {
3332
3374
  if (!height)
3333
3375
  return false;
3334
- const heightIsANumber = !isNaN(parseFloat(height));
3376
+ const heightIsANumber = !isNaN(Number(height)) && !isNaN(parseFloat(height));
3335
3377
  if (heightIsANumber)
3336
3378
  return false;
3337
3379
  const heightIsPercentage = height.endsWith("%");
@@ -3410,6 +3452,8 @@ function DataTable(props) {
3410
3452
  });
3411
3453
  }
3412
3454
  },
3455
+ enableColumnResizing: Boolean(props.columnResizing),
3456
+ columnResizeMode: typeof props.columnResizing === "boolean" ? "onChange" : props.columnResizing,
3413
3457
  enableSorting: sorting == null ? void 0 : sorting.enableSorting,
3414
3458
  manualSorting: sorting == null ? void 0 : sorting.manualSorting,
3415
3459
  enableExpanding: Boolean(props.expansion),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/apollo-components",
3
- "version": "3.1.7",
3
+ "version": "3.1.8-beta.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",