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