UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

128 lines (127 loc) 5.17 kB
'use client'; import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["children", "title", "desc", "className"]; import * as React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import { warnOnce } from '@mui/x-internals/warning'; import { styled, useThemeProps } from '@mui/material/styles'; import useForkRef from '@mui/utils/useForkRef'; import useId from '@mui/utils/useId'; import { useUtilityClasses } from "../ChartsSurface/chartsSurfaceClasses.mjs"; import { selectorChartPropsHeight, selectorChartPropsWidth } from "../internals/plugins/corePlugins/useChartDimensions/index.mjs"; import { selectorChartsIsKeyboardNavigationEnabled } from "../internals/plugins/featurePlugins/useChartKeyboardNavigation/index.mjs"; import { useChartsContext } from "../context/ChartsProvider/index.mjs"; import { useChartsLayerContainerRef } from "../hooks/index.mjs"; import { useRegisterPointerInteractions } from "../internals/plugins/featurePlugins/shared/useRegisterPointerInteractions.mjs"; // eslint-disable-next-line import/no-cycle import { ChartsSurface } from "../ChartsSurface/index.mjs"; import { ChartsAccessibilityProxy } from "../internals/components/ChartsAccessibilityProxy/index.mjs"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const ChartsLayerContainerDiv = styled('div', { name: 'MuiChartsLayerContainer', slot: 'Root' })(({ ownerState }) => ({ width: ownerState.width ?? '100%', height: ownerState.height ?? '100%', display: 'flex', position: 'relative', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', touchAction: 'pan-y', userSelect: 'none', gridArea: 'chart', '&:focus': { outline: 'none' // By default, don't show focus outline } })); /** * A component that contains the chart layers, such as `<ChartsSvgLayer>`, and `<ChartsWebGLLayer>`. * It is responsible for positioning itself and providing the dimensions and interaction context to its children layers. */ const ChartsLayerContainer = /*#__PURE__*/React.forwardRef(function ChartsLayerContainer(inProps, ref) { const { store, instance } = useChartsContext(); const propsWidth = store.use(selectorChartPropsWidth); const propsHeight = store.use(selectorChartPropsHeight); const isKeyboardNavigationEnabled = store.use(selectorChartsIsKeyboardNavigationEnabled); useRegisterPointerInteractions(); const themeProps = useThemeProps({ props: inProps, name: 'MuiChartsLayerContainer' }); const { children, title, desc, className } = themeProps, other = _objectWithoutPropertiesLoose(themeProps, _excluded); const classes = useUtilityClasses(); const chartsLayerContainerRef = useChartsLayerContainerRef(); const handleRef = useForkRef(chartsLayerContainerRef, ref); const descId = useId(); if (process.env.NODE_ENV !== 'production') { React.Children.forEach(children, child => { if (typeof child === 'object' && child != null && 'type' in child && child.type === ChartsSurface) { warnOnce('MUI X Charts: ChartsSurface should not be used inside ChartsLayerContainer. Render a ChartsSvgLayer instead.', 'error'); } }); } return /*#__PURE__*/_jsxs(ChartsLayerContainerDiv, _extends({ ref: handleRef, ownerState: { width: propsWidth, height: propsHeight }, role: "presentation", "aria-label": title, "aria-describedby": desc ? descId : undefined, className: clsx(classes.root, className) }, other, { onPointerEnter: event => { other.onPointerEnter?.(event); instance.handlePointerEnter?.(event); }, onPointerLeave: event => { other.onPointerLeave?.(event); instance.handlePointerLeave?.(event); }, onClick: event => { other.onClick?.(event); instance.handleClick?.(event); }, children: [isKeyboardNavigationEnabled && /*#__PURE__*/_jsx(ChartsAccessibilityProxy, {}), desc && /*#__PURE__*/_jsx("span", { id: descId, style: { display: 'none' }, children: desc }), children] })); }); if (process.env.NODE_ENV !== "production") ChartsLayerContainer.displayName = "ChartsLayerContainer"; process.env.NODE_ENV !== "production" ? ChartsLayerContainer.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "pnpm proptypes" | // ---------------------------------------------------------------------- /** * The description of the chart. * Used to provide an accessible description for the chart. */ desc: PropTypes.string, sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]), /** * The title of the chart. * Used to provide an accessible label for the chart. */ title: PropTypes.string } : void 0; export { ChartsLayerContainer };