UNPKG

@mui/x-charts

Version:

The community edition of the charts components (MUI X).

132 lines 5.1 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps"]; import * as React from 'react'; import PropTypes from 'prop-types'; import composeClasses from '@mui/utils/composeClasses'; import { useSlotProps } from '@mui/base/utils'; import generateUtilityClass from '@mui/utils/generateUtilityClass'; import { styled } from '@mui/material/styles'; import generateUtilityClasses from '@mui/utils/generateUtilityClasses'; import { color as d3Color } from 'd3-color'; import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps'; import { InteractionContext } from '../context/InteractionProvider'; import { jsx as _jsx } from "react/jsx-runtime"; export function getAreaElementUtilityClass(slot) { return generateUtilityClass('MuiAreaElement', slot); } export var areaElementClasses = generateUtilityClasses('MuiAreaElement', ['root', 'highlighted', 'faded']); var useUtilityClasses = function useUtilityClasses(ownerState) { var classes = ownerState.classes, id = ownerState.id, isFaded = ownerState.isFaded, isHighlighted = ownerState.isHighlighted; var slots = { root: ['root', "series-".concat(id), isHighlighted && 'highlighted', isFaded && 'faded'] }; return composeClasses(slots, getAreaElementUtilityClass, classes); }; export var AreaElementPath = styled('path', { name: 'MuiAreaElement', slot: 'Root', overridesResolver: function overridesResolver(_, styles) { return styles.root; } })(function (_ref) { var ownerState = _ref.ownerState; return { stroke: 'none', fill: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(1).formatHex() : d3Color(ownerState.color).brighter(0.5).formatHex(), transition: 'opacity 0.2s ease-in, fill 0.2s ease-in', opacity: ownerState.isFaded ? 0.3 : 1 }; }); AreaElementPath.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "yarn proptypes" | // ---------------------------------------------------------------------- as: PropTypes.elementType, ownerState: PropTypes.shape({ classes: PropTypes.object, color: PropTypes.string.isRequired, id: PropTypes.string.isRequired, isFaded: PropTypes.bool.isRequired, isHighlighted: PropTypes.bool.isRequired }).isRequired, sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]) }; /** * Demos: * * - [Lines](https://mui.com/x/react-charts/lines/) * - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/) * * API: * * - [AreaElement API](https://mui.com/x/api/charts/area-element/) */ function AreaElement(props) { var _slots$area; var id = props.id, innerClasses = props.classes, color = props.color, highlightScope = props.highlightScope, slots = props.slots, slotProps = props.slotProps, other = _objectWithoutProperties(props, _excluded); var getInteractionItemProps = useInteractionItemProps(highlightScope); var _React$useContext = React.useContext(InteractionContext), item = _React$useContext.item; var isHighlighted = getIsHighlighted(item, { type: 'line', seriesId: id }, highlightScope); var isFaded = !isHighlighted && getIsFaded(item, { type: 'line', seriesId: id }, highlightScope); var ownerState = { id: id, classes: innerClasses, color: color, isFaded: isFaded, isHighlighted: isHighlighted }; var classes = useUtilityClasses(ownerState); var Area = (_slots$area = slots == null ? void 0 : slots.area) != null ? _slots$area : AreaElementPath; var areaProps = useSlotProps({ elementType: Area, externalSlotProps: slotProps == null ? void 0 : slotProps.area, additionalProps: _extends({}, other, getInteractionItemProps({ type: 'line', seriesId: id }), { className: classes.root }), ownerState: ownerState }); return /*#__PURE__*/_jsx(Area, _extends({}, areaProps)); } process.env.NODE_ENV !== "production" ? AreaElement.propTypes = { // ----------------------------- Warning -------------------------------- // | These PropTypes are generated from the TypeScript type definitions | // | To update them edit the TypeScript types and run "yarn proptypes" | // ---------------------------------------------------------------------- classes: PropTypes.object, highlightScope: PropTypes.shape({ faded: PropTypes.oneOf(['global', 'none', 'series']), highlighted: PropTypes.oneOf(['item', 'none', 'series']) }), /** * The props used for each component slot. * @default {} */ slotProps: PropTypes.object, /** * Overridable component slots. * @default {} */ slots: PropTypes.object } : void 0; export { AreaElement };