@trackunit/react-form-components 0.0.139 → 0.0.141

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/index.cjs.js CHANGED
@@ -97,12 +97,12 @@ const ActionButton = ({ type, value, dataTestId, iconSize, disabled, className,
97
97
  const getIconName = () => {
98
98
  switch (type) {
99
99
  case "PHONE_NUMBER":
100
- return "PhoneArrowUpRightIcon";
100
+ return "PhoneArrowUpRight";
101
101
  case "WEB_ADDRESS":
102
- return "ArrowTopRightOnSquareIcon";
102
+ return "ArrowTopRightOnSquare";
103
103
  case "EMAIL":
104
104
  default:
105
- return "EnvelopeIcon";
105
+ return "Envelope";
106
106
  }
107
107
  };
108
108
  const ButtonAction = () => {
@@ -2922,7 +2922,7 @@ const DateInput = React.forwardRef((_a, ref) => {
2922
2922
  const formatDateToInputString = (date) => date instanceof Date ? format(date, "yyyy-MM-dd") : date;
2923
2923
  // Chrome and Firefox need their default icon to have datepicker functionality.
2924
2924
  const showIcon = !/Chrome/.test(navigator.userAgent) && !/Firefox/.test(navigator.userAgent);
2925
- return (jsxRuntime.jsx(BaseInput, Object.assign({ type: "date", value: formatDateToInputString(value), defaultValue: formatDateToInputString(defaultValue), min: formatDateToInputString(min), max: formatDateToInputString(max), ref: ref, suffix: showIcon && jsxRuntime.jsx(reactComponents.Icon, { dataTestId: "calendar", name: "CalendarIcon", size: "medium", type: "solid" }) }, rest)));
2925
+ return (jsxRuntime.jsx(BaseInput, Object.assign({ type: "date", value: formatDateToInputString(value), defaultValue: formatDateToInputString(defaultValue), min: formatDateToInputString(min), max: formatDateToInputString(max), ref: ref, suffix: showIcon && jsxRuntime.jsx(reactComponents.Icon, { dataTestId: "calendar", name: "Calendar", size: "medium", type: "solid" }) }, rest)));
2926
2926
  });
2927
2927
 
2928
2928
  /**
@@ -3063,7 +3063,7 @@ const DropZone = (_a) => {
3063
3063
  e.preventDefault();
3064
3064
  e.stopPropagation();
3065
3065
  }
3066
- } }, rest, { children: [jsxRuntime.jsx("input", { title: "Hidden File Input", type: "file", id: "input-file-upload", onChange: handleChange, className: "hidden" }), jsxRuntime.jsxs("label", { className: cvaDropZoneLabel(), htmlFor: "input-file-upload", "data-testid": dataTestId && `${dataTestId}-label`, children: [jsxRuntime.jsx(reactComponents.Icon, { type: "solid", name: "ArrowUpCircleIcon", color: isInvalid ? "danger" : "neutral", style: !isInvalid ? { color: "rgb(156 163 175)" } : {} }), jsxRuntime.jsx("span", { children: label })] })] })));
3066
+ } }, rest, { children: [jsxRuntime.jsx("input", { title: "Hidden File Input", type: "file", id: "input-file-upload", onChange: handleChange, className: "hidden" }), jsxRuntime.jsxs("label", { className: cvaDropZoneLabel(), htmlFor: "input-file-upload", "data-testid": dataTestId && `${dataTestId}-label`, children: [jsxRuntime.jsx(reactComponents.Icon, { type: "solid", name: "ArrowUpCircle", color: isInvalid ? "danger" : "neutral", style: !isInvalid ? { color: "rgb(156 163 175)" } : {} }), jsxRuntime.jsx("span", { children: label })] })] })));
3067
3067
  };
3068
3068
 
3069
3069
  /**
@@ -14090,7 +14090,7 @@ const getOrderedOptions = (options, value) => {
14090
14090
  * @returns {JSX.Element} SingleSelectMenuItem
14091
14091
  */
14092
14092
  const SingleSelectMenuItem = ({ label, icon, onClick, selected, dataTestId, focused, disabled, }) => {
14093
- return (jsxRuntime.jsx(reactComponents.MenuItem, { dataTestId: dataTestId, label: label, prefix: icon, onClick: onClick, selected: selected, disabled: disabled, focused: focused, suffix: selected ? jsxRuntime.jsx(reactComponents.Icon, { name: "CheckIcon", size: "small" }) : undefined }));
14093
+ return (jsxRuntime.jsx(reactComponents.MenuItem, { dataTestId: dataTestId, label: label, prefix: icon, onClick: onClick, selected: selected, disabled: disabled, focused: focused, suffix: selected ? jsxRuntime.jsx(reactComponents.Icon, { name: "Check", size: "small" }) : undefined }));
14094
14094
  };
14095
14095
  /**
14096
14096
  * A multi select menu item is a basic wrapper around Menu item designed to be used as a multi value render in Select list
@@ -14239,13 +14239,13 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
14239
14239
  }, LoadingIndicator: props => {
14240
14240
  return jsxRuntime.jsx(reactComponents.Spinner, { size: "small", className: "mt-1.5 mr-1" });
14241
14241
  }, DropdownIndicator: props => {
14242
- const icon = props.selectProps.menuIsOpen ? (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronUpIcon", size: "medium" })) : (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronDownIcon", size: "medium" }));
14242
+ const icon = props.selectProps.menuIsOpen ? (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronUp", size: "medium" })) : (jsxRuntime.jsx(reactComponents.Icon, { name: "ChevronDown", size: "medium" }));
14243
14243
  return props.selectProps.isLoading ? null : (jsxRuntime.jsx(components.DropdownIndicator, Object.assign({}, props, { children: jsxRuntime.jsx("div", { className: cvaSelectIcon(), children: dropdownIcon ? dropdownIcon : icon }) })));
14244
14244
  }, IndicatorSeparator: () => null, ClearIndicator: props => {
14245
14245
  if (disabled) {
14246
14246
  return null;
14247
14247
  }
14248
- return (jsxRuntime.jsx(components.ClearIndicator, Object.assign({}, props, { children: jsxRuntime.jsx("div", { className: cvaSelectXIcon(), onClick: props.clearValue, "data-testid": dataTestId && `${dataTestId}-XMarkIcon`, children: jsxRuntime.jsx(reactComponents.Icon, { name: "XCircleIcon", size: "medium" }) }) })));
14248
+ return (jsxRuntime.jsx(components.ClearIndicator, Object.assign({}, props, { children: jsxRuntime.jsx("div", { className: cvaSelectXIcon(), onClick: props.clearValue, "data-testid": dataTestId && `${dataTestId}-XMarkIcon`, children: jsxRuntime.jsx(reactComponents.Icon, { name: "XCircle", size: "medium" }) }) })));
14249
14249
  }, Control: props => {
14250
14250
  return jsxRuntime.jsx(components.Control, Object.assign({}, props, { className: props.isDisabled ? "bg-slate-100" : "" }));
14251
14251
  }, SingleValue: props => {
@@ -14760,6 +14760,117 @@ const Schedule = ({ className, dataTestId, schedule, onChange, invalidKeys = []
14760
14760
  }) }));
14761
14761
  };
14762
14762
 
14763
+ const weekDay = {
14764
+ Monday: "monday",
14765
+ Tuesday: "tuesday",
14766
+ Wednesday: "wednesday",
14767
+ Thursday: "thursday",
14768
+ Friday: "friday",
14769
+ Saturday: "saturday",
14770
+ Sunday: "sunday",
14771
+ };
14772
+ exports.ScheduleVariant = void 0;
14773
+ (function (ScheduleVariant) {
14774
+ ScheduleVariant["ALL_DAYS"] = "all";
14775
+ ScheduleVariant["WEEKDAYS"] = "week";
14776
+ ScheduleVariant["CUSTOM"] = "custom";
14777
+ })(exports.ScheduleVariant || (exports.ScheduleVariant = {}));
14778
+ /**
14779
+ * Parse a string of week range schedule string to human readable schedule range.
14780
+ *
14781
+ * @param {string} scheduleString String of week schedule
14782
+ * @returns {WeekSchedule} Week schedule range
14783
+ */
14784
+ const parseSchedule = (scheduleString) => {
14785
+ if (!scheduleString) {
14786
+ return {
14787
+ variant: exports.ScheduleVariant.ALL_DAYS,
14788
+ schedule: [],
14789
+ };
14790
+ }
14791
+ const schedule = scheduleString.split(",").map(daySchedule => {
14792
+ const [day, timeRange] = daySchedule.split("#");
14793
+ const [timeFrom, timeTo] = timeRange.split("-");
14794
+ const isAllDay = timeFrom === "00:00" && timeTo === "24:00";
14795
+ return {
14796
+ day: Number(day),
14797
+ range: isAllDay
14798
+ ? undefined
14799
+ : {
14800
+ timeFrom,
14801
+ timeTo,
14802
+ },
14803
+ isAllDay,
14804
+ };
14805
+ });
14806
+ const filteredSchedule = schedule
14807
+ .filter(daySchedule => daySchedule.range !== null && daySchedule.range !== undefined)
14808
+ .map(daySchedule => ({ day: daySchedule.day, range: daySchedule.range, isAllDay: daySchedule.isAllDay }));
14809
+ let variant;
14810
+ switch (schedule.length) {
14811
+ case 7:
14812
+ const areEqual = schedule.every((day, _, collection) => {
14813
+ var _a, _b, _c, _d, _e, _f;
14814
+ return ((_b = (_a = collection === null || collection === void 0 ? void 0 : collection[0]) === null || _a === void 0 ? void 0 : _a.range) === null || _b === void 0 ? void 0 : _b.timeFrom) === ((_c = day === null || day === void 0 ? void 0 : day.range) === null || _c === void 0 ? void 0 : _c.timeFrom) &&
14815
+ ((_e = (_d = collection === null || collection === void 0 ? void 0 : collection[0]) === null || _d === void 0 ? void 0 : _d.range) === null || _e === void 0 ? void 0 : _e.timeTo) === ((_f = day === null || day === void 0 ? void 0 : day.range) === null || _f === void 0 ? void 0 : _f.timeTo);
14816
+ });
14817
+ if (areEqual) {
14818
+ variant = exports.ScheduleVariant.ALL_DAYS;
14819
+ }
14820
+ else {
14821
+ variant = exports.ScheduleVariant.CUSTOM;
14822
+ }
14823
+ break;
14824
+ case 5:
14825
+ const days = [1, 2, 3, 4, 5];
14826
+ const hasConsecutiveDays = schedule.every(({ day }, index) => day === days[index]);
14827
+ if (hasConsecutiveDays) {
14828
+ variant = exports.ScheduleVariant.WEEKDAYS;
14829
+ }
14830
+ else {
14831
+ variant = exports.ScheduleVariant.CUSTOM;
14832
+ }
14833
+ break;
14834
+ default:
14835
+ return {
14836
+ variant: exports.ScheduleVariant.CUSTOM,
14837
+ schedule: filteredSchedule,
14838
+ };
14839
+ }
14840
+ return {
14841
+ variant,
14842
+ schedule: filteredSchedule,
14843
+ };
14844
+ };
14845
+ /**
14846
+ * Serialize week schedule to string schedule
14847
+ *
14848
+ * @param {WeekSchedule} weekSchedule Week schedule range
14849
+ * @returns {string} Schedule string
14850
+ */
14851
+ const serializeSchedule = (weekSchedule) => {
14852
+ return weekSchedule.schedule
14853
+ .filter(({ range, day, isAllDay }) => {
14854
+ const hasRange = (range === null || range === void 0 ? void 0 : range.timeFrom) && (range === null || range === void 0 ? void 0 : range.timeTo);
14855
+ switch (weekSchedule.variant) {
14856
+ case exports.ScheduleVariant.WEEKDAYS:
14857
+ return day <= 5 && hasRange;
14858
+ case exports.ScheduleVariant.ALL_DAYS:
14859
+ return day <= 7 && hasRange;
14860
+ case exports.ScheduleVariant.CUSTOM:
14861
+ default:
14862
+ return hasRange || isAllDay;
14863
+ }
14864
+ })
14865
+ .map(({ day, range, isAllDay }) => {
14866
+ if (isAllDay) {
14867
+ return `${day}#00:00-24:00`;
14868
+ }
14869
+ return `${day}#${range.timeFrom}-${range.timeTo}`;
14870
+ })
14871
+ .join(",");
14872
+ };
14873
+
14763
14874
  /**
14764
14875
  * A thin wrapper around the `BaseInput` component for text input fields.
14765
14876
  *
@@ -14801,9 +14912,9 @@ const cvaSearch = cssClassVarianceUtilities.cvaMerge([
14801
14912
  */
14802
14913
  const Search = (_a) => {
14803
14914
  var { className, placeholder = "Search", value, widenInputOnFocus, showBorderWhenNotInFocus = false, disabled, onKeyUp, onChange, onFocus, onBlur, name, onClear, dataTestId, autoComplete = "on" } = _a, rest = __rest(_a, ["className", "placeholder", "value", "widenInputOnFocus", "showBorderWhenNotInFocus", "disabled", "onKeyUp", "onChange", "onFocus", "onBlur", "name", "onClear", "dataTestId", "autoComplete"]);
14804
- return (jsxRuntime.jsx(TextInput, Object.assign({}, rest, { dataTestId: dataTestId, name: name, className: cvaSearch({ className, border: showBorderWhenNotInFocus, widenOnFocus: widenInputOnFocus }), placeholder: placeholder, prefix: jsxRuntime.jsx(reactComponents.Icon, { name: "MagnifyingGlassIcon", size: "medium" }), suffix: onClear ? (jsxRuntime.jsx("button", { "data-testid": dataTestId && `${dataTestId}_suffix_component`, onClick: () => {
14915
+ return (jsxRuntime.jsx(TextInput, Object.assign({}, rest, { dataTestId: dataTestId, name: name, className: cvaSearch({ className, border: showBorderWhenNotInFocus, widenOnFocus: widenInputOnFocus }), placeholder: placeholder, prefix: jsxRuntime.jsx(reactComponents.Icon, { name: "MagnifyingGlass", size: "medium" }), suffix: onClear ? (jsxRuntime.jsx("button", { "data-testid": dataTestId && `${dataTestId}_suffix_component`, onClick: () => {
14805
14916
  onClear();
14806
- }, children: jsxRuntime.jsx(reactComponents.Icon, { name: "XMarkIcon", size: "small" }) })) : undefined, value: value, disabled: disabled, onChange: onChange, onKeyUp: onKeyUp, onFocus: onFocus, onBlur: onBlur, autoComplete: autoComplete })));
14917
+ }, children: jsxRuntime.jsx(reactComponents.Icon, { name: "XMark", size: "small" }) })) : undefined, value: value, disabled: disabled, onChange: onChange, onKeyUp: onKeyUp, onFocus: onFocus, onBlur: onBlur, autoComplete: autoComplete })));
14807
14918
  };
14808
14919
 
14809
14920
  const cvaTextArea = cssClassVarianceUtilities.cvaMerge([
@@ -15087,5 +15198,8 @@ exports.cvaSelectPrefix = cvaSelectPrefix;
15087
15198
  exports.cvaSelectXIcon = cvaSelectXIcon;
15088
15199
  exports.getOrderedOptions = getOrderedOptions;
15089
15200
  exports.isMultiValue = isMultiValue;
15201
+ exports.parseSchedule = parseSchedule;
15202
+ exports.serializeSchedule = serializeSchedule;
15090
15203
  exports.useCustomComponents = useCustomComponents;
15091
15204
  exports.usePhoneInput = usePhoneInput;
15205
+ exports.weekDay = weekDay;
package/index.esm.js CHANGED
@@ -71,12 +71,12 @@ const ActionButton = ({ type, value, dataTestId, iconSize, disabled, className,
71
71
  const getIconName = () => {
72
72
  switch (type) {
73
73
  case "PHONE_NUMBER":
74
- return "PhoneArrowUpRightIcon";
74
+ return "PhoneArrowUpRight";
75
75
  case "WEB_ADDRESS":
76
- return "ArrowTopRightOnSquareIcon";
76
+ return "ArrowTopRightOnSquare";
77
77
  case "EMAIL":
78
78
  default:
79
- return "EnvelopeIcon";
79
+ return "Envelope";
80
80
  }
81
81
  };
82
82
  const ButtonAction = () => {
@@ -2896,7 +2896,7 @@ const DateInput = forwardRef((_a, ref) => {
2896
2896
  const formatDateToInputString = (date) => date instanceof Date ? format(date, "yyyy-MM-dd") : date;
2897
2897
  // Chrome and Firefox need their default icon to have datepicker functionality.
2898
2898
  const showIcon = !/Chrome/.test(navigator.userAgent) && !/Firefox/.test(navigator.userAgent);
2899
- return (jsx$1(BaseInput, Object.assign({ type: "date", value: formatDateToInputString(value), defaultValue: formatDateToInputString(defaultValue), min: formatDateToInputString(min), max: formatDateToInputString(max), ref: ref, suffix: showIcon && jsx$1(Icon, { dataTestId: "calendar", name: "CalendarIcon", size: "medium", type: "solid" }) }, rest)));
2899
+ return (jsx$1(BaseInput, Object.assign({ type: "date", value: formatDateToInputString(value), defaultValue: formatDateToInputString(defaultValue), min: formatDateToInputString(min), max: formatDateToInputString(max), ref: ref, suffix: showIcon && jsx$1(Icon, { dataTestId: "calendar", name: "Calendar", size: "medium", type: "solid" }) }, rest)));
2900
2900
  });
2901
2901
 
2902
2902
  /**
@@ -3037,7 +3037,7 @@ const DropZone = (_a) => {
3037
3037
  e.preventDefault();
3038
3038
  e.stopPropagation();
3039
3039
  }
3040
- } }, rest, { children: [jsx$1("input", { title: "Hidden File Input", type: "file", id: "input-file-upload", onChange: handleChange, className: "hidden" }), jsxs("label", { className: cvaDropZoneLabel(), htmlFor: "input-file-upload", "data-testid": dataTestId && `${dataTestId}-label`, children: [jsx$1(Icon, { type: "solid", name: "ArrowUpCircleIcon", color: isInvalid ? "danger" : "neutral", style: !isInvalid ? { color: "rgb(156 163 175)" } : {} }), jsx$1("span", { children: label })] })] })));
3040
+ } }, rest, { children: [jsx$1("input", { title: "Hidden File Input", type: "file", id: "input-file-upload", onChange: handleChange, className: "hidden" }), jsxs("label", { className: cvaDropZoneLabel(), htmlFor: "input-file-upload", "data-testid": dataTestId && `${dataTestId}-label`, children: [jsx$1(Icon, { type: "solid", name: "ArrowUpCircle", color: isInvalid ? "danger" : "neutral", style: !isInvalid ? { color: "rgb(156 163 175)" } : {} }), jsx$1("span", { children: label })] })] })));
3041
3041
  };
3042
3042
 
3043
3043
  /**
@@ -14064,7 +14064,7 @@ const getOrderedOptions = (options, value) => {
14064
14064
  * @returns {JSX.Element} SingleSelectMenuItem
14065
14065
  */
14066
14066
  const SingleSelectMenuItem = ({ label, icon, onClick, selected, dataTestId, focused, disabled, }) => {
14067
- return (jsx$1(MenuItem, { dataTestId: dataTestId, label: label, prefix: icon, onClick: onClick, selected: selected, disabled: disabled, focused: focused, suffix: selected ? jsx$1(Icon, { name: "CheckIcon", size: "small" }) : undefined }));
14067
+ return (jsx$1(MenuItem, { dataTestId: dataTestId, label: label, prefix: icon, onClick: onClick, selected: selected, disabled: disabled, focused: focused, suffix: selected ? jsx$1(Icon, { name: "Check", size: "small" }) : undefined }));
14068
14068
  };
14069
14069
  /**
14070
14070
  * A multi select menu item is a basic wrapper around Menu item designed to be used as a multi value render in Select list
@@ -14213,13 +14213,13 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
14213
14213
  }, LoadingIndicator: props => {
14214
14214
  return jsx$1(Spinner, { size: "small", className: "mt-1.5 mr-1" });
14215
14215
  }, DropdownIndicator: props => {
14216
- const icon = props.selectProps.menuIsOpen ? (jsx$1(Icon, { name: "ChevronUpIcon", size: "medium" })) : (jsx$1(Icon, { name: "ChevronDownIcon", size: "medium" }));
14216
+ const icon = props.selectProps.menuIsOpen ? (jsx$1(Icon, { name: "ChevronUp", size: "medium" })) : (jsx$1(Icon, { name: "ChevronDown", size: "medium" }));
14217
14217
  return props.selectProps.isLoading ? null : (jsx$1(components.DropdownIndicator, Object.assign({}, props, { children: jsx$1("div", { className: cvaSelectIcon(), children: dropdownIcon ? dropdownIcon : icon }) })));
14218
14218
  }, IndicatorSeparator: () => null, ClearIndicator: props => {
14219
14219
  if (disabled) {
14220
14220
  return null;
14221
14221
  }
14222
- return (jsx$1(components.ClearIndicator, Object.assign({}, props, { children: jsx$1("div", { className: cvaSelectXIcon(), onClick: props.clearValue, "data-testid": dataTestId && `${dataTestId}-XMarkIcon`, children: jsx$1(Icon, { name: "XCircleIcon", size: "medium" }) }) })));
14222
+ return (jsx$1(components.ClearIndicator, Object.assign({}, props, { children: jsx$1("div", { className: cvaSelectXIcon(), onClick: props.clearValue, "data-testid": dataTestId && `${dataTestId}-XMarkIcon`, children: jsx$1(Icon, { name: "XCircle", size: "medium" }) }) })));
14223
14223
  }, Control: props => {
14224
14224
  return jsx$1(components.Control, Object.assign({}, props, { className: props.isDisabled ? "bg-slate-100" : "" }));
14225
14225
  }, SingleValue: props => {
@@ -14734,6 +14734,117 @@ const Schedule = ({ className, dataTestId, schedule, onChange, invalidKeys = []
14734
14734
  }) }));
14735
14735
  };
14736
14736
 
14737
+ const weekDay = {
14738
+ Monday: "monday",
14739
+ Tuesday: "tuesday",
14740
+ Wednesday: "wednesday",
14741
+ Thursday: "thursday",
14742
+ Friday: "friday",
14743
+ Saturday: "saturday",
14744
+ Sunday: "sunday",
14745
+ };
14746
+ var ScheduleVariant;
14747
+ (function (ScheduleVariant) {
14748
+ ScheduleVariant["ALL_DAYS"] = "all";
14749
+ ScheduleVariant["WEEKDAYS"] = "week";
14750
+ ScheduleVariant["CUSTOM"] = "custom";
14751
+ })(ScheduleVariant || (ScheduleVariant = {}));
14752
+ /**
14753
+ * Parse a string of week range schedule string to human readable schedule range.
14754
+ *
14755
+ * @param {string} scheduleString String of week schedule
14756
+ * @returns {WeekSchedule} Week schedule range
14757
+ */
14758
+ const parseSchedule = (scheduleString) => {
14759
+ if (!scheduleString) {
14760
+ return {
14761
+ variant: ScheduleVariant.ALL_DAYS,
14762
+ schedule: [],
14763
+ };
14764
+ }
14765
+ const schedule = scheduleString.split(",").map(daySchedule => {
14766
+ const [day, timeRange] = daySchedule.split("#");
14767
+ const [timeFrom, timeTo] = timeRange.split("-");
14768
+ const isAllDay = timeFrom === "00:00" && timeTo === "24:00";
14769
+ return {
14770
+ day: Number(day),
14771
+ range: isAllDay
14772
+ ? undefined
14773
+ : {
14774
+ timeFrom,
14775
+ timeTo,
14776
+ },
14777
+ isAllDay,
14778
+ };
14779
+ });
14780
+ const filteredSchedule = schedule
14781
+ .filter(daySchedule => daySchedule.range !== null && daySchedule.range !== undefined)
14782
+ .map(daySchedule => ({ day: daySchedule.day, range: daySchedule.range, isAllDay: daySchedule.isAllDay }));
14783
+ let variant;
14784
+ switch (schedule.length) {
14785
+ case 7:
14786
+ const areEqual = schedule.every((day, _, collection) => {
14787
+ var _a, _b, _c, _d, _e, _f;
14788
+ return ((_b = (_a = collection === null || collection === void 0 ? void 0 : collection[0]) === null || _a === void 0 ? void 0 : _a.range) === null || _b === void 0 ? void 0 : _b.timeFrom) === ((_c = day === null || day === void 0 ? void 0 : day.range) === null || _c === void 0 ? void 0 : _c.timeFrom) &&
14789
+ ((_e = (_d = collection === null || collection === void 0 ? void 0 : collection[0]) === null || _d === void 0 ? void 0 : _d.range) === null || _e === void 0 ? void 0 : _e.timeTo) === ((_f = day === null || day === void 0 ? void 0 : day.range) === null || _f === void 0 ? void 0 : _f.timeTo);
14790
+ });
14791
+ if (areEqual) {
14792
+ variant = ScheduleVariant.ALL_DAYS;
14793
+ }
14794
+ else {
14795
+ variant = ScheduleVariant.CUSTOM;
14796
+ }
14797
+ break;
14798
+ case 5:
14799
+ const days = [1, 2, 3, 4, 5];
14800
+ const hasConsecutiveDays = schedule.every(({ day }, index) => day === days[index]);
14801
+ if (hasConsecutiveDays) {
14802
+ variant = ScheduleVariant.WEEKDAYS;
14803
+ }
14804
+ else {
14805
+ variant = ScheduleVariant.CUSTOM;
14806
+ }
14807
+ break;
14808
+ default:
14809
+ return {
14810
+ variant: ScheduleVariant.CUSTOM,
14811
+ schedule: filteredSchedule,
14812
+ };
14813
+ }
14814
+ return {
14815
+ variant,
14816
+ schedule: filteredSchedule,
14817
+ };
14818
+ };
14819
+ /**
14820
+ * Serialize week schedule to string schedule
14821
+ *
14822
+ * @param {WeekSchedule} weekSchedule Week schedule range
14823
+ * @returns {string} Schedule string
14824
+ */
14825
+ const serializeSchedule = (weekSchedule) => {
14826
+ return weekSchedule.schedule
14827
+ .filter(({ range, day, isAllDay }) => {
14828
+ const hasRange = (range === null || range === void 0 ? void 0 : range.timeFrom) && (range === null || range === void 0 ? void 0 : range.timeTo);
14829
+ switch (weekSchedule.variant) {
14830
+ case ScheduleVariant.WEEKDAYS:
14831
+ return day <= 5 && hasRange;
14832
+ case ScheduleVariant.ALL_DAYS:
14833
+ return day <= 7 && hasRange;
14834
+ case ScheduleVariant.CUSTOM:
14835
+ default:
14836
+ return hasRange || isAllDay;
14837
+ }
14838
+ })
14839
+ .map(({ day, range, isAllDay }) => {
14840
+ if (isAllDay) {
14841
+ return `${day}#00:00-24:00`;
14842
+ }
14843
+ return `${day}#${range.timeFrom}-${range.timeTo}`;
14844
+ })
14845
+ .join(",");
14846
+ };
14847
+
14737
14848
  /**
14738
14849
  * A thin wrapper around the `BaseInput` component for text input fields.
14739
14850
  *
@@ -14775,9 +14886,9 @@ const cvaSearch = cvaMerge([
14775
14886
  */
14776
14887
  const Search = (_a) => {
14777
14888
  var { className, placeholder = "Search", value, widenInputOnFocus, showBorderWhenNotInFocus = false, disabled, onKeyUp, onChange, onFocus, onBlur, name, onClear, dataTestId, autoComplete = "on" } = _a, rest = __rest(_a, ["className", "placeholder", "value", "widenInputOnFocus", "showBorderWhenNotInFocus", "disabled", "onKeyUp", "onChange", "onFocus", "onBlur", "name", "onClear", "dataTestId", "autoComplete"]);
14778
- return (jsx$1(TextInput, Object.assign({}, rest, { dataTestId: dataTestId, name: name, className: cvaSearch({ className, border: showBorderWhenNotInFocus, widenOnFocus: widenInputOnFocus }), placeholder: placeholder, prefix: jsx$1(Icon, { name: "MagnifyingGlassIcon", size: "medium" }), suffix: onClear ? (jsx$1("button", { "data-testid": dataTestId && `${dataTestId}_suffix_component`, onClick: () => {
14889
+ return (jsx$1(TextInput, Object.assign({}, rest, { dataTestId: dataTestId, name: name, className: cvaSearch({ className, border: showBorderWhenNotInFocus, widenOnFocus: widenInputOnFocus }), placeholder: placeholder, prefix: jsx$1(Icon, { name: "MagnifyingGlass", size: "medium" }), suffix: onClear ? (jsx$1("button", { "data-testid": dataTestId && `${dataTestId}_suffix_component`, onClick: () => {
14779
14890
  onClear();
14780
- }, children: jsx$1(Icon, { name: "XMarkIcon", size: "small" }) })) : undefined, value: value, disabled: disabled, onChange: onChange, onKeyUp: onKeyUp, onFocus: onFocus, onBlur: onBlur, autoComplete: autoComplete })));
14891
+ }, children: jsx$1(Icon, { name: "XMark", size: "small" }) })) : undefined, value: value, disabled: disabled, onChange: onChange, onKeyUp: onKeyUp, onFocus: onFocus, onBlur: onBlur, autoComplete: autoComplete })));
14781
14892
  };
14782
14893
 
14783
14894
  const cvaTextArea = cvaMerge([
@@ -15008,4 +15119,4 @@ const UploadField = forwardRef((_a, ref) => {
15008
15119
  */
15009
15120
  setupLibraryTranslations();
15010
15121
 
15011
- export { ActionButton, BaseInput, Checkbox, CreatableSelect, DateField, DateInput, DropZone, EmailField, EmailInput, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PhoneField, PhoneInput, RadioGroup, RadioItem, Schedule, Search, Select, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, StateManagedSelect$1 as ValueType, cvaInput, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefix, cvaSelectXIcon, getOrderedOptions, isMultiValue, useCustomComponents, usePhoneInput };
15122
+ export { ActionButton, BaseInput, Checkbox, CreatableSelect, DateField, DateInput, DropZone, EmailField, EmailInput, FormGroup, Label, MultiSelectMenuItem, NumberField, NumberInput, OptionCard, PhoneField, PhoneInput, RadioGroup, RadioItem, Schedule, ScheduleVariant, Search, Select, SingleSelectMenuItem, TextArea, TextAreaField, TextField, TextInput, TimeRange, TimeRangeField, Toggle, UploadField, UploadInput, StateManagedSelect$1 as ValueType, cvaInput, cvaInputAddon, cvaInputAddonAfter, cvaInputAddonBefore, cvaInputBase, cvaInputBaseDisabled, cvaInputBaseInvalid, cvaInputField, cvaInputPrefix, cvaInputSuffix, cvaSelect, cvaSelectCounter, cvaSelectDynamicTagContainer, cvaSelectIcon, cvaSelectMenu, cvaSelectMenuList, cvaSelectPrefix, cvaSelectXIcon, getOrderedOptions, isMultiValue, parseSchedule, serializeSchedule, useCustomComponents, usePhoneInput, weekDay };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "0.0.139",
3
+ "version": "0.0.141",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -9,8 +9,9 @@
9
9
  "dependencies": {
10
10
  "@trackunit/css-class-variance-utilities": "0.0.14",
11
11
  "@trackunit/i18n-library-translation": "0.0.77",
12
- "@trackunit/react-components": "0.1.156",
12
+ "@trackunit/react-components": "0.1.157",
13
13
  "@trackunit/shared-utils": "0.0.7",
14
+ "@trackunit/ui-icons": "0.0.76",
14
15
  "date-fns": "2.29.3",
15
16
  "libphonenumber-js": "1.10.36",
16
17
  "react": "18.2.0",
@@ -0,0 +1,39 @@
1
+ import { TimeRangeInput } from "../TimeRange";
2
+ export declare const weekDay: {
3
+ readonly Monday: "monday";
4
+ readonly Tuesday: "tuesday";
5
+ readonly Wednesday: "wednesday";
6
+ readonly Thursday: "thursday";
7
+ readonly Friday: "friday";
8
+ readonly Saturday: "saturday";
9
+ readonly Sunday: "sunday";
10
+ };
11
+ export type WeekDay = (typeof weekDay)[keyof typeof weekDay];
12
+ export declare enum ScheduleVariant {
13
+ ALL_DAYS = "all",
14
+ WEEKDAYS = "week",
15
+ CUSTOM = "custom"
16
+ }
17
+ export interface DaySchedule {
18
+ day: number;
19
+ range: TimeRangeInput;
20
+ isAllDay: boolean;
21
+ }
22
+ export interface WeekSchedule {
23
+ variant: ScheduleVariant;
24
+ schedule: DaySchedule[];
25
+ }
26
+ /**
27
+ * Parse a string of week range schedule string to human readable schedule range.
28
+ *
29
+ * @param {string} scheduleString String of week schedule
30
+ * @returns {WeekSchedule} Week schedule range
31
+ */
32
+ export declare const parseSchedule: (scheduleString: string) => WeekSchedule;
33
+ /**
34
+ * Serialize week schedule to string schedule
35
+ *
36
+ * @param {WeekSchedule} weekSchedule Week schedule range
37
+ * @returns {string} Schedule string
38
+ */
39
+ export declare const serializeSchedule: (weekSchedule: WeekSchedule) => string;
package/src/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from "./components/PhoneField/PhoneField";
15
15
  export * from "./components/PhoneInput/PhoneInput";
16
16
  export * from "./components/RadioGroup";
17
17
  export * from "./components/Schedule/Schedule";
18
+ export * from "./components/Schedule/ScheduleParser";
18
19
  export * from "./components/Search";
19
20
  export * from "./components/Select";
20
21
  export * from "./components/TextArea";