@activecollab/components
Version:
ActiveCollab Components
53 lines • 2.66 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 = _ref.value,
_ref$variant = _ref.variant,
variant = _ref$variant === void 0 ? "Body 2" : _ref$variant,
_ref$thousandSeparato = _ref.thousandSeparator,
thousandSeparator = _ref$thousandSeparato === void 0 ? "," : _ref$thousandSeparato,
_ref$decimalSeparator = _ref.decimalSeparator,
decimalSeparator = _ref$decimalSeparator === void 0 ? "." : _ref$decimalSeparator,
_ref$trimZeroMinutes = _ref.trimZeroMinutes,
trimZeroMinutes = _ref$trimZeroMinutes === void 0 ? false : _ref$trimZeroMinutes,
_ref$trimDecimals = _ref.trimDecimals,
trimDecimals = _ref$trimDecimals === void 0 ? true : _ref$trimDecimals,
_ref$decimalSpaces = _ref.decimalSpaces,
decimalSpaces = _ref$decimalSpaces === void 0 ? 2 : _ref$decimalSpaces,
_ref$format = _ref.format,
format = _ref$format === void 0 ? "long" : _ref$format,
_ref$disableTooltip = _ref.disableTooltip,
disableTooltip = _ref$disableTooltip === void 0 ? false : _ref$disableTooltip,
className = _ref.className,
withLeadingZero = _ref.withLeadingZero,
_ref$as = _ref.as,
as = _ref$as === void 0 ? "span" : _ref$as,
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