META-INF.resources.js.components.CustomTooltip.js Maven / Gradle / Ivy
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
import PropTypes from 'prop-types';
import React from 'react';
/**
* Component to customize the content of recharts Tooltip
* http://recharts.org/en-US/api/Tooltip#content
*/
export default function CustomTooltip(props) {
const {
formatter,
label,
labelFormatter,
payload,
publishDateFill,
separator = '',
showPublishedDateLabel,
} = props;
return label ? (
{labelFormatter ? labelFormatter(label) : label}
{showPublishedDateLabel && (
{Liferay.Language.get('published')}
)}
{payload.map((item) => {
const [value, name, iconType] = formatter
? formatter(item.value, item.name, item.iconType)
: [item.value, item.name, item.iconType];
return (
-
{name}
{separator}
{value}
);
})}
) : null;
}
CustomTooltip.propTypes = {
formatter: PropTypes.func,
label: PropTypes.string,
labelFormatter: PropTypes.func,
payload: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string.isRequired,
value: PropTypes.number.isRequired,
})
),
publishDateFill: PropTypes.string,
separator: PropTypes.string,
showPublishedDateLabel: PropTypes.bool,
};