49 lines
2.3 KiB
JavaScript
49 lines
2.3 KiB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
var _excluded = ["onClick"];
|
|
import * as React from 'react';
|
|
import { unstable_useId as useId } from '@mui/material/utils';
|
|
import { useGridSelector } from '../../hooks/utils/useGridSelector';
|
|
import { gridPreferencePanelStateSelector } from '../../hooks/features/preferencesPanel/gridPreferencePanelSelector';
|
|
import { GridPreferencePanelsValue } from '../../hooks/features/preferencesPanel/gridPreferencePanelsValue';
|
|
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
|
|
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
|
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
export var GridToolbarColumnsButton = /*#__PURE__*/React.forwardRef(function GridToolbarColumnsButton(props, ref) {
|
|
var _rootProps$slotProps;
|
|
var onClick = props.onClick,
|
|
other = _objectWithoutProperties(props, _excluded);
|
|
var columnButtonId = useId();
|
|
var columnPanelId = useId();
|
|
var apiRef = useGridApiContext();
|
|
var rootProps = useGridRootProps();
|
|
var preferencePanel = useGridSelector(apiRef, gridPreferencePanelStateSelector);
|
|
var showColumns = function showColumns(event) {
|
|
if (preferencePanel.open && preferencePanel.openedPanelValue === GridPreferencePanelsValue.columns) {
|
|
apiRef.current.hidePreferences();
|
|
} else {
|
|
apiRef.current.showPreferences(GridPreferencePanelsValue.columns, columnPanelId, columnButtonId);
|
|
}
|
|
onClick == null || onClick(event);
|
|
};
|
|
|
|
// Disable the button if the corresponding is disabled
|
|
if (rootProps.disableColumnSelector) {
|
|
return null;
|
|
}
|
|
var isOpen = preferencePanel.open && preferencePanel.panelId === columnPanelId;
|
|
return /*#__PURE__*/_jsx(rootProps.slots.baseButton, _extends({
|
|
ref: ref,
|
|
id: columnButtonId,
|
|
size: "small",
|
|
"aria-label": apiRef.current.getLocaleText('toolbarColumnsLabel'),
|
|
"aria-haspopup": "menu",
|
|
"aria-expanded": isOpen,
|
|
"aria-controls": isOpen ? columnPanelId : undefined,
|
|
startIcon: /*#__PURE__*/_jsx(rootProps.slots.columnSelectorIcon, {})
|
|
}, other, {
|
|
onClick: showColumns
|
|
}, (_rootProps$slotProps = rootProps.slotProps) == null ? void 0 : _rootProps$slotProps.baseButton, {
|
|
children: apiRef.current.getLocaleText('toolbarColumns')
|
|
}));
|
|
}); |