@mui/x-charts
Version:
The community edition of MUI X Charts components.
151 lines (149 loc) • 4.63 kB
JavaScript
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["type", "markShape", "color", "className", "classes"];
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { styled, useTheme } from '@mui/material/styles';
import { symbol as d3Symbol, symbolsFill as d3SymbolsFill } from '@mui/x-charts-vendor/d3-shape';
import { labelMarkClasses, useUtilityClasses } from "./labelMarkClasses.mjs";
import { consumeThemeProps } from "../internals/consumeThemeProps.mjs";
import { getSymbol } from "../internals/getSymbol.mjs";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const Root = styled('div', {
name: 'MuiChartsLabelMark',
slot: 'Root'
})(() => {
return {
display: 'flex',
width: 14,
height: 14,
['& > *']: {
width: '100%',
height: '100%'
},
[`&.${labelMarkClasses.line}`]: {
width: 16,
height: 8,
alignItems: 'center'
},
[`&.${labelMarkClasses.lineAndMark}`]: {
width: 16,
height: 16,
alignItems: 'center'
},
[`&.${labelMarkClasses.square}`]: {
height: 13,
width: 13,
borderRadius: 2,
overflow: 'hidden'
},
[`&.${labelMarkClasses.circle}`]: {
height: 15,
width: 15
},
svg: {
display: 'block'
}
};
});
/**
* Generates the label mark for the tooltip and legend.
* @ignore - internal component.
*/
const ChartsLabelMark = consumeThemeProps('MuiChartsLabelMark', {
defaultProps: {
type: 'square'
},
classesResolver: useUtilityClasses
}, function ChartsLabelMark(props, ref) {
const {
type,
markShape,
color,
className,
classes
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const Component = type;
const theme = useTheme();
return /*#__PURE__*/_jsx(Root, _extends({
className: clsx(classes?.root, className),
ownerState: props,
"aria-hidden": "true",
ref: ref
}, other, {
children: typeof Component === 'function' ? /*#__PURE__*/_jsx(Component, {
className: classes?.fill,
color: color
}) : /*#__PURE__*/_jsxs(React.Fragment, {
children: [type === 'circle' && /*#__PURE__*/_jsx("svg", {
viewBox: "0 0 15 15",
children: /*#__PURE__*/_jsx("circle", {
className: classes?.fill,
r: "7.5",
cx: "7.5",
cy: "7.5",
fill: color
})
}), type === 'line' && /*#__PURE__*/_jsx("svg", {
viewBox: "0 0 16 8",
preserveAspectRatio: "none",
children: /*#__PURE__*/_jsx("path", {
className: classes?.fill,
d: "M 2 4 L 14 4",
stroke: color,
strokeWidth: "4",
strokeLinecap: "round",
vectorEffect: "non-scaling-stroke"
})
}), type === 'line+mark' && /*#__PURE__*/_jsxs("svg", {
viewBox: "0 0 16 16",
preserveAspectRatio: "none",
children: [/*#__PURE__*/_jsx("path", {
className: classes?.fill,
d: "M 1 8 L 15 8",
stroke: color,
strokeWidth: 2,
strokeLinecap: "round",
vectorEffect: "non-scaling-stroke"
}), markShape && /*#__PURE__*/_jsx("path", {
d: d3Symbol(d3SymbolsFill[getSymbol(markShape)], 32)(),
transform: "translate(8, 8) ",
stroke: color,
strokeWidth: 2,
fill: (theme.vars || theme).palette.background.paper
})]
}), type !== 'line' && type !== 'circle' && type !== 'line+mark' && /*#__PURE__*/_jsx("svg", {
viewBox: "0 0 13 13",
children: /*#__PURE__*/_jsx("rect", {
className: classes?.fill,
width: "13",
height: "13",
fill: color
})
})]
})
}));
});
process.env.NODE_ENV !== "production" ? ChartsLabelMark.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* The color of the mark.
*/
color: PropTypes.string,
/**
* The type of the mark.
* @default 'square'
*/
type: PropTypes.oneOf(['circle', 'line', 'square'])
} : void 0;
export { ChartsLabelMark };