131 lines
3.6 KiB
JavaScript
131 lines
3.6 KiB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
const _excluded = ["seriesId", "classes", "color", "dataIndex", "barLabel", "slots", "slotProps", "xOrigin", "yOrigin", "x", "y", "width", "height", "value", "skipAnimation", "layout"],
|
|
_excluded2 = ["ownerState"];
|
|
import * as React from 'react';
|
|
import useSlotProps from '@mui/utils/useSlotProps';
|
|
import PropTypes from 'prop-types';
|
|
import { useUtilityClasses } from "./barLabelClasses.js";
|
|
import { getBarLabel } from "./getBarLabel.js";
|
|
import { BarLabel } from "./BarLabel.js";
|
|
import { useItemHighlighted } from "../../hooks/useItemHighlighted.js";
|
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
/**
|
|
* @ignore - internal component.
|
|
*/
|
|
function BarLabelItem(props) {
|
|
const {
|
|
seriesId,
|
|
classes: innerClasses,
|
|
color,
|
|
dataIndex,
|
|
barLabel,
|
|
slots,
|
|
slotProps,
|
|
xOrigin,
|
|
yOrigin,
|
|
x,
|
|
y,
|
|
width,
|
|
height,
|
|
value,
|
|
skipAnimation,
|
|
layout
|
|
} = props,
|
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
const {
|
|
isFaded,
|
|
isHighlighted
|
|
} = useItemHighlighted({
|
|
seriesId,
|
|
dataIndex
|
|
});
|
|
const ownerState = {
|
|
seriesId,
|
|
classes: innerClasses,
|
|
color,
|
|
isFaded,
|
|
isHighlighted,
|
|
dataIndex,
|
|
skipAnimation,
|
|
layout
|
|
};
|
|
const classes = useUtilityClasses(ownerState);
|
|
const Component = slots?.barLabel ?? BarLabel;
|
|
const _useSlotProps = useSlotProps({
|
|
elementType: Component,
|
|
externalSlotProps: slotProps?.barLabel,
|
|
additionalProps: _extends({}, other, {
|
|
xOrigin,
|
|
yOrigin,
|
|
x,
|
|
y,
|
|
width,
|
|
height,
|
|
className: classes.root
|
|
}),
|
|
ownerState
|
|
}),
|
|
{
|
|
ownerState: barLabelOwnerState
|
|
} = _useSlotProps,
|
|
barLabelProps = _objectWithoutPropertiesLoose(_useSlotProps, _excluded2);
|
|
if (!barLabel) {
|
|
return null;
|
|
}
|
|
const formattedLabelText = getBarLabel({
|
|
barLabel,
|
|
value,
|
|
dataIndex,
|
|
seriesId,
|
|
height,
|
|
width
|
|
});
|
|
if (!formattedLabelText) {
|
|
return null;
|
|
}
|
|
return /*#__PURE__*/_jsx(Component, _extends({}, barLabelProps, barLabelOwnerState, {
|
|
children: formattedLabelText
|
|
}));
|
|
}
|
|
process.env.NODE_ENV !== "production" ? BarLabelItem.propTypes = {
|
|
// ----------------------------- Warning --------------------------------
|
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
// ----------------------------------------------------------------------
|
|
/**
|
|
* If provided, the function will be used to format the label of the bar.
|
|
* It can be set to 'value' to display the current value.
|
|
* @param {BarItem} item The item to format.
|
|
* @param {BarLabelContext} context data about the bar.
|
|
* @returns {string} The formatted label.
|
|
*/
|
|
barLabel: PropTypes.oneOfType([PropTypes.oneOf(['value']), PropTypes.func]),
|
|
classes: PropTypes.object,
|
|
color: PropTypes.string.isRequired,
|
|
dataIndex: PropTypes.number.isRequired,
|
|
/**
|
|
* The height of the bar.
|
|
*/
|
|
height: PropTypes.number.isRequired,
|
|
seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
|
/**
|
|
* The props used for each component slot.
|
|
* @default {}
|
|
*/
|
|
slotProps: PropTypes.object,
|
|
/**
|
|
* Overridable component slots.
|
|
* @default {}
|
|
*/
|
|
slots: PropTypes.object,
|
|
/**
|
|
* The value of the data point.
|
|
*/
|
|
value: PropTypes.number,
|
|
/**
|
|
* The width of the bar.
|
|
*/
|
|
width: PropTypes.number.isRequired
|
|
} : void 0;
|
|
export { BarLabelItem }; |