@activecollab/components 2.0.117 → 2.0.118
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.
- package/dist/cjs/components/EditableHours/EditableHours.js +1 -1
- package/dist/cjs/components/EditableHours/EditableHours.js.map +1 -1
- package/dist/cjs/components/SelectTrigger/SelectTrigger.js +11 -1
- package/dist/cjs/components/SelectTrigger/SelectTrigger.js.map +1 -1
- package/dist/cjs/components/SelectTrigger/Styles.js +6 -3
- package/dist/cjs/components/SelectTrigger/Styles.js.map +1 -1
- package/dist/cjs/hooks/useInputHours.js +3 -3
- package/dist/cjs/hooks/useInputHours.js.map +1 -1
- package/dist/cjs/utils/index.js +7 -0
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/timeUtils.js +87 -33
- package/dist/cjs/utils/timeUtils.js.map +1 -1
- package/dist/cjs/utils/timeUtils.test.js +1 -1
- package/dist/cjs/utils/timeUtils.test.js.map +1 -1
- package/dist/esm/components/EditableHours/EditableHours.js +2 -2
- package/dist/esm/components/EditableHours/EditableHours.js.map +1 -1
- package/dist/esm/components/SelectTrigger/SelectTrigger.d.ts +2 -3
- package/dist/esm/components/SelectTrigger/SelectTrigger.d.ts.map +1 -1
- package/dist/esm/components/SelectTrigger/SelectTrigger.js +12 -2
- package/dist/esm/components/SelectTrigger/SelectTrigger.js.map +1 -1
- package/dist/esm/components/SelectTrigger/Styles.d.ts +2 -3
- package/dist/esm/components/SelectTrigger/Styles.d.ts.map +1 -1
- package/dist/esm/components/SelectTrigger/Styles.js +8 -3
- package/dist/esm/components/SelectTrigger/Styles.js.map +1 -1
- package/dist/esm/hooks/useInputHours.js +4 -4
- package/dist/esm/hooks/useInputHours.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/timeUtils.d.ts +34 -0
- package/dist/esm/utils/timeUtils.d.ts.map +1 -1
- package/dist/esm/utils/timeUtils.js +83 -30
- package/dist/esm/utils/timeUtils.js.map +1 -1
- package/dist/esm/utils/timeUtils.test.js +2 -2
- package/dist/esm/utils/timeUtils.test.js.map +1 -1
- package/dist/index.js +108 -40
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -767,38 +767,23 @@
|
|
|
767
767
|
};
|
|
768
768
|
var useResizeObserver$1 = useResizeObserver;
|
|
769
769
|
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
// minutes_decimal = parseInt(minutes_decimal);
|
|
788
|
-
// } // if
|
|
789
|
-
//
|
|
790
|
-
// const minutes = Math.round((minutes_decimal / 100) * 60);
|
|
791
|
-
//
|
|
792
|
-
// if (hours < 10) {
|
|
793
|
-
// hours = `0${hours}`;
|
|
794
|
-
// }
|
|
795
|
-
// return {
|
|
796
|
-
// hours: hours,
|
|
797
|
-
// minutes: minutes,
|
|
798
|
-
// };
|
|
799
|
-
// };
|
|
800
|
-
|
|
801
|
-
var decimalToHours = function decimalToHours(num) {
|
|
770
|
+
/**
|
|
771
|
+
* @function formatHours
|
|
772
|
+
* @description
|
|
773
|
+
* Formats a decimal number representing hours into a formatted string (HH:MM).
|
|
774
|
+
* The input can be a number, string, or undefined. The function handles various formats
|
|
775
|
+
* and can optionally add a leading zero to the hours component.
|
|
776
|
+
*
|
|
777
|
+
* @param {number | string | undefined} num - The input representing the hours, which can be in decimal format, a time string, or undefined.
|
|
778
|
+
* @param {boolean} [withLeadingZeroHours=false] - Whether to add a leading zero to the hours part of the output.
|
|
779
|
+
*
|
|
780
|
+
* @returns {string} - A formatted time string in HH:MM format.
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* formatHours(1.5) // "1:30"
|
|
784
|
+
* formatHours("3.5", true) // "03:30"
|
|
785
|
+
*/
|
|
786
|
+
var formatHours = function formatHours(num) {
|
|
802
787
|
var withLeadingZeroHours = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
803
788
|
if (!num) {
|
|
804
789
|
return "";
|
|
@@ -848,6 +833,75 @@
|
|
|
848
833
|
var minutes_formatted = Math.round(parseInt(minutes, 10) / 100 * 60);
|
|
849
834
|
return "".concat(hours, ":").concat(withLeadingZero(minutes_formatted));
|
|
850
835
|
};
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* @function decimalToHours
|
|
839
|
+
* @deprecated
|
|
840
|
+
* @description
|
|
841
|
+
* Converts a decimal number representing hours into a formatted string (HH:MM).
|
|
842
|
+
* The input can be a number, string, or undefined. The function handles various formats
|
|
843
|
+
* and can optionally add a leading zero to the hours component.
|
|
844
|
+
*
|
|
845
|
+
* @param {number | string | undefined} num - The input representing the hours, which can be in decimal format, a time string, or undefined.
|
|
846
|
+
* @param {boolean} [withLeadingZeroHours=false] - Whether to add a leading zero to the hours part of the output.
|
|
847
|
+
*
|
|
848
|
+
* @returns {string} - A formatted time string in HH:MM format.
|
|
849
|
+
*
|
|
850
|
+
* @example
|
|
851
|
+
* decimalToHours(1.5) // "1:30"
|
|
852
|
+
* decimalToHours("3.5", true) // "03:30"
|
|
853
|
+
*/
|
|
854
|
+
var decimalToHours = function decimalToHours(num) {
|
|
855
|
+
var withLeadingZeroHours = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
856
|
+
console.warn("Deprecated. Please use formatHours from @activecollab/components.");
|
|
857
|
+
if (!num) {
|
|
858
|
+
return "";
|
|
859
|
+
}
|
|
860
|
+
if (typeof num === "string" && !num) {
|
|
861
|
+
return withLeadingZeroHours ? "00:00" : "0:00";
|
|
862
|
+
}
|
|
863
|
+
if (typeof num === "string" && num.indexOf(":") >= 0) {
|
|
864
|
+
//eslint-disable-next-line
|
|
865
|
+
var _num$split3 = num.split(":"),
|
|
866
|
+
_num$split4 = _slicedToArray(_num$split3, 2),
|
|
867
|
+
_hours = _num$split4[0],
|
|
868
|
+
_minutes = _num$split4[1];
|
|
869
|
+
if (_minutes && _minutes.length === 1 && Number(_minutes) < 10) {
|
|
870
|
+
_minutes = "".concat(Number(_minutes), "0");
|
|
871
|
+
}
|
|
872
|
+
if (_hours && _minutes) {
|
|
873
|
+
if (withLeadingZeroHours) {
|
|
874
|
+
return "".concat(withLeadingZero(_hours), ":").concat(_minutes);
|
|
875
|
+
}
|
|
876
|
+
return "".concat(_hours, ":").concat(_minutes);
|
|
877
|
+
} else if (!_hours && _minutes) {
|
|
878
|
+
return withLeadingZeroHours ? "00:".concat(_minutes) : "0:".concat(_minutes);
|
|
879
|
+
} else if (!_minutes && _hours) {
|
|
880
|
+
return withLeadingZeroHours ? "".concat(withLeadingZero(_hours), ":00") : "".concat(_hours, ":00");
|
|
881
|
+
} else {
|
|
882
|
+
return withLeadingZeroHours ? "00:00" : "0:00";
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
if (typeof num === "string" && num.indexOf(",") >= 0) {
|
|
886
|
+
num = num.replace(",", ".");
|
|
887
|
+
}
|
|
888
|
+
var input = typeof num === "string" ? parseFloat(num) : num;
|
|
889
|
+
if (!isDecimal(input)) {
|
|
890
|
+
if (withLeadingZeroHours) {
|
|
891
|
+
return "".concat(withLeadingZero(input), ":00");
|
|
892
|
+
}
|
|
893
|
+
return "".concat(input, ":00");
|
|
894
|
+
}
|
|
895
|
+
var decimal = input.toFixed(2);
|
|
896
|
+
var time = decimal.toString().split(".");
|
|
897
|
+
var hours = time[0];
|
|
898
|
+
if (withLeadingZeroHours) {
|
|
899
|
+
hours = withLeadingZero(hours);
|
|
900
|
+
}
|
|
901
|
+
var minutes = time[1];
|
|
902
|
+
var minutes_formatted = Math.round(parseInt(minutes, 10) / 100 * 60);
|
|
903
|
+
return "".concat(hours, ":").concat(withLeadingZero(minutes_formatted));
|
|
904
|
+
};
|
|
851
905
|
var withLeadingZero = function withLeadingZero(num) {
|
|
852
906
|
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
853
907
|
var s = "".concat(num);
|
|
@@ -13561,13 +13615,13 @@
|
|
|
13561
13615
|
onChange = _ref.onChange,
|
|
13562
13616
|
onClick = _ref.onClick;
|
|
13563
13617
|
var _useState = React.useState(function () {
|
|
13564
|
-
return
|
|
13618
|
+
return formatHours(value, withLeadingZero);
|
|
13565
13619
|
}),
|
|
13566
13620
|
_useState2 = _slicedToArray(_useState, 2),
|
|
13567
13621
|
currentValue = _useState2[0],
|
|
13568
13622
|
setCurrentValue = _useState2[1];
|
|
13569
13623
|
var _useState3 = React.useState(function () {
|
|
13570
|
-
return
|
|
13624
|
+
return formatHours(value, withLeadingZero);
|
|
13571
13625
|
}),
|
|
13572
13626
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
13573
13627
|
prevValue = _useState4[0],
|
|
@@ -13578,7 +13632,7 @@
|
|
|
13578
13632
|
setCurrentValue(prevValue);
|
|
13579
13633
|
} else {
|
|
13580
13634
|
if (e.target.value.trim().length > 0 && prevValue !== e.target.value) {
|
|
13581
|
-
var _value =
|
|
13635
|
+
var _value = formatHours(e.target.value, withLeadingZero);
|
|
13582
13636
|
setPrevValue(_value);
|
|
13583
13637
|
setCurrentValue(_value);
|
|
13584
13638
|
typeof onSave === "function" && onSave(e);
|
|
@@ -16549,7 +16603,7 @@
|
|
|
16549
16603
|
var StyledSelectTrigger = styled__default["default"](Trigger).withConfig({
|
|
16550
16604
|
displayName: "Styles__StyledSelectTrigger",
|
|
16551
16605
|
componentId: "sc-9799p2-0"
|
|
16552
|
-
})(["display:flex;align-items:center;justify-content:space-between;padding:0 4px 0 8px;width:300px;transition:border-color 0.3s ease;background-color:transparent;border:none;", " ", " ", " ", " ", " ", " ", ";"], function (_ref) {
|
|
16606
|
+
})(["display:flex;align-items:center;justify-content:space-between;padding:0 4px 0 8px;width:300px;transition:border-color 0.3s ease;background-color:transparent;border:none;", " ", " ", " ", " ", " ", " ", ";", ";"], function (_ref) {
|
|
16553
16607
|
var $mode = _ref.$mode;
|
|
16554
16608
|
return $mode === "outlined" && styled.css(["border:1px solid var(--color-theme-500);background-color:var(--input-background-color);"]);
|
|
16555
16609
|
}, function (_ref2) {
|
|
@@ -16577,13 +16631,16 @@
|
|
|
16577
16631
|
}, function (_ref7) {
|
|
16578
16632
|
var $size = _ref7.$size;
|
|
16579
16633
|
return $size === "big" && styled.css(["height:40px;border-radius:var(--ac-br-8);"]);
|
|
16634
|
+
}, function (_ref8) {
|
|
16635
|
+
var $size = _ref8.$size;
|
|
16636
|
+
return $size === "biggest" && styled.css(["height:48px;border-radius:var(--ac-br-8);"]);
|
|
16580
16637
|
});
|
|
16581
16638
|
StyledSelectTrigger.displayName = "StyledSelectTrigger";
|
|
16582
16639
|
var StyledCaretIcon = styled__default["default"](CollapseExpandSingleIcon$1).withConfig({
|
|
16583
16640
|
displayName: "Styles__StyledCaretIcon",
|
|
16584
16641
|
componentId: "sc-9799p2-1"
|
|
16585
|
-
})(["margin-left:8px;flex-shrink:0;transition:transform 200ms ease;", ""], function (
|
|
16586
|
-
var $open =
|
|
16642
|
+
})(["margin-left:8px;flex-shrink:0;transition:transform 200ms ease;", ""], function (_ref9) {
|
|
16643
|
+
var $open = _ref9.$open;
|
|
16587
16644
|
return !$open && styled.css(["transform:rotate(180deg);"]);
|
|
16588
16645
|
});
|
|
16589
16646
|
StyledCaretIcon.displayName = "StyledCaretIcon";
|
|
@@ -16604,6 +16661,15 @@
|
|
|
16604
16661
|
_ref$mode = _ref.mode,
|
|
16605
16662
|
mode = _ref$mode === void 0 ? "outlined" : _ref$mode,
|
|
16606
16663
|
rest = _objectWithoutProperties(_ref, _excluded$n);
|
|
16664
|
+
var variant = React.useMemo(function () {
|
|
16665
|
+
if (size === "big") {
|
|
16666
|
+
return "Body 1";
|
|
16667
|
+
}
|
|
16668
|
+
if (size === "biggest") {
|
|
16669
|
+
return "Header 2";
|
|
16670
|
+
}
|
|
16671
|
+
return "Body 2";
|
|
16672
|
+
}, [size]);
|
|
16607
16673
|
return /*#__PURE__*/React__default["default"].createElement(StyledSelectTrigger, _extends({
|
|
16608
16674
|
ref: ref,
|
|
16609
16675
|
role: "button",
|
|
@@ -16616,7 +16682,8 @@
|
|
|
16616
16682
|
as: "div",
|
|
16617
16683
|
overflow: "truncate",
|
|
16618
16684
|
whitespace: "no-wrap",
|
|
16619
|
-
variant:
|
|
16685
|
+
variant: variant,
|
|
16686
|
+
weight: size === "biggest" ? "bold" : "regular",
|
|
16620
16687
|
color: mode === "flat" && invalid ? "alert" : undefined
|
|
16621
16688
|
}, typographyProps), children), endAdornment ? endAdornment : /*#__PURE__*/React__default["default"].createElement(StyledCaretIcon, {
|
|
16622
16689
|
$open: open
|
|
@@ -18073,7 +18140,7 @@
|
|
|
18073
18140
|
React.useEffect(function () {
|
|
18074
18141
|
var _value;
|
|
18075
18142
|
if (defaultValue !== undefined) {
|
|
18076
|
-
_value =
|
|
18143
|
+
_value = formatHours(defaultValue, withLeadingZero);
|
|
18077
18144
|
}
|
|
18078
18145
|
setCurrentValue(function (prevState) {
|
|
18079
18146
|
if (prevState !== _value) {
|
|
@@ -19963,6 +20030,7 @@
|
|
|
19963
20030
|
exports.colors = colors$1;
|
|
19964
20031
|
exports.decimalToHours = decimalToHours;
|
|
19965
20032
|
exports.formatCurrency = formatCurrency;
|
|
20033
|
+
exports.formatHours = formatHours;
|
|
19966
20034
|
exports.formatNumber = formatNumber;
|
|
19967
20035
|
exports.getNumberFromString = getNumberFromString;
|
|
19968
20036
|
exports.isOptionGroup = isOptionGroup;
|