@activecollab/components
Version:
ActiveCollab Components
42 lines • 1.61 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import React, { forwardRef } from "react";
import { formatNumber } from "../../utils";
import { Tooltip } from "../Tooltip";
import { Typography } from "../Typography/Typography";
export const DisplayNumber = /*#__PURE__*/forwardRef((_ref, ref) => {
let {
value,
variant = "Body 2",
thousandSeparator = ",",
decimalSeparator = ".",
trimDecimals = true,
decimalSpaces = 2,
format = "long",
disableTooltip = false,
className,
as = "span",
shortenThreshold = 1000,
...rest
} = _ref;
const formattedValue = formatNumber(value, thousandSeparator, decimalSeparator, trimDecimals, decimalSpaces, format, shortenThreshold);
const formattedLongValue = formatNumber(value, thousandSeparator, decimalSeparator, trimDecimals, decimalSpaces, "long");
if (format === "short") {
return /*#__PURE__*/React.createElement(Tooltip, {
title: formatNumber(value, thousandSeparator, decimalSeparator, false, decimalSpaces, "long"),
disable: disableTooltip || !formattedLongValue.includes(thousandSeparator) && !formattedLongValue.includes(decimalSeparator)
}, /*#__PURE__*/React.createElement(Typography, _extends({
as: as,
variant: variant,
className: className,
ref: ref
}, rest), formattedValue));
}
return /*#__PURE__*/React.createElement(Typography, _extends({
as: as,
variant: variant,
className: className,
ref: ref
}, rest), formattedLongValue);
});
DisplayNumber.displayName = "DisplayNumber";
//# sourceMappingURL=DisplayNumber.js.map