@activecollab/components
Version:
ActiveCollab Components
46 lines • 1.83 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["value", "variant", "thousandSeparator", "decimalSeparator", "trimZeroMinutes", "trimDecimals", "decimalSpaces", "format", "disableTooltip", "className", "withLeadingZero", "as"];
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"
} = _ref,
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
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