@mezzanine-ui/react 0.14.6 → 0.14.8

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/Table/Table.d.ts CHANGED
@@ -10,7 +10,7 @@ export interface TableBaseProps<T> extends Omit<NativeElementPropsWithoutKeyAndR
10
10
  /**
11
11
  * customized body row className
12
12
  */
13
- bodyRowClassName?: string;
13
+ bodyRowClassName?: string | ((source: T) => string);
14
14
  /**
15
15
  * Columns of table <br />
16
16
  * `column.render` allowed customizing the column body cell rendering. <br />
package/Table/Table.js CHANGED
@@ -27,11 +27,13 @@ const Table = forwardRef(function Table(props, ref) {
27
27
  selectedRowKey: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.selectedRowKey,
28
28
  onChange: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.onChange,
29
29
  dataSource: dataSourceProp,
30
+ disabledRowKeys: rowSelectionProp === null || rowSelectionProp === void 0 ? void 0 : rowSelectionProp.disabledRowKeys,
30
31
  });
31
32
  const rowSelection = useMemo(() => (rowSelectionProp ? {
32
33
  selectedRowKeys,
33
34
  onChange: setSelectedRowKey,
34
35
  actions: rowSelectionProp.actions,
36
+ disabledRowKeys: rowSelectionProp.disabledRowKeys,
35
37
  } : undefined), [
36
38
  rowSelectionProp,
37
39
  selectedRowKeys,
@@ -143,6 +145,15 @@ const Table = forwardRef(function Table(props, ref) {
143
145
  });
144
146
  }, [(_a = components === null || components === void 0 ? void 0 : components.body) === null || _a === void 0 ? void 0 : _a.cell]);
145
147
  const tableRefs = useComposeRefs([ref, scrollBody.target]);
148
+ const rowClassName = useMemo(() => {
149
+ if (bodyRowClassName) {
150
+ if (typeof bodyRowClassName === 'string') {
151
+ return (() => bodyRowClassName);
152
+ }
153
+ return ((source) => bodyRowClassName === null || bodyRowClassName === void 0 ? void 0 : bodyRowClassName(source));
154
+ }
155
+ return undefined;
156
+ }, [bodyRowClassName]);
146
157
  return (jsx(TableContext.Provider, { value: tableContextValue, children: jsx(TableDataContext.Provider, { value: tableDataContextValue, children: jsx(TableComponentContext.Provider, { value: tableComponentContextValue, children: jsx(DragDropContext, { onBeforeDragStart: onBeforeDragStart, onDragEnd: onDragEnd, children: jsx(Loading, { loading: loading, stretch: true, tip: loadingTip, overlayProps: {
147
158
  className: tableClasses.loading,
148
159
  }, children: jsx(Droppable, { droppableId: "mzn-table-dnd", isDropDisabled: !(draggableProp === null || draggableProp === void 0 ? void 0 : draggableProp.enabled), children: (provided) => (jsxs(Fragment, { children: [jsx("div", { ...provided.droppableProps, ref: composeRefs([scrollBody.ref, provided.innerRef]), className: cx(tableClasses.scrollContainer, scrollContainerClassName), onScroll: scrollBody.onScroll, style: tableContextValue.scroll ? {
@@ -152,7 +163,7 @@ const Table = forwardRef(function Table(props, ref) {
152
163
  '--table-scroll-y': tableContextValue.scroll.y
153
164
  ? `${tableContextValue.scroll.y}px`
154
165
  : 'unset',
155
- } : undefined, children: jsxs("table", { ref: tableRefs, ...rest, className: cx(tableClasses.host, className), children: [isRefreshShow ? (jsx("tbody", { children: jsx("tr", { children: jsx("td", { "aria-label": "Refresh", children: jsx(TableRefresh, { onClick: refreshProp.onClick }) }) }) })) : null, jsx(TableHeader, { className: headerClassName }), jsx(TableBody, { ref: bodyRef, className: bodyClassName, rowClassName: bodyRowClassName }), jsx("tbody", { children: provided.placeholder })] }) }), paginationProp ? (jsx(TablePagination, { bodyRef: bodyRef })) : null, jsx("div", { ref: scrollElement.trackRef, "aria-label": "Scroll Track", style: scrollElement.trackStyle, onMouseDown: scrollElement.onMouseDown, onMouseUp: scrollElement.onMouseUp, role: "button", tabIndex: -1, className: "mzn-table-scroll-bar-track", children: jsx("div", { style: {
166
+ } : undefined, children: jsxs("table", { ref: tableRefs, ...rest, className: cx(tableClasses.host, className), children: [isRefreshShow ? (jsx("tbody", { children: jsx("tr", { children: jsx("td", { "aria-label": "Refresh", children: jsx(TableRefresh, { onClick: refreshProp.onClick }) }) }) })) : null, jsx(TableHeader, { className: headerClassName }), jsx(TableBody, { ref: bodyRef, className: bodyClassName, rowClassName: rowClassName }), jsx("tbody", { children: provided.placeholder })] }) }), paginationProp ? (jsx(TablePagination, { bodyRef: bodyRef })) : null, jsx("div", { ref: scrollElement.trackRef, "aria-label": "Scroll Track", style: scrollElement.trackStyle, onMouseDown: scrollElement.onMouseDown, onMouseUp: scrollElement.onMouseUp, role: "button", tabIndex: -1, className: "mzn-table-scroll-bar-track", children: jsx("div", { style: {
156
167
  width: '100%',
157
168
  height: '100%',
158
169
  position: 'relative',
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
+ import { TableDataSource } from '@mezzanine-ui/core/table';
2
3
  import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types';
3
4
  export interface TableBodyProps extends NativeElementPropsWithoutKeyAndRef<'div'> {
4
5
  /**
5
6
  * customize row className
6
7
  */
