@mui/x-data-grid
Version:
The Community plan edition of the Data Grid components (MUI X).
63 lines • 2.1 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import PropTypes from 'prop-types';
import useEventCallback from '@mui/utils/useEventCallback';
import HTMLElementType from '@mui/utils/HTMLElementType';
import { useGridApiContext } from "../../../hooks/utils/useGridApiContext.js";
import { GridMenu } from "../GridMenu.js";
import { jsx as _jsx } from "react/jsx-runtime";
function GridColumnHeaderMenu({
columnMenuId,
columnMenuButtonId,
ContentComponent,
contentComponentProps,
field,
open,
target,
onExited
}) {
const apiRef = useGridApiContext();
const colDef = apiRef.current.getColumn(field);
const hideMenu = useEventCallback(event => {
if (event) {
// Prevent triggering the sorting
event.stopPropagation();
if (target?.contains(event.target)) {
return;
}
}
apiRef.current.hideColumnMenu();
});
if (!target || !colDef) {
return null;
}
return /*#__PURE__*/_jsx(GridMenu, {
position: `bottom-${colDef.align === 'right' ? 'start' : 'end'}`,
open: open,
target: target,
onClose: hideMenu,
onExited: onExited,
children: /*#__PURE__*/_jsx(ContentComponent, _extends({
colDef: colDef,
hideMenu: hideMenu,
open: open,
id: columnMenuId,
labelledby: columnMenuButtonId
}, contentComponentProps))
});
}
process.env.NODE_ENV !== "production" ? GridColumnHeaderMenu.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
columnMenuButtonId: PropTypes.string,
columnMenuId: PropTypes.string,
ContentComponent: PropTypes.elementType.isRequired,
contentComponentProps: PropTypes.any,
field: PropTypes.string.isRequired,
onExited: PropTypes.func,
open: PropTypes.bool.isRequired,
target: HTMLElementType
} : void 0;
export { GridColumnHeaderMenu };