@vendorflow/components 2.0.81 → 2.0.82

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.
@@ -3,6 +3,7 @@
3
3
  import { jsx } from '@emotion/react';
4
4
  import { Column, UseSortByColumnProps, HeaderGroup, UseSortByOptions, TableOptions, UseSortByColumnOptions, PluginHook, UsePaginationOptions, UseSortByInstanceProps, UsePaginationInstanceProps, TableInstance, TableState, UseSortByState, UsePaginationState, UseRowSelectOptions, UseRowSelectInstanceProps, UseRowSelectState, ColumnInstance, Row, UseRowSelectRowProps, UseExpandedOptions, UseExpandedInstanceProps, UseExpandedState, UseExpandedRowProps, ActionType, UseGlobalFiltersInstanceProps, UseGlobalFiltersState, UseFiltersOptions, UseFiltersInstanceProps, UseFiltersState, UseFiltersColumnOptions, UseFiltersColumnProps, Renderer, FilterProps, UseTableOptions, UseGlobalFiltersOptions, UseResizeColumnsColumnOptions, UseResizeColumnsColumnProps, UseResizeColumnsState } from 'react-table';
5
5
  import { ReactNode } from 'react';
6
+ export declare const ACTION_COLUMN_ID = "action-column";
6
7
  export declare type Mode = 'single' | 'multi';
7
8
  export declare type CustomColumnConfigProps<D extends object> = {
8
9
  name?: string;
@@ -73,7 +73,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
73
73
  return (mod && mod.__esModule) ? mod : { "default": mod };
74
74
  };
75
75
  Object.defineProperty(exports, "__esModule", { value: true });
76
- exports.getColumnFilterConfig = exports.renderSingleLineCell = exports.useDefaultTableInstance = exports.usePluginConfig = exports.CELL_PADDING = void 0;
76
+ exports.getColumnFilterConfig = exports.renderSingleLineCell = exports.useDefaultTableInstance = exports.usePluginConfig = exports.CELL_PADDING = exports.ACTION_COLUMN_ID = void 0;
77
77
  /** @jsxRuntime classic */
78
78
  /** @jsx jsx */
79
79
  var react_1 = require("@emotion/react");
@@ -95,6 +95,7 @@ var react_scrollbar_size_1 = __importDefault(require("react-scrollbar-size"));
95
95
  var Table_1 = __importDefault(require("./TablePieces/Table"));
96
96
  var HeaderCell_1 = __importDefault(require("./TablePieces/HeaderCell"));
97
97
  var TableBodyContent_1 = __importDefault(require("./TablePieces/TableBodyContent"));
98
+ exports.ACTION_COLUMN_ID = 'action-column';
98
99
  exports.CELL_PADDING = 4;
99
100
  var EXPAND_BTN_WIDTH = 24;
100
101
  var NO_MATCH_TEXT = 'Sorry, no matching records found';
@@ -179,13 +180,13 @@ function DataTable(_a) {
179
180
  return ((0, react_1.jsx)(HeaderCell_1.default, { key: key, header: header, headerProps: restOfHeaderProps, flexLayoutEnabled: (tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.flexLayoutEnabled) || false }));
180
181
  })));
181
182
  })),
