UNPKG

@activecollab/components

Version:

ActiveCollab Components

44 lines 1.96 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["value", "variant", "thousandSeparator", "decimalSeparator", "trimDecimals", "decimalSpaces", "format", "disableTooltip", "className", "as", "shortenThreshold"]; 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 } = _ref, rest = _objectWithoutPropertiesLoose(_ref, _excluded); 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