UNPKG

@mui/x-data-grid

Version:

The community edition of the data grid component (MUI X).

93 lines (87 loc) 3.1 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["className"]; import * as React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import { unstable_composeClasses as composeClasses } from '@mui/material'; import { styled } from '@mui/material/styles'; import { isOverflown } from '../../utils/domUtils'; import { getDataGridUtilityClass } from '../../constants/gridClasses'; import { useGridRootProps } from '../../hooks/utils/useGridRootProps'; import { jsx as _jsx } from "react/jsx-runtime"; const useUtilityClasses = ownerState => { const { classes } = ownerState; const slots = { root: ['columnHeaderTitle'] }; return composeClasses(slots, getDataGridUtilityClass, classes); }; const GridColumnHeaderTitleRoot = styled('div', { name: 'MuiDataGrid', slot: 'ColumnHeaderTitle', overridesResolver: (props, styles) => styles.columnHeaderTitle })(({ theme }) => ({ textOverflow: 'ellipsis', overflow: 'hidden', whiteSpace: 'nowrap', fontWeight: theme.typography.fontWeightMedium })); const ColumnHeaderInnerTitle = /*#__PURE__*/React.forwardRef(function ColumnHeaderInnerTitle(props, ref) { const { className } = props, other = _objectWithoutPropertiesLoose(props, _excluded); const rootProps = useGridRootProps(); const ownerState = { classes: rootProps.classes }; const classes = useUtilityClasses(ownerState); return /*#__PURE__*/_jsx(GridColumnHeaderTitleRoot, _extends({ ref: ref, className: clsx(classes.root, className) }, other)); }); // No React.memo here as if we display the sort icon, we need to recalculate the isOver function GridColumnHeaderTitle(props) { const { label, description, columnWidth } = props; const rootProps = useGridRootProps(); const titleRef = React.useRef(null); const [tooltip, setTooltip] = React.useState(''); React.useEffect(() => { if (!description && titleRef && titleRef.current) { const isOver = isOverflown(titleRef.current); if (isOver) { setTooltip(label); } else { setTooltip(''); } } }, [titleRef, columnWidth, description, label]); return /*#__PURE__*/_jsx(rootProps.components.BaseTooltip, _extends({ title: description || tooltip }, rootProps.componentsProps?.baseTooltip, { children: /*#__PURE__*/_jsx(ColumnHeaderInnerTitle, { ref: titleRef, children: label }) })); } process.env.NODE_ENV !== "production" ? GridColumnHeaderTitle.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "yarn proptypes" | // ---------------------------------------------------------------------- columnWidth: PropTypes.number.isRequired, description: PropTypes.node, label: PropTypes.string.isRequired } : void 0; export { GridColumnHeaderTitle };