diff --git a/docs/data/data-grid/column-menu/AddNewColumnMenuGrid.js b/docs/data/data-grid/column-menu/AddNewColumnMenuGrid.js index c5b3f9897630f..c2cbc530b462e 100644 --- a/docs/data/data-grid/column-menu/AddNewColumnMenuGrid.js +++ b/docs/data/data-grid/column-menu/AddNewColumnMenuGrid.js @@ -22,11 +22,11 @@ function CustomColumnMenu(props) { return ( ( @@ -97,42 +97,42 @@ const columns = [ const rows = [ { id: 1, - slot: 'ColumnMenuSortItem', + slot: 'columnMenuSortItem', defaultComponent: 'GridColumnMenuSortItem', displayOrder: 10, plan: 'Community', }, { id: 3, - slot: 'ColumnMenuFilterItem', + slot: 'columnMenuFilterItem', defaultComponent: 'GridColumnMenuFilterItem', displayOrder: 20, plan: 'Community', }, { id: 7, - slot: 'ColumnMenuColumnsItem', + slot: 'columnMenuColumnsItem', defaultComponent: 'GridColumnMenuColumnsItem', displayOrder: 30, plan: 'Community', }, { id: 9, - slot: 'ColumnMenuPinningItem', + slot: 'columnMenuPinningItem', defaultComponent: 'GridColumnMenuPinningItem', displayOrder: 15, plan: 'Pro', }, { id: 11, - slot: 'ColumnMenuAggregationItem', + slot: 'columnMenuAggregationItem', defaultComponent: 'GridColumnMenuAggregationItem', displayOrder: 23, plan: 'Premium', }, { id: 13, - slot: 'ColumnMenuGroupingItem', + slot: 'columnMenuGroupingItem', defaultComponent: 'GridColumnMenuGroupingItem', displayOrder: 27, plan: 'Premium', diff --git a/docs/data/data-grid/column-menu/ColumnMenuGridReferencesNoSnap.tsx b/docs/data/data-grid/column-menu/ColumnMenuGridReferencesNoSnap.tsx index f83bbd801c962..15ce7536261d9 100644 --- a/docs/data/data-grid/column-menu/ColumnMenuGridReferencesNoSnap.tsx +++ b/docs/data/data-grid/column-menu/ColumnMenuGridReferencesNoSnap.tsx @@ -69,7 +69,7 @@ function ComponentTag(props: { value?: string; plan?: string }) { const columns = [ { field: 'slot', - headerName: 'Component', + headerName: 'Slot', width: 240, renderCell: (params: GridRenderCellParams) => ( @@ -89,42 +89,42 @@ const columns = [ const rows = [ { id: 1, - slot: 'ColumnMenuSortItem', + slot: 'columnMenuSortItem', defaultComponent: 'GridColumnMenuSortItem', displayOrder: 10, plan: 'Community', }, { id: 3, - slot: 'ColumnMenuFilterItem', + slot: 'columnMenuFilterItem', defaultComponent: 'GridColumnMenuFilterItem', displayOrder: 20, plan: 'Community', }, { id: 7, - slot: 'ColumnMenuColumnsItem', + slot: 'columnMenuColumnsItem', defaultComponent: 'GridColumnMenuColumnsItem', displayOrder: 30, plan: 'Community', }, { id: 9, - slot: 'ColumnMenuPinningItem', + slot: 'columnMenuPinningItem', defaultComponent: 'GridColumnMenuPinningItem', displayOrder: 15, plan: 'Pro', }, { id: 11, - slot: 'ColumnMenuAggregationItem', + slot: 'columnMenuAggregationItem', defaultComponent: 'GridColumnMenuAggregationItem', displayOrder: 23, plan: 'Premium', }, { id: 13, - slot: 'ColumnMenuGroupingItem', + slot: 'columnMenuGroupingItem', defaultComponent: 'GridColumnMenuGroupingItem', displayOrder: 27, plan: 'Premium', diff --git a/docs/data/data-grid/column-menu/HideColumnMenuGrid.js b/docs/data/data-grid/column-menu/HideColumnMenuGrid.js index 12fb92026a0a2..497eea99d2b8d 100644 --- a/docs/data/data-grid/column-menu/HideColumnMenuGrid.js +++ b/docs/data/data-grid/column-menu/HideColumnMenuGrid.js @@ -6,9 +6,9 @@ function CustomColumnMenu(props) { return ( ); diff --git a/docs/data/data-grid/column-menu/HideColumnMenuGrid.tsx b/docs/data/data-grid/column-menu/HideColumnMenuGrid.tsx index 6d7dc650d12eb..c1e65d8e2c860 100644 --- a/docs/data/data-grid/column-menu/HideColumnMenuGrid.tsx +++ b/docs/data/data-grid/column-menu/HideColumnMenuGrid.tsx @@ -6,9 +6,9 @@ function CustomColumnMenu(props: GridColumnMenuProps) { return ( ); diff --git a/docs/data/data-grid/column-menu/OverrideColumnMenuGrid.js b/docs/data/data-grid/column-menu/OverrideColumnMenuGrid.js index da967a69d650c..6cd8cdc025348 100644 --- a/docs/data/data-grid/column-menu/OverrideColumnMenuGrid.js +++ b/docs/data/data-grid/column-menu/OverrideColumnMenuGrid.js @@ -37,9 +37,9 @@ function CustomColumnMenu(props) { return ( ); diff --git a/docs/data/data-grid/column-menu/OverrideColumnMenuGrid.tsx b/docs/data/data-grid/column-menu/OverrideColumnMenuGrid.tsx index c53cc12a85941..d3b8c2e6b87bd 100644 --- a/docs/data/data-grid/column-menu/OverrideColumnMenuGrid.tsx +++ b/docs/data/data-grid/column-menu/OverrideColumnMenuGrid.tsx @@ -36,9 +36,9 @@ function CustomColumnMenu(props: GridColumnMenuProps) { return ( ); diff --git a/docs/data/data-grid/column-menu/ReorderColumnMenuGrid.js b/docs/data/data-grid/column-menu/ReorderColumnMenuGrid.js index d1bf1458d1076..12105d6516477 100644 --- a/docs/data/data-grid/column-menu/ReorderColumnMenuGrid.js +++ b/docs/data/data-grid/column-menu/ReorderColumnMenuGrid.js @@ -6,7 +6,7 @@ function CustomColumnMenu(props) { return ( ` component: +You can customize the column menu items by passing the `slots` and `slotProps` props to the `` component: -- `components` - use this prop to override default column menu components or add new components. -- `componentsProps` - use this prop to override or pass [`displayOrder`](/x/react-data-grid/column-menu/#reordering-menu-items) for column menu items. You can also use this to pass extra props to custom column menu components. - -:::warning -The `components` prop uses pascal case (`ColumnMenuFilterItem`), while `componentsProps` uses camel case (`columnMenuFilterItem`). -::: +- `slots` - use this prop to override default column menu slots or add new slots. +- `slotProps` - use this prop to override or pass [`displayOrder`](/x/react-data-grid/column-menu/#reordering-menu-items) for column menu items. You can also use this to pass extra props to custom column menu slots. ### Adding a menu item -To add a new menu item, create a new item slot and pass it to the `components` prop. In the example below, the new slot is called `ColumnMenuUserItem` but you can choose any name and it'll be added to the menu automatically. -You can also set the `displayOrder` (default `100`) or pass new props to the components using `componentsProps` prop. +To add a new menu item, create a new item slot and pass it to the `slots` prop. In the example below, the new slot is called `columnMenuUserItem` but you can choose any name and it'll be added to the menu automatically. +You can also set the `displayOrder` (default `100`) or pass new props to the slots using the `slotProps` prop. ```tsx function CustomColumnMenu(props: GridColumnMenuProps) { return ( ); @@ -74,7 +70,7 @@ function CustomColumnMenu(props: GridColumnMenuProps) { ### Hiding a menu item -To hide a menu item, you can set its respective slot in `components` to `null`. +To hide a menu item, you can set its respective slot in `slots` to `null`. Check [this table](/x/react-data-grid/column-menu/#default-column-menu-items) to know the slot name for each menu item. ```tsx @@ -82,9 +78,9 @@ function CustomColumnMenu(props: GridColumnMenuProps) { return ( ); @@ -97,7 +93,7 @@ function CustomColumnMenu(props: GridColumnMenuProps) { Every item is assigned a `displayOrder` based on which it is shown before or after other items. It works in ascending order; the smaller the number is, the earlier it is displayed on the list. For new items default value for `displayOrder` is **100**. -You can override `displayOrder` for the default or new items in `componentsProps`. +You can override `displayOrder` for the default or new items in `slotProps`. Check [this table](/x/react-data-grid/column-menu/#default-column-menu-items) to see default `displayOrder` for each menu item. @@ -106,7 +102,7 @@ function CustomColumnMenu(props: GridColumnMenuProps) { return ( Tip: The `ColumnMenu` component and its components slots receive the `colDef` prop corresponding to the current column; you can use this to conditionally render some items or change some logic. +Tip: The `columnMenu` component and its components slots receive the `colDef` prop corresponding to the current column; you can use this to conditionally render some items or change some logic. ::: ## Disable column menu diff --git a/packages/grid/x-data-grid-premium/src/components/GridPremiumColumnMenu.tsx b/packages/grid/x-data-grid-premium/src/components/GridPremiumColumnMenu.tsx index 2c4595f6f8a85..81f88af2aac35 100644 --- a/packages/grid/x-data-grid-premium/src/components/GridPremiumColumnMenu.tsx +++ b/packages/grid/x-data-grid-premium/src/components/GridPremiumColumnMenu.tsx @@ -3,8 +3,8 @@ import PropTypes from 'prop-types'; import { GridGenericColumnMenu, GridColumnMenuProps, - GRID_COLUMN_MENU_COMPONENTS, - GRID_COLUMN_MENU_COMPONENTS_PROPS, + GRID_COLUMN_MENU_SLOTS, + GRID_COLUMN_MENU_SLOT_PROPS, GridColumnMenuItemProps, } from '@mui/x-data-grid-pro'; import { GridColumnMenuAggregationItem } from './GridColumnMenuAggregationItem'; @@ -23,14 +23,14 @@ export function GridColumnMenuGroupingItem(props: GridColumnMenuItemProps) { return null; } -export const GRID_COLUMN_MENU_COMPONENTS_PREMIUM = { - ...GRID_COLUMN_MENU_COMPONENTS, - ColumnMenuAggregationItem: GridColumnMenuAggregationItem, - ColumnMenuGroupingItem: GridColumnMenuGroupingItem, +export const GRID_COLUMN_MENU_SLOTS_PREMIUM = { + ...GRID_COLUMN_MENU_SLOTS, + columnMenuAggregationItem: GridColumnMenuAggregationItem, + columnMenuGroupingItem: GridColumnMenuGroupingItem, }; -export const GRID_COLUMN_MENU_COMPONENTS_PROPS_PREMIUM = { - ...GRID_COLUMN_MENU_COMPONENTS_PROPS, +export const GRID_COLUMN_MENU_SLOT_PROPS_PREMIUM = { + ...GRID_COLUMN_MENU_SLOT_PROPS, columnMenuAggregationItem: { displayOrder: 23 }, columnMenuGroupingItem: { displayOrder: 27 }, }; @@ -41,8 +41,8 @@ const GridPremiumColumnMenu = React.forwardRef ); }, diff --git a/packages/grid/x-data-grid-premium/src/components/reexports.ts b/packages/grid/x-data-grid-premium/src/components/reexports.ts index f4df5a2daef7d..068dc96975ee0 100644 --- a/packages/grid/x-data-grid-premium/src/components/reexports.ts +++ b/packages/grid/x-data-grid-premium/src/components/reexports.ts @@ -1,5 +1,5 @@ export { GridPremiumColumnMenu as GridColumnMenu, - GRID_COLUMN_MENU_COMPONENTS_PREMIUM as GRID_COLUMN_MENU_COMPONENTS, - GRID_COLUMN_MENU_COMPONENTS_PROPS_PREMIUM as GRID_COLUMN_MENU_COMPONENTS_PROPS, + GRID_COLUMN_MENU_SLOTS_PREMIUM as GRID_COLUMN_MENU_SLOTS, + GRID_COLUMN_MENU_SLOT_PROPS_PREMIUM as GRID_COLUMN_MENU_SLOT_PROPS, } from './GridPremiumColumnMenu'; diff --git a/packages/grid/x-data-grid-premium/src/hooks/features/aggregation/useGridAggregationPreProcessors.tsx b/packages/grid/x-data-grid-premium/src/hooks/features/aggregation/useGridAggregationPreProcessors.tsx index 2102a894e5cb7..3a3c3f226115f 100644 --- a/packages/grid/x-data-grid-premium/src/hooks/features/aggregation/useGridAggregationPreProcessors.tsx +++ b/packages/grid/x-data-grid-premium/src/hooks/features/aggregation/useGridAggregationPreProcessors.tsx @@ -120,7 +120,7 @@ export const useGridAggregationPreProcessors = ( return columnMenuItems; } - return [...columnMenuItems, 'ColumnMenuAggregationItem']; + return [...columnMenuItems, 'columnMenuAggregationItem']; }, [props.aggregationFunctions, props.disableAggregation], ); diff --git a/packages/grid/x-data-grid-premium/src/hooks/features/rowGrouping/useGridRowGrouping.tsx b/packages/grid/x-data-grid-premium/src/hooks/features/rowGrouping/useGridRowGrouping.tsx index e8968812f08e9..b779e23a2064a 100644 --- a/packages/grid/x-data-grid-premium/src/hooks/features/rowGrouping/useGridRowGrouping.tsx +++ b/packages/grid/x-data-grid-premium/src/hooks/features/rowGrouping/useGridRowGrouping.tsx @@ -158,7 +158,7 @@ export const useGridRowGrouping = ( return columnMenuItems; } if (isGroupingColumn(colDef.field) || colDef.groupable) { - return [...columnMenuItems, 'ColumnMenuGroupingItem']; + return [...columnMenuItems, 'columnMenuGroupingItem']; } return columnMenuItems; }, diff --git a/packages/grid/x-data-grid-premium/src/index.ts b/packages/grid/x-data-grid-premium/src/index.ts index 73c064d0d8f33..e9c95459a71fe 100644 --- a/packages/grid/x-data-grid-premium/src/index.ts +++ b/packages/grid/x-data-grid-premium/src/index.ts @@ -31,6 +31,6 @@ export type { GridApi, GridInitialState, GridState } from './typeOverloads/reexp export { GridColumnMenu, - GRID_COLUMN_MENU_COMPONENTS, - GRID_COLUMN_MENU_COMPONENTS_PROPS, + GRID_COLUMN_MENU_SLOTS, + GRID_COLUMN_MENU_SLOT_PROPS, } from './components/reexports'; diff --git a/packages/grid/x-data-grid-pro/src/components/GridProColumnMenu.tsx b/packages/grid/x-data-grid-pro/src/components/GridProColumnMenu.tsx index 058235332070a..b9ff646078fcd 100644 --- a/packages/grid/x-data-grid-pro/src/components/GridProColumnMenu.tsx +++ b/packages/grid/x-data-grid-pro/src/components/GridProColumnMenu.tsx @@ -3,18 +3,18 @@ import PropTypes from 'prop-types'; import { GridGenericColumnMenu, GridColumnMenuProps, - GRID_COLUMN_MENU_COMPONENTS, - GRID_COLUMN_MENU_COMPONENTS_PROPS, + GRID_COLUMN_MENU_SLOTS, + GRID_COLUMN_MENU_SLOT_PROPS, } from '@mui/x-data-grid'; import { GridColumnMenuPinningItem } from './GridColumnMenuPinningItem'; -export const GRID_COLUMN_MENU_COMPONENTS_PRO = { - ...GRID_COLUMN_MENU_COMPONENTS, - ColumnMenuPinningItem: GridColumnMenuPinningItem, +export const GRID_COLUMN_MENU_SLOTS_PRO = { + ...GRID_COLUMN_MENU_SLOTS, + columnMenuPinningItem: GridColumnMenuPinningItem, }; -export const GRID_COLUMN_MENU_COMPONENTS_PROPS_PRO = { - ...GRID_COLUMN_MENU_COMPONENTS_PROPS, +export const GRID_COLUMN_MENU_SLOT_PROPS_PRO = { + ...GRID_COLUMN_MENU_SLOT_PROPS, columnMenuPinningItem: { displayOrder: 15, }, @@ -26,8 +26,8 @@ const GridProColumnMenu = React.forwardRef ); }, diff --git a/packages/grid/x-data-grid-pro/src/components/reexports.ts b/packages/grid/x-data-grid-pro/src/components/reexports.ts index efb1b4c9dd75d..50e0ac07859ae 100644 --- a/packages/grid/x-data-grid-pro/src/components/reexports.ts +++ b/packages/grid/x-data-grid-pro/src/components/reexports.ts @@ -1,5 +1,5 @@ export { GridProColumnMenu as GridColumnMenu, - GRID_COLUMN_MENU_COMPONENTS_PRO as GRID_COLUMN_MENU_COMPONENTS, - GRID_COLUMN_MENU_COMPONENTS_PROPS_PRO as GRID_COLUMN_MENU_COMPONENTS_PROPS, + GRID_COLUMN_MENU_SLOTS_PRO as GRID_COLUMN_MENU_SLOTS, + GRID_COLUMN_MENU_SLOT_PROPS_PRO as GRID_COLUMN_MENU_SLOT_PROPS, } from './GridProColumnMenu'; diff --git a/packages/grid/x-data-grid-pro/src/hooks/features/columnPinning/useGridColumnPinning.tsx b/packages/grid/x-data-grid-pro/src/hooks/features/columnPinning/useGridColumnPinning.tsx index 8a0999e5a5b79..e71a812d9d97a 100644 --- a/packages/grid/x-data-grid-pro/src/hooks/features/columnPinning/useGridColumnPinning.tsx +++ b/packages/grid/x-data-grid-pro/src/hooks/features/columnPinning/useGridColumnPinning.tsx @@ -188,7 +188,7 @@ export const useGridColumnPinning = ( return columnMenuItems; } - return [...columnMenuItems, 'ColumnMenuPinningItem']; + return [...columnMenuItems, 'columnMenuPinningItem']; }, [props.disableColumnPinning], ); diff --git a/packages/grid/x-data-grid-pro/src/index.ts b/packages/grid/x-data-grid-pro/src/index.ts index 851dd8d5ebcfb..69e2db262617f 100644 --- a/packages/grid/x-data-grid-pro/src/index.ts +++ b/packages/grid/x-data-grid-pro/src/index.ts @@ -28,8 +28,8 @@ export type { GridApi, GridInitialState, GridState } from './typeOverloads/reexp export { GridColumnMenu, - GRID_COLUMN_MENU_COMPONENTS, - GRID_COLUMN_MENU_COMPONENTS_PROPS, + GRID_COLUMN_MENU_SLOTS, + GRID_COLUMN_MENU_SLOT_PROPS, } from './components/reexports'; export { GridColumnHeaders } from './components/GridColumnHeaders'; diff --git a/packages/grid/x-data-grid/src/components/menu/columnMenu/GridColumnMenu.tsx b/packages/grid/x-data-grid/src/components/menu/columnMenu/GridColumnMenu.tsx index 96f29ccb29e80..882d8e879c8a3 100644 --- a/packages/grid/x-data-grid/src/components/menu/columnMenu/GridColumnMenu.tsx +++ b/packages/grid/x-data-grid/src/components/menu/columnMenu/GridColumnMenu.tsx @@ -1,20 +1,20 @@ import * as React from 'react'; import PropTypes from 'prop-types'; -import { useGridColumnMenuComponents } from '../../../hooks/features/columnMenu/useGridColumnMenuComponents'; +import { useGridColumnMenuSlots } from '../../../hooks/features/columnMenu/useGridColumnMenuSlots'; import { GridColumnMenuContainer } from './GridColumnMenuContainer'; import { GridColumnMenuColumnsItem } from './menuItems/GridColumnMenuColumnsItem'; import { GridColumnMenuFilterItem } from './menuItems/GridColumnMenuFilterItem'; import { GridColumnMenuSortItem } from './menuItems/GridColumnMenuSortItem'; import { GridColumnMenuProps, GridGenericColumnMenuProps } from './GridColumnMenuProps'; -export const GRID_COLUMN_MENU_COMPONENTS = { - ColumnMenuSortItem: GridColumnMenuSortItem, - ColumnMenuFilterItem: GridColumnMenuFilterItem, - ColumnMenuColumnsItem: GridColumnMenuColumnsItem, +export const GRID_COLUMN_MENU_SLOTS = { + columnMenuSortItem: GridColumnMenuSortItem, + columnMenuFilterItem: GridColumnMenuFilterItem, + columnMenuColumnsItem: GridColumnMenuColumnsItem, }; -export const GRID_COLUMN_MENU_COMPONENTS_PROPS = { +export const GRID_COLUMN_MENU_SLOT_PROPS = { columnMenuSortItem: { displayOrder: 10 }, columnMenuFilterItem: { displayOrder: 20 }, columnMenuColumnsItem: { displayOrder: 30 }, @@ -22,21 +22,20 @@ export const GRID_COLUMN_MENU_COMPONENTS_PROPS = { const GridGenericColumnMenu = React.forwardRef( function GridGenericColumnMenu(props, ref) { - const { defaultComponents, defaultComponentsProps, components, componentsProps, ...other } = - props; + const { defaultSlots, defaultSlotProps, slots, slotProps, ...other } = props; - const orderedComponents = useGridColumnMenuComponents({ + const orderedSlots = useGridColumnMenuSlots({ ...other, - defaultComponents, - defaultComponentsProps, - components, - componentsProps, + defaultSlots, + defaultSlotProps, + slots, + slotProps, }); return ( - {orderedComponents.map(([Component, componentProps], index) => ( - + {orderedSlots.map(([Component, otherProps], index) => ( + ))} ); @@ -49,8 +48,8 @@ const GridColumnMenu = React.forwardRef( ); }, @@ -62,21 +61,21 @@ GridColumnMenu.propTypes = { // | To update them edit the TypeScript types and run "yarn proptypes" | // ---------------------------------------------------------------------- colDef: PropTypes.object.isRequired, - /** - * `components` could be used to add new and (or) override default column menu items - * If you register a nee component you must pass it's `displayOrder` in `componentsProps` - * or it will be placed in the end of the list - */ - components: PropTypes.object, - /** - * Could be used to pass new props or override props specific to a column menu component - * e.g. `displayOrder` - */ - componentsProps: PropTypes.object, hideMenu: PropTypes.func.isRequired, id: PropTypes.string, labelledby: PropTypes.string, open: PropTypes.bool.isRequired, + /** + * Could be used to pass new props or override props specific to a column menu component + * e.g. `displayOrder` + */ + slotProps: PropTypes.object, + /** + * `slots` could be used to add new and (or) override default column menu items + * If you register a nee component you must pass it's `displayOrder` in `slotProps` + * or it will be placed in the end of the list + */ + slots: PropTypes.object, } as any; export { GridColumnMenu, GridGenericColumnMenu }; diff --git a/packages/grid/x-data-grid/src/components/menu/columnMenu/GridColumnMenuProps.ts b/packages/grid/x-data-grid/src/components/menu/columnMenu/GridColumnMenuProps.ts index b87a5d6d385e3..c8d337446c124 100644 --- a/packages/grid/x-data-grid/src/components/menu/columnMenu/GridColumnMenuProps.ts +++ b/packages/grid/x-data-grid/src/components/menu/columnMenu/GridColumnMenuProps.ts @@ -15,4 +15,4 @@ export interface GridGenericColumnMenuProps GridColumnMenuContainerProps {} export interface GridColumnMenuProps - extends Omit {} + extends Omit {} diff --git a/packages/grid/x-data-grid/src/components/reexportable.ts b/packages/grid/x-data-grid/src/components/reexportable.ts index 6732f3187ce22..a8141d2d7ebcb 100644 --- a/packages/grid/x-data-grid/src/components/reexportable.ts +++ b/packages/grid/x-data-grid/src/components/reexportable.ts @@ -1,5 +1,5 @@ export { GridColumnMenu, - GRID_COLUMN_MENU_COMPONENTS, - GRID_COLUMN_MENU_COMPONENTS_PROPS, + GRID_COLUMN_MENU_SLOTS, + GRID_COLUMN_MENU_SLOT_PROPS, } from './menu/columnMenu/GridColumnMenu'; diff --git a/packages/grid/x-data-grid/src/hooks/features/columnMenu/columnMenuInterfaces.ts b/packages/grid/x-data-grid/src/hooks/features/columnMenu/columnMenuInterfaces.ts index f37d9c80d07c9..3cdc5968a75b2 100644 --- a/packages/grid/x-data-grid/src/hooks/features/columnMenu/columnMenuInterfaces.ts +++ b/packages/grid/x-data-grid/src/hooks/features/columnMenu/columnMenuInterfaces.ts @@ -5,7 +5,7 @@ export interface GridColumnMenuState { field?: string; } -export interface GridColumnMenuComponentProps { +export interface GridColumnMenuSlotProps { /** * Every item has a `displayOrder` based which it will be placed before or after other * items in the column menu, `array.prototype.sort` is applied to sort the items. @@ -19,24 +19,24 @@ export interface GridColumnMenuComponentProps { export interface GridColumnMenuRootProps { /** - * Initial `components` - it is internal, to be overridden by Pro or Premium packages + * Initial `slots` - it is internal, to be overrriden by Pro or Premium packages * @ignore - do not document. */ - defaultComponents: { [key: string]: React.JSXElementConstructor }; + defaultSlots: { [key: string]: React.JSXElementConstructor }; /** - * Initial `componentsProps` - it is internal, to be overridden by Pro or Premium packages + * Initial `slotProps` - it is internal, to be overrriden by Pro or Premium packages * @ignore - do not document. */ - defaultComponentsProps: { [key: string]: GridColumnMenuComponentProps }; + defaultSlotProps: { [key: string]: GridColumnMenuSlotProps }; /** - * `components` could be used to add new and (or) override default column menu items - * If you register a nee component you must pass it's `displayOrder` in `componentsProps` + * `slots` could be used to add new and (or) override default column menu items + * If you register a nee component you must pass it's `displayOrder` in `slotProps` * or it will be placed in the end of the list */ - components?: { [key: string]: React.JSXElementConstructor | null }; + slots?: { [key: string]: React.JSXElementConstructor | null }; /** * Could be used to pass new props or override props specific to a column menu component * e.g. `displayOrder` */ - componentsProps?: { [key: string]: GridColumnMenuComponentProps }; + slotProps?: { [key: string]: GridColumnMenuSlotProps }; } diff --git a/packages/grid/x-data-grid/src/hooks/features/columnMenu/useGridColumnMenuComponents.ts b/packages/grid/x-data-grid/src/hooks/features/columnMenu/useGridColumnMenuSlots.ts similarity index 54% rename from packages/grid/x-data-grid/src/hooks/features/columnMenu/useGridColumnMenuComponents.ts rename to packages/grid/x-data-grid/src/hooks/features/columnMenu/useGridColumnMenuSlots.ts index 849c84672e905..ee8b2fecd978f 100644 --- a/packages/grid/x-data-grid/src/hooks/features/columnMenu/useGridColumnMenuComponents.ts +++ b/packages/grid/x-data-grid/src/hooks/features/columnMenu/useGridColumnMenuSlots.ts @@ -4,63 +4,57 @@ import { GridColumnMenuRootProps } from './columnMenuInterfaces'; import { GridColDef } from '../../../models/colDef/gridColDef'; import { useGridPrivateApiContext } from '../../utils/useGridPrivateApiContext'; -interface UseGridColumnMenuComponentsProps extends GridColumnMenuRootProps { +interface UseGridColumnMenuSlotsProps extends GridColumnMenuRootProps { colDef: GridColDef; hideMenu: (event: React.SyntheticEvent) => void; addDividers?: boolean; } -type UseGridColumnMenuComponentsResponse = Array< +type UseGridColumnMenuSlotsResponse = Array< [React.JSXElementConstructor, { [key: string]: any }] >; -const camelize = (pascalCase: string) => { - const camelCase = pascalCase.split(''); - camelCase[0] = camelCase[0].toLowerCase(); - return camelCase.join(''); -}; - -const useGridColumnMenuComponents = (props: UseGridColumnMenuComponentsProps) => { +const useGridColumnMenuSlots = (props: UseGridColumnMenuSlotsProps) => { const apiRef = useGridPrivateApiContext(); const { - defaultComponents, - defaultComponentsProps, - components = {}, - componentsProps = {}, + defaultSlots, + defaultSlotProps, + slots = {}, + slotProps = {}, hideMenu, colDef, addDividers = true, } = props; const processedComponents = React.useMemo( - () => ({ ...defaultComponents, ...components }), - [defaultComponents, components], + () => ({ ...defaultSlots, ...slots }), + [defaultSlots, slots], ); - const processedComponentsProps = React.useMemo(() => { - if (!componentsProps || Object.keys(componentsProps).length === 0) { - return defaultComponentsProps; + const processedSlotProps = React.useMemo(() => { + if (!slotProps || Object.keys(slotProps).length === 0) { + return defaultSlotProps; } - const mergedProps = { ...componentsProps } as typeof defaultComponentsProps; - Object.entries(defaultComponentsProps).forEach(([key, currentComponentProps]) => { - mergedProps[key] = { ...currentComponentProps, ...(componentsProps[key] || {}) }; + const mergedProps = { ...slotProps } as typeof defaultSlotProps; + Object.entries(defaultSlotProps).forEach(([key, currentSlotProps]) => { + mergedProps[key] = { ...currentSlotProps, ...(slotProps[key] || {}) }; }); return mergedProps; - }, [defaultComponentsProps, componentsProps]); + }, [defaultSlotProps, slotProps]); const defaultItems = apiRef.current.unstable_applyPipeProcessors('columnMenu', [], props.colDef); const userItems = React.useMemo(() => { - const defaultComponentKeys = Object.keys(defaultComponents); - return Object.keys(components).filter((key) => !defaultComponentKeys.includes(key)); - }, [components, defaultComponents]); + const defaultComponentKeys = Object.keys(defaultSlots); + return Object.keys(slots).filter((key) => !defaultComponentKeys.includes(key)); + }, [slots, defaultSlots]); return React.useMemo(() => { const uniqueItems = Array.from(new Set([...defaultItems, ...userItems])); const cleansedItems = uniqueItems.filter((key) => processedComponents[key] != null); const sorted = cleansedItems.sort((a, b) => { - const leftItemProps = processedComponentsProps[camelize(a)]; - const rightItemProps = processedComponentsProps[camelize(b)]; + const leftItemProps = processedSlotProps[a]; + const rightItemProps = processedSlotProps[b]; const leftDisplayOrder = Number.isFinite(leftItemProps?.displayOrder) ? leftItemProps.displayOrder : 100; @@ -69,9 +63,9 @@ const useGridColumnMenuComponents = (props: UseGridColumnMenuComponentsProps) => : 100; return leftDisplayOrder! - rightDisplayOrder!; }); - return sorted.reduce((acc, key, index) => { + return sorted.reduce((acc, key, index) => { let itemProps = { colDef, onClick: hideMenu }; - const processedComponentProps = processedComponentsProps[camelize(key)]; + const processedComponentProps = processedSlotProps[key]; if (processedComponentProps) { const { displayOrder, ...customProps } = processedComponentProps; itemProps = { ...itemProps, ...customProps }; @@ -86,9 +80,9 @@ const useGridColumnMenuComponents = (props: UseGridColumnMenuComponentsProps) => defaultItems, hideMenu, processedComponents, - processedComponentsProps, + processedSlotProps, userItems, ]); }; -export { useGridColumnMenuComponents }; +export { useGridColumnMenuSlots }; diff --git a/packages/grid/x-data-grid/src/hooks/features/columns/useGridColumns.tsx b/packages/grid/x-data-grid/src/hooks/features/columns/useGridColumns.tsx index bdccb66977e31..3d182876c0454 100644 --- a/packages/grid/x-data-grid/src/hooks/features/columns/useGridColumns.tsx +++ b/packages/grid/x-data-grid/src/hooks/features/columns/useGridColumns.tsx @@ -366,7 +366,7 @@ export function useGridColumns( return columnMenuItems; } - return [...columnMenuItems, 'ColumnMenuColumnsItem']; + return [...columnMenuItems, 'columnMenuColumnsItem']; }, [props.disableColumnSelector], ); diff --git a/packages/grid/x-data-grid/src/hooks/features/filter/useGridFilter.tsx b/packages/grid/x-data-grid/src/hooks/features/filter/useGridFilter.tsx index 97a5fd4b62a01..60031283873a5 100644 --- a/packages/grid/x-data-grid/src/hooks/features/filter/useGridFilter.tsx +++ b/packages/grid/x-data-grid/src/hooks/features/filter/useGridFilter.tsx @@ -103,7 +103,7 @@ export const useGridFilter = ( return columnMenuItems; } - return [...columnMenuItems, 'ColumnMenuFilterItem']; + return [...columnMenuItems, 'columnMenuFilterItem']; }, [props.disableColumnFilter], ); diff --git a/packages/grid/x-data-grid/src/hooks/features/sorting/useGridSorting.ts b/packages/grid/x-data-grid/src/hooks/features/sorting/useGridSorting.ts index 03f4d9ddf24a0..c5fb01768eab4 100644 --- a/packages/grid/x-data-grid/src/hooks/features/sorting/useGridSorting.ts +++ b/packages/grid/x-data-grid/src/hooks/features/sorting/useGridSorting.ts @@ -125,7 +125,7 @@ export const useGridSorting = ( const sortingOrder = colDef.sortingOrder || props.sortingOrder; if (sortingOrder.some((item) => !!item)) { - return [...columnMenuItems, 'ColumnMenuSortItem']; + return [...columnMenuItems, 'columnMenuSortItem']; } return columnMenuItems; diff --git a/packages/grid/x-data-grid/src/index.ts b/packages/grid/x-data-grid/src/index.ts index baffcef773ef7..c19ff07a5b819 100644 --- a/packages/grid/x-data-grid/src/index.ts +++ b/packages/grid/x-data-grid/src/index.ts @@ -27,8 +27,8 @@ export { GridColumnHeaders } from './components/GridColumnHeaders'; */ export { GridColumnMenu, - GRID_COLUMN_MENU_COMPONENTS, - GRID_COLUMN_MENU_COMPONENTS_PROPS, + GRID_COLUMN_MENU_SLOTS, + GRID_COLUMN_MENU_SLOT_PROPS, } from './components/reexportable'; /** diff --git a/scripts/x-data-grid-premium.exports.json b/scripts/x-data-grid-premium.exports.json index 74111443b900f..b83778d9d7908 100644 --- a/scripts/x-data-grid-premium.exports.json +++ b/scripts/x-data-grid-premium.exports.json @@ -65,8 +65,8 @@ { "name": "GRID_BOOLEAN_COL_DEF", "kind": "Variable" }, { "name": "GRID_CHECKBOX_SELECTION_COL_DEF", "kind": "Variable" }, { "name": "GRID_CHECKBOX_SELECTION_FIELD", "kind": "Variable" }, - { "name": "GRID_COLUMN_MENU_COMPONENTS", "kind": "Variable" }, - { "name": "GRID_COLUMN_MENU_COMPONENTS_PROPS", "kind": "Variable" }, + { "name": "GRID_COLUMN_MENU_SLOT_PROPS", "kind": "Variable" }, + { "name": "GRID_COLUMN_MENU_SLOTS", "kind": "Variable" }, { "name": "GRID_DATE_COL_DEF", "kind": "Variable" }, { "name": "GRID_DATETIME_COL_DEF", "kind": "Variable" }, { "name": "GRID_DEFAULT_LOCALE_TEXT", "kind": "Variable" }, @@ -185,7 +185,6 @@ { "name": "GridColumnMenuAggregationItem", "kind": "Function" }, { "name": "GridColumnMenuApi", "kind": "Interface" }, { "name": "GridColumnMenuColumnsItem", "kind": "Function" }, - { "name": "GridColumnMenuComponentProps", "kind": "Interface" }, { "name": "GridColumnMenuContainer", "kind": "Variable" }, { "name": "GridColumnMenuContainerProps", "kind": "Interface" }, { "name": "GridColumnMenuFilterItem", "kind": "Function" }, @@ -197,6 +196,7 @@ { "name": "GridColumnMenuProps", "kind": "Interface" }, { "name": "GridColumnMenuRootProps", "kind": "Interface" }, { "name": "gridColumnMenuSelector", "kind": "Variable" }, + { "name": "GridColumnMenuSlotProps", "kind": "Interface" }, { "name": "GridColumnMenuSortItem", "kind": "Function" }, { "name": "GridColumnMenuState", "kind": "Interface" }, { "name": "GridColumnNode", "kind": "TypeAlias" }, diff --git a/scripts/x-data-grid-pro.exports.json b/scripts/x-data-grid-pro.exports.json index 4fd52f44e74a7..3a2d753507e36 100644 --- a/scripts/x-data-grid-pro.exports.json +++ b/scripts/x-data-grid-pro.exports.json @@ -60,8 +60,8 @@ { "name": "GRID_BOOLEAN_COL_DEF", "kind": "Variable" }, { "name": "GRID_CHECKBOX_SELECTION_COL_DEF", "kind": "Variable" }, { "name": "GRID_CHECKBOX_SELECTION_FIELD", "kind": "Variable" }, - { "name": "GRID_COLUMN_MENU_COMPONENTS", "kind": "Variable" }, - { "name": "GRID_COLUMN_MENU_COMPONENTS_PROPS", "kind": "Variable" }, + { "name": "GRID_COLUMN_MENU_SLOT_PROPS", "kind": "Variable" }, + { "name": "GRID_COLUMN_MENU_SLOTS", "kind": "Variable" }, { "name": "GRID_DATE_COL_DEF", "kind": "Variable" }, { "name": "GRID_DATETIME_COL_DEF", "kind": "Variable" }, { "name": "GRID_DEFAULT_LOCALE_TEXT", "kind": "Variable" }, @@ -160,7 +160,6 @@ { "name": "GridColumnMenu", "kind": "Variable" }, { "name": "GridColumnMenuApi", "kind": "Interface" }, { "name": "GridColumnMenuColumnsItem", "kind": "Function" }, - { "name": "GridColumnMenuComponentProps", "kind": "Interface" }, { "name": "GridColumnMenuContainer", "kind": "Variable" }, { "name": "GridColumnMenuContainerProps", "kind": "Interface" }, { "name": "GridColumnMenuFilterItem", "kind": "Function" }, @@ -171,6 +170,7 @@ { "name": "GridColumnMenuProps", "kind": "Interface" }, { "name": "GridColumnMenuRootProps", "kind": "Interface" }, { "name": "gridColumnMenuSelector", "kind": "Variable" }, + { "name": "GridColumnMenuSlotProps", "kind": "Interface" }, { "name": "GridColumnMenuSortItem", "kind": "Function" }, { "name": "GridColumnMenuState", "kind": "Interface" }, { "name": "GridColumnNode", "kind": "TypeAlias" }, diff --git a/scripts/x-data-grid.exports.json b/scripts/x-data-grid.exports.json index 81f615155328e..513789b16f9f9 100644 --- a/scripts/x-data-grid.exports.json +++ b/scripts/x-data-grid.exports.json @@ -57,8 +57,8 @@ { "name": "GRID_BOOLEAN_COL_DEF", "kind": "Variable" }, { "name": "GRID_CHECKBOX_SELECTION_COL_DEF", "kind": "Variable" }, { "name": "GRID_CHECKBOX_SELECTION_FIELD", "kind": "Variable" }, - { "name": "GRID_COLUMN_MENU_COMPONENTS", "kind": "Variable" }, - { "name": "GRID_COLUMN_MENU_COMPONENTS_PROPS", "kind": "Variable" }, + { "name": "GRID_COLUMN_MENU_SLOT_PROPS", "kind": "Variable" }, + { "name": "GRID_COLUMN_MENU_SLOTS", "kind": "Variable" }, { "name": "GRID_DATE_COL_DEF", "kind": "Variable" }, { "name": "GRID_DATETIME_COL_DEF", "kind": "Variable" }, { "name": "GRID_DEFAULT_LOCALE_TEXT", "kind": "Variable" }, @@ -153,7 +153,6 @@ { "name": "GridColumnMenu", "kind": "Variable" }, { "name": "GridColumnMenuApi", "kind": "Interface" }, { "name": "GridColumnMenuColumnsItem", "kind": "Function" }, - { "name": "GridColumnMenuComponentProps", "kind": "Interface" }, { "name": "GridColumnMenuContainer", "kind": "Variable" }, { "name": "GridColumnMenuContainerProps", "kind": "Interface" }, { "name": "GridColumnMenuFilterItem", "kind": "Function" }, @@ -163,6 +162,7 @@ { "name": "GridColumnMenuProps", "kind": "Interface" }, { "name": "GridColumnMenuRootProps", "kind": "Interface" }, { "name": "gridColumnMenuSelector", "kind": "Variable" }, + { "name": "GridColumnMenuSlotProps", "kind": "Interface" }, { "name": "GridColumnMenuSortItem", "kind": "Function" }, { "name": "GridColumnMenuState", "kind": "Interface" }, { "name": "GridColumnNode", "kind": "TypeAlias" },