182
- (0, react_1.jsx)(TableBodyContent_1.default, { defaultRowHeight: defaultRowHeight, ExpandedComponent: ExpandedComponent, flexLayoutEnabled: (tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.flexLayoutEnabled) || false, hasScrollbarRefCallback: hasScrollbarRefCallback, height: tableBodyContentRect.height, isVirtualizeEnabled: !!(virtualizeConfig === null || virtualizeConfig === void 0 ? void 0 : virtualizeConfig.enabled), noMatchLabel: noMatchLabel, prepareRow: prepareRow, scrollContainerRef: scrollContainerRef, setScrollLeft: setScrollLeft, tableBodyRef: tableBodyRef, tableBodyMeasureRefCallback: tableBodyMeasureRefCallback, tableRows: tableRows, totalColumnsWidth: totalColumnsWidth, width: tableBodyContentRect.width }))),
183
+ (0, react_1.jsx)(TableBodyContent_1.default, { defaultRowHeight: defaultRowHeight, ExpandedComponent: ExpandedComponent, flexLayoutEnabled: (tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.flexLayoutEnabled) || false, hasScrollbar: hasScrollbar, hasScrollbarRefCallback: hasScrollbarRefCallback, height: tableBodyContentRect.height, isVirtualizeEnabled: !!(virtualizeConfig === null || virtualizeConfig === void 0 ? void 0 : virtualizeConfig.enabled), noMatchLabel: noMatchLabel, prepareRow: prepareRow, scrollContainerRef: scrollContainerRef, scrollbarWidth: scrollbarWidth, setScrollLeft: setScrollLeft, tableBodyRef: tableBodyRef, tableBodyMeasureRefCallback: tableBodyMeasureRefCallback, tableRows: tableRows, totalColumnsWidth: totalColumnsWidth, width: tableBodyContentRect.width }))),
183
184
  (paginationConfig === null || paginationConfig === void 0 ? void 0 : paginationConfig.enabled) && ((0, react_1.jsx)(material_1.TablePagination, { ref: paginationRef, className: "DataTable__Pagination", component: "div", count: rows.length, page: pageIndex, onPageChange: function (evt, newPage) { return gotoPage(newPage); }, onRowsPerPageChange: function (evt) { return setPageSize(Number(evt.target.value)); }, rowsPerPage: pageSize, rowsPerPageOptions: pageOptions }))));
184
185
  }
185
186
  exports.default = DataTable;
186
187
  function usePluginConfig(options) {
187
188
  var filters = options.filters, globalSearch = options.globalSearch, pagination = options.pagination, rowExpanding = options.rowExpanding, sorting = options.sorting, rowSelect = options.rowSelect, columnHiding = options.columnHiding, columnResizing = options.columnResizing, virtualize = options.virtualize;
188
- var customCellWidth = (rowExpanding === null || rowExpanding === void 0 ? void 0 : rowExpanding.enabled) && (rowSelect === null || rowSelect === void 0 ? void 0 : rowSelect.enabled)
189
+ var actionColumnCellWidth = (rowExpanding === null || rowExpanding === void 0 ? void 0 : rowExpanding.enabled) && (rowSelect === null || rowSelect === void 0 ? void 0 : rowSelect.enabled)
189
190
  ? exports.CELL_PADDING * 2 + EXPAND_BTN_WIDTH + IndeterminateCheckbox_1.CHECKBOX_WIDTH
190
191
  : Math.max(EXPAND_BTN_WIDTH, IndeterminateCheckbox_1.CHECKBOX_WIDTH) + exports.CELL_PADDING * 2;
191
192
  return (0, react_2.useMemo)(function () {
@@ -223,10 +224,10 @@ function usePluginConfig(options) {
223
224
  result.push(function (hooks) {
224
225
  hooks.visibleColumns.push(function (columns) { return __spreadArray([
225
226
  {
226
- id: 'custom',
227
- width: customCellWidth,
228
- minWidth: customCellWidth,
229
- maxWidth: customCellWidth,
227
+ id: exports.ACTION_COLUMN_ID,
228
+ width: actionColumnCellWidth,
229
+ minWidth: actionColumnCellWidth,
230
+ maxWidth: actionColumnCellWidth,
230
231
  Header: function (props) {
231
232
  var _a = props, getToggleAllRowsSelectedProps = _a.getToggleAllRowsSelectedProps, getToggleAllPageRowsSelectedProps = _a.getToggleAllPageRowsSelectedProps;
232
233
  return ((0, react_1.jsx)(react_2.Fragment, null,
@@ -51,7 +51,7 @@ function DataTable() {
51
51
  pageSize: 10,
52
52
  },
53
53
  virtualize: {
54
- enabled: true,
54
+ enabled: false,
55
55
  },
56
56
  rowSelect: {
57
57
  enabled: true,
@@ -38,11 +38,12 @@ var DataTable_1 = require("../DataTable");
38
38
  function BodyCell(_a) {
39
39
  var cell = _a.cell, cellProps = _a.cellProps;
40
40
  var style = cellProps.style, className = cellProps.className, restOfCellProps = __rest(cellProps, ["style", "className"]);
41
+ var isActionColumn = cell.column.id === DataTable_1.ACTION_COLUMN_ID;
41
42
  return ((0, react_1.jsx)(react_1.ClassNames, null, function (_a) {
42
43
  var css = _a.css, cx = _a.cx;
43
44
  return ((0, react_1.jsx)(material_1.TableCell, __assign({ css: cx(
44
45
  // @ts-ignore
45
- css(style), css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n && {\n padding: ", "px;\n display: block;\n border-bottom: none;\n }\n "], ["\n && {\n padding: ", "px;\n display: block;\n border-bottom: none;\n }\n "])), DataTable_1.CELL_PADDING)), className: (0, classnames_1.default)(className, cell.column.id === 'custom' ? 'cell-Custom' : undefined) }, restOfCellProps, { component: "div", variant: "body" }), cell.render('Cell')));
46
+ css(style), css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n && {\n padding: ", "px;\n display: block;\n border-bottom: none;\n ", "\n }\n "], ["\n && {\n padding: ", "px;\n display: block;\n border-bottom: none;\n ", "\n }\n "])), DataTable_1.CELL_PADDING, isActionColumn ? 'flex: none;' : '')), className: (0, classnames_1.default)(className, isActionColumn ? 'cell-ActionColumn' : undefined) }, restOfCellProps, { component: "div", variant: "body" }), cell.render('Cell')));
46
47
  }));
47
48
  }
48
49
  exports.default = BodyCell;
@@ -50,7 +50,7 @@ function HeaderCell(_a) {
50
50
  (0, react_1.jsx)("div", { css: cx(css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n position: relative;\n display: flex;\n flex-direction: row;\n justify-content: ", ";\n align-items: center;\n width: 100%;\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n "], ["\n position: relative;\n display: flex;\n flex-direction: row;\n justify-content: ", ";\n align-items: center;\n width: 100%;\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n "])), header.columns != null ? 'center' : 'flex-start')) },
51
51
  (0, react_1.jsx)("span", { css: cx(css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n font-weight: 600;\n flex: none;\n "], ["\n font-weight: 600;\n flex: none;\n "])))) }, header.render('Header')),
52
52
  (0, react_1.jsx)(SortIndicator_1.default, { canSort: header.canSort, isSorted: header.isSorted, isSortedDesc: header.isSortedDesc }),
53
- header.id !== 'custom' && !header.id.includes('_placeholder') && !!header.getResizerProps && ((0, react_1.jsx)(icons_material_1.DragIndicator, __assign({ css: css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n position: absolute;\n right: 0;\n top: 50%;\n transform: translate(-50%, -50%);\n color: #b2b2b2;\n background-color: white;\n "], ["\n position: absolute;\n right: 0;\n top: 50%;\n transform: translate(-50%, -50%);\n color: #b2b2b2;\n background-color: white;\n "]))) }, header.getResizerProps()))))));
53
+ header.id !== DataTable_1.ACTION_COLUMN_ID && !header.id.includes('_placeholder') && !!header.getResizerProps && ((0, react_1.jsx)(icons_material_1.DragIndicator, __assign({ css: css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n position: absolute;\n right: 0;\n top: 50%;\n transform: translate(-50%, -50%);\n color: #b2b2b2;\n background-color: white;\n "], ["\n position: absolute;\n right: 0;\n top: 50%;\n transform: translate(-50%, -50%);\n color: #b2b2b2;\n background-color: white;\n "]))) }, header.getResizerProps()))))));
54
54
  }));
55
55
  }
56
56
  exports.default = HeaderCell;
@@ -3,17 +3,20 @@
3
3
  import { jsx } from '@emotion/react';
4
4
  import { Dispatch, MutableRefObject, SetStateAction } from 'react';
5
5
  import { Row } from 'react-table';
6
+ import { HasScrollbar } from '@vendorflow/common/lib/hooks';
6
7
  interface Props<D extends object> {
7
8
  defaultRowHeight: number;
8
9
  ExpandedComponent: ((props: {
9
10
  data: D;
10
11
  }) => JSX.Element) | undefined;
11
12
  flexLayoutEnabled: boolean;
13
+ hasScrollbar: HasScrollbar;
12
14
  hasScrollbarRefCallback: (node: HTMLDivElement | null) => void;
13
15
  height: number | undefined;
14
16
  isVirtualizeEnabled: boolean;
15
17
  noMatchLabel?: string;
16
18
  prepareRow: (row: Row<D>) => void;
19
+ scrollbarWidth: number;
17
20
  scrollContainerRef: MutableRefObject<HTMLDivElement | null>;
18
21
  setScrollLeft: Dispatch<SetStateAction<number>>;
19
22
  tableBodyRef: MutableRefObject<HTMLDivElement | null>;
@@ -22,5 +25,5 @@ interface Props<D extends object> {
22
25
  totalColumnsWidth: number;
23
26
  width: number | undefined;
24
27
  }
25
- export default function TableBodyContent<D extends object>({ defaultRowHeight, ExpandedComponent, flexLayoutEnabled, hasScrollbarRefCallback, height, isVirtualizeEnabled, noMatchLabel, prepareRow, scrollContainerRef, setScrollLeft, tableBodyRef, tableBodyMeasureRefCallback, tableRows, totalColumnsWidth, width, }: Props<D>): jsx.JSX.Element;
28
+ export default function TableBodyContent<D extends object>({ defaultRowHeight, ExpandedComponent, flexLayoutEnabled, hasScrollbar, hasScrollbarRefCallback, height, isVirtualizeEnabled, noMatchLabel, prepareRow, scrollbarWidth, scrollContainerRef, setScrollLeft, tableBodyRef, tableBodyMeasureRefCallback, tableRows, totalColumnsWidth, width, }: Props<D>): jsx.JSX.Element;
26
29
  export {};
@@ -25,20 +25,28 @@ var react_virtualized_1 = require("react-virtualized");
25
25
  var BodyRow_1 = __importDefault(require("./BodyRow"));
26
26
  var material_1 = require("@mui/material");
27
27
  var react_2 = require("react");
28
+ var hooks_1 = require("@vendorflow/common/lib/hooks");
28
29
  function TableBodyContent(_a) {
29
- var defaultRowHeight = _a.defaultRowHeight, ExpandedComponent = _a.ExpandedComponent, flexLayoutEnabled = _a.flexLayoutEnabled, hasScrollbarRefCallback = _a.hasScrollbarRefCallback, height = _a.height, isVirtualizeEnabled = _a.isVirtualizeEnabled, noMatchLabel = _a.noMatchLabel, prepareRow = _a.prepareRow, scrollContainerRef = _a.scrollContainerRef, setScrollLeft = _a.setScrollLeft, tableBodyRef = _a.tableBodyRef, tableBodyMeasureRefCallback = _a.tableBodyMeasureRefCallback, tableRows = _a.tableRows, totalColumnsWidth = _a.totalColumnsWidth, width = _a.width;
30
- var defaultWidth = (0, react_2.useMemo)(function () { return (flexLayoutEnabled && width && width > totalColumnsWidth ? width : totalColumnsWidth); }, [flexLayoutEnabled, totalColumnsWidth, width]);
31
- var cache = (0, react_2.useRef)(new react_virtualized_1.CellMeasurerCache({ fixedWidth: true, defaultHeight: defaultRowHeight, defaultWidth: defaultWidth }));
30
+ var defaultRowHeight = _a.defaultRowHeight, ExpandedComponent = _a.ExpandedComponent, flexLayoutEnabled = _a.flexLayoutEnabled, hasScrollbar = _a.hasScrollbar, hasScrollbarRefCallback = _a.hasScrollbarRefCallback, height = _a.height, isVirtualizeEnabled = _a.isVirtualizeEnabled, noMatchLabel = _a.noMatchLabel, prepareRow = _a.prepareRow, scrollbarWidth = _a.scrollbarWidth, scrollContainerRef = _a.scrollContainerRef, setScrollLeft = _a.setScrollLeft, tableBodyRef = _a.tableBodyRef, tableBodyMeasureRefCallback = _a.tableBodyMeasureRefCallback, tableRows = _a.tableRows, totalColumnsWidth = _a.totalColumnsWidth, width = _a.width;
31
+ var scrollContentWidth = (0, react_2.useMemo)(function () {
32
+ if (!flexLayoutEnabled || !width) {
33
+ return totalColumnsWidth;
34
+ }
35
+ return width - (hasScrollbar.vertical ? scrollbarWidth : 0);
36
+ }, [flexLayoutEnabled, totalColumnsWidth, width, hasScrollbar, scrollbarWidth]);
37
+ var forceUpdate = (0, hooks_1.useForceUpdate)();
38
+ var cache = (0, react_2.useRef)(new react_virtualized_1.CellMeasurerCache({ fixedWidth: true, defaultHeight: defaultRowHeight, defaultWidth: scrollContentWidth }));
32
39
  (0, react_2.useEffect)(function () {
33
40
  if (isVirtualizeEnabled) {
34
41
  cache.current = new react_virtualized_1.CellMeasurerCache({
35
42
  fixedWidth: true,
36
43
  defaultHeight: defaultRowHeight,
37
- defaultWidth: defaultWidth,
44
+ defaultWidth: scrollContentWidth,
38
45
  });
39
46
  cache.current.clearAll();
47
+ forceUpdate();
40
48
  }
41
- }, [defaultWidth]);
49
+ }, [scrollContentWidth]);
42
50
  function renderRow(_a) {
43
51
  var columnIndex = _a.columnIndex, rowIndex = _a.rowIndex, key = _a.key, parent = _a.parent, style = _a.style;
44
52
  var row = tableRows[rowIndex];
@@ -70,7 +78,7 @@ function TableBodyContent(_a) {
70
78
  var scrollLeft = evt.target.scrollLeft;
71
79
  setScrollLeft(scrollLeft);
72
80
  } },
73
- (0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: ", "px;\n "], ["\n width: ", "px;\n "])), defaultWidth) }, tableRows.length > 0 ? (tableRows.map(function (row) {
81
+ (0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: ", "px;\n "], ["\n width: ", "px;\n "])), scrollContentWidth) }, tableRows.length > 0 ? (tableRows.map(function (row) {
74
82
  prepareRow(row);
75
83
  var _a = row.getRowProps(), key = _a.key, restOfRowProps = __rest(_a, ["key"]);
76
84
  return ((0, react_1.jsx)(BodyRow_1.default, { key: key, ExpandedComponent: ExpandedComponent, row: row, rowProps: restOfRowProps }));
@@ -42,6 +42,7 @@ var material_1 = require("@mui/material");
42
42
  var icons_material_1 = require("@mui/icons-material");
43
43
  var nanoid_1 = require("nanoid");
44
44
  var IndeterminateCheckbox_1 = __importDefault(require("./IndeterminateCheckbox"));
45
+ var DataTable_1 = require("../DataTable");
45
46
  function ViewColumnTool(_a) {
46
47
  var allColumns = _a.allColumns, columnNameById = _a.columnNameById;
47
48
  var id = (0, react_2.useMemo)(function () { return (0, nanoid_1.nanoid)(); }, []);
@@ -65,7 +66,7 @@ function ViewColumnTool(_a) {
65
66
  (0, react_1.jsx)(material_1.IconButton, { onClick: handleClose },
66
67
  (0, react_1.jsx)(icons_material_1.Close, null)))),
67
68
  (0, react_1.jsx)("div", { css: (0, react_1.css)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n justify-content: flex-start;\n align-items: flex-start;\n "], ["\n display: flex;\n flex-direction: column;\n justify-content: flex-start;\n align-items: flex-start;\n "]))) }, allColumns
68
- .filter(function (column) { return column.id !== 'custom'; })
69
+ .filter(function (column) { return column.id !== DataTable_1.ACTION_COLUMN_ID; })
69
70
  .map(function (column) {
70
71
  return ((0, react_1.jsx)(material_1.FormControlLabel, { key: column.id, label: columnNameById[column.id],
71
72
  // @ts-ignore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendorflow/components",
3
- "version": "2.0.81",
3
+ "version": "2.0.82",
4
4
  "description": "React components for vendorflow",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -62,7 +62,7 @@
62
62
  "@types/react-table": "^7.7.6",
63
63
  "@typescript-eslint/eslint-plugin": "^4.32.0",
64
64
  "@typescript-eslint/parser": "^4.32.0",
65
- "@vendorflow/common": "^1.0.44",
65
+ "@vendorflow/common": "^1.0.50",
66
66
  "babel-eslint": "10.1.0",
67
67
  "babel-jest": "^24.9.0",
68
68
  "babel-loader": "^8.2.2",