@equinor/apollo-components 1.12.2 → 2.0.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.mjs CHANGED
@@ -310,12 +310,11 @@ var CellWrapper2 = styled8.div`
310
310
  margin-left: -16px;
311
311
  z-index: 2;
312
312
  `;
313
- function SelectColumnDef(props = {}) {
314
- const selectionMode = props.rowSelectionMode;
315
- const showBothSelectAndSubRowsToggle = props.hideExpandControls === false;
313
+ function SelectColumnDef(props) {
314
+ const selectionMode = props.mode;
316
315
  return {
317
316
  id: "select",
318
- size: showBothSelectAndSubRowsToggle ? 96 : 48,
317
+ size: props.includeExpansionButton ? 96 : 48,
319
318
  header: ({ table }) => selectionMode !== "single" ? /* @__PURE__ */ jsx7(CellWrapper2, {
320
319
  children: /* @__PURE__ */ jsx7(Checkbox, {
321
320
  checked: table.getIsAllRowsSelected(),
@@ -358,55 +357,142 @@ function SelectColumnDef(props = {}) {
358
357
  };
359
358
  }
360
359
 
361
- // src/DataTable/DataTableRaw.tsx
362
- import { useRef as useRef2 } from "react";
363
- import styled16 from "styled-components";
360
+ // src/DataTable/components/ColumnSelect.tsx
361
+ import { Button as Button3, Checkbox as Checkbox2, Divider, Icon as Icon4, Popover, Tooltip } from "@equinor/eds-core-react";
362
+ import { close, view_column } from "@equinor/eds-icons";
363
+ import { useRef, useState as useState2 } from "react";
364
+ import styled9 from "styled-components";
364
365
 
365
- // src/DataTable/components/BasicTable.tsx
366
- import { Table as EdsTable } from "@equinor/eds-core-react";
366
+ // src/DataTable/utils.tsx
367
+ function capitalizeHeader(context) {
368
+ const header = context.header.id;
369
+ return header.charAt(0).toUpperCase() + header.slice(1);
370
+ }
371
+ function enableOrUndefined(enabled, value) {
372
+ return Boolean(enabled) ? value : void 0;
373
+ }
374
+ function getColumnHeader(column) {
375
+ const columnHeader = column.columnDef.header;
376
+ if (!columnHeader)
377
+ return column.id;
378
+ return typeof columnHeader === "string" ? columnHeader : column.id;
379
+ }
380
+ function prependSelectColumn(columns, config) {
381
+ if (!(config == null ? void 0 : config.selectColumn))
382
+ return columns;
383
+ if (config.selectColumn === "default")
384
+ return [SelectColumnDef(config), ...columns];
385
+ return [config.selectColumn(), ...columns];
386
+ }
387
+ function getFunctionValueOrDefault(valueOrFn, fnProps, defaultValue) {
388
+ if (valueOrFn === void 0)
389
+ return defaultValue;
390
+ if (typeof valueOrFn === "function")
391
+ return valueOrFn(fnProps);
392
+ return valueOrFn;
393
+ }
367
394
 
368
- // src/DataTable/components/PlaceholderRow.tsx
369
- import { DotProgress, Table as Table3, Typography } from "@equinor/eds-core-react";
370
- import styled9 from "styled-components";
371
- import { jsx as jsx8 } from "react/jsx-runtime";
372
- var PlaceholderTextWrapper = styled9.div`
395
+ // src/DataTable/components/ColumnSelect.tsx
396
+ import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
397
+ var ColumnSelectContent = styled9.div`
398
+ display: grid;
399
+ grid-template-columns: repeat(2, 1fr);
400
+ grid-gap: 0.5rem;
401
+ `;
402
+ var ActionsWrapper = styled9.div`
373
403
  display: flex;
374
- justify-content: center;
404
+ align-items: center;
405
+ justify-content: flex-end;
406
+ gap: 0.5rem;
375
407
  `;
376
- function PlaceholderRow({ isLoading }) {
377
- return /* @__PURE__ */ jsx8(Table3.Row, {
378
- children: /* @__PURE__ */ jsx8(Table3.Cell, {
379
- colSpan: 100,
380
- children: /* @__PURE__ */ jsx8(PlaceholderTextWrapper, {
381
- children: isLoading ? /* @__PURE__ */ jsx8(DotProgress, {
382
- color: "primary"
383
- }) : /* @__PURE__ */ jsx8(Typography, {
384
- children: "No data available"
408
+ function ColumnSelect({ table }) {
409
+ const [isOpen, setIsOpen] = useState2(false);
410
+ const referenceElement = useRef(null);
411
+ const selectableColumns = table.getAllLeafColumns().filter((column) => column.id !== "select");
412
+ return /* @__PURE__ */ jsxs5(Fragment2, {
413
+ children: [
414
+ /* @__PURE__ */ jsx8(Tooltip, {
415
+ title: "Select columns",
416
+ placement: "left",
417
+ children: /* @__PURE__ */ jsx8(Button3, {
418
+ "aria-haspopup": true,
419
+ id: "column-select-anchor",
420
+ "aria-controls": "column-select-popover",
421
+ "aria-expanded": isOpen,
422
+ ref: referenceElement,
423
+ variant: "ghost_icon",
424
+ onClick: () => setIsOpen(true),
425
+ children: /* @__PURE__ */ jsx8(Icon4, {
426
+ name: "view_column",
427
+ data: view_column
428
+ })
385
429
  })
430
+ }),
431
+ /* @__PURE__ */ jsxs5(Popover, {
432
+ open: isOpen,
433
+ id: "column-select-popover",
434
+ anchorEl: referenceElement.current,
435
+ placement: "bottom-end",
436
+ onClose: () => setIsOpen(false),
437
+ children: [
438
+ /* @__PURE__ */ jsxs5(Popover.Header, {
439
+ children: [
440
+ /* @__PURE__ */ jsx8(Popover.Title, {
441
+ children: "Column settings"
442
+ }),
443
+ /* @__PURE__ */ jsx8(Button3, {
444
+ variant: "ghost_icon",
445
+ "aria-label": "Close column select",
446
+ onClick: () => setIsOpen(false),
447
+ children: /* @__PURE__ */ jsx8(Icon4, {
448
+ name: "close",
449
+ data: close,
450
+ size: 24
451
+ })
452
+ })
453
+ ]
454
+ }),
455
+ /* @__PURE__ */ jsxs5(Popover.Content, {
456
+ children: [
457
+ /* @__PURE__ */ jsx8(ColumnSelectContent, {
458
+ children: selectableColumns.map((column) => {
459
+ return /* @__PURE__ */ jsx8(Checkbox2, {
460
+ checked: column.getIsVisible(),
461
+ label: getColumnHeader(column),
462
+ onChange: column.getToggleVisibilityHandler()
463
+ }, column.id);
464
+ })
465
+ }),
466
+ /* @__PURE__ */ jsx8(Divider, {
467
+ variant: "small"
468
+ }),
469
+ /* @__PURE__ */ jsx8(ActionsWrapper, {
470
+ children: /* @__PURE__ */ jsx8(Button3, {
471
+ color: "secondary",
472
+ variant: "ghost",
473
+ disabled: table.getIsAllColumnsVisible(),
474
+ onClick: () => table.toggleAllColumnsVisible(true),
475
+ children: "Reset to default"
476
+ })
477
+ })
478
+ ]
479
+ })
480
+ ]
386
481
  })
387
- })
482
+ ]
388
483
  });
389
484
  }
390
485
 
391
- // src/DataTable/components/TableBody.tsx
392
- import { Table as Table4 } from "@equinor/eds-core-react";
393
- import styled10 from "styled-components";
394
- var TableBody = styled10(Table4.Body)`
395
- // The following attribute are important for fixed column width
396
- // CHANGE THES WITH CAUTION
397
- background: inherit;
398
- `;
399
-
400
486
  // src/DataTable/components/TableHeader.tsx
401
- import { Table as Table6 } from "@equinor/eds-core-react";
487
+ import { Table as Table4 } from "@equinor/eds-core-react";
402
488
 
403
489
  // src/cells/HeaderCell.tsx
404
- import { Icon as Icon4, Table as Table5 } from "@equinor/eds-core-react";
490
+ import { Icon as Icon5, Table as Table3 } from "@equinor/eds-core-react";
405
491
  import { arrow_drop_down, arrow_drop_up } from "@equinor/eds-icons";
406
492
  import { flexRender as flexRender2 } from "@tanstack/react-table";
407
- import styled11 from "styled-components";
408
- import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
409
- var HeaderDiv = styled11.div`
493
+ import styled10 from "styled-components";
494
+ import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
495
+ var HeaderDiv = styled10.div`
410
496
  display: flex;
411
497
  align-items: center;
412
498
  gap: 0.25rem;
@@ -432,7 +518,7 @@ var HeaderCell = ({ header }) => {
432
518
  })
433
519
  }, header.id);
434
520
  }
435
- return /* @__PURE__ */ jsx9(Table5.Cell, {
521
+ return /* @__PURE__ */ jsx9(Table3.Cell, {
436
522
  ...cellProps,
437
523
  children: /* @__PURE__ */ jsx9(HeaderContent, {
438
524
  header
@@ -442,17 +528,17 @@ var HeaderCell = ({ header }) => {
442
528
  function HeaderContent({ header }) {
443
529
  if (header.isPlaceholder)
444
530
  return null;
445
- return /* @__PURE__ */ jsxs5(HeaderDiv, {
531
+ return /* @__PURE__ */ jsxs6(HeaderDiv, {
446
532
  children: [
447
533
  flexRender2(header.column.columnDef.header, header.getContext()),
448
534
  {
449
- asc: /* @__PURE__ */ jsx9(Icon4, {
535
+ asc: /* @__PURE__ */ jsx9(Icon5, {
450
536
  data: arrow_drop_up
451
537
  }),
452
- desc: /* @__PURE__ */ jsx9(Icon4, {
538
+ desc: /* @__PURE__ */ jsx9(Icon5, {
453
539
  data: arrow_drop_down
454
540
  }),
455
- none: /* @__PURE__ */ jsx9(Icon4, {
541
+ none: /* @__PURE__ */ jsx9(Icon5, {
456
542
  data: arrow_drop_down
457
543
  })
458
544
  }[header.column.getIsSorted()] ?? null
@@ -475,9 +561,9 @@ function getSort({ column }) {
475
561
  // src/DataTable/components/TableHeader.tsx
476
562
  import { jsx as jsx10 } from "react/jsx-runtime";
477
563
  function TableHeader({ table, sticky }) {
478
- return /* @__PURE__ */ jsx10(Table6.Head, {
564
+ return /* @__PURE__ */ jsx10(Table4.Head, {
479
565
  sticky,
480
- children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx10(Table6.Row, {
566
+ children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx10(Table4.Row, {
481
567
  children: headerGroup.headers.map((header) => /* @__PURE__ */ jsx10(HeaderCell, {
482
568
  header
483
569
  }, header.id))
@@ -485,14 +571,60 @@ function TableHeader({ table, sticky }) {
485
571
  });
486
572
  }
487
573
 
574
+ // src/DataTable/DataTable.tsx
575
+ import {
576
+ getCoreRowModel,
577
+ getExpandedRowModel,
578
+ getFilteredRowModel,
579
+ getSortedRowModel,
580
+ useReactTable
581
+ } from "@tanstack/react-table";
582
+ import { useEffect as useEffect3, useRef as useRef2, useState as useState4 } from "react";
583
+ import styled16 from "styled-components";
584
+
585
+ // src/DataTable/components/BasicTable.tsx
586
+ import { Table as EdsTable } from "@equinor/eds-core-react";
587
+
588
+ // src/DataTable/components/PlaceholderRow.tsx
589
+ import { DotProgress, Table as Table5, Typography } from "@equinor/eds-core-react";
590
+ import styled11 from "styled-components";
591
+ import { jsx as jsx11 } from "react/jsx-runtime";
592
+ var PlaceholderTextWrapper = styled11.div`
593
+ display: flex;
594
+ justify-content: center;
595
+ `;
596
+ function PlaceholderRow({ isLoading }) {
597
+ return /* @__PURE__ */ jsx11(Table5.Row, {
598
+ children: /* @__PURE__ */ jsx11(Table5.Cell, {
599
+ colSpan: 100,
600
+ children: /* @__PURE__ */ jsx11(PlaceholderTextWrapper, {
601
+ children: isLoading ? /* @__PURE__ */ jsx11(DotProgress, {
602
+ color: "primary"
603
+ }) : /* @__PURE__ */ jsx11(Typography, {
604
+ children: "No data available"
605
+ })
606
+ })
607
+ })
608
+ });
609
+ }
610
+
611
+ // src/DataTable/components/TableBody.tsx
612
+ import { Table as Table6 } from "@equinor/eds-core-react";
613
+ import styled12 from "styled-components";
614
+ var TableBody = styled12(Table6.Body)`
615
+ // The following attribute are important for fixed column width
616
+ // CHANGE THES WITH CAUTION
617
+ background: inherit;
618
+ `;
619
+
488
620
  // src/DataTable/components/TableRow.tsx
489
621
  import { Table as Table7 } from "@equinor/eds-core-react";
490
- import styled12 from "styled-components";
491
- import { jsx as jsx11 } from "react/jsx-runtime";
622
+ import styled13 from "styled-components";
623
+ import { jsx as jsx12 } from "react/jsx-runtime";
492
624
  function TableRow({ row, rowConfig, cellConfig }) {
493
625
  var _a;
494
626
  const rowWrapper = rowConfig == null ? void 0 : rowConfig.rowWrapper;
495
- const tableRowContent = /* @__PURE__ */ jsx11(StyledTableRow, {
627
+ const tableRowContent = /* @__PURE__ */ jsx12(StyledTableRow, {
496
628
  active: row.getIsSelected(),
497
629
  style: {
498
630
  cursor: (rowConfig == null ? void 0 : rowConfig.onClick) ? "pointer" : "initial",
@@ -506,7 +638,7 @@ function TableRow({ row, rowConfig, cellConfig }) {
506
638
  onMouseLeave: handleRowEvent(row, rowConfig == null ? void 0 : rowConfig.onMouseLeave),
507
639
  children: row.getVisibleCells().map((cell) => {
508
640
  var _a2;
509
- return /* @__PURE__ */ jsx11(DynamicCell, {
641
+ return /* @__PURE__ */ jsx12(DynamicCell, {
510
642
  cell,
511
643
  getStickyCellColor: cellConfig == null ? void 0 : cellConfig.getStickyCellColor,
512
644
  highlight: (_a2 = cellConfig == null ? void 0 : cellConfig.getShouldHighlight) == null ? void 0 : _a2.call(cellConfig, cell)
@@ -515,7 +647,7 @@ function TableRow({ row, rowConfig, cellConfig }) {
515
647
  });
516
648
  return rowWrapper ? rowWrapper({ row, children: tableRowContent }) : tableRowContent;
517
649
  }
518
- var StyledTableRow = styled12(Table7.Row)`
650
+ var StyledTableRow = styled13(Table7.Row)`
519
651
  /* Background color must be inherited here. Does not work with inline styling */
520
652
  ${({ active }) => active ? "" : "background-color: inherit;"}
521
653
  `;
@@ -528,27 +660,32 @@ function handleRowEvent(row, handler) {
528
660
  }
529
661
 
530
662
  // src/DataTable/components/BasicTable.tsx
531
- import { jsx as jsx12, jsxs as jsxs6 } from "react/jsx-runtime";
663
+ import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
532
664
  function BasicTable({
533
665
  table,
534
666
  rowConfig,
535
667
  cellConfig,
536
668
  stickyHeader,
537
- isLoading
669
+ isLoading,
670
+ tableCaption
538
671
  }) {
539
672
  const tableRows = table.getRowModel().rows;
540
- return /* @__PURE__ */ jsxs6(EdsTable, {
673
+ return /* @__PURE__ */ jsxs7(EdsTable, {
541
674
  children: [
542
- /* @__PURE__ */ jsx12(TableHeader, {
675
+ /* @__PURE__ */ jsx13(EdsTable.Caption, {
676
+ hidden: true,
677
+ children: tableCaption
678
+ }),
679
+ /* @__PURE__ */ jsx13(TableHeader, {
543
680
  sticky: stickyHeader,
544
681
  table
545
682
  }),
546
- /* @__PURE__ */ jsx12(TableBody, {
547
- children: tableRows.length ? tableRows.map((row) => /* @__PURE__ */ jsx12(TableRow, {
683
+ /* @__PURE__ */ jsx13(TableBody, {
684
+ children: tableRows.length ? tableRows.map((row) => /* @__PURE__ */ jsx13(TableRow, {
548
685
  row,
549
686
  rowConfig,
550
687
  cellConfig
551
- }, row.id)) : /* @__PURE__ */ jsx12(PlaceholderRow, {
688
+ }, row.id)) : /* @__PURE__ */ jsx13(PlaceholderRow, {
552
689
  isLoading
553
690
  })
554
691
  })
@@ -559,27 +696,18 @@ function BasicTable({
559
696
  // src/DataTable/components/DataTableHeader.tsx
560
697
  import { Typography as Typography2 } from "@equinor/eds-core-react";
561
698
  import { search } from "@equinor/eds-icons";
562
- import { useAtom } from "jotai";
563
699
  import styled15 from "styled-components";
564
700
 
565
- // src/DataTable/atoms.ts
566
- import { atom } from "jotai";
567
- var columnVisibilityAtom = atom({});
568
- var globalFilterAtom = atom("");
569
- var rowSelectionAtom = atom({});
570
- var tableSortingAtom = atom([]);
571
- var expandedRowsAtom = atom({});
572
-
573
701
  // src/DataTable/filters/DebouncedInput.tsx
574
- import { Button as Button3, Icon as Icon5, Input, Tooltip } from "@equinor/eds-core-react";
575
- import { close } from "@equinor/eds-icons";
576
- import { useEffect, useState as useState2 } from "react";
577
- import styled13 from "styled-components";
578
- import { jsx as jsx13 } from "react/jsx-runtime";
579
- var Wrapper3 = styled13.div`
702
+ import { Button as Button4, Icon as Icon6, Input, Tooltip as Tooltip2 } from "@equinor/eds-core-react";
703
+ import { close as close2 } from "@equinor/eds-icons";
704
+ import { useEffect, useState as useState3 } from "react";
705
+ import styled14 from "styled-components";
706
+ import { jsx as jsx14 } from "react/jsx-runtime";
707
+ var Wrapper3 = styled14.div`
580
708
  width: 200px;
581
709
  `;
582
- var CloseButton = styled13(Button3)`
710
+ var CloseButton = styled14(Button4)`
583
711
  width: 24px;
584
712
  height: 24px;
585
713
  `;
@@ -590,7 +718,7 @@ function DebouncedInput({
590
718
  debounce = 500,
591
719
  ...props
592
720
  }) {
593
- const [value, setValue] = useState2(initialValue);
721
+ const [value, setValue] = useState3(initialValue);
594
722
  useEffect(() => {
595
723
  setValue(initialValue);
596
724
  }, [initialValue]);
@@ -600,23 +728,23 @@ function DebouncedInput({
600
728
  }, debounce);
601
729
  return () => clearTimeout(timeout);
602
730
  }, [value]);
603
- return /* @__PURE__ */ jsx13(Wrapper3, {
604
- children: /* @__PURE__ */ jsx13(Input, {
731
+ return /* @__PURE__ */ jsx14(Wrapper3, {
732
+ children: /* @__PURE__ */ jsx14(Input, {
605
733
  ...props,
606
734
  value,
607
- leftAdornments: icon && /* @__PURE__ */ jsx13(Icon5, {
735
+ leftAdornments: icon && /* @__PURE__ */ jsx14(Icon6, {
608
736
  name: icon.name,
609
737
  data: icon,
610
738
  size: 18
611
739
  }),
612
- rightAdornments: !!value && /* @__PURE__ */ jsx13(Tooltip, {
740
+ rightAdornments: !!value && /* @__PURE__ */ jsx14(Tooltip2, {
613
741
  title: "Clear input",
614
- children: /* @__PURE__ */ jsx13(CloseButton, {
742
+ children: /* @__PURE__ */ jsx14(CloseButton, {
615
743
  variant: "ghost_icon",
616
744
  onClick: () => setValue(""),
617
- children: /* @__PURE__ */ jsx13(Icon5, {
618
- name: close.name,
619
- data: close,
745
+ children: /* @__PURE__ */ jsx14(Icon6, {
746
+ name: close2.name,
747
+ data: close2,
620
748
  size: 18
621
749
  })
622
750
  })
@@ -636,128 +764,6 @@ var fuzzyFilter = (row, columnId, value, addMeta) => {
636
764
  return itemRank.passed;
637
765
  };
638
766
 
639
- // src/DataTable/components/ColumnSelect.tsx
640
- import { Button as Button4, Checkbox as Checkbox2, Divider, Icon as Icon6, Popover } from "@equinor/eds-core-react";
641
- import { close as close2, view_column } from "@equinor/eds-icons";
642
- import { useRef, useState as useState3 } from "react";
643
- import styled14 from "styled-components";
644
-
645
- // src/DataTable/utils.tsx
646
- function capitalizeHeader(context) {
647
- const header = context.header.id;
648
- return header.charAt(0).toUpperCase() + header.slice(1);
649
- }
650
- function enableOrUndefined(enabled, value) {
651
- return Boolean(enabled) ? value : void 0;
652
- }
653
- function getColumnHeader(column) {
654
- const columnHeader = column.columnDef.header;
655
- if (!columnHeader)
656
- return column.id;
657
- return typeof columnHeader === "string" ? columnHeader : column.id;
658
- }
659
- function prependSelectColumn(columns, config) {
660
- if (!(config == null ? void 0 : config.selectColumn))
661
- return columns;
662
- if (config.selectColumn === "default")
663
- return [SelectColumnDef(config), ...columns];
664
- return [config.selectColumn(), ...columns];
665
- }
666
- function getFunctionValueOrDefault(valueOrFn, fnProps, defaultValue) {
667
- if (valueOrFn === void 0)
668
- return defaultValue;
669
- if (typeof valueOrFn === "function")
670
- return valueOrFn(fnProps);
671
- return valueOrFn;
672
- }
673
-
674
- // src/DataTable/components/ColumnSelect.tsx
675
- import { Fragment as Fragment2, jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
676
- var ColumnSelectContent = styled14.div`
677
- display: grid;
678
- grid-template-columns: repeat(2, 1fr);
679
- grid-gap: 0.5rem;
680
- `;
681
- var ActionsWrapper = styled14.div`
682
- display: flex;
683
- align-items: center;
684
- justify-content: flex-end;
685
- gap: 0.5rem;
686
- `;
687
- function ColumnSelect({ table }) {
688
- const [isOpen, setIsOpen] = useState3(false);
689
- const referenceElement = useRef(null);
690
- const selectableColumns = table.getAllLeafColumns().filter((column) => column.id !== "select");
691
- return /* @__PURE__ */ jsxs7(Fragment2, {
692
- children: [
693
- /* @__PURE__ */ jsx14(Button4, {
694
- "aria-haspopup": true,
695
- id: "column-select-anchor",
696
- "aria-controls": "column-select-popover",
697
- "aria-expanded": isOpen,
698
- ref: referenceElement,
699
- variant: "ghost_icon",
700
- onClick: () => setIsOpen(true),
701
- children: /* @__PURE__ */ jsx14(Icon6, {
702
- name: "view_column",
703
- data: view_column
704
- })
705
- }),
706
- /* @__PURE__ */ jsxs7(Popover, {
707
- open: isOpen,
708
- id: "column-select-popover",
709
- anchorEl: referenceElement.current,
710
- placement: "bottom-end",
711
- onClose: () => setIsOpen(false),
712
- children: [
713
- /* @__PURE__ */ jsxs7(Popover.Header, {
714
- children: [
715
- /* @__PURE__ */ jsx14(Popover.Title, {
716
- children: "Column settings"
717
- }),
718
- /* @__PURE__ */ jsx14(Button4, {
719
- variant: "ghost_icon",
720
- "aria-label": "Close column select",
721
- onClick: () => setIsOpen(false),
722
- children: /* @__PURE__ */ jsx14(Icon6, {
723
- name: "close",
724
- data: close2,
725
- size: 24
726
- })
727
- })
728
- ]
729
- }),
730
- /* @__PURE__ */ jsxs7(Popover.Content, {
731
- children: [
732
- /* @__PURE__ */ jsx14(ColumnSelectContent, {
733
- children: selectableColumns.map((column) => {
734
- return /* @__PURE__ */ jsx14(Checkbox2, {
735
- checked: column.getIsVisible(),
736
- label: getColumnHeader(column),
737
- onChange: column.getToggleVisibilityHandler()
738
- }, column.id);
739
- })
740
- }),
741
- /* @__PURE__ */ jsx14(Divider, {
742
- variant: "small"
743
- }),
744
- /* @__PURE__ */ jsx14(ActionsWrapper, {
745
- children: /* @__PURE__ */ jsx14(Button4, {
746
- color: "secondary",
747
- variant: "ghost",
748
- disabled: table.getIsAllColumnsVisible(),
749
- onClick: () => table.toggleAllColumnsVisible(true),
750
- children: "Reset to default"
751
- })
752
- })
753
- ]
754
- })
755
- ]
756
- })
757
- ]
758
- });
759
- }
760
-
761
767
  // src/DataTable/components/DataTableHeader.tsx
762
768
  import { Fragment as Fragment3, jsx as jsx15, jsxs as jsxs8 } from "react/jsx-runtime";
763
769
  var DataTableHeaderWrapper = styled15.div`
@@ -765,7 +771,7 @@ var DataTableHeaderWrapper = styled15.div`
765
771
  align-items: center;
766
772
  justify-content: space-between;
767
773
  gap: 0.5rem;
768
- padding: ${(props) => props.captionPadding ?? "1rem"};
774
+ padding: 1rem;
769
775
  `;
770
776
  var FilterContainer = styled15.div`
771
777
  display: flex;
@@ -773,30 +779,47 @@ var FilterContainer = styled15.div`
773
779
  gap: 1rem;
774
780
  justify-content: flex-end;
775
781
  `;
776
- function DataTableHeader({ config, table, ...props }) {
782
+ function ActionsHeaderRow({
783
+ table,
784
+ actionsRow,
785
+ tableCaption,
786
+ globalFilter
787
+ }) {
777
788
  var _a;
778
- const [globalFilter, setGlobalFilter] = useAtom(globalFilterAtom);
779
789
  return /* @__PURE__ */ jsxs8(DataTableHeaderWrapper, {
780
790
  className: "--table-caption",
781
- captionPadding: props.captionPadding,
782
791
  children: [
783
- (props == null ? void 0 : props.tableCaption) && /* @__PURE__ */ jsx15(Typography2, {
784
- variant: "h3",
785
- children: props == null ? void 0 : props.tableCaption
792
+ /* @__PURE__ */ jsxs8(FilterContainer, {
793
+ className: "--filter-container-left",
794
+ children: [
795
+ (actionsRow == null ? void 0 : actionsRow.enableTableCaption) && /* @__PURE__ */ jsx15(Typography2, {
796
+ variant: "h3",
797
+ children: tableCaption
798
+ }),
799
+ (_a = actionsRow == null ? void 0 : actionsRow.customActions) == null ? void 0 : _a.call(actionsRow, table)
800
+ ]
786
801
  }),
787
802
  /* @__PURE__ */ jsx15(FilterContainer, {
788
- className: "--filter-container",
803
+ className: "--filter-container-right",
789
804
  children: /* @__PURE__ */ jsxs8(Fragment3, {
790
805
  children: [
791
- (config == null ? void 0 : config.globalFilter) && /* @__PURE__ */ jsx15(DebouncedInput, {
792
- value: globalFilter,
806
+ (actionsRow == null ? void 0 : actionsRow.enableGlobalFilterInput) && /* @__PURE__ */ jsx15(DebouncedInput, {
807
+ value: globalFilter.state,
793
808
  icon: search,
794
- placeholder: (config == null ? void 0 : config.globalFilterPlaceholder) ?? "Search all columns",
795
- onChange: (value) => setGlobalFilter(String(value))
809
+ placeholder: actionsRow.globalFilterPlaceholder ?? "Search all columns",
810
+ onChange: (value) => globalFilter.onChange(String(value))
796
811
  }),
797
- (_a = config == null ? void 0 : config.filterActions) == null ? void 0 : _a.call(config, table),
798
- (config == null ? void 0 : config.columnSelect) && /* @__PURE__ */ jsx15(ColumnSelect, {
812
+ (actionsRow == null ? void 0 : actionsRow.enableColumnSelect) && /* @__PURE__ */ jsx15(ColumnSelect, {
799
813
  table
814
+ }),
815
+ (actionsRow == null ? void 0 : actionsRow.totalRowCount) && /* @__PURE__ */ jsxs8("span", {
816
+ children: [
817
+ table.options.data.length.toLocaleString(),
818
+ " /",
819
+ " ",
820
+ actionsRow.totalRowCount.toLocaleString(),
821
+ " rows"
822
+ ]
800
823
  })
801
824
  ]
802
825
  })
@@ -844,6 +867,10 @@ function VirtualTable({
844
867
  const paddingBottom = virtualRows.length > 0 ? rowVirtualizer.getTotalSize() - (((_b = virtualRows == null ? void 0 : virtualRows[virtualRows.length - 1]) == null ? void 0 : _b.end) || 0) : 0;
845
868
  return /* @__PURE__ */ jsxs9(Table9, {
846
869
  children: [
870
+ /* @__PURE__ */ jsx17(Table9.Caption, {
871
+ hidden: true,
872
+ children: props.tableCaption
873
+ }),
847
874
  /* @__PURE__ */ jsx17(TableHeader, {
848
875
  sticky: props.stickyHeader,
849
876
  table
@@ -872,7 +899,36 @@ function VirtualTable({
872
899
  });
873
900
  }
874
901
 
875
- // src/DataTable/DataTableRaw.tsx
902
+ // src/DataTable/hooks/useFetchMoreOnBottomReached.tsx
903
+ import { useCallback, useEffect as useEffect2 } from "react";
904
+ function useFetchMoreOnBottomReached(tableContainerRef, infiniteScrollConfig) {
905
+ const fetchMoreOnBottomReached = useCallback(
906
+ (tableContainer) => {
907
+ if (!infiniteScrollConfig)
908
+ return;
909
+ if (!tableContainer)
910
+ return;
911
+ const { onBottomScroll, offset = 300 } = infiniteScrollConfig;
912
+ const { scrollHeight, scrollTop, clientHeight } = tableContainer;
913
+ if (scrollHeight - scrollTop - clientHeight < offset) {
914
+ onBottomScroll();
915
+ }
916
+ },
917
+ [infiniteScrollConfig]
918
+ );
919
+ const onTableContainerScroll = useCallback(
920
+ (event) => fetchMoreOnBottomReached(event.target),
921
+ [fetchMoreOnBottomReached]
922
+ );
923
+ useEffect2(() => {
924
+ if (!infiniteScrollConfig)
925
+ return;
926
+ fetchMoreOnBottomReached(tableContainerRef.current);
927
+ }, [fetchMoreOnBottomReached]);
928
+ return onTableContainerScroll;
929
+ }
930
+
931
+ // src/DataTable/DataTable.tsx
876
932
  import { jsx as jsx18, jsxs as jsxs10 } from "react/jsx-runtime";
877
933
  var DataTableWrapper = styled16.div`
878
934
  width: ${(props) => props.width ?? "100%"};
@@ -885,146 +941,144 @@ var DataTableWrapper = styled16.div`
885
941
  table {
886
942
  width: 100%;
887
943
 
888
- // The following attributes are important for fixed column width
944
+ // The following attribute is important for fixed column width
889
945
  // CHANGE THES WITH CAUTION
890
- overflow: auto;
891
946
  table-layout: ${(props) => props.tableLayout ?? "auto"};
892
947
  }
893
948
  }
894
949
  `;
895
- function DataTableRaw(props) {
896
- const { isLoading, header, filters, config, rowConfig, cellConfig, table } = props;
897
- const tableContainerRef = useRef2(null);
898
- return /* @__PURE__ */ jsxs10(DataTableWrapper, {
899
- captionPadding: header == null ? void 0 : header.captionPadding,
900
- height: config == null ? void 0 : config.height,
901
- width: config == null ? void 0 : config.width,
902
- tableLayout: config == null ? void 0 : config.tableLayout,
903
- children: [
904
- /* @__PURE__ */ jsx18(DataTableHeader, {
905
- tableCaption: header == null ? void 0 : header.tableCaption,
906
- captionPadding: header == null ? void 0 : header.captionPadding,
907
- table,
908
- config: filters
909
- }),
910
- /* @__PURE__ */ jsx18("div", {
911
- ref: tableContainerRef,
912
- className: "--table-container",
913
- children: (config == null ? void 0 : config.virtual) ? /* @__PURE__ */ jsx18(VirtualTable, {
914
- containerRef: tableContainerRef,
915
- table,
916
- rowConfig,
917
- cellConfig,
918
- isLoading,
919
- stickyHeader: header == null ? void 0 : header.stickyHeader
920
- }) : /* @__PURE__ */ jsx18(BasicTable, {
921
- table,
922
- rowConfig,
923
- cellConfig,
924
- isLoading,
925
- stickyHeader: header == null ? void 0 : header.stickyHeader
926
- })
927
- })
928
- ]
929
- });
930
- }
931
-
932
- // src/DataTable/useDataTable.tsx
933
- import {
934
- getCoreRowModel,
935
- getExpandedRowModel,
936
- getFilteredRowModel,
937
- getSortedRowModel,
938
- useReactTable
939
- } from "@tanstack/react-table";
940
- import { useAtom as useAtom2 } from "jotai";
941
- import { useEffect as useEffect2 } from "react";
942
- import { jsx as jsx19 } from "react/jsx-runtime";
943
- function useDataTable(props) {
944
- const { columns, data, filters, config, cellConfig, sortConfig } = props;
945
- const [columnVisibility, setColumnVisibility] = useAtom2(columnVisibilityAtom);
946
- const [globalFilter, setGlobalFilter] = useAtom2(globalFilterAtom);
947
- const [sorting, setSorting] = useAtom2(tableSortingAtom);
948
- const [rowSelectionState, setRowSelectionState] = useAtom2(rowSelectionAtom);
949
- const [expanded, setExpanded] = useAtom2(expandedRowsAtom);
950
+ function DataTable(props) {
951
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
952
+ const { columns, data, actionsRow, cellConfig, sorting } = props;
953
+ const [internalColumnVisibility, setInternalColumnVisibility] = useState4({});
954
+ const [columnVisibility, setColumnVisibility] = [
955
+ ((_a = props.columnVisibility) == null ? void 0 : _a.state) ?? internalColumnVisibility,
956
+ ((_b = props.columnVisibility) == null ? void 0 : _b.onChange) ?? setInternalColumnVisibility
957
+ ];
958
+ const [internalGlobalFilterState, setInternalGlobalFilterState] = useState4("");
959
+ const [globalFilterState, setGlobalFilterState] = [
960
+ ((_c = props.globalFilter) == null ? void 0 : _c.state) ?? internalGlobalFilterState,
961
+ ((_d = props.globalFilter) == null ? void 0 : _d.onChange) ?? setInternalGlobalFilterState
962
+ ];
963
+ const shouldEnableGlobalFilter = ((_e = props.actionsRow) == null ? void 0 : _e.enableGlobalFilterInput) || Boolean(props.globalFilter);
950
964
  function enableGlobalFilter(value) {
951
- return enableOrUndefined(filters == null ? void 0 : filters.globalFilter, value);
965
+ return enableOrUndefined(shouldEnableGlobalFilter, value);
952
966
  }
967
+ const [internalSortingState, setInternalSortingState] = useState4([]);
968
+ const [sortingState, setSortingState] = [
969
+ ((_f = props.sorting) == null ? void 0 : _f.state) ?? internalSortingState,
970
+ ((_g = props.sorting) == null ? void 0 : _g.onChange) ?? setInternalSortingState
971
+ ];
972
+ const [internalRowSelectionState, setInternalRowSelectionState] = useState4({});
973
+ const [rowSelectionState, setRowSelectionState] = [
974
+ ((_h = props.rowSelection) == null ? void 0 : _h.state) ?? internalRowSelectionState,
975
+ ((_i = props.rowSelection) == null ? void 0 : _i.onChange) ?? setInternalRowSelectionState
976
+ ];
977
+ const [internalExpandedState, setInternalExpandedState] = useState4({});
978
+ const [expandedState, setExpandedState] = [
979
+ ((_j = props.expansion) == null ? void 0 : _j.state) ?? internalExpandedState,
980
+ ((_k = props.expansion) == null ? void 0 : _k.onChange) ?? setInternalExpandedState
981
+ ];
953
982
  const table = useReactTable({
954
- columns: prependSelectColumn(columns, config),
983
+ columns: prependSelectColumn(columns, props.rowSelection),
955
984
  data,
956
985
  globalFilterFn: enableGlobalFilter(fuzzyFilter),
957
986
  state: {
958
- expanded,
959
- globalFilter: enableGlobalFilter(globalFilter),
960
- sorting: (sortConfig == null ? void 0 : sortConfig.enableSorting) || (config == null ? void 0 : config.sortable) ? (sortConfig == null ? void 0 : sortConfig.sorting) ?? sorting : void 0,
987
+ expanded: expandedState,
988
+ globalFilter: enableGlobalFilter(globalFilterState),
989
+ sorting: ((_l = props.sorting) == null ? void 0 : _l.enableSorting) ? ((_m = props.sorting) == null ? void 0 : _m.state) ?? sortingState : void 0,
961
990
  rowSelection: rowSelectionState,
962
991
  columnVisibility
963
992
  },
964
993
  defaultColumn: {
965
994
  cell: ({ cell }) => {
966
995
  const truncateMode = getFunctionValueOrDefault(cellConfig == null ? void 0 : cellConfig.truncateMode, cell, "hover");
967
- return /* @__PURE__ */ jsx19(TypographyCustom, {
996
+ return /* @__PURE__ */ jsx18(TypographyCustom, {
968
997
  truncate: truncateMode === "hover",
969
998
  children: cell.getValue()
970
999
  });
971
1000
  }
972
1001
  },
973
- enableSorting: (sortConfig == null ? void 0 : sortConfig.enableSorting) ?? (config == null ? void 0 : config.sortable),
974
- manualSorting: sortConfig == null ? void 0 : sortConfig.manualSorting,
975
- enableExpanding: !(config == null ? void 0 : config.hideExpandControls),
976
- enableMultiRowSelection: (config == null ? void 0 : config.rowSelectionMode) === "multiple",
977
- enableSubRowSelection: (config == null ? void 0 : config.rowSelectionMode) !== "single",
978
- filterFromLeafRows: filters == null ? void 0 : filters.filterFromLeafRows,
1002
+ enableSorting: sorting == null ? void 0 : sorting.enableSorting,
1003
+ manualSorting: sorting == null ? void 0 : sorting.manualSorting,
1004
+ enableExpanding: Boolean(props.expansion),
1005
+ enableMultiRowSelection: ((_n = props.rowSelection) == null ? void 0 : _n.mode) === "multiple",
1006
+ enableSubRowSelection: ((_o = props.rowSelection) == null ? void 0 : _o.mode) !== "single",
1007
+ filterFromLeafRows: actionsRow == null ? void 0 : actionsRow.filterFromLeafRows,
979
1008
  getFilteredRowModel: enableGlobalFilter(getFilteredRowModel()),
980
1009
  getCoreRowModel: getCoreRowModel(),
981
1010
  getExpandedRowModel: getExpandedRowModel(),
982
1011
  getSortedRowModel: getSortedRowModel(),
983
- onExpandedChange: setExpanded,
1012
+ onExpandedChange: setExpandedState,
984
1013
  onRowSelectionChange: setRowSelectionState,
985
- onSortingChange: (sortConfig == null ? void 0 : sortConfig.enableSorting) || (config == null ? void 0 : config.sortable) ? (sortConfig == null ? void 0 : sortConfig.onSortingChange) ?? setSorting : void 0,
1014
+ onSortingChange: (sorting == null ? void 0 : sorting.enableSorting) ? (sorting == null ? void 0 : sorting.onChange) ?? setSortingState : void 0,
986
1015
  onColumnVisibilityChange: setColumnVisibility,
987
- onGlobalFilterChange: enableGlobalFilter(setGlobalFilter),
988
- getSubRows: config == null ? void 0 : config.getSubRows,
989
- getRowId: config == null ? void 0 : config.getRowId
1016
+ onGlobalFilterChange: enableGlobalFilter(setGlobalFilterState),
1017
+ getSubRows: props == null ? void 0 : props.getSubRows,
1018
+ getRowId: props == null ? void 0 : props.getRowId
990
1019
  });
991
- useEffect2(() => {
992
- if (config && config.expandAllByDefault) {
1020
+ useEffect3(() => {
1021
+ var _a2;
1022
+ if ((_a2 = props.expansion) == null ? void 0 : _a2.expandAllByDefault) {
993
1023
  table.toggleAllRowsExpanded();
994
1024
  }
995
- }, [table, config == null ? void 0 : config.expandAllByDefault]);
996
- return table;
997
- }
998
-
999
- // src/DataTable/DataTable.tsx
1000
- import { jsx as jsx20 } from "react/jsx-runtime";
1001
- function DataTable(props) {
1002
- const table = useDataTable(props);
1003
- return /* @__PURE__ */ jsx20(DataTableRaw, {
1004
- table,
1005
- ...props
1006
- });
1007
- }
1008
-
1009
- // src/DataTable/Provider.tsx
1010
- import { Provider } from "jotai";
1011
- import { jsx as jsx21 } from "react/jsx-runtime";
1012
- function DataTableProvider({ children, ...props }) {
1013
- return /* @__PURE__ */ jsx21(Provider, {
1014
- ...props,
1015
- children
1025
+ }, [table, (_p = props.expansion) == null ? void 0 : _p.expandAllByDefault]);
1026
+ const { isLoading, rowConfig } = props;
1027
+ const tableContainerRef = useRef2(null);
1028
+ const onTableContainerScroll = useFetchMoreOnBottomReached(
1029
+ tableContainerRef,
1030
+ props.infiniteScroll
1031
+ );
1032
+ return /* @__PURE__ */ jsxs10(DataTableWrapper, {
1033
+ height: props == null ? void 0 : props.height,
1034
+ width: props == null ? void 0 : props.width,
1035
+ tableLayout: props == null ? void 0 : props.tableLayout,
1036
+ children: [
1037
+ props.actionsRow && /* @__PURE__ */ jsx18(ActionsHeaderRow, {
1038
+ table,
1039
+ actionsRow: props.actionsRow,
1040
+ globalFilter: { state: globalFilterState, onChange: setGlobalFilterState },
1041
+ tableCaption: props.tableCaption
1042
+ }),
1043
+ /* @__PURE__ */ jsx18("div", {
1044
+ ...props.tableContainerProps,
1045
+ className: "--table-container " + ((_q = props.tableContainerProps) == null ? void 0 : _q.className),
1046
+ onScroll: ((_r = props.tableContainerProps) == null ? void 0 : _r.onScroll) ?? onTableContainerScroll,
1047
+ ref: (node) => {
1048
+ var _a2;
1049
+ if (node) {
1050
+ tableContainerRef.current = node;
1051
+ if ((_a2 = props.tableContainerProps) == null ? void 0 : _a2.ref) {
1052
+ props.tableContainerProps.ref.current = node;
1053
+ }
1054
+ }
1055
+ },
1056
+ children: (props == null ? void 0 : props.virtual) ? /* @__PURE__ */ jsx18(VirtualTable, {
1057
+ containerRef: tableContainerRef,
1058
+ tableCaption: props.tableCaption,
1059
+ table,
1060
+ rowConfig,
1061
+ cellConfig,
1062
+ isLoading,
1063
+ stickyHeader: (_s = props.headerConfig) == null ? void 0 : _s.sticky
1064
+ }) : /* @__PURE__ */ jsx18(BasicTable, {
1065
+ tableCaption: props.tableCaption,
1066
+ table,
1067
+ rowConfig,
1068
+ cellConfig,
1069
+ isLoading,
1070
+ stickyHeader: (_t = props.headerConfig) == null ? void 0 : _t.sticky
1071
+ })
1072
+ })
1073
+ ]
1016
1074
  });
1017
1075
  }
1018
-
1019
- // src/DataTable/index.ts
1020
- var DataTable2 = DataTable;
1021
- DataTable2.Provider = DataTableProvider;
1022
1076
  export {
1023
1077
  AppShell,
1024
1078
  AppSidebar,
1025
1079
  ChipsCell,
1026
1080
  ColumnSelect,
1027
- DataTable2 as DataTable,
1081
+ DataTable,
1028
1082
  DynamicCell,
1029
1083
  HierarchyCell,
1030
1084
  SelectColumnDef,
@@ -1032,9 +1086,5 @@ export {
1032
1086
  TableHeader,
1033
1087
  TypographyCustom,
1034
1088
  capitalizeHeader,
1035
- columnVisibilityAtom,
1036
- globalFilterAtom,
1037
- prependSelectColumn,
1038
- rowSelectionAtom,
1039
- tableSortingAtom
1089
+ prependSelectColumn
1040
1090
  };