146 lines
5.7 KiB
JavaScript
146 lines
5.7 KiB
JavaScript
"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.ChartsLegend = void 0;
|
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
var React = _interopRequireWildcard(require("react"));
|
|
var _styles = require("@mui/material/styles");
|
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
var _clsx = _interopRequireDefault(require("clsx"));
|
|
var _useLegend = require("../hooks/useLegend");
|
|
var _ChartsLabelMark = require("../ChartsLabel/ChartsLabelMark");
|
|
var _onClickContextBuilder = require("./onClickContextBuilder");
|
|
var _chartsLegendClasses = require("./chartsLegendClasses");
|
|
var _consumeSlots = require("../internals/consumeSlots");
|
|
var _ChartsLabel = require("../ChartsLabel/ChartsLabel");
|
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
const _excluded = ["direction", "onItemClick", "className", "classes"];
|
|
const RootElement = (0, _styles.styled)('ul', {
|
|
name: 'MuiChartsLegend',
|
|
slot: 'Root'
|
|
})(({
|
|
ownerState,
|
|
theme
|
|
}) => (0, _extends2.default)({}, theme.typography.caption, {
|
|
color: (theme.vars || theme).palette.text.primary,
|
|
lineHeight: '100%',
|
|
display: 'flex',
|
|
flexDirection: ownerState.direction === 'vertical' ? 'column' : 'row',
|
|
alignItems: ownerState.direction === 'vertical' ? undefined : 'center',
|
|
flexShrink: 0,
|
|
gap: theme.spacing(2),
|
|
listStyleType: 'none',
|
|
paddingInlineStart: 0,
|
|
marginBlock: theme.spacing(1),
|
|
marginInline: theme.spacing(1),
|
|
flexWrap: 'wrap',
|
|
li: {
|
|
display: ownerState.direction === 'horizontal' ? 'inline-flex' : undefined
|
|
},
|
|
[`button.${_chartsLegendClasses.legendClasses.series}`]: {
|
|
// Reset button styles
|
|
background: 'none',
|
|
border: 'none',
|
|
padding: 0,
|
|
fontFamily: 'inherit',
|
|
fontWeight: 'inherit',
|
|
fontSize: 'inherit',
|
|
letterSpacing: 'inherit',
|
|
color: 'inherit'
|
|
},
|
|
[`& .${_chartsLegendClasses.legendClasses.series}`]: {
|
|
display: ownerState.direction === 'vertical' ? 'flex' : 'inline-flex',
|
|
alignItems: 'center',
|
|
gap: theme.spacing(1)
|
|
}
|
|
}));
|
|
const ChartsLegend = exports.ChartsLegend = (0, _consumeSlots.consumeSlots)('MuiChartsLegend', 'legend', {
|
|
defaultProps: {
|
|
direction: 'horizontal'
|
|
},
|
|
// @ts-expect-error position is used only in the slots, but it is passed to the SVG wrapper.
|
|
// We omit it here to avoid passing to slots.
|
|
omitProps: ['position'],
|
|
classesResolver: _chartsLegendClasses.useUtilityClasses
|
|
}, /*#__PURE__*/React.forwardRef(function ChartsLegend(props, ref) {
|
|
const data = (0, _useLegend.useLegend)();
|
|
const {
|
|
onItemClick,
|
|
className,
|
|
classes
|
|
} = props,
|
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
if (data.items.length === 0) {
|
|
return null;
|
|
}
|
|
const Element = onItemClick ? 'button' : 'div';
|
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(RootElement, (0, _extends2.default)({
|
|
className: (0, _clsx.default)(classes?.root, className),
|
|
ref: ref
|
|
}, other, {
|
|
ownerState: props,
|
|
children: data.items.map((item, i) => {
|
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
|
|
className: classes?.item,
|
|
"data-series": item.id,
|
|
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Element, {
|
|
className: classes?.series,
|
|
role: onItemClick ? 'button' : undefined,
|
|
type: onItemClick ? 'button' : undefined,
|
|
onClick: onItemClick ?
|
|
// @ts-ignore onClick is only attached to a button
|
|
event => onItemClick(event, (0, _onClickContextBuilder.seriesContextBuilder)(item), i) : undefined,
|
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLabelMark.ChartsLabelMark, {
|
|
className: classes?.mark,
|
|
color: item.color,
|
|
type: item.markType
|
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLabel.ChartsLabel, {
|
|
className: classes?.label,
|
|
children: item.label
|
|
})]
|
|
})
|
|
}, item.id);
|
|
})
|
|
}));
|
|
}));
|
|
if (process.env.NODE_ENV !== "production") ChartsLegend.displayName = "ChartsLegend";
|
|
process.env.NODE_ENV !== "production" ? ChartsLegend.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.default.object,
|
|
className: _propTypes.default.string,
|
|
/**
|
|
* The direction of the legend layout.
|
|
* The default depends on the chart.
|
|
*/
|
|
direction: _propTypes.default.oneOf(['horizontal', 'vertical']),
|
|
/**
|
|
* Callback fired when a legend item is clicked.
|
|
* @param {React.MouseEvent<HTMLButtonElement, MouseEvent>} event The click event.
|
|
* @param {SeriesLegendItemContext} legendItem The legend item data.
|
|
* @param {number} index The index of the clicked legend item.
|
|
*/
|
|
onItemClick: _propTypes.default.func,
|
|
/**
|
|
* The props used for each component slot.
|
|
* @default {}
|
|
*/
|
|
slotProps: _propTypes.default.object,
|
|
/**
|
|
* Overridable component slots.
|
|
* @default {}
|
|
*/
|
|
slots: _propTypes.default.object,
|
|
sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object])
|
|
} : void 0; |