@activecollab/components 2.0.196 → 2.0.197

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/cjs/components/Display/DisplayHours.js +9 -8
  2. package/dist/cjs/components/Display/DisplayHours.js.map +1 -1
  3. package/dist/cjs/components/Display/types.js.map +1 -1
  4. package/dist/cjs/utils/currencyUtils.js +20 -1
  5. package/dist/cjs/utils/currencyUtils.js.map +1 -1
  6. package/dist/cjs/utils/currencyUtils.test.js +5 -0
  7. package/dist/cjs/utils/currencyUtils.test.js.map +1 -1
  8. package/dist/cjs/utils/timeUtils.js +28 -9
  9. package/dist/cjs/utils/timeUtils.js.map +1 -1
  10. package/dist/cjs/utils/timeUtils.test.js +3 -2
  11. package/dist/cjs/utils/timeUtils.test.js.map +1 -1
  12. package/dist/cjs/utils/types.js.map +1 -1
  13. package/dist/esm/components/Display/DisplayHours.d.ts.map +1 -1
  14. package/dist/esm/components/Display/DisplayHours.js +9 -8
  15. package/dist/esm/components/Display/DisplayHours.js.map +1 -1
  16. package/dist/esm/components/Display/types.d.ts +3 -2
  17. package/dist/esm/components/Display/types.d.ts.map +1 -1
  18. package/dist/esm/components/Display/types.js.map +1 -1
  19. package/dist/esm/utils/currencyUtils.d.ts +1 -0
  20. package/dist/esm/utils/currencyUtils.d.ts.map +1 -1
  21. package/dist/esm/utils/currencyUtils.js +10 -0
  22. package/dist/esm/utils/currencyUtils.js.map +1 -1
  23. package/dist/esm/utils/currencyUtils.test.js +6 -1
  24. package/dist/esm/utils/currencyUtils.test.js.map +1 -1
  25. package/dist/esm/utils/timeUtils.d.ts +11 -7
  26. package/dist/esm/utils/timeUtils.d.ts.map +1 -1
  27. package/dist/esm/utils/timeUtils.js +31 -10
  28. package/dist/esm/utils/timeUtils.js.map +1 -1
  29. package/dist/esm/utils/timeUtils.test.js +5 -2
  30. package/dist/esm/utils/timeUtils.test.js.map +1 -1
  31. package/dist/esm/utils/types.d.ts +2 -1
  32. package/dist/esm/utils/types.d.ts.map +1 -1
  33. package/dist/esm/utils/types.js.map +1 -1
  34. package/dist/index.js +48 -17
  35. package/dist/index.js.map +1 -1
  36. package/dist/index.min.js +1 -1
  37. package/dist/index.min.js.map +1 -1
  38. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,MAAM,OAAO,CACjB,CAAC,SAAS,MAAM,GAAG,CAAC,iBAAiB,GAAG,KAAK,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAC1E,GAAG,CAAC,wBAAwB,CAAC,CAAC,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvE,KAAK,MAAM,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,IAAI;IACzC;;;OAGG;IACH,EAAE,CAAC,EAAE,CAAC,CAAC;CACR,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,CACzB,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACrC,aAAa,GAAG,IAAI,CAAC,aAAa,EAAE,MAAM,aAAa,CAAC,CAAC;AAE7D;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,CACjC,CAAC,SAAS,KAAK,CAAC,WAAW,EAC3B,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC7B,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAEvC;;;GAGG;AACH,MAAM,MAAM,yBAAyB,CACnC,CAAC,SAAS,KAAK,CAAC,WAAW,EAC3B,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC7B,uBAAuB,CAAC,CAAC,EAAE,KAAK,GAAG,MAA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;IACpC,gBAAgB,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACzC;AAED,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/utils/types.ts"],"sourcesContent":["import React from \"react\";\n\n// Source: https://github.com/emotion-js/emotion/blob/master/packages/styled-base/types/helper.d.ts\n// A more precise version of just React.ComponentPropsWithoutRef on its own\nexport type PropsOf<\n C extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<unknown>\n> = JSX.LibraryManagedAttributes<C, React.ComponentPropsWithoutRef<C>>;\n\ntype AsProp<C extends React.ElementType> = {\n /**\n * An override of the default HTML tag.\n * Can also be another React component.\n */\n as?: C;\n};\n\n/**\n * Allows for extending a set of props (`ExtendedProps`) by an overriding set of props\n * (`OverrideProps`), ensuring that any duplicates are overridden by the overriding\n * set of props.\n */\nexport type ExtendableProps<\n ExtendedProps = Record<string, unknown>,\n OverrideProps = Record<string, unknown>\n> = OverrideProps & Omit<ExtendedProps, keyof OverrideProps>;\n\n/**\n * Allows for inheriting the props from the specified element type so that\n * props like children, className & style work, as well as element-specific\n * attributes like aria roles. The component (`C`) must be passed in.\n */\nexport type InheritableElementProps<\n C extends React.ElementType,\n Props = Record<string, unknown>\n> = ExtendableProps<PropsOf<C>, Props>;\n\n/**\n * A more sophisticated version of `InheritableElementProps` where\n * the passed in `as` prop will determine which props can be included\n */\nexport type PolymorphicComponentProps<\n C extends React.ElementType,\n Props = Record<string, unknown>\n> = InheritableElementProps<C, Props & AsProp<C>>;\n\n/**\n * Utility type to extract the `ref` prop from a polymorphic component\n */\nexport type PolymorphicRef<C extends React.ElementType> =\n React.ComponentPropsWithRef<C>[\"ref\"];\n/**\n * A wrapper of `PolymorphicComponentProps` that also includes the `ref`\n * prop for the polymorphic component\n */\nexport type PolymorphicComponentPropsWithRef<\n C extends React.ElementType,\n Props = Record<string, unknown>\n> = PolymorphicComponentProps<C, Props> & { ref?: PolymorphicRef<C> };\n\nexport interface FormatNumberArgs {\n value: string | number;\n thousandSeparator?: \",\" | \".\" | \" \";\n decimalSeparator?: \",\" | \".\";\n trimDecimals?: boolean;\n decimalSpaces?: number;\n format?: \"long\" | \"short\";\n}\n\nexport interface FormatCurrencyArgs extends FormatNumberArgs {\n currencyCode?: string;\n currencyCodePosition?: \"right\" | \"left\";\n}\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/utils/types.ts"],"sourcesContent":["import React from \"react\";\n\n// Source: https://github.com/emotion-js/emotion/blob/master/packages/styled-base/types/helper.d.ts\n// A more precise version of just React.ComponentPropsWithoutRef on its own\nexport type PropsOf<\n C extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<unknown>\n> = JSX.LibraryManagedAttributes<C, React.ComponentPropsWithoutRef<C>>;\n\ntype AsProp<C extends React.ElementType> = {\n /**\n * An override of the default HTML tag.\n * Can also be another React component.\n */\n as?: C;\n};\n\n/**\n * Allows for extending a set of props (`ExtendedProps`) by an overriding set of props\n * (`OverrideProps`), ensuring that any duplicates are overridden by the overriding\n * set of props.\n */\nexport type ExtendableProps<\n ExtendedProps = Record<string, unknown>,\n OverrideProps = Record<string, unknown>\n> = OverrideProps & Omit<ExtendedProps, keyof OverrideProps>;\n\n/**\n * Allows for inheriting the props from the specified element type so that\n * props like children, className & style work, as well as element-specific\n * attributes like aria roles. The component (`C`) must be passed in.\n */\nexport type InheritableElementProps<\n C extends React.ElementType,\n Props = Record<string, unknown>\n> = ExtendableProps<PropsOf<C>, Props>;\n\n/**\n * A more sophisticated version of `InheritableElementProps` where\n * the passed in `as` prop will determine which props can be included\n */\nexport type PolymorphicComponentProps<\n C extends React.ElementType,\n Props = Record<string, unknown>\n> = InheritableElementProps<C, Props & AsProp<C>>;\n\n/**\n * Utility type to extract the `ref` prop from a polymorphic component\n */\nexport type PolymorphicRef<C extends React.ElementType> =\n React.ComponentPropsWithRef<C>[\"ref\"];\n/**\n * A wrapper of `PolymorphicComponentProps` that also includes the `ref`\n * prop for the polymorphic component\n */\nexport type PolymorphicComponentPropsWithRef<\n C extends React.ElementType,\n Props = Record<string, unknown>\n> = PolymorphicComponentProps<C, Props> & { ref?: PolymorphicRef<C> };\n\nexport interface FormatNumberArgs {\n value: string | number;\n thousandSeparator?: \",\" | \".\" | \" \";\n decimalSeparator?: \",\" | \".\";\n trimDecimals?: boolean;\n decimalSpaces?: number;\n format?: FormatType;\n}\n\nexport interface FormatCurrencyArgs extends FormatNumberArgs {\n currencyCode?: string;\n currencyCodePosition?: \"right\" | \"left\";\n}\n\nexport type FormatType = \"short\" | \"long\";\n"],"mappings":""}
