UNPKG

@mui/x-data-grid

Version:

The Community plan edition of the MUI X Data Grid components.

113 lines (110 loc) 4.91 kB
"use strict"; 'use client'; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.ToolbarRoot = exports.Toolbar = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); var React = _interopRequireWildcard(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _styles = require("@mui/material/styles"); var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses")); var _clsx = _interopRequireDefault(require("clsx")); var _forwardRef = require("@mui/x-internals/forwardRef"); var _useComponentRenderer = require("@mui/x-internals/useComponentRenderer"); var _ToolbarContext = require("@mui/x-internals/ToolbarContext"); var _cssVariables = require("../../constants/cssVariables"); var _variables = require("../../material/variables"); var _gridClasses = require("../../constants/gridClasses"); var _useGridRootProps = require("../../hooks/utils/useGridRootProps"); var _jsxRuntime = require("react/jsx-runtime"); const _excluded = ["render", "className"]; const useUtilityClasses = ownerState => { const { classes } = ownerState; const slots = { root: ['toolbar'] }; return (0, _composeClasses.default)(slots, _gridClasses.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 = exports.ToolbarRoot = (0, _styles.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(${_cssVariables.vars.keys.spacingUnit}, ${(0, _variables.getSpacingUnit)(theme)})`; const borderColor = `var(${_cssVariables.vars.keys.colors.border.base}, ${(0, _variables.getBorderColor)(theme)})`; const background = `var(${_cssVariables.vars.keys.colors.background.base}, ${(0, _variables.getBackgroundBase)(theme)})`; const foreground = `var(${_cssVariables.vars.keys.colors.foreground.base}, ${(theme.vars || theme).palette.text.primary})`; const fontBody = (0, _variables.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(${_cssVariables.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 = exports.Toolbar = (0, _forwardRef.forwardRef)(function Toolbar(props, ref) { const { render, className } = props, other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded); const rootProps = (0, _useGridRootProps.useGridRootProps)(); const classes = useUtilityClasses(rootProps); const element = (0, _useComponentRenderer.useComponentRenderer)(ToolbarRoot, render, (0, _extends2.default)({ role: 'toolbar', 'aria-orientation': 'horizontal', 'aria-label': rootProps.label || undefined, className: (0, _clsx.default)(classes.root, className) }, other, { ref })); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ToolbarContext.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.default.oneOfType([_propTypes.default.element, _propTypes.default.func]) } : void 0;