UNPKG

@mui/x-data-grid-premium

Version:

The Premium plan edition of the MUI X Data Grid Components.

92 lines 3.6 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["render", "className", "onClick", "onPointerUp"]; import * as React from 'react'; import PropTypes from 'prop-types'; import useId from '@mui/utils/useId'; import { forwardRef } from '@mui/x-internals/forwardRef'; import { useComponentRenderer } from '@mui/x-internals/useComponentRenderer'; import { useGridSelector } from '@mui/x-data-grid-pro'; import { useGridApiContext } from "../../hooks/utils/useGridApiContext.js"; import { useGridRootProps } from "../../hooks/utils/useGridRootProps.js"; import { gridPivotPanelOpenSelector, gridPivotActiveSelector } from "../../hooks/features/pivoting/gridPivotingSelectors.js"; import { GridSidebarValue } from "../../hooks/features/sidebar/index.js"; import { jsx as _jsx } from "react/jsx-runtime"; /** * A button that opens and closes the pivot panel. * It renders the `baseButton` slot. * * Demos: * * - [Pivot Panel](https://mui.com/x/react-data-grid/components/pivot-panel/) * * API: * * - [PivotPanelTrigger API](https://mui.com/x/api/data-grid/pivot-panel-trigger/) */ const PivotPanelTrigger = forwardRef(function PivotPanelTrigger(props, ref) { const { render, className, onClick } = props, other = _objectWithoutPropertiesLoose(props, _excluded); const rootProps = useGridRootProps(); const buttonId = useId(); const panelId = useId(); const apiRef = useGridApiContext(); const open = useGridSelector(apiRef, gridPivotPanelOpenSelector); const active = useGridSelector(apiRef, gridPivotActiveSelector); const state = { open, active }; const resolvedClassName = typeof className === 'function' ? className(state) : className; const handleClick = event => { if (open) { apiRef.current.hideSidebar(); } else { apiRef.current.showSidebar(GridSidebarValue.Pivot, panelId, buttonId); } onClick?.(event); }; const element = useComponentRenderer(rootProps.slots.baseButton, render, _extends({}, rootProps.slotProps?.baseButton, { id: buttonId, // TODO: Hook up the panel/trigger IDs to the pivot panel 'aria-haspopup': 'true', 'aria-expanded': open ? 'true' : undefined, 'aria-controls': open ? panelId : undefined, onClick: handleClick, className: resolvedClassName }, other, { ref }), state); return /*#__PURE__*/_jsx(React.Fragment, { children: element }); }); if (process.env.NODE_ENV !== "production") PivotPanelTrigger.displayName = "PivotPanelTrigger"; process.env.NODE_ENV !== "production" ? PivotPanelTrigger.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "pnpm proptypes" | // ---------------------------------------------------------------------- /** * A function to customize rendering of the component. */ className: PropTypes.oneOfType([PropTypes.func, PropTypes.string]), disabled: PropTypes.bool, id: PropTypes.string, /** * A function to customize rendering of the component. */ render: PropTypes.oneOfType([PropTypes.element, PropTypes.func]), role: PropTypes.string, size: PropTypes.oneOf(['large', 'medium', 'small']), startIcon: PropTypes.node, style: PropTypes.object, tabIndex: PropTypes.number, title: PropTypes.string, touchRippleRef: PropTypes.any } : void 0; export { PivotPanelTrigger };