package/dist/index.js CHANGED
@@ -723,6 +723,19 @@
723
723
  }
724
724
  return currencyCodePosition === "right" ? "".concat(formattedNum, " ").concat(currencyCode) : "".concat(currencyCode, " ").concat(formattedNum);
725
725
  };
726
+ var parseValueToNumber = function parseValueToNumber(value, thousandSeparator, decimalSeparator) {
727
+ var stringValue = String(value).trim();
728
+ if (stringValue.includes(":")) {
729
+ var _stringValue$split = stringValue.split(":"),
730
+ _stringValue$split2 = _slicedToArray(_stringValue$split, 2),
731
+ hoursPart = _stringValue$split2[0],
732
+ minutesPart = _stringValue$split2[1];
733
+ var hours = parseFloat(hoursPart) || 0;
734
+ var minutes = parseFloat(minutesPart) || 0;
735
+ return hours + minutes / 60;
736
+ }
737
+ return +stringValue.replaceAll(thousandSeparator, "").replace(decimalSeparator, ".");
738
+ };
726
739
 
727
740
  var validateStopwatchTime = function validateStopwatchTime(value) {
728
741
  return /^([0-9]{0,2})?(((:([0-5][0-9])?)|(:[0-5]?))|(\.[0-9]{0,2})|(,[0-9]{0,2}))?$/g.test(value);
@@ -795,29 +808,36 @@
795
808
  /**
796
809
  * @function formatHours
797
810
  * @description
798
- * Formats a decimal number representing hours into a formatted string (HH:MM).
799
- * The input can be a number, string, or undefined. The function handles various formats
800
- * and can optionally add a leading zero to the hours component.
811
+ * Formats a decimal number representing hours into a formatted string (HH:MM) or a short form if needed.
812
+ * The input can be a number, string, or undefined. It handles various formats and can optionally add a
813
+ * leading zero to the hours component. With the new "format" argument, if set to "short" and the value is
814
+ * greater than or equal to 1000, it will return a shortened format (e.g., 1K) similar to formatNumber.
801
815
  *
802
- * @param {number | string | undefined} num - The input representing the hours, which can be in decimal format, a time string, or undefined.
803
- * @param {boolean} [withLeadingZeroHours=false] - Whether to add a leading zero to the hours part of the output.
816
+ * @param {number | string | undefined} num - The input representing the hours.
817
+ * @param {boolean} [withLeadingZeroHours=false] - Whether to add a leading zero to the hours part.
804
818
  * @param {boolean} [trimZeroMinutes=false] - Whether to remove minutes if they are zero.
819
+ * @param {"long" | "short"} [format="long"] - The format type, either "long" for full numbers or "short" for abbreviated output.
805
820
  *
806
- * @returns {string} - A formatted time string in HH:MM format.
821
+ * @returns {string} - A formatted time string or a shortened string.
807
822
  *
808
823
  * @example
809
824
  * formatHours(1.5) // "1:30"
810
825
  * formatHours("3.5", true) // "03:30"
826
+ * formatHours(1500, false, false, "short") // "1K" (using formatNumber)
811
827
  */
812
828
  var formatHours = function formatHours(num) {
813
829
  var withLeadingZeroHours = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
814
830
  var trimZeroMinutes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
831
+ var format = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "long";
832
+ // Handle the explicit zero case.
815
833
  if (num === 0 || num === "0") {
816
834
  return trimZeroMinutes ? "0" : withLeadingZeroHours ? "00:00" : "0:00";
817
835
  }
818
836
  if (!num) {
819
837
  return "";
820
838
  }
839
+
840
+ // If the input is in colon format, process it as before.
821
841
  if (typeof num === "string" && num.indexOf(":") >= 0) {
822
842
  // eslint-disable-next-line prefer-const
823
843
  var _num$split = num.split(":"),
@@ -841,16 +861,27 @@
841
861
  }
842
862
  return withLeadingZeroHours ? "00:".concat(_minutes) : "0:".concat(_minutes);
843
863
  }
864
+
865
+ // Replace comma with dot if needed.
844
866
  if (typeof num === "string" && num.indexOf(",") >= 0) {
845
867
  num = num.replace(",", ".");
846
868
  }
847
869
  var input = typeof num === "string" ? parseFloat(num) : num;
870
+
871
+ // Use short formatting if specified and the value is >= 1000.
872
+ if (format === "short" && input >= 1000) {
873
+ return formatNumber(input, ",", ".", true, 2, "short");
874
+ }
875
+
876
+ // For whole numbers.
848
877
  if (!isDecimal(input)) {
849
878
  if (trimZeroMinutes) {
850
879
  return withLeadingZeroHours ? withLeadingZero(input) : String(Number(input));
851
880
  }
852
881
  return withLeadingZeroHours ? "".concat(withLeadingZero(input), ":00") : "".concat(input, ":00");
853
882
  }
883
+
884
+ // Process decimal hours.
854
885
  var decimal = input.toFixed(2);
855
886
  var time = decimal.toString().split(".");
856
887
  var hours = time[0];
@@ -858,11 +889,11 @@
858
889
  hours = withLeadingZero(hours);
859
890
  }
860
891
  var minutes = time[1];
861
- var minutes_formatted = Math.round(parseInt(minutes, 10) / 100 * 60);
862
- if (trimZeroMinutes && minutes_formatted === 0) {
892
+ var minutesFormatted = Math.round(parseInt(minutes, 10) / 100 * 60);
893
+ if (trimZeroMinutes && minutesFormatted === 0) {
863
894
  return hours;
864
895
  }
865
- return "".concat(hours, ":").concat(withLeadingZero(minutes_formatted));
896
+ return "".concat(hours, ":").concat(withLeadingZero(minutesFormatted));
866
897
  };
867
898
  var withLeadingZero = function withLeadingZero(num) {
868
899
  var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
@@ -17676,27 +17707,27 @@
17676
17707
  _ref$as = _ref.as,
17677
17708
  as = _ref$as === void 0 ? "span" : _ref$as,
17678
17709
  rest = _objectWithoutProperties(_ref, _excluded$y);
17679
- var numberValue = +String(value).replaceAll(thousandSeparator, "").replace(decimalSeparator, ".");
17680
- var formattedValue = formatNumber(numberValue, thousandSeparator, decimalSeparator, trimDecimals, decimalSpaces, "short");
17681
- var formattedLongValue = formatHours(numberValue, withLeadingZero, trimZeroMinutes);
17682
- var showShortVersion = numberValue > 1000;
17683
- if (format === "short" && showShortVersion) {
17710
+ var numberValue = parseValueToNumber(value, thousandSeparator, decimalSeparator);
17711
+ var shouldDisplayShort = format === "short" && numberValue >= 1000;
17712
+ var longValue = formatHours(numberValue, withLeadingZero, trimZeroMinutes, "long");
17713
+ var shortValue = formatNumber(numberValue, thousandSeparator, decimalSeparator, trimDecimals, decimalSpaces, "short");
17714
+ if (shouldDisplayShort) {
17684
17715
  return /*#__PURE__*/React__default["default"].createElement(Tooltip, {
17685
- title: formattedLongValue,
17716
+ title: formatHours(numberValue),
17686
17717
  disable: disableTooltip
17687
17718
  }, /*#__PURE__*/React__default["default"].createElement(Typography, _extends({
17688
17719
  as: as,
17689
17720
  variant: variant,
17690
17721
  className: className,
17691
17722
  ref: ref
17692
- }, rest), formattedValue));
17723
+ }, rest), shortValue));
17693
17724
  }
17694
17725
  return /*#__PURE__*/React__default["default"].createElement(Typography, _extends({
17695
17726
  as: as,
17696
17727
  variant: variant,
17697
17728
  className: className,
17698
17729
  ref: ref
17699
- }, rest), formattedLongValue);
17730
+ }, rest), longValue);
17700
17731
  });
17701
17732
  DisplayHours.displayName = "DisplayHours";
17702
17733