@mui/x-data-grid 7.8.0 → 7.9.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/DataGrid/useDataGridProps.js +9 -2
  3. package/components/GridLoadingOverlay.d.ts +15 -3
  4. package/components/GridLoadingOverlay.js +48 -4
  5. package/components/GridRow.js +2 -1
  6. package/components/GridSkeletonLoadingOverlay.d.ts +3 -0
  7. package/components/GridSkeletonLoadingOverlay.js +181 -0
  8. package/components/base/GridOverlays.d.ts +11 -1
  9. package/components/base/GridOverlays.js +25 -39
  10. package/components/cell/GridSkeletonCell.d.ts +13 -6
  11. package/components/cell/GridSkeletonCell.js +61 -19
  12. package/components/containers/GridRootStyles.js +11 -2
  13. package/components/virtualization/GridVirtualScroller.js +7 -5
  14. package/constants/gridClasses.d.ts +9 -0
  15. package/constants/gridClasses.js +1 -1
  16. package/hooks/features/overlays/useGridOverlays.d.ts +11 -0
  17. package/hooks/features/overlays/useGridOverlays.js +35 -0
  18. package/hooks/features/virtualization/useGridVirtualScroller.js +1 -1
  19. package/hooks/utils/index.d.ts +0 -1
  20. package/hooks/utils/index.js +0 -1
  21. package/index.js +1 -1
  22. package/models/gridSlotsComponentsProps.d.ts +2 -1
  23. package/modern/DataGrid/useDataGridProps.js +9 -2
  24. package/modern/components/GridLoadingOverlay.js +48 -4
  25. package/modern/components/GridRow.js +2 -1
  26. package/modern/components/GridSkeletonLoadingOverlay.js +181 -0
  27. package/modern/components/base/GridOverlays.js +25 -39
  28. package/modern/components/cell/GridSkeletonCell.js +61 -19
  29. package/modern/components/containers/GridRootStyles.js +11 -2
  30. package/modern/components/virtualization/GridVirtualScroller.js +7 -5
  31. package/modern/constants/gridClasses.js +1 -1
  32. package/modern/hooks/features/overlays/useGridOverlays.js +35 -0
  33. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +1 -1
  34. package/modern/hooks/utils/index.js +0 -1
  35. package/modern/index.js +1 -1
  36. package/modern/utils/utils.js +10 -2
  37. package/node/DataGrid/useDataGridProps.js +9 -2
  38. package/node/components/GridLoadingOverlay.js +48 -4
  39. package/node/components/GridRow.js +2 -1
  40. package/node/components/GridSkeletonLoadingOverlay.js +189 -0
  41. package/node/components/base/GridOverlays.js +25 -39
  42. package/node/components/cell/GridSkeletonCell.js +60 -18
  43. package/node/components/containers/GridRootStyles.js +11 -2
  44. package/node/components/virtualization/GridVirtualScroller.js +6 -4
  45. package/node/constants/gridClasses.js +1 -1
  46. package/node/hooks/features/overlays/useGridOverlays.js +42 -0
  47. package/node/hooks/features/virtualization/useGridVirtualScroller.js +1 -1
  48. package/node/hooks/utils/index.js +0 -12
  49. package/node/index.js +1 -1
  50. package/node/utils/utils.js +11 -3
  51. package/package.json +5 -4
  52. package/utils/utils.d.ts +8 -1
  53. package/utils/utils.js +10 -2
  54. package/hooks/utils/useResizeObserver.d.ts +0 -2
  55. package/hooks/utils/useResizeObserver.js +0 -36
  56. package/modern/hooks/utils/useResizeObserver.js +0 -36
  57. package/node/hooks/utils/useResizeObserver.js +0 -44
@@ -1,52 +1,88 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["field", "align", "width", "height"];
3
+ const _excluded = ["field", "type", "align", "width", "height", "empty", "style", "className"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import Skeleton from '@mui/material/Skeleton';
7
7
  import { unstable_composeClasses as composeClasses, unstable_capitalize as capitalize } from '@mui/utils';
8
+ import clsx from 'clsx';
8
9
  import { fastMemo } from '../../utils/fastMemo';
9
- import { randomNumberBetween } from '../../utils/utils';
10
+ import { createRandomNumberGenerator } from '../../utils/utils';
10
11
  import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
11
12
  import { getDataGridUtilityClass } from '../../constants/gridClasses';
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
13
- const randomWidth = randomNumberBetween(10000, 20, 80);
14
+ const CIRCULAR_CONTENT_SIZE = '1.3em';
15
+ const CONTENT_HEIGHT = '1.2em';
16
+ const DEFAULT_CONTENT_WIDTH_RANGE = [40, 80];
17
+ const CONTENT_WIDTH_RANGE_BY_TYPE = {
18
+ number: [40, 60],
19
+ string: [40, 80],
20
+ date: [40, 60],
21
+ dateTime: [60, 80],
22
+ singleSelect: [40, 80]
23
+ };
14
24
  const useUtilityClasses = ownerState => {
15
25
  const {
16
26
  align,
17
- classes
27
+ classes,
28
+ empty
18
29
  } = ownerState;
19
30
  const slots = {
20
- root: ['cell', 'cellSkeleton', `cell--text${capitalize(align)}`, 'withBorderColor']
31
+ root: ['cell', 'cellSkeleton', `cell--text${align ? capitalize(align) : 'Left'}`, empty && 'cellEmpty']
21
32
  };
22
33
  return composeClasses(slots, getDataGridUtilityClass, classes);
23
34
  };
35
+ const randomNumberGenerator = createRandomNumberGenerator(12345);
24
36
  function GridSkeletonCell(props) {
25
37
  const {
38
+ field,
39
+ type,
26
40
  align,
27
41
  width,
28
- height
42
+ height,
43
+ empty = false,
44
+ style,
45
+ className
29
46
  } = props,
30
47
  other = _objectWithoutPropertiesLoose(props, _excluded);
31
48
  const rootProps = useGridRootProps();
32
49
  const ownerState = {
33
50
  classes: rootProps.classes,
34
- align
51
+ align,
52
+ empty
35
53
  };
36
54
  const classes = useUtilityClasses(ownerState);
37
- const contentWidth = Math.round(randomWidth());
55
+
56
+ // Memo prevents the non-circular skeleton widths changing to random widths on every render
57
+ const skeletonProps = React.useMemo(() => {
58
+ const isCircularContent = type === 'boolean' || type === 'actions';
59
+ if (isCircularContent) {
60
+ return {
61
+ variant: 'circular',
62
+ width: CIRCULAR_CONTENT_SIZE,
63
+ height: CIRCULAR_CONTENT_SIZE
64
+ };
65
+ }
66
+
67
+ // The width of the skeleton is a random number between the min and max values
68
+ // The min and max values are determined by the type of the column
69
+ const [min, max] = type ? CONTENT_WIDTH_RANGE_BY_TYPE[type] ?? DEFAULT_CONTENT_WIDTH_RANGE : DEFAULT_CONTENT_WIDTH_RANGE;
70
+ return {
71
+ variant: 'text',
72
+ width: `${Math.round(randomNumberGenerator(min, max))}%`,
73
+ height: CONTENT_HEIGHT
74
+ };
75
+ }, [type]);
38
76
  return /*#__PURE__*/_jsx("div", _extends({
39
- className: classes.root,
40
- style: {
77
+ "data-field": field,
78
+ className: clsx(classes.root, className),
79
+ style: _extends({
41
80
  height,
42
81
  maxWidth: width,
43
82
  minWidth: width
44
- }
83
+ }, style)
45
84
  }, other, {
46
- children: /*#__PURE__*/_jsx(Skeleton, {
47
- width: `${contentWidth}%`,
48
- height: 25
49
- })
85
+ children: !empty && /*#__PURE__*/_jsx(Skeleton, _extends({}, skeletonProps))
50
86
  }));
51
87
  }
52
88
  process.env.NODE_ENV !== "production" ? GridSkeletonCell.propTypes = {
@@ -54,10 +90,16 @@ process.env.NODE_ENV !== "production" ? GridSkeletonCell.propTypes = {
54
90
  // | These PropTypes are generated from the TypeScript type definitions |
55
91
  // | To update them edit the TypeScript types and run "pnpm proptypes" |
56
92
  // ----------------------------------------------------------------------
57
- align: PropTypes.string.isRequired,
58
- field: PropTypes.string.isRequired,
59
- height: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]).isRequired,
60
- width: PropTypes.number.isRequired
93
+ align: PropTypes.string,
94
+ /**
95
+ * If `true`, the cell will not display the skeleton but still reserve the cell space.
96
+ * @default false
97
+ */
98
+ empty: PropTypes.bool,
99
+ field: PropTypes.string,
100
+ height: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.number]),
101
+ type: PropTypes.oneOf(['actions', 'boolean', 'custom', 'date', 'dateTime', 'number', 'singleSelect', 'string']),
102
+ width: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
61
103
  } : void 0;
62
104
  const Memoized = fastMemo(GridSkeletonCell);
63
105
  export { Memoized as GridSkeletonCell };
@@ -161,7 +161,7 @@ export const GridRootStyles = styled('div', {
161
161
  const selectedOpacity = (t.vars || t).palette.action.selectedOpacity;
162
162
  const selectedBackground = t.vars ? `rgba(${t.vars.palette.primary.mainChannel} / ${selectedOpacity})` : alpha(t.palette.primary.main, selectedOpacity);
163
163
  const selectedHoverBackground = t.vars ? `rgba(${t.vars.palette.primary.mainChannel} / calc(
164
- ${t.vars.palette.action.selectedOpacity} +
164
+ ${t.vars.palette.action.selectedOpacity} +
165
165
  ${t.vars.palette.action.hoverOpacity}
166
166
  ))` : alpha(t.palette.primary.main, t.palette.action.selectedOpacity + t.palette.action.hoverOpacity);
167
167
  const pinnedHoverBackground = t.vars ? hoverColor : blend(pinnedBackground, hoverColor, hoverOpacity);
@@ -425,6 +425,9 @@ export const GridRootStyles = styled('div', {
425
425
  backgroundColor: 'transparent'
426
426
  }
427
427
  },
428
+ [`&.${c.rowSkeleton}:hover`]: {
429
+ backgroundColor: 'transparent'
430
+ },
428
431
  '&.Mui-selected': selectedStyles
429
432
  },
430
433
  [`& .${c['container--top']}, & .${c['container--bottom']}`]: {
@@ -631,7 +634,7 @@ export const GridRootStyles = styled('div', {
631
634
  minWidth: 'calc(var(--DataGrid-hasScrollY) * var(--DataGrid-scrollbarSize))',
632
635
  alignSelf: 'stretch',
633
636
  [`&.${c['scrollbarFiller--borderTop']}`]: {
634
- borderTop: '1px solid var(--DataGrid-rowBorderColor)'
637
+ borderTop: '1px solid var(--rowBorderColor)'
635
638
  },
636
639
  [`&.${c['scrollbarFiller--pinnedRight']}`]: {
637
640
  backgroundColor: 'var(--DataGrid-pinnedBackground)',
@@ -644,6 +647,12 @@ export const GridRootStyles = styled('div', {
644
647
  },
645
648
  [`& .${c['filler--borderTop']}`]: {
646
649
  borderTop: '1px solid var(--DataGrid-rowBorderColor)'
650
+ },
651
+ /* Hide grid rows and vertical scrollbar when skeleton overlay is visible */
652
+ [`& .${c['main--hasSkeletonLoadingOverlay']}`]: {
653
+ [`& .${c.virtualScrollerContent}, & .${c['scrollbar--vertical']}, & .${c.pinnedRows}`]: {
654
+ display: 'none'
655
+ }
647
656
  }
648
657
  });
649
658
  return gridStyle;
@@ -9,7 +9,8 @@ import { useGridSelector } from '../../hooks/utils/useGridSelector';
9
9
  import { getDataGridUtilityClass } from '../../constants/gridClasses';
10
10
  import { gridDimensionsSelector } from '../../hooks/features/dimensions';
11
11
  import { useGridVirtualScroller } from '../../hooks/features/virtualization/useGridVirtualScroller';
12
- import { GridOverlays } from '../base/GridOverlays';
12
+ import { useGridOverlays } from '../../hooks/features/overlays/useGridOverlays';
13
+ import { GridOverlays as Overlays } from '../base/GridOverlays';
13
14
  import { GridHeaders } from '../GridHeaders';
14
15
  import { GridMainContainer as Container } from './GridMainContainer';
15
16
  import { GridTopContainer as TopContainer } from './GridTopContainer';
@@ -19,12 +20,12 @@ import { GridVirtualScrollerFiller as SpaceFiller } from './GridVirtualScrollerF
19
20
  import { GridVirtualScrollerRenderZone as RenderZone } from './GridVirtualScrollerRenderZone';
20
21
  import { GridVirtualScrollbar as Scrollbar } from './GridVirtualScrollbar';
21
22
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
22
- const useUtilityClasses = (ownerState, dimensions) => {
23
+ const useUtilityClasses = (ownerState, dimensions, loadingOverlayVariant) => {
23
24
  const {
24
25
  classes
25
26
  } = ownerState;
26
27
  const slots = {
27
- root: ['main', dimensions.rightPinnedWidth > 0 && 'main--hasPinnedRight'],
28
+ root: ['main', dimensions.rightPinnedWidth > 0 && 'main--hasPinnedRight', loadingOverlayVariant === 'skeleton' && 'main--hasSkeletonLoadingOverlay'],
28
29
  scroller: ['virtualScroller']
29
30
  };
30
31
  return composeClasses(slots, getDataGridUtilityClass, classes);
@@ -51,7 +52,8 @@ function GridVirtualScroller(props) {
51
52
  const apiRef = useGridApiContext();
52
53
  const rootProps = useGridRootProps();
53
54
  const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
54
- const classes = useUtilityClasses(rootProps, dimensions);
55
+ const overlaysProps = useGridOverlays();
56
+ const classes = useUtilityClasses(rootProps, dimensions, overlaysProps.loadingOverlayVariant);
55
57
  const virtualScroller = useGridVirtualScroller();
56
58
  const {
57
59
  getContainerProps,
@@ -79,7 +81,7 @@ function GridVirtualScroller(props) {
79
81
  position: "top",
80
82
  virtualScroller: virtualScroller
81
83
  })]
82
- }), /*#__PURE__*/_jsx(GridOverlays, {}), /*#__PURE__*/_jsx(Content, _extends({}, getContentProps(), {
84
+ }), /*#__PURE__*/_jsx(Overlays, _extends({}, overlaysProps)), /*#__PURE__*/_jsx(Content, _extends({}, getContentProps(), {
83
85
  children: /*#__PURE__*/_jsxs(RenderZone, _extends({}, getRenderZoneProps(), {
84
86
  children: [rows, /*#__PURE__*/_jsx(rootProps.slots.detailPanels, {
85
87
  virtualScroller: virtualScroller
@@ -2,4 +2,4 @@ import { unstable_generateUtilityClasses as generateUtilityClasses, unstable_gen
2
2
  export function getDataGridUtilityClass(slot) {
3
3
  return generateUtilityClass('MuiDataGrid', slot);
4
4
  }
5
- export const gridClasses = generateUtilityClasses('MuiDataGrid', ['actionsCell', 'aggregationColumnHeader', 'aggregationColumnHeader--alignLeft', 'aggregationColumnHeader--alignCenter', 'aggregationColumnHeader--alignRight', 'aggregationColumnHeaderLabel', 'autoHeight', 'autosizing', 'booleanCell', 'cell--editable', 'cell--editing', 'cell--flex', 'cell--textCenter', 'cell--textLeft', 'cell--textRight', 'cell--rangeTop', 'cell--rangeBottom', 'cell--rangeLeft', 'cell--rangeRight', 'cell--pinnedLeft', 'cell--pinnedRight', 'cell--selectionMode', 'cell', 'cellCheckbox', 'cellEmpty', 'cellSkeleton', 'cellOffsetLeft', 'checkboxInput', 'columnHeader', 'columnHeader--alignCenter', 'columnHeader--alignLeft', 'columnHeader--alignRight', 'columnHeader--dragging', 'columnHeader--moving', 'columnHeader--numeric', 'columnHeader--sortable', 'columnHeader--sorted', 'columnHeader--filtered', 'columnHeader--pinnedLeft', 'columnHeader--pinnedRight', 'columnHeader--last', 'columnHeaderCheckbox', 'columnHeaderDraggableContainer', 'columnHeaderTitle', 'columnHeaderTitleContainer', 'columnHeaderTitleContainerContent', 'columnHeader--filledGroup', 'columnHeader--emptyGroup', 'columnHeaders', 'columnSeparator--resizable', 'columnSeparator--resizing', 'columnSeparator--sideLeft', 'columnSeparator--sideRight', 'columnSeparator', 'columnsManagement', 'columnsManagementRow', 'columnsManagementHeader', 'columnsManagementFooter', 'container--top', 'container--bottom', 'detailPanel', 'detailPanels', 'detailPanelToggleCell', 'detailPanelToggleCell--expanded', 'footerCell', 'panel', 'panelHeader', 'panelWrapper', 'panelContent', 'panelFooter', 'paper', 'editBooleanCell', 'editInputCell', 'filler', 'filler--borderTop', 'filler--pinnedLeft', 'filler--pinnedRight', 'filterForm', 'filterFormDeleteIcon', 'filterFormLogicOperatorInput', 'filterFormColumnInput', 'filterFormOperatorInput', 'filterFormValueInput', 'filterIcon', 'footerContainer', 'headerFilterRow', 'iconButtonContainer', 'iconSeparator', 'main', 'main--hasPinnedRight', 'menu', 'menuIcon', 'menuIconButton', 'menuOpen', 'menuList', 'overlay', 'overlayWrapper', 'overlayWrapperInner', 'root', 'root--densityStandard', 'root--densityComfortable', 'root--densityCompact', 'root--disableUserSelection', 'row', 'row--editable', 'row--editing', 'row--firstVisible', 'row--lastVisible', 'row--dragging', 'row--dynamicHeight', 'row--detailPanelExpanded', 'rowReorderCellPlaceholder', 'rowCount', 'rowReorderCellContainer', 'rowReorderCell', 'rowReorderCell--draggable', 'scrollArea--left', 'scrollArea--right', 'scrollArea', 'scrollbar', 'scrollbar--vertical', 'scrollbar--horizontal', 'scrollbarFiller', 'scrollbarFiller--header', 'scrollbarFiller--borderTop', 'scrollbarFiller--pinnedRight', 'selectedRowCount', 'sortIcon', 'toolbarContainer', 'toolbarFilterList', 'virtualScroller', 'virtualScrollerContent', 'virtualScrollerContent--overflowed', 'virtualScrollerRenderZone', 'pinnedColumns', 'withVerticalBorder', 'withBorderColor', 'cell--withRightBorder', 'cell--withLeftBorder', 'columnHeader--withRightBorder', 'columnHeader--withLeftBorder', 'treeDataGroupingCell', 'treeDataGroupingCellToggle', 'treeDataGroupingCellLoadingContainer', 'groupingCriteriaCell', 'groupingCriteriaCellToggle', 'pinnedRows', 'pinnedRows--top', 'pinnedRows--bottom', 'pinnedRowsRenderZone']);
5
+ export const gridClasses = generateUtilityClasses('MuiDataGrid', ['actionsCell', 'aggregationColumnHeader', 'aggregationColumnHeader--alignLeft', 'aggregationColumnHeader--alignCenter', 'aggregationColumnHeader--alignRight', 'aggregationColumnHeaderLabel', 'autoHeight', 'autosizing', 'booleanCell', 'cell--editable', 'cell--editing', 'cell--flex', 'cell--textCenter', 'cell--textLeft', 'cell--textRight', 'cell--rangeTop', 'cell--rangeBottom', 'cell--rangeLeft', 'cell--rangeRight', 'cell--pinnedLeft', 'cell--pinnedRight', 'cell--selectionMode', 'cell', 'cellCheckbox', 'cellEmpty', 'cellSkeleton', 'cellOffsetLeft', 'checkboxInput', 'columnHeader', 'columnHeader--alignCenter', 'columnHeader--alignLeft', 'columnHeader--alignRight', 'columnHeader--dragging', 'columnHeader--moving', 'columnHeader--numeric', 'columnHeader--sortable', 'columnHeader--sorted', 'columnHeader--filtered', 'columnHeader--pinnedLeft', 'columnHeader--pinnedRight', 'columnHeader--last', 'columnHeaderCheckbox', 'columnHeaderDraggableContainer', 'columnHeaderTitle', 'columnHeaderTitleContainer', 'columnHeaderTitleContainerContent', 'columnHeader--filledGroup', 'columnHeader--emptyGroup', 'columnHeaders', 'columnSeparator--resizable', 'columnSeparator--resizing', 'columnSeparator--sideLeft', 'columnSeparator--sideRight', 'columnSeparator', 'columnsManagement', 'columnsManagementRow', 'columnsManagementHeader', 'columnsManagementFooter', 'container--top', 'container--bottom', 'detailPanel', 'detailPanels', 'detailPanelToggleCell', 'detailPanelToggleCell--expanded', 'footerCell', 'panel', 'panelHeader', 'panelWrapper', 'panelContent', 'panelFooter', 'paper', 'editBooleanCell', 'editInputCell', 'filler', 'filler--borderTop', 'filler--pinnedLeft', 'filler--pinnedRight', 'filterForm', 'filterFormDeleteIcon', 'filterFormLogicOperatorInput', 'filterFormColumnInput', 'filterFormOperatorInput', 'filterFormValueInput', 'filterIcon', 'footerContainer', 'headerFilterRow', 'iconButtonContainer', 'iconSeparator', 'main', 'main--hasPinnedRight', 'main--hasSkeletonLoadingOverlay', 'menu', 'menuIcon', 'menuIconButton', 'menuOpen', 'menuList', 'overlay', 'overlayWrapper', 'overlayWrapperInner', 'root', 'root--densityStandard', 'root--densityComfortable', 'root--densityCompact', 'root--disableUserSelection', 'row', 'row--editable', 'row--editing', 'row--firstVisible', 'row--lastVisible', 'row--dragging', 'row--dynamicHeight', 'row--detailPanelExpanded', 'rowReorderCellPlaceholder', 'rowCount', 'rowReorderCellContainer', 'rowReorderCell', 'rowReorderCell--draggable', 'rowSkeleton', 'scrollArea--left', 'scrollArea--right', 'scrollArea', 'scrollbar', 'scrollbar--vertical', 'scrollbar--horizontal', 'scrollbarFiller', 'scrollbarFiller--header', 'scrollbarFiller--borderTop', 'scrollbarFiller--pinnedRight', 'selectedRowCount', 'sortIcon', 'toolbarContainer', 'toolbarFilterList', 'virtualScroller', 'virtualScrollerContent', 'virtualScrollerContent--overflowed', 'virtualScrollerRenderZone', 'pinnedColumns', 'withVerticalBorder', 'withBorderColor', 'cell--withRightBorder', 'cell--withLeftBorder', 'columnHeader--withRightBorder', 'columnHeader--withLeftBorder', 'treeDataGroupingCell', 'treeDataGroupingCellToggle', 'treeDataGroupingCellLoadingContainer', 'groupingCriteriaCell', 'groupingCriteriaCellToggle', 'pinnedRows', 'pinnedRows--top', 'pinnedRows--bottom', 'pinnedRowsRenderZone']);
@@ -0,0 +1,35 @@
1
+ import { useGridSelector } from '../../utils';
2
+ import { useGridApiContext } from '../../utils/useGridApiContext';
3
+ import { useGridRootProps } from '../../utils/useGridRootProps';
4
+ import { gridExpandedRowCountSelector } from '../filter';
5
+ import { gridRowCountSelector, gridRowsLoadingSelector } from '../rows';
6
+ /**
7
+ * Uses the grid state to determine which overlay to display.
8
+ * Returns the active overlay type and the active loading overlay variant.
9
+ */
10
+ export const useGridOverlays = () => {
11
+ const apiRef = useGridApiContext();
12
+ const rootProps = useGridRootProps();
13
+ const totalRowCount = useGridSelector(apiRef, gridRowCountSelector);
14
+ const visibleRowCount = useGridSelector(apiRef, gridExpandedRowCountSelector);
15
+ const noRows = totalRowCount === 0;
16
+ const loading = useGridSelector(apiRef, gridRowsLoadingSelector);
17
+ const showNoRowsOverlay = !loading && noRows;
18
+ const showNoResultsOverlay = !loading && totalRowCount > 0 && visibleRowCount === 0;
19
+ let overlayType = null;
20
+ let loadingOverlayVariant = null;
21
+ if (showNoRowsOverlay) {
22
+ overlayType = 'noRowsOverlay';
23
+ }
24
+ if (showNoResultsOverlay) {
25
+ overlayType = 'noResultsOverlay';
26
+ }
27
+ if (loading) {
28
+ overlayType = 'loadingOverlay';
29
+ loadingOverlayVariant = rootProps.slotProps?.loadingOverlay?.[noRows ? 'noRowsVariant' : 'variant'] || null;
30
+ }
31
+ return {
32
+ overlayType,
33
+ loadingOverlayVariant
34
+ };
35
+ };
@@ -4,11 +4,11 @@ import * as ReactDOM from 'react-dom';
4
4
  import { unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback } from '@mui/utils';
5
5
  import useLazyRef from '@mui/utils/useLazyRef';
6
6
  import useTimeout from '@mui/utils/useTimeout';
7
+ import { useResizeObserver } from '@mui/x-internals/useResizeObserver';
7
8
  import { useTheme } from '@mui/material/styles';
8
9
  import { useGridPrivateApiContext } from '../../utils/useGridPrivateApiContext';
9
10
  import { useGridRootProps } from '../../utils/useGridRootProps';
10
11
  import { useGridSelector } from '../../utils/useGridSelector';
11
- import { useResizeObserver } from '../../utils/useResizeObserver';
12
12
  import { useRunOnce } from '../../utils/useRunOnce';
13
13
  import { gridVisibleColumnDefinitionsSelector, gridVisiblePinnedColumnDefinitionsSelector, gridColumnPositionsSelector, gridHasColSpanSelector } from '../columns/gridColumnsSelector';
14
14
  import { gridDimensionsSelector } from '../dimensions/gridDimensionsSelectors';
@@ -5,5 +5,4 @@ export { useGridSelector } from './useGridSelector';
5
5
  export * from './useGridNativeEventListener';
6
6
  export * from './useFirstRender';
7
7
  export * from './useOnMount';
8
- export * from './useResizeObserver';
9
8
  export * from './useRunOnce';
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v7.8.0
2
+ * @mui/x-data-grid v7.9.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -172,9 +172,17 @@ function mulberry32(a) {
172
172
  /* eslint-enable */
173
173
  };
174
174
  }
175
- export function randomNumberBetween(seed, min, max) {
175
+
176
+ /**
177
+ * Create a random number generator from a seed. The seed
178
+ * ensures that the random number generator produces the
179
+ * same sequence of 'random' numbers on every render. It
180
+ * returns a function that generates a random number between
181
+ * a specified min and max.
182
+ */
183
+ export function createRandomNumberGenerator(seed) {
176
184
  const random = mulberry32(seed);
177
- return () => min + (max - min) * random();
185
+ return (min, max) => min + (max - min) * random();
178
186
  }
179
187
  export function deepClone(obj) {
180
188
  if (typeof structuredClone === 'function') {
@@ -94,9 +94,16 @@ const useDataGridProps = inProps => {
94
94
  defaultSlots,
95
95
  slots: themedProps.slots
96
96
  }), [themedProps.slots]);
97
- return React.useMemo(() => (0, _extends2.default)({}, DATA_GRID_PROPS_DEFAULT_VALUES, themedProps, {
97
+ const injectDefaultProps = React.useMemo(() => {
98
+ return Object.keys(DATA_GRID_PROPS_DEFAULT_VALUES).reduce((acc, key) => {
99
+ // @ts-ignore
100
+ acc[key] = themedProps[key] ?? DATA_GRID_PROPS_DEFAULT_VALUES[key];
101
+ return acc;
102
+ }, {});
103
+ }, [themedProps]);
104
+ return React.useMemo(() => (0, _extends2.default)({}, themedProps, injectDefaultProps, {
98
105
  localeText,
99
106
  slots
100
- }, DATA_GRID_FORCED_PROPS), [themedProps, localeText, slots]);
107
+ }, DATA_GRID_FORCED_PROPS), [themedProps, localeText, slots, injectDefaultProps]);
101
108
  };
102
109
  exports.useDataGridProps = useDataGridProps;
@@ -6,18 +6,52 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.GridLoadingOverlay = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
10
  var React = _interopRequireWildcard(require("react"));
10
11
  var _propTypes = _interopRequireDefault(require("prop-types"));
12
+ var _LinearProgress = _interopRequireDefault(require("@mui/material/LinearProgress"));
11
13
  var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress"));
12
14
  var _GridOverlay = require("./containers/GridOverlay");
15
+ var _GridSkeletonLoadingOverlay = require("./GridSkeletonLoadingOverlay");
16
+ var _useGridApiContext = require("../hooks/utils/useGridApiContext");
17
+ var _hooks = require("../hooks");
13
18
  var _jsxRuntime = require("react/jsx-runtime");
19
+ const _excluded = ["variant", "noRowsVariant", "style"];
14
20
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
21
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
+ const LOADING_VARIANTS = {
23
+ 'circular-progress': {
24
+ component: _CircularProgress.default,
25
+ style: {}
26
+ },
27
+ 'linear-progress': {
28
+ component: _LinearProgress.default,
29
+ style: {
30
+ display: 'block'
31
+ }
32
+ },
33
+ skeleton: {
34
+ component: _GridSkeletonLoadingOverlay.GridSkeletonLoadingOverlay,
35
+ style: {
36
+ display: 'block'
37
+ }
38
+ }
39
+ };
16
40
  const GridLoadingOverlay = exports.GridLoadingOverlay = /*#__PURE__*/React.forwardRef(function GridLoadingOverlay(props, ref) {
41
+ const {
42
+ variant = 'circular-progress',
43
+ noRowsVariant = 'circular-progress',
44
+ style
45
+ } = props,
46
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
47
+ const apiRef = (0, _useGridApiContext.useGridApiContext)();
48
+ const rowsCount = (0, _hooks.useGridSelector)(apiRef, _hooks.gridRowCountSelector);
49
+ const activeVariant = LOADING_VARIANTS[rowsCount === 0 ? noRowsVariant : variant];
17
50
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridOverlay.GridOverlay, (0, _extends2.default)({
18
- ref: ref
19
- }, props, {
20
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {})
51
+ ref: ref,
52
+ style: (0, _extends2.default)({}, activeVariant.style, style)
53
+ }, other, {
54
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(activeVariant.component, {})
21
55
  }));
22
56
  });
23
57
  process.env.NODE_ENV !== "production" ? GridLoadingOverlay.propTypes = {
@@ -25,5 +59,15 @@ process.env.NODE_ENV !== "production" ? GridLoadingOverlay.propTypes = {
25
59
  // | These PropTypes are generated from the TypeScript type definitions |
26
60
  // | To update them edit the TypeScript types and run "pnpm proptypes" |
27
61
  // ----------------------------------------------------------------------
28
- sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object])
62
+ /**
63
+ * The variant of the overlay when no rows are displayed.
64
+ * @default 'circular-progress'
65
+ */
66
+ noRowsVariant: _propTypes.default.oneOf(['circular-progress', 'linear-progress', 'skeleton']),
67
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
68
+ /**
69
+ * The variant of the overlay.
70
+ * @default 'circular-progress'
71
+ */
72
+ variant: _propTypes.default.oneOf(['circular-progress', 'linear-progress', 'skeleton'])
29
73
  } : void 0;
@@ -258,10 +258,11 @@ const GridRow = /*#__PURE__*/React.forwardRef(function GridRow(props, refProp) {
258
258
  const pinnedOffset = (0, _getPinnedCellOffset.getPinnedCellOffset)(_GridCell.gridPinnedColumnPositionLookup[pinnedPosition], column.computedWidth, indexRelativeToAllColumns, columnPositions, dimensions);
259
259
  if (rowNode?.type === 'skeletonRow') {
260
260
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(slots.skeletonCell, {
261
+ type: column.type,
261
262
  width: width,
262
263
  height: rowHeight,
263
264
  field: column.field,
264
- align: column.align ?? 'left'
265
+ align: column.align
265
266
  }, column.field);
266
267
  }
267
268
  const editCellState = editRowsState[rowId]?.[column.field] ?? null;
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.GridSkeletonLoadingOverlay = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _clsx = _interopRequireDefault(require("clsx"));
11
+ var _system = require("@mui/system");
12
+ var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
13
+ var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
14
+ var _useGridApiContext = require("../hooks/utils/useGridApiContext");
15
+ var _useGridRootProps = require("../hooks/utils/useGridRootProps");
16
+ var _hooks = require("../hooks");
17
+ var _gridClasses = require("../constants/gridClasses");
18
+ var _getPinnedCellOffset = require("../internals/utils/getPinnedCellOffset");
19
+ var _cellBorderUtils = require("../utils/cellBorderUtils");
20
+ var _domUtils = require("../utils/domUtils");
21
+ var _GridScrollbarFillerCell = require("./GridScrollbarFillerCell");
22
+ var _jsxRuntime = require("react/jsx-runtime");
23
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
24
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
25
+ const SkeletonOverlay = (0, _system.styled)('div', {
26
+ name: 'MuiDataGrid',
27
+ slot: 'SkeletonLoadingOverlay',
28
+ overridesResolver: (props, styles) => styles.skeletonLoadingOverlay
29
+ })({
30
+ minWidth: '100%',
31
+ width: 'max-content',
32
+ // prevents overflow: clip; cutting off the x axis
33
+ height: '100%',
34
+ overflow: 'clip' // y axis is hidden while the x axis is allowed to overflow
35
+ });
36
+ const useUtilityClasses = ownerState => {
37
+ const {
38
+ classes
39
+ } = ownerState;
40
+ const slots = {
41
+ root: ['skeletonLoadingOverlay']
42
+ };
43
+ return (0, _composeClasses.default)(slots, _gridClasses.getDataGridUtilityClass, classes);
44
+ };
45
+ const getColIndex = el => parseInt(el.getAttribute('data-colindex'), 10);
46
+ const GridSkeletonLoadingOverlay = exports.GridSkeletonLoadingOverlay = /*#__PURE__*/React.forwardRef(function GridSkeletonLoadingOverlay(props, forwardedRef) {
47
+ const rootProps = (0, _useGridRootProps.useGridRootProps)();
48
+ const {
49
+ slots
50
+ } = rootProps;
51
+ const classes = useUtilityClasses({
52
+ classes: rootProps.classes
53
+ });
54
+ const ref = React.useRef(null);
55
+ const handleRef = (0, _useForkRef.default)(ref, forwardedRef);
56
+ const apiRef = (0, _useGridApiContext.useGridApiContext)();
57
+ const dimensions = (0, _hooks.useGridSelector)(apiRef, _hooks.gridDimensionsSelector);
58
+ const viewportHeight = dimensions?.viewportInnerSize.height ?? 0;
59
+ const skeletonRowsCount = Math.ceil(viewportHeight / dimensions.rowHeight);
60
+ const totalWidth = (0, _hooks.useGridSelector)(apiRef, _hooks.gridColumnsTotalWidthSelector);
61
+ const positions = (0, _hooks.useGridSelector)(apiRef, _hooks.gridColumnPositionsSelector);
62
+ const inViewportCount = React.useMemo(() => positions.filter(value => value <= totalWidth).length, [totalWidth, positions]);
63
+ const allVisibleColumns = (0, _hooks.useGridSelector)(apiRef, _hooks.gridVisibleColumnDefinitionsSelector);
64
+ const columns = React.useMemo(() => allVisibleColumns.slice(0, inViewportCount), [allVisibleColumns, inViewportCount]);
65
+ const pinnedColumns = (0, _hooks.useGridSelector)(apiRef, _hooks.gridVisiblePinnedColumnDefinitionsSelector);
66
+ const getPinnedStyle = React.useCallback((computedWidth, index, position) => {
67
+ const pinnedOffset = (0, _getPinnedCellOffset.getPinnedCellOffset)(position, computedWidth, index, positions, dimensions);
68
+ return {
69
+ [position]: pinnedOffset
70
+ };
71
+ }, [dimensions, positions]);
72
+ const getPinnedPosition = React.useCallback(field => {
73
+ if (pinnedColumns.left.findIndex(col => col.field === field) !== -1) {
74
+ return _hooks.GridPinnedColumnPosition.LEFT;
75
+ }
76
+ if (pinnedColumns.right.findIndex(col => col.field === field) !== -1) {
77
+ return _hooks.GridPinnedColumnPosition.RIGHT;
78
+ }
79
+ return undefined;
80
+ }, [pinnedColumns.left, pinnedColumns.right]);
81
+ const children = React.useMemo(() => {
82
+ const array = [];
83
+ for (let i = 0; i < skeletonRowsCount; i += 1) {
84
+ const rowCells = [];
85
+ for (let colIndex = 0; colIndex < columns.length; colIndex += 1) {
86
+ const column = columns[colIndex];
87
+ const pinnedPosition = getPinnedPosition(column.field);
88
+ const isPinnedLeft = pinnedPosition === _hooks.GridPinnedColumnPosition.LEFT;
89
+ const isPinnedRight = pinnedPosition === _hooks.GridPinnedColumnPosition.RIGHT;
90
+ const sectionLength = pinnedPosition ? pinnedColumns[pinnedPosition].length // pinned section
91
+ : columns.length - pinnedColumns.left.length - pinnedColumns.right.length; // middle section
92
+ const sectionIndex = pinnedPosition ? pinnedColumns[pinnedPosition].findIndex(col => col.field === column.field) // pinned section
93
+ : colIndex - pinnedColumns.left.length; // middle section
94
+ const pinnedStyle = pinnedPosition && getPinnedStyle(column.computedWidth, colIndex, pinnedPosition);
95
+ const gridHasFiller = dimensions.columnsTotalWidth < dimensions.viewportOuterSize.width;
96
+ const showRightBorder = (0, _cellBorderUtils.shouldCellShowRightBorder)(pinnedPosition, sectionIndex, sectionLength, rootProps.showCellVerticalBorder, gridHasFiller);
97
+ const showLeftBorder = (0, _cellBorderUtils.shouldCellShowLeftBorder)(pinnedPosition, sectionIndex);
98
+ const isLastColumn = colIndex === columns.length - 1;
99
+ const isFirstPinnedRight = isPinnedRight && sectionIndex === 0;
100
+ const hasFillerBefore = isFirstPinnedRight && gridHasFiller;
101
+ const hasFillerAfter = isLastColumn && !isFirstPinnedRight && gridHasFiller;
102
+ const expandedWidth = dimensions.viewportOuterSize.width - dimensions.columnsTotalWidth;
103
+ const emptyCellWidth = Math.max(0, expandedWidth);
104
+ const emptyCell = /*#__PURE__*/(0, _jsxRuntime.jsx)(slots.skeletonCell, {
105
+ width: emptyCellWidth,
106
+ empty: true
107
+ }, `skeleton-filler-column-${i}`);
108
+ const scrollbarWidth = dimensions.hasScrollY ? dimensions.scrollbarSize : 0;
109
+ const hasScrollbarFiller = isLastColumn && scrollbarWidth !== 0;
110
+ if (hasFillerBefore) {
111
+ rowCells.push(emptyCell);
112
+ }
113
+ rowCells.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(slots.skeletonCell, {
114
+ field: column.field,
115
+ type: column.type,
116
+ align: column.align,
117
+ width: "var(--width)",
118
+ height: dimensions.rowHeight,
119
+ "data-colindex": colIndex,
120
+ className: (0, _clsx.default)(isPinnedLeft && _gridClasses.gridClasses['cell--pinnedLeft'], isPinnedRight && _gridClasses.gridClasses['cell--pinnedRight'], showRightBorder && _gridClasses.gridClasses['cell--withRightBorder'], showLeftBorder && _gridClasses.gridClasses['cell--withLeftBorder']),
121
+ style: (0, _extends2.default)({
122
+ '--width': `${column.computedWidth}px`
123
+ }, pinnedStyle)
124
+ }, `skeleton-column-${i}-${column.field}`));
125
+ if (hasFillerAfter) {
126
+ rowCells.push(emptyCell);
127
+ }
128
+ if (hasScrollbarFiller) {
129
+ rowCells.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_GridScrollbarFillerCell.GridScrollbarFillerCell, {
130
+ pinnedRight: pinnedColumns.right.length > 0
131
+ }));
132
+ }
133
+ }
134
+ array.push( /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
135
+ className: (0, _clsx.default)(_gridClasses.gridClasses.row, _gridClasses.gridClasses.rowSkeleton, i === 0 && _gridClasses.gridClasses['row--firstVisible']),
136
+ children: rowCells
137
+ }, `skeleton-row-${i}`));
138
+ }
139
+ return array;
140
+ }, [slots, columns, pinnedColumns, skeletonRowsCount, rootProps.showCellVerticalBorder, dimensions.columnsTotalWidth, dimensions.viewportOuterSize.width, dimensions.rowHeight, dimensions.hasScrollY, dimensions.scrollbarSize, getPinnedPosition, getPinnedStyle]);
141
+
142
+ // Sync the column resize of the overlay columns with the grid
143
+ const handleColumnResize = params => {
144
+ const {
145
+ colDef,
146
+ width
147
+ } = params;
148
+ const cells = ref.current?.querySelectorAll(`[data-field="${(0, _domUtils.escapeOperandAttributeSelector)(colDef.field)}"]`);
149
+ if (!cells) {
150
+ throw new Error('MUI X: Expected skeleton cells to be defined with `data-field` attribute.');
151
+ }
152
+ const resizedColIndex = columns.findIndex(col => col.field === colDef.field);
153
+ const pinnedPosition = getPinnedPosition(colDef.field);
154
+ const isPinnedLeft = pinnedPosition === _hooks.GridPinnedColumnPosition.LEFT;
155
+ const isPinnedRight = pinnedPosition === _hooks.GridPinnedColumnPosition.RIGHT;
156
+ const currentWidth = getComputedStyle(cells[0]).getPropertyValue('--width');
157
+ const delta = parseInt(currentWidth, 10) - width;
158
+ if (cells) {
159
+ cells.forEach(element => {
160
+ element.style.setProperty('--width', `${width}px`);
161
+ });
162
+ }
163
+ if (isPinnedLeft) {
164
+ const pinnedCells = ref.current?.querySelectorAll(`.${_gridClasses.gridClasses['cell--pinnedLeft']}`);
165
+ pinnedCells?.forEach(element => {
166
+ const colIndex = getColIndex(element);
167
+ if (colIndex > resizedColIndex) {
168
+ element.style.left = `${parseInt(getComputedStyle(element).left, 10) - delta}px`;
169
+ }
170
+ });
171
+ }
172
+ if (isPinnedRight) {
173
+ const pinnedCells = ref.current?.querySelectorAll(`.${_gridClasses.gridClasses['cell--pinnedRight']}`);
174
+ pinnedCells?.forEach(element => {
175
+ const colIndex = getColIndex(element);
176
+ if (colIndex < resizedColIndex) {
177
+ element.style.right = `${parseInt(getComputedStyle(element).right, 10) + delta}px`;
178
+ }
179
+ });
180
+ }
181
+ };
182
+ (0, _hooks.useGridApiEventHandler)(apiRef, 'columnResize', handleColumnResize);
183
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(SkeletonOverlay, (0, _extends2.default)({
184
+ className: classes.root,
185
+ ref: handleRef
186
+ }, props, {
187
+ children: children
188
+ }));
189
+ });