@mui/x-data-grid
Version:
The Community plan edition of the Data Grid components (MUI X).
90 lines • 3.47 kB
JavaScript
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
const _excluded = ["direction", "index", "sortingOrder", "disabled", "className"];
import * as React from 'react';
import PropTypes from 'prop-types';
import composeClasses from '@mui/utils/composeClasses';
import clsx from 'clsx';
import { useGridApiContext } from "../../hooks/utils/useGridApiContext.js";
import { getDataGridUtilityClass } from "../../constants/gridClasses.js";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.js";
import { GridIconButtonContainer } from "./GridIconButtonContainer.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['sortButton'],
icon: ['sortIcon']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
function getIcon(icons, direction, className, sortingOrder) {
let Icon;
const iconProps = {};
if (direction === 'asc') {
Icon = icons.columnSortedAscendingIcon;
} else if (direction === 'desc') {
Icon = icons.columnSortedDescendingIcon;
} else {
Icon = icons.columnUnsortedIcon;
iconProps.sortingOrder = sortingOrder;
}
return Icon ? /*#__PURE__*/_jsx(Icon, _extends({
fontSize: "small",
className: className
}, iconProps)) : null;
}
function GridColumnHeaderSortIconRaw(props) {
const {
direction,
index,
sortingOrder,
disabled,
className
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const apiRef = useGridApiContext();
const rootProps = useGridRootProps();
const ownerState = _extends({}, props, {
classes: rootProps.classes
});
const classes = useUtilityClasses(ownerState);
const iconElement = getIcon(rootProps.slots, direction, classes.icon, sortingOrder);
if (!iconElement) {
return null;
}
const iconButton = /*#__PURE__*/_jsx(rootProps.slots.baseIconButton, _extends({
tabIndex: -1,
"aria-label": apiRef.current.getLocaleText('columnHeaderSortIconLabel'),
title: apiRef.current.getLocaleText('columnHeaderSortIconLabel'),
size: "small",
disabled: disabled,
className: clsx(classes.root, className)
}, rootProps.slotProps?.baseIconButton, other, {
children: iconElement
}));
return /*#__PURE__*/_jsxs(GridIconButtonContainer, {
children: [index != null && /*#__PURE__*/_jsx(rootProps.slots.baseBadge, {
badgeContent: index,
color: "default",
overlap: "circular",
children: iconButton
}), index == null && iconButton]
});
}
const GridColumnHeaderSortIcon = /*#__PURE__*/React.memo(GridColumnHeaderSortIconRaw);
process.env.NODE_ENV !== "production" ? GridColumnHeaderSortIconRaw.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
className: PropTypes.string,
direction: PropTypes.oneOf(['asc', 'desc']),
disabled: PropTypes.bool,
field: PropTypes.string.isRequired,
index: PropTypes.number,
sortingOrder: PropTypes.arrayOf(PropTypes.oneOf(['asc', 'desc'])).isRequired
} : void 0;
export { GridColumnHeaderSortIcon };