Skip to content

Commit

Permalink
[DataGrid] Refactor: move Badge to leaf import (mui#15879)
Browse files Browse the repository at this point in the history
  • Loading branch information
romgrk authored Dec 16, 2024
1 parent 8427ea4 commit fd31143
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@mui/utils';
import { ButtonProps } from '@mui/material/Button';
import { TooltipProps } from '@mui/material/Tooltip';
import { BadgeProps } from '@mui/material/Badge';
import { BadgeProps } from '../../models/gridBaseSlots';
import { gridColumnLookupSelector } from '../../hooks/features/columns/gridColumnsSelector';
import { useGridSelector } from '../../hooks/utils/useGridSelector';
import { gridFilterActiveItemsSelector } from '../../hooks/features/filter/gridFilterSelector';
Expand Down Expand Up @@ -42,6 +42,7 @@ const GridToolbarFilterListRoot = styled('ul', {
padding: theme.spacing(0, 1),
}));

// FIXME(v8:romgrk): override slotProps
export interface GridToolbarFilterButtonProps {
/**
* The props used for each slot inside.
Expand Down
23 changes: 23 additions & 0 deletions packages/x-data-grid/src/models/gridBaseSlots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export type BadgeProps = {
badgeContent?: React.ReactNode;
children: React.ReactNode;
color?: 'primary' | 'default' | 'error';
overlap?: 'circular';
variant?: 'dot';
invisible?: boolean;
};

export type DividerProps = {};

export type MenuItemProps = {
autoFocus?: boolean;
children: React.ReactNode;
/** For items that aren't interactive themselves (but may contain an interactive widget) */
inert?: boolean;
disabled?: boolean;
onClick?: React.MouseEventHandler<HTMLElement>;
iconStart?: React.ReactNode;
iconEnd?: React.ReactNode;
selected?: boolean;
value?: number | string | readonly string[];
};
40 changes: 24 additions & 16 deletions packages/x-data-grid/src/models/gridSlotsComponentsProps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import type { BadgeProps } from '@mui/material/Badge';
import type { BadgeProps as MUIBadgeProps } from '@mui/material/Badge';
import type { CheckboxProps } from '@mui/material/Checkbox';
import type { MenuListProps } from '@mui/material/MenuList';
import type { MenuItemProps as MUIMenuItemProps } from '@mui/material/MenuItem';
import type { TextFieldProps } from '@mui/material/TextField';
import type { FormControlProps } from '@mui/material/FormControl';
import type { SelectProps } from '@mui/material/Select';
Expand Down Expand Up @@ -32,24 +33,11 @@ import type { GridColumnsManagementProps } from '../components/columnsManagement
import type { GridLoadingOverlayProps } from '../components/GridLoadingOverlay';
import type { GridRowCountProps } from '../components/GridRowCount';
import type { GridColumnHeaderSortIconProps } from '../components/columnHeaders/GridColumnHeaderSortIcon';
import type { BadgeProps, DividerProps, MenuItemProps } from './gridBaseSlots';

type DividerProps = {};
type RootProps = React.HTMLAttributes<HTMLDivElement> & Record<`data-${string}`, string>;
type MainProps = React.HTMLAttributes<HTMLDivElement> & Record<`data-${string}`, string>;

type MenuItemProps = {
autoFocus?: boolean;
children: React.ReactNode;
/** For items that aren't interactive themselves (but may contain an interactive widget) */
inert?: boolean;
disabled?: boolean;
onClick?: React.MouseEventHandler<HTMLElement>;
iconStart?: React.ReactNode;
iconEnd?: React.ReactNode;
selected?: boolean;
value?: number | string | readonly string[];
};

// Overrides for module augmentation
export interface BaseBadgePropsOverrides {}
export interface BaseCheckboxPropsOverrides {}
Expand Down Expand Up @@ -88,7 +76,7 @@ export interface PinnedRowsPropsOverrides {}
export interface SkeletonCellPropsOverrides {}
export interface RowPropsOverrides {}

export interface GridSlotProps {
interface BaseSlotProps {
baseBadge: BadgeProps & BaseBadgePropsOverrides;
baseCheckbox: CheckboxProps & BaseCheckboxPropsOverrides;
baseDivider: DividerProps & BaseDividerPropsOverrides;
Expand All @@ -110,6 +98,14 @@ export interface GridSlotProps {
children?: React.ReactNode;
} & BaseSelectOptionPropsOverrides;
baseChip: ChipProps & BaseChipPropsOverrides;
}

interface MaterialSlotProps {
baseBadge: MUIBadgeProps;
baseMenuItem: MUIMenuItemProps;
}

interface ElementSlotProps {
cell: GridCellProps & CellPropsOverrides;
columnHeaders: GridColumnHeadersProps;
columnHeaderFilterIconButton: ColumnHeaderFilterIconButtonProps &
Expand Down Expand Up @@ -141,6 +137,18 @@ export interface GridSlotProps {
root: RootProps;
}

/* Merge MUI types into base types to keep slotProps working. */
type Merge<A, B> = {
[K in keyof A | keyof B]: K extends keyof A & keyof B
? A[K] & B[K]
: K extends keyof B
? B[K]
: K extends keyof A
? A[K]
: never;
};
export type GridSlotProps = Merge<BaseSlotProps, MaterialSlotProps> & ElementSlotProps;

/**
* Overridable components props dynamically passed to the component at rendering.
*/
Expand Down
2 changes: 1 addition & 1 deletion scripts/x-data-grid-premium.exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@
{ "name": "GridSkeletonCell", "kind": "Variable" },
{ "name": "GridSkeletonCellProps", "kind": "Interface" },
{ "name": "GridSkeletonRowNode", "kind": "Interface" },
{ "name": "GridSlotProps", "kind": "Interface" },
{ "name": "GridSlotProps", "kind": "TypeAlias" },
{ "name": "GridSlots", "kind": "Interface" },
{ "name": "GridSlotsComponent", "kind": "Interface" },
{ "name": "GridSlotsComponentsProps", "kind": "TypeAlias" },
Expand Down
2 changes: 1 addition & 1 deletion scripts/x-data-grid-pro.exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@
{ "name": "GridSkeletonCell", "kind": "Variable" },
{ "name": "GridSkeletonCellProps", "kind": "Interface" },
{ "name": "GridSkeletonRowNode", "kind": "Interface" },
{ "name": "GridSlotProps", "kind": "Interface" },
{ "name": "GridSlotProps", "kind": "TypeAlias" },
{ "name": "GridSlots", "kind": "Interface" },
{ "name": "GridSlotsComponent", "kind": "Interface" },
{ "name": "GridSlotsComponentsProps", "kind": "TypeAlias" },
Expand Down
2 changes: 1 addition & 1 deletion scripts/x-data-grid.exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@
{ "name": "GridSkeletonCell", "kind": "Variable" },
{ "name": "GridSkeletonCellProps", "kind": "Interface" },
{ "name": "GridSkeletonRowNode", "kind": "Interface" },
{ "name": "GridSlotProps", "kind": "Interface" },
{ "name": "GridSlotProps", "kind": "TypeAlias" },
{ "name": "GridSlots", "kind": "Interface" },
{ "name": "GridSlotsComponent", "kind": "Interface" },
{ "name": "GridSlotsComponentsProps", "kind": "TypeAlias" },
Expand Down

0 comments on commit fd31143

Please sign in to comment.