@mui/x-data-grid
Version:
The Community plan edition of the MUI X Data Grid components.
107 lines (104 loc) • 4.17 kB
JavaScript
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["render", "className"];
import * as React from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import composeClasses from '@mui/utils/composeClasses';
import clsx from 'clsx';
import { forwardRef } from '@mui/x-internals/forwardRef';
import { useComponentRenderer } from '@mui/x-internals/useComponentRenderer';
import { ToolbarContextProvider } from '@mui/x-internals/ToolbarContext';
import { vars } from "../../constants/cssVariables.mjs";
import { getBackgroundBase, getBorderColor, getFontBody, getSpacingUnit } from "../../material/variables.mjs";
import { getDataGridUtilityClass } from "../../constants/gridClasses.mjs";
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
classes
} = ownerState;
const slots = {
root: ['toolbar']
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
/**
* The styled `<div />` element rendered by the `<Toolbar />` component.
* Use it to apply the toolbar styles to other elements, inside or outside of a Data Grid.
*/
const ToolbarRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'Toolbar'
})(({
theme
}) => {
// The Data Grid CSS variables are only defined on the Data Grid root element, so they are
// declared with a fallback to keep the styles working when rendered outside of a Data Grid.
const spacingUnit = `var(${vars.keys.spacingUnit}, ${getSpacingUnit(theme)})`;
const borderColor = `var(${vars.keys.colors.border.base}, ${getBorderColor(theme)})`;
const background = `var(${vars.keys.colors.background.base}, ${getBackgroundBase(theme)})`;
const foreground = `var(${vars.keys.colors.foreground.base}, ${(theme.vars || theme).palette.text.primary})`;
const fontBody = getFontBody(theme);
return {
flex: '0 1 1px',
display: 'flex',
alignItems: 'center',
justifyContent: 'end',
gap: `calc(${spacingUnit} * 0.25)`,
padding: `calc(${spacingUnit} * 0.75)`,
minHeight: 52,
boxSizing: 'border-box',
borderBottom: `1px solid ${borderColor}`,
// Inherited from the Data Grid root inside a grid, declared here so the component keeps
// matching it when rendered on its own.
backgroundColor: background,
color: foreground,
font: fontBody ? `var(${vars.keys.typography.font.body}, ${fontBody})` : undefined
};
});
/**
* The top level Toolbar component that provides context to child components.
* It renders a styled `<div />` element.
*
* Demos:
*
* - [Toolbar](https://mui.com/x/react-data-grid/components/toolbar/)
*
* API:
*
* - [Toolbar API](https://mui.com/x/api/data-grid/toolbar/)
*/
const Toolbar = forwardRef(function Toolbar(props, ref) {
const {
render,
className
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const rootProps = useGridRootProps();
const classes = useUtilityClasses(rootProps);
const element = useComponentRenderer(ToolbarRoot, render, _extends({
role: 'toolbar',
'aria-orientation': 'horizontal',
'aria-label': rootProps.label || undefined,
className: clsx(classes.root, className)
}, other, {
ref
}));
return /*#__PURE__*/_jsx(ToolbarContextProvider, {
children: element
});
});
if (process.env.NODE_ENV !== "production") Toolbar.displayName = "Toolbar";
process.env.NODE_ENV !== "production" ? Toolbar.propTypes /* remove-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.
*/
render: PropTypes.oneOfType([PropTypes.element, PropTypes.func])
} : void 0;
export { Toolbar, ToolbarRoot };