@symply.io/basic-components 1.7.0-beta.1 → 1.7.0-beta.3

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.
@@ -24,7 +24,7 @@ import useInteractions from "./useInteractions";
24
24
  var VirtualDataTable = function (props, ref) {
25
25
  var rows = props.rows, columns = props.columns, dense = props.dense, height = props.height, _a = props.noDataText, noDataText = _a === void 0 ? "No Data" : _a, headerBgColor = props.headerBgColor, headerTextColor = props.headerTextColor, footerBgColor = props.footerBgColor, footerTextColor = props.footerTextColor, sortingDisabled = props.sortingDisabled, options = props.options, initialState = props.initialState, onSort = props.onSort, onRowClick = props.onRowClick, onContextMenu = props.onContextMenu, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
26
26
  var _b = useState(null), rowDataIndex = _b[0], setRowDataIndex = _b[1];
27
- var _c = useInteractions({ rows: rows, columns: columns, initialState: initialState, sortingDisabled: sortingDisabled, onSort: onSort }), normalCols = _c.normalCols, pinnedLeftCols = _c.pinnedLeftCols, pinnedRightCols = _c.pinnedRightCols, leftShadowVisible = _c.leftShadowVisible, rightShadowVisible = _c.rightShadowVisible, onScroll = _c.onScroll, handleSort = _c.handleSort, onResetSorting = _c.onResetSorting, renderSortingSymbol = _c.renderSortingSymbol;
27
+ var _c = useInteractions({ rows: rows, columns: columns, initialState: initialState, sortingDisabled: sortingDisabled, onSort: onSort }), normalCols = _c.normalCols, pinnedLeftCols = _c.pinnedLeftCols, pinnedRightCols = _c.pinnedRightCols, leftShadowVisible = _c.leftShadowVisible, rightShadowVisible = _c.rightShadowVisible, onScroll = _c.onScroll, handleSort = _c.handleSort, onResetSorting = _c.onResetSorting, reflectScrollerRef = _c.reflectScrollerRef, renderSortingSymbol = _c.renderSortingSymbol;
28
28
  useImperativeHandle(ref, function () { return ({
29
29
  onResetSorting: onResetSorting,
30
30
  }); }, [onResetSorting]);
@@ -330,6 +330,6 @@ var VirtualDataTable = function (props, ref) {
330
330
  TableBody: forwardRef(function (props, ref) { return (_jsx(TableBody, __assign({}, props, { ref: ref }))); }),
331
331
  TableFoot: forwardRef(function (props, ref) { return (_jsx(TableFooter, __assign({}, props, { ref: ref }))); }),
332
332
  }); }, [onRowClick, onContextMenu, handleCustomizeRowBgColor]);
333
- return (_jsx(TableVirtuoso, { data: rows, style: { height: height }, onResize: onScroll, onScroll: onScroll, components: VirtuosoTableComponents, fixedHeaderContent: fixedHeaderContent, fixedFooterContent: fixedFooterContent, itemContent: itemContent, followOutput: "smooth", increaseViewportBy: 5 }));
333
+ return (_jsx(TableVirtuoso, { data: rows, increaseViewportBy: { top: 5, bottom: 8 }, initialTopMostItemIndex: 0, style: { height: height }, onScroll: onScroll, onResize: onScroll, components: VirtuosoTableComponents, fixedHeaderContent: fixedHeaderContent, fixedFooterContent: fixedFooterContent, itemContent: itemContent, followOutput: "smooth", scrollerRef: reflectScrollerRef }));
334
334
  };
335
335
  export default forwardRef(VirtualDataTable);
@@ -1,4 +1,3 @@
1
- import { UIEventHandler } from "react";
2
1
  import type { InteractionProps, TVirtualTableRow, TVirtualTableColumn, VirtualDataTableSortingProps } from "./types";
3
2
  declare function useInteractions<RowProps extends TVirtualTableRow>(props: InteractionProps<RowProps>): {
4
3
  normalCols: TVirtualTableColumn[];
@@ -6,9 +5,10 @@ declare function useInteractions<RowProps extends TVirtualTableRow>(props: Inter
6
5
  pinnedRightCols: TVirtualTableColumn[];
7
6
  leftShadowVisible: boolean;
8
7
  rightShadowVisible: boolean;
9
- onScroll: UIEventHandler<HTMLDivElement>;
8
+ onScroll: () => void;
10
9
  handleSort: ({ accessor }: Pick<VirtualDataTableSortingProps, "accessor">) => void;
11
10
  onResetSorting: () => void;
11
+ reflectScrollerRef: (ref: HTMLElement | Window | null) => void;
12
12
  renderSortingSymbol: (accessor: string) => "" | "↑" | "↓";
13
13
  };
14
14
  export default useInteractions;
@@ -9,15 +9,16 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { useMemo, useState, useCallback } from "react";
12
+ import { useMemo, useState, useCallback, useEffect } from "react";
13
13
  import useMediaQuery from "@mui/material/useMediaQuery";
14
14
  import useTheme from "@mui/material/styles/useTheme";
15
15
  function useInteractions(props) {
16
16
  var rows = props.rows, columns = props.columns, sortingDisabled = props.sortingDisabled, initialState = props.initialState, onSort = props.onSort;
17
17
  var theme = useTheme();
18
18
  var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
19
- var _a = useState(false), leftShadowVisible = _a[0], setLeftShadowVisible = _a[1];
20
- var _b = useState(columns.filter(function (c) { return c.fixable === "right"; }).length > 0 || false), rightShadowVisible = _b[0], setRightShadowVisible = _b[1];
19
+ var _a = useState(null), scrollerRef = _a[0], setScrollerRef = _a[1];
20
+ var _b = useState(false), leftShadowVisible = _b[0], setLeftShadowVisible = _b[1];
21
+ var _c = useState(columns.filter(function (c) { return c.fixable === "right"; }).length > 0 || false), rightShadowVisible = _c[0], setRightShadowVisible = _c[1];
21
22
  var initialSortingProps = useMemo(function () {
22
23
  var sortBy = (initialState || {}).sortBy;
23
24
  var _a = sortBy || {}, accessor = _a.accessor, order = _a.order;
@@ -26,7 +27,7 @@ function useInteractions(props) {
26
27
  order: !!accessor ? order || "NONE" : "NONE",
27
28
  };
28
29
  }, [initialState]);
29
- var _c = useState(initialSortingProps), sortingProps = _c[0], setSortingProps = _c[1];
30
+ var _d = useState(initialSortingProps), sortingProps = _d[0], setSortingProps = _d[1];
30
31
  var handleSort = useCallback(function (_a) {
31
32
  var accessor = _a.accessor;
32
33
  if (!sortingDisabled) {
@@ -63,16 +64,21 @@ function useInteractions(props) {
63
64
  }
64
65
  return "↓";
65
66
  }, [sortingProps]);
66
- var onScroll = useCallback(function (event) {
67
- var target = event.currentTarget;
68
- var scrollLeft = target.scrollLeft;
69
- var scrollWidth = target.scrollWidth;
70
- var clientWidth = target.clientWidth;
71
- var hasScrollBar = scrollWidth > clientWidth;
72
- setLeftShadowVisible(hasScrollBar && scrollLeft > 0);
73
- setRightShadowVisible(hasScrollBar && scrollWidth - scrollLeft > clientWidth + 1);
67
+ var reflectScrollerRef = useCallback(function (ref) {
68
+ setScrollerRef(ref);
74
69
  }, []);
75
- var _d = useMemo(function () {
70
+ var onScroll = useCallback(function () {
71
+ var target = scrollerRef;
72
+ if (target) {
73
+ var scrollLeft = target.scrollLeft;
74
+ var scrollWidth = target.scrollWidth;
75
+ var clientWidth = target.clientWidth;
76
+ var hasScrollBar = scrollWidth > clientWidth;
77
+ setLeftShadowVisible(hasScrollBar && scrollLeft > 0);
78
+ setRightShadowVisible(hasScrollBar && scrollWidth - scrollLeft > clientWidth + 1);
79
+ }
80
+ }, [scrollerRef]);
81
+ var _e = useMemo(function () {
76
82
  var hasData = rows.length > 0;
77
83
  if (isUpMd && hasData) {
78
84
  var left = columns.filter(function (c) { return c.fixable === "left"; });
@@ -83,7 +89,15 @@ function useInteractions(props) {
83
89
  else {
84
90
  return [[], columns, []];
85
91
  }
86
- }, [isUpMd, rows, columns]), pinnedLeftCols = _d[0], normalCols = _d[1], pinnedRightCols = _d[2];
92
+ }, [isUpMd, rows, columns]), pinnedLeftCols = _e[0], normalCols = _e[1], pinnedRightCols = _e[2];
93
+ useEffect(function () {
94
+ if (columns) {
95
+ onScroll();
96
+ }
97
+ }, [columns, onScroll]);
98
+ useEffect(function () {
99
+ window.addEventListener("resize", onScroll);
100
+ }, [onScroll]);
87
101
  return {
88
102
  normalCols: normalCols,
89
103
  pinnedLeftCols: pinnedLeftCols,
@@ -93,6 +107,7 @@ function useInteractions(props) {
93
107
  onScroll: onScroll,
94
108
  handleSort: handleSort,
95
109
  onResetSorting: onResetSorting,
110
+ reflectScrollerRef: reflectScrollerRef,
96
111
  renderSortingSymbol: renderSortingSymbol,
97
112
  };
98
113
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.7.0-beta.1",
3
+ "version": "1.7.0-beta.3",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",