7
- rowClassName?: string;
8
+ rowClassName?: (source: TableDataSource) => string;
8
9
  }
9
10
  declare const TableBody: import("react").ForwardRefExoticComponent<TableBodyProps & import("react").RefAttributes<HTMLTableSectionElement>>;
10
11
  export default TableBody;
@@ -18,7 +18,7 @@ const TableBody = forwardRef(function TableBody(props, ref) {
18
18
  const currentStartCount = (paginationOptions === null || paginationOptions === void 0 ? void 0 : paginationOptions.pageSize) && currentPage ? ((paginationOptions.pageSize) * (currentPage - 1)) : 0;
19
19
  const currentEndCount = (paginationOptions === null || paginationOptions === void 0 ? void 0 : paginationOptions.pageSize) && currentPage && total ? (Math.min(((paginationOptions.pageSize) * currentPage), total)) : 0;
20
20
  const currentDataSource = pagination && !disableAutoSlicing ? (dataSource.slice(currentStartCount, currentEndCount)) : dataSource;
21
- return (jsxs("tbody", { ...rest, ref: ref, className: cx(tableClasses.body, className), children: [currentDataSource.length ? currentDataSource.map((rowData, index) => (jsx(TableBodyRow, { className: rowClassName, rowData: rowData, rowIndex: index }, (rowData.key || rowData.id)))) : (jsx("tr", { children: jsx("td", { children: jsx(Empty, { ...restEmptyProps, className: cx(tableClasses.bodyEmpty, emptyComponentClassName), fullHeight: emptyComponentFullHeight, children: emptyComponentChildren }) }) })), (fetchMore === null || fetchMore === void 0 ? void 0 : fetchMore.isFetching) ? (jsx("tr", { className: tableClasses.bodyFetchMore, children: jsx("td", { "aria-label": "Loading", children: jsx(Loading, { loading: true }) }) })) : null] }));
21
+ return (jsxs("tbody", { ...rest, ref: ref, className: cx(tableClasses.body, className), children: [currentDataSource.length ? currentDataSource.map((rowData, index) => (jsx(TableBodyRow, { className: rowClassName === null || rowClassName === void 0 ? void 0 : rowClassName(rowData), rowData: rowData, rowIndex: index }, (rowData.key || rowData.id)))) : (jsx("tr", { children: jsx("td", { children: jsx(Empty, { ...restEmptyProps, className: cx(tableClasses.bodyEmpty, emptyComponentClassName), fullHeight: emptyComponentFullHeight, children: emptyComponentChildren }) }) })), (fetchMore === null || fetchMore === void 0 ? void 0 : fetchMore.isFetching) ? (jsx("tr", { className: tableClasses.bodyFetchMore, children: jsx("td", { "aria-label": "Loading", children: jsx(Loading, { loading: true }) }) })) : null] }));
22
22
  });
23
23
  var TableBody$1 = TableBody;
24
24
 
@@ -5,6 +5,7 @@ import { EmptyProps } from '../Empty';
5
5
  export interface RowSelectionContext extends Pick<TableRowSelection, 'actions'> {
6
6
  selectedRowKeys: string[];
7
7
  onChange(v: string): void;
8
+ disabledRowKeys?: string[];
8
9
  }
9
10
  /** typeof sorting */
10
11
  export interface SortingContext {
package/Table/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export { TableRefreshProps, default as TableRefresh, } from './refresh/TableRefr
3
3
  export { TableCellProps, default as TableCell, } from './TableCell';
4
4
  export { EditableBodyCellProps, } from './editable/TableEditRenderWrapper';
5
5
  export { useTableDraggable, } from './draggable/useTableDraggable';
6
+ export { useTableRowSelection, SELECTED_ALL_KEY, } from './rowSelection/useTableRowSelection';
6
7
  export { default as useTableScroll, } from './useTableScroll';
package/Table/index.js CHANGED
@@ -2,4 +2,5 @@ export { default } from './Table.js';
2
2
  export { default as TableRefresh } from './refresh/TableRefresh.js';
3
3
  export { default as TableCell } from './TableCell.js';
4
4
  export { useTableDraggable } from './draggable/useTableDraggable.js';
5
+ export { SELECTED_ALL_KEY, useTableRowSelection } from './rowSelection/useTableRowSelection.js';
5
6
  export { default as useTableScroll } from './useTableScroll.js';
@@ -1,6 +1,7 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { forwardRef, useContext, useCallback, useMemo, useEffect, useState } from 'react';
3
3
  import { tableClasses } from '@mezzanine-ui/core/table';
4
+ import xor from 'lodash/xor';
4
5
  import { MoreVerticalIcon } from '@mezzanine-ui/icons';
5
6
  import { TableContext, TableDataContext } from '../TableContext.js';
6
7
  import { SELECTED_ALL_KEY } from './useTableRowSelection.js';
@@ -12,7 +13,7 @@ import Icon from '../../Icon/Icon.js';
12
13
  import cx from 'clsx';
13
14
 
14
15
  const TableRowSelection = forwardRef(function TableRowSelection(props, ref) {
15
- var _a, _b;
16
+ var _a, _b, _c;
16
17
  const { rowKey, setChecked, showDropdownIcon, ...rest } = props;
17
18
  const { rowSelection, expanding, } = useContext(TableContext) || {};
18
19
  const { dataSource = [], } = useContext(TableDataContext) || {};
@@ -21,14 +22,15 @@ const TableRowSelection = forwardRef(function TableRowSelection(props, ref) {
21
22
  rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.onChange(rowKey);
22
23
  }, [rowSelection, rowKey]);
23
24
  const checkboxStatus = useMemo(() => {
24
- var _a;
25
+ var _a, _b;
25
26
  const selectedRowKeys = (_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys) !== null && _a !== void 0 ? _a : [];
26
27
  if (!selectedRowKeys.length)
27
28
  return 'none';
28
- if (selectedRowKeys.length === dataSource.length)
29
+ const validDataSource = xor((_b = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.disabledRowKeys) !== null && _b !== void 0 ? _b : [], dataSource.map((d) => (d.id || d.key)));
30
+ if (selectedRowKeys.length === validDataSource.length)
29
31
  return 'all';
30
32
  return 'indeterminate';
31
- }, [rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys, dataSource.length]);
33
+ }, [rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys, rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.disabledRowKeys, dataSource]);
32
34
  const selfChecked = useMemo(() => {
33
35
  var _a;
34
36
  return (((_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.selectedRowKeys) !== null && _a !== void 0 ? _a : []).some((key) => key === rowKey));
@@ -70,9 +72,11 @@ const TableRowSelection = forwardRef(function TableRowSelection(props, ref) {
70
72
  toggleOpen(false);
71
73
  };
72
74
  const actionMenu = (jsx(Menu, { size: "medium", children: ((_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.actions) !== null && _a !== void 0 ? _a : []).map(((action) => (jsx(MenuItem, { className: action.className, onClick: (evt) => onMenuItemClicked(evt, action), children: action.text }, action.key)))) }));
73
- return (jsxs("div", { ref: ref, ...rest, className: tableClasses.selections, style: hiddenIconWithExpandableStyle.host, children: [jsx(Checkbox, { checked: checked, disabled: false, indeterminate: indeterminate, inputProps: {
75
+ return (jsxs("div", { ref: ref, ...rest, className: tableClasses.selections, style: hiddenIconWithExpandableStyle.host, children: [jsx(Checkbox, { checked: checked, disabled: ((_b = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.disabledRowKeys) === null || _b === void 0 ? void 0 : _b.length)
76
+ ? rowSelection.disabledRowKeys.includes(rowKey)
77
+ : false, indeterminate: indeterminate, inputProps: {
74
78
  name,
75
- }, onChange: onSelected, size: "medium" }), ((_b = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.actions) === null || _b === void 0 ? void 0 : _b.length) ? (jsx("div", { className: tableClasses.icon, style: hiddenIconWithExpandableStyle.icon, children: showDropdownIcon ? (jsx(Dropdown, { menu: actionMenu, onClose: () => toggleOpen(false), popperProps: {
79
+ }, onChange: onSelected, size: "medium" }), ((_c = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.actions) === null || _c === void 0 ? void 0 : _c.length) ? (jsx("div", { className: tableClasses.icon, style: hiddenIconWithExpandableStyle.icon, children: showDropdownIcon ? (jsx(Dropdown, { menu: actionMenu, onClose: () => toggleOpen(false), popperProps: {
76
80
  open,
77
81
  options: {
78
82
  placement: 'bottom-start',
@@ -1,3 +1,4 @@
1
+ import xor from 'lodash/xor';
1
2
  import { useControlValueState } from '../../Form/useControlValueState.js';
2
3
  import { useLastCallback } from '../../hooks/useLastCallback.js';
3
4
 
@@ -8,7 +9,7 @@ const equalityFn = (a, b) => {
8
9
  };
9
10
  const SELECTED_ALL_KEY = 'MZN-TABLE-ROW-SELECTION-ALL';
10
11
  function useTableRowSelection(props) {
11
- const { selectedRowKey: selectedRowKeyProp, onChange: onChangeProp, dataSource, } = props;
12
+ const { selectedRowKey: selectedRowKeyProp, onChange: onChangeProp, disabledRowKeys = [], dataSource, } = props;
12
13
  const [selectedRowKey, setSelectedRowKey] = useControlValueState({
13
14
  defaultValue: [],
14
15
  equalityFn,
@@ -18,13 +19,14 @@ function useTableRowSelection(props) {
18
19
  if (!dataSource.length)
19
20
  return;
20
21
  const allSourceKeys = dataSource.map((source) => (source.key || source.id));
22
+ const validSourceKeys = xor(disabledRowKeys, allSourceKeys);
21
23
  let nextSelectedRowKey = selectedRowKey;
22
24
  if (rowKey === SELECTED_ALL_KEY) {
23
- if (equalityFn(selectedRowKey, allSourceKeys)) {
25
+ if (equalityFn(selectedRowKey, validSourceKeys)) {
24
26
  nextSelectedRowKey = [];
25
27
  }
26
28
  else {
27
- nextSelectedRowKey = allSourceKeys;
29
+ nextSelectedRowKey = validSourceKeys;
28
30
  }
29
31
  }
30
32
  else {
package/index.d.ts CHANGED
@@ -52,7 +52,7 @@ export { AccordionProps, AccordionSummaryProps, AccordionSummary, AccordionDetai
52
52
  export { BadgeContainerProps, BadgeContainer, BadgeProps, default as Badge, } from './Badge';
53
53
  export { CardProps, CardActionsProps, CardActions, default as Card, } from './Card';
54
54
  export { EmptyProps, default as Empty, } from './Empty';
55
- export { TableProps, TableRefreshProps, TableRefresh, useTableDraggable, useTableScroll, default as Table, } from './Table';
55
+ export { TableProps, TableRefreshProps, TableRefresh, useTableDraggable, useTableScroll, useTableRowSelection, SELECTED_ALL_KEY, default as Table, } from './Table';
56
56
  export { TagSize, TagProps, default as Tag, } from './Tag';
57
57
  export { usePagination, PaginationItemProps, PaginationItemType, PaginationItem, PaginationJumperProps, PaginationJumper, PaginationPageSizeProps, PaginationPageSize, PaginationProps, default as Pagination, } from './Pagination';
58
58
  export { TreeNodeProp, TreeNodeData, TreeNodeEntity, TreeNodeEntities, TreeNodeRefsShape, TreeNodeRefs, TreeExpandControl, uniqueArray, toggleValue, toggleValueWithStatusControl, traverseTree, UseTreeExpandedValueProps, useTreeExpandedValue, GetTreeNodeEntitiesProps, getTreeNodeEntities, TreeNodeElementProps, TreeNodeProps, TreeNode, TreeNodeListElementProps, TreeNodeListProps, TreeNodeList, TreeProps, default as Tree, } from './Tree';
package/index.js CHANGED
@@ -60,6 +60,7 @@ export { default as Card } from './Card/Card.js';
60
60
  export { default as Empty } from './Empty/Empty.js';
61
61
  export { default as TableRefresh } from './Table/refresh/TableRefresh.js';
62
62
  export { useTableDraggable } from './Table/draggable/useTableDraggable.js';
63
+ export { SELECTED_ALL_KEY, useTableRowSelection } from './Table/rowSelection/useTableRowSelection.js';
63
64
  export { default as Table } from './Table/Table.js';
64
65
  export { default as Tag } from './Tag/Tag.js';
65
66
  export { usePagination } from './Pagination/usePagination.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mezzanine-ui/react",
3
- "version": "0.14.6",
3
+ "version": "0.14.8",
4
4
  "description": "React components for mezzanine-ui",
5
5
  "author": "Mezzanine",
6
6
  "repository": {
@@ -28,9 +28,9 @@
28
28
  "react-dom": "^18.2.0"
29
29
  },
30
30
  "dependencies": {
31
- "@mezzanine-ui/core": "^0.14.6",
32
- "@mezzanine-ui/icons": "^0.14.6",
33
- "@mezzanine-ui/system": "^0.14.6",
31
+ "@mezzanine-ui/core": "^0.14.8",
32
+ "@mezzanine-ui/icons": "^0.14.8",
33
+ "@mezzanine-ui/system": "^0.14.8",
34
34
  "@popperjs/core": "^2.11.6",
35
35
  "@types/react-transition-group": "^4.4.8",
36
36
  "clsx": "^2.0.0",