Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Refactor: move Badge to leaf import #15879

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/gridSlotsComponentsProps';
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
38 changes: 34 additions & 4 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 @@ -33,9 +34,18 @@ import type { GridLoadingOverlayProps } from '../components/GridLoadingOverlay';
import type { GridRowCountProps } from '../components/GridRowCount';
import type { GridColumnHeaderSortIconProps } from '../components/columnHeaders/GridColumnHeaderSortIcon';

type DividerProps = {};
export type BadgeProps = {
badgeContent?: React.ReactNode;
children: React.ReactNode;
color?: 'primary' | 'default' | 'error';
overlap?: 'circular';
variant?: 'dot';
invisible?: boolean;
};

export type DividerProps = {};

type MenuItemProps = {
export type MenuItemProps = {
autoFocus?: boolean;
children: React.ReactNode;
/** For items that aren't interactive themselves (but may contain an interactive widget) */
Expand Down Expand Up @@ -86,7 +96,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 @@ -108,6 +118,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 All @@ -131,6 +149,18 @@ export interface GridSlotProps {
toolbar: GridToolbarProps & ToolbarPropsOverrides;
}

/* Merge MUI types into base types to keep slotProps working. */
type Merge<A, B> = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we define this in a more general (utils) space? This seems as if it could be useful elsewhere as well!

[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
Loading