bianic-ui 1.15.0-beta.2 → 1.16.0-beta.0

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/index.js CHANGED
@@ -2773,8 +2773,32 @@ var oneDayValue = 24 * 60 * 60 * 1000; // milliseconds in one day
2773
2773
  var todayValue = Date.now() -
2774
2774
  (Date.now() % oneDayValue) +
2775
2775
  new Date().getTimezoneOffset() * 1000 * 60; // today in milliseconds
2776
+ // Supporting functions
2777
+ var checkDateEquals = function (date1, date2) {
2778
+ if (!date2 || !date1)
2779
+ return false;
2780
+ return (date1.getFullYear() === date2.getFullYear() &&
2781
+ date1.getMonth() === date2.getMonth() &&
2782
+ date1.getDate() === date2.getDate());
2783
+ };
2784
+ var checkIsValidDate = function (dateString) {
2785
+ // format check YYYY-MM-DD
2786
+ var regex = /^\d{4}-\d{2}-\d{2}$/;
2787
+ if (!regex.test(dateString)) {
2788
+ return false;
2789
+ }
2790
+ // Date validity check
2791
+ var parts = dateString.split('-');
2792
+ var year = parseInt(parts[0], 10);
2793
+ var month = parseInt(parts[1], 10);
2794
+ var day = parseInt(parts[2], 10);
2795
+ var date = new Date(Date.UTC(year, month - 1, day));
2796
+ return (date.getUTCFullYear() === year &&
2797
+ date.getUTCMonth() === month - 1 && // Check against 0-based month
2798
+ date.getUTCDate() === day);
2799
+ };
2776
2800
  var PickerCalendar = function (_a) {
2777
- var _b = _a.selectedDate, selectedDate = _b === void 0 ? null : _b, onDateChange = _a.onDateChange, ref = _a.ref;
2801
+ var _b = _a.selectedDate, selectedDate = _b === void 0 ? null : _b, onDateChange = _a.onDateChange, ref = _a.ref, minDate = _a.minDate, maxDate = _a.maxDate;
2778
2802
  // Constants
2779
2803
  var daysMap = [
2780
2804
  'Monday',
@@ -2803,10 +2827,12 @@ var PickerCalendar = function (_a) {
2803
2827
  // Mode Controller
2804
2828
  var _c = React.useState(modeMap[0]), pickerMode = _c[0], setPickerMode = _c[1];
2805
2829
  var _d = React.useState(''), prevMode = _d[0], setPrevMode = _d[1];
2830
+ var minDateValue = minDate && checkIsValidDate(minDate || '') ? new Date(minDate) : null;
2831
+ var maxDateValue = maxDate && checkIsValidDate(maxDate || '') ? new Date(maxDate) : null;
2806
2832
  // styling constants and functions
2807
- var chevronButtonStyle = 'text-bia-coolgrey';
2833
+ var chevronButtonStyle = 'text-bia-coolgrey disabled:text-bia-coolgrey-light-50';
2808
2834
  var selectedDateStyle = function (date, dateSelected) {
2809
- var isSelected = checkDateEquals(date, dateSelected);
2835
+ var isSelected = checkDateEquals(date, new Date(dateSelected));
2810
2836
  var isToday = checkDateEquals(date, new Date(todayValue));
2811
2837
  if (isSelected) {
2812
2838
  return 'bg-bia-blue-dark-10 text-bia-white rounded-full border border-bia-blue-dark-10';
@@ -2818,30 +2844,14 @@ var PickerCalendar = function (_a) {
2818
2844
  return 'hover:bg-bia-blue-pastel rounded-full';
2819
2845
  }
2820
2846
  };
2821
- var datesColorStyle = function (date, viewMonth) {
2822
- if (date.getMonth() === viewMonth) {
2823
- return 'text-bia-black';
2824
- }
2825
- else {
2826
- return 'text-bia-coolgrey';
2827
- }
2828
- };
2829
- var selectedMonthStyle = function (month, monthSelected) {
2830
- if (month === monthSelected) {
2847
+ var selectedStyle = function (match) {
2848
+ if (match) {
2831
2849
  return 'bg-bia-blue-dark-10 text-bia-white rounded-full border border-bia-blue-dark-10';
2832
2850
  }
2833
2851
  else {
2834
- return 'hover:bg-bia-blue-pastel rounded-full';
2852
+ return 'enabled:hover:bg-bia-blue-pastel rounded-full';
2835
2853
  }
2836
2854
  };
2837
- // Supporting functions
2838
- var checkDateEquals = function (date1, date2) {
2839
- if (!date2 || !date1)
2840
- return false;
2841
- return (date1.getFullYear() === date2.getFullYear() &&
2842
- date1.getMonth() === date2.getMonth() &&
2843
- date1.getDate() === date2.getDate());
2844
- };
2845
2855
  // handler
2846
2856
  var handleViewNextMonth = function () {
2847
2857
  if (viewMonthValue === 11) {
@@ -2908,7 +2918,7 @@ var PickerCalendar = function (_a) {
2908
2918
  setViewYearValue(date.getFullYear());
2909
2919
  }
2910
2920
  if (onDateChange) {
2911
- onDateChange(date);
2921
+ onDateChange(dateToInputString$1(date));
2912
2922
  }
2913
2923
  };
2914
2924
  var handlePickerMode = function (mode) {
@@ -2948,17 +2958,59 @@ var PickerCalendar = function (_a) {
2948
2958
  var yearDisplayRange = getDecadeRange(viewDecadeValue);
2949
2959
  // Variable display
2950
2960
  var dateDisplay = (React.createElement("div", { className: "".concat(pickerMode === 'date' ? '' : 'hidden') },
2951
- React.createElement("div", { className: "bianic-datepicker-calendar-days-grid-header grid grid-cols-7 gap-[3px] pb-1.5", style: { zIndex: 100 } }, daysMap.map(function (day) { return (React.createElement("div", { key: day, className: "bianic-datepicker-calendar-day flex h-[18px] w-[31px] items-center justify-center text-bia-coolgrey" },
2952
- React.createElement(Text, { variant: "small-text" }, day.slice(0, 3)))); })),
2953
- React.createElement("div", { className: "bianic-datepicker-calendar-days-grid-body grid grid-cols-7 gap-y-1.5" }, displayDays.map(function (date) { return (React.createElement("button", { key: date.toString(), className: "bianic-datepicker-calendar-day flex h-[31px] w-[31px] items-center justify-center ".concat(datesColorStyle(date, viewMonthValue), " ").concat(selectedDateStyle(date, selectedDate)), onClick: function () {
2954
- // Handle date selection logic here
2955
- handleSetSelectedDate(date);
2956
- } },
2957
- React.createElement(Text, { variant: "small-text", extended: checkDateEquals(date, selectedDate) ? 'text-bia-white' : '' }, date.getDate()))); }))));
2958
- var monthDisplay = (React.createElement("div", { className: "bianic-datepicker-calendar-month-grid grid grid-cols-3 gap-y-1.5 ".concat(pickerMode === 'month' ? '' : 'hidden') }, monthMap.map(function (month, index) { return (React.createElement("button", { className: "bianic-datepicker-calendar-month mx-[15px] flex h-[31px] items-center justify-center ".concat(selectedMonthStyle(index, viewMonthValue)), key: index, onClick: function () { return handleSetMonth(index); } },
2959
- React.createElement(Text, { variant: "small-text" }, month.slice(0, 3)))); })));
2960
- var yearDisplay = (React.createElement("div", { className: "bianic-datepicker-calendar-year-grid grid grid-cols-4 gap-y-1.5 ".concat(pickerMode === 'year' ? '' : 'hidden') }, yearDisplayRange.map(function (year, index) { return (React.createElement("button", { className: "bianic-datepicker-calendar-month mx-[6px] flex h-[31px] items-center justify-center ".concat(selectedMonthStyle(year, viewYearValue), " ").concat(index === 0 || index === 11 ? 'text-bia-coolgrey' : 'text-bia-black'), key: index, onClick: function () { return handleSetYear(year); } },
2961
- React.createElement(Text, { variant: "small-text" }, year))); })));
2961
+ React.createElement("div", { className: "bianic-datepicker-calendar-days-grid-header grid grid-cols-7 gap-[3px] pb-1.5", style: { zIndex: 100 } }, daysMap.map(function (day) { return (React.createElement("div", { key: day, className: "bianic-datepicker-calendar-day flex h-[18px] w-[31px] items-center justify-center" },
2962
+ React.createElement(Text, { variant: "small-text", extended: "text-bia-coolgrey" }, day.slice(0, 3)))); })),
2963
+ React.createElement("div", { className: "bianic-datepicker-calendar-days-grid-body grid grid-cols-7 gap-y-1.5" }, displayDays.map(function (date) {
2964
+ var isOutOfRange = !!((minDateValue && date < minDateValue) ||
2965
+ (maxDateValue && date > maxDateValue));
2966
+ var isOutOfMonth = date.getMonth() !== viewMonthValue;
2967
+ var calendarDateStyle = isOutOfMonth
2968
+ ? 'text-bia-coolgrey'
2969
+ : 'text-bia-black';
2970
+ var dateDisplayStyle = isOutOfRange
2971
+ ? 'text-bia-coolgrey-light-50'
2972
+ : calendarDateStyle;
2973
+ return (React.createElement("button", { key: date.toString(), className: "bianic-datepicker-calendar-day flex h-[31px] w-[31px] items-center justify-center ".concat(isOutOfRange ? '' : selectedDateStyle(date, selectedDate)), disabled: isOutOfRange, onClick: function () {
2974
+ handleSetSelectedDate(date);
2975
+ } },
2976
+ React.createElement(Text, { variant: "small-text", extended: selectedDate &&
2977
+ date.getDate() === parseInt(selectedDate.slice(8, 10)) &&
2978
+ date.getMonth() + 1 === parseInt(selectedDate.slice(5, 7)) &&
2979
+ date.getFullYear() === parseInt(selectedDate.slice(0, 4))
2980
+ ? 'text-bia-white'
2981
+ : dateDisplayStyle }, date.getDate())));
2982
+ }))));
2983
+ var monthDisplay = (React.createElement("div", { className: "bianic-datepicker-calendar-month-grid grid grid-cols-3 gap-y-1.5 ".concat(pickerMode === 'month' ? '' : 'hidden') }, monthMap.map(function (month, index) {
2984
+ var isOutOfRange = !!((minDateValue &&
2985
+ (minDateValue.getFullYear() < viewYearValue ||
2986
+ index <
2987
+ (minDateValue.getFullYear() === viewYearValue
2988
+ ? minDateValue.getMonth()
2989
+ : 0))) ||
2990
+ (maxDateValue &&
2991
+ (maxDateValue.getFullYear() > viewYearValue ||
2992
+ index >
2993
+ (maxDateValue.getFullYear() === viewYearValue
2994
+ ? maxDateValue.getMonth()
2995
+ : 11))));
2996
+ var monthDisplayStyle = isOutOfRange
2997
+ ? 'text-bia-coolgrey-light-50'
2998
+ : 'text-bia-black';
2999
+ return (React.createElement("button", { className: "bianic-datepicker-calendar-month mx-[15px] flex h-[31px] items-center justify-center ".concat(selectedStyle(viewYearValue === new Number(selectedDate === null || selectedDate === void 0 ? void 0 : selectedDate.slice(0, 4)) && index === viewMonthValue)), key: index, disabled: isOutOfRange, onClick: function () { return handleSetMonth(index); } },
3000
+ React.createElement(Text, { variant: "small-text", extended: viewYearValue === new Number(selectedDate === null || selectedDate === void 0 ? void 0 : selectedDate.slice(0, 4)) &&
3001
+ index === viewMonthValue
3002
+ ? 'text-bia-white'
3003
+ : monthDisplayStyle }, month.slice(0, 3))));
3004
+ })));
3005
+ var yearDisplay = (React.createElement("div", { className: "bianic-datepicker-calendar-year-grid grid grid-cols-4 gap-y-1.5 ".concat(pickerMode === 'year' ? '' : 'hidden') }, yearDisplayRange.map(function (year, index) {
3006
+ var isOutOfRange = !!((minDateValue && year < minDateValue.getFullYear()) ||
3007
+ (maxDateValue && year > maxDateValue.getFullYear()));
3008
+ var yearDisplayStyle = isOutOfRange
3009
+ ? 'text-bia-coolgrey-light-50'
3010
+ : 'text-bia-black';
3011
+ return (React.createElement("button", { className: "bianic-datepicker-calendar-month mx-[6px] flex h-[31px] items-center justify-center ".concat(selectedStyle(year === viewYearValue), " ").concat(index === 0 || index === 11 ? 'text-bia-coolgrey' : 'text-bia-black'), key: index, disabled: isOutOfRange, onClick: function () { return handleSetYear(year); } },
3012
+ React.createElement(Text, { variant: "small-text", extended: year === viewYearValue ? 'text-bia-white' : yearDisplayStyle }, year)));
3013
+ })));
2962
3014
  // useEffect to update displayDays when viewMonthValue or viewYearValue changes
2963
3015
  React.useEffect(function () {
2964
3016
  var tempDisplayDays = [];
@@ -2969,7 +3021,10 @@ var PickerCalendar = function (_a) {
2969
3021
  }, [viewMonthValue, viewYearValue, selectedDate]);
2970
3022
  return (React.createElement("div", { className: "bianic-datepicker-calendar flex flex-col gap-[15px] text-bia-black", ref: ref },
2971
3023
  React.createElement("div", { className: "bianic-datepicker-calendar-controller flex w-full items-center justify-between" },
2972
- React.createElement("button", { className: "bianic-datepicker-calendar-prev-button ".concat(chevronButtonStyle), onClick: function () { return handlePrevAction(); } },
3024
+ React.createElement("button", { className: "bianic-datepicker-calendar-prev-button ".concat(chevronButtonStyle), disabled: minDateValue !== null &&
3025
+ yearDisplayRange.includes(minDateValue.getFullYear()) &&
3026
+ viewYearValue <= minDateValue.getFullYear() &&
3027
+ viewMonthValue <= minDateValue.getMonth(), onClick: function () { return handlePrevAction(); } },
2973
3028
  React.createElement(TbChevronLeft, { size: 18 })),
2974
3029
  React.createElement("div", { className: "bianic-datepicker-calendar-current-month gap flex items-center justify-center gap-1" },
2975
3030
  React.createElement("button", { className: "".concat(pickerMode === 'date' ? '' : 'hidden'), onClick: function () { return handlePickerMode('month'); } },
@@ -2980,13 +3035,25 @@ var PickerCalendar = function (_a) {
2980
3035
  React.createElement(Text, { variant: "normal-text" }, viewYearValue)),
2981
3036
  React.createElement("button", { className: "".concat(pickerMode === 'year' ? '' : 'hidden') },
2982
3037
  React.createElement(Text, { variant: "normal-text" }, "".concat(yearDisplayRange[1], " - ").concat(yearDisplayRange[10])))),
2983
- React.createElement("button", { className: "bianic-datepicker-calendar-next-button ".concat(chevronButtonStyle), onClick: function () { return handleNextAction(); } },
3038
+ React.createElement("button", { className: "bianic-datepicker-calendar-next-button ".concat(chevronButtonStyle), disabled: maxDateValue !== null &&
3039
+ yearDisplayRange.includes(maxDateValue.getFullYear()) &&
3040
+ viewYearValue >= maxDateValue.getFullYear() &&
3041
+ viewMonthValue >= maxDateValue.getMonth(), onClick: function () { return handleNextAction(); } },
2984
3042
  React.createElement(TbChevronRight, { size: 18 }))),
2985
3043
  React.createElement("div", { className: "bianic-datepicker-calendar-days-grid flex flex-col " },
2986
3044
  dateDisplay,
2987
3045
  monthDisplay,
2988
3046
  yearDisplay)));
2989
3047
  };
3048
+ var dateToInputString$1 = function (dateObj) {
3049
+ if (!(dateObj instanceof Date) || isNaN(dateObj))
3050
+ return ''; // Return empty string for invalid dates
3051
+ // Use local time methods for consistent display/input
3052
+ var year = dateObj.getFullYear();
3053
+ var month = String(dateObj.getMonth() + 1).padStart(2, '0');
3054
+ var day = String(dateObj.getDate()).padStart(2, '0');
3055
+ return "".concat(year, "-").concat(month, "-").concat(day);
3056
+ };
2990
3057
 
2991
3058
  var monthMap = [
2992
3059
  'January',
@@ -3002,8 +3069,72 @@ var monthMap = [
3002
3069
  'November',
3003
3070
  'December',
3004
3071
  ];
3072
+ var DateInputDisplay = function (_a) {
3073
+ var value = _a.value, setValue = _a.setValue, _b = _a.placeholder, placeholder = _b === void 0 ? 'YYYY-MM-DD' : _b, label = _a.label, required = _a.required, id = _a.id, _c = _a.size, size = _c === void 0 ? 'sm' : _c, className = _a.className, _d = _a.disabled, disabled = _d === void 0 ? false : _d, buttonAction = _a.buttonAction, nullDisplay = _a.nullDisplay, props = __rest(_a, ["value", "setValue", "placeholder", "label", "required", "id", "size", "className", "disabled", "buttonAction", "nullDisplay"]);
3074
+ var _e = React.useState(false), isEditing = _e[0], setIsEditing = _e[1];
3075
+ var _f = React.useState(value), dateString = _f[0], setDateString = _f[1];
3076
+ var _g = styleConfig['text'], fieldStyle = _g.fieldStyle;
3077
+ var _h = sizeConfig$c[size], iconSize = _h.iconSize, fieldSize = _h.fieldSize, iconPosition = _h.iconPosition;
3078
+ var borderStyle = 'border border-bia-grey-dark-10 bg-primary-white';
3079
+ var extendedInputClassName = "".concat(fieldStyle, " ").concat(fieldSize, " ").concat(borderStyle, " ").concat(className);
3080
+ var labelStatus = props.readOnly ? 'read-only:pointer-events-none' : '';
3081
+ var handleTextChange = function (event) {
3082
+ var rawValue = event.target.value;
3083
+ setDateString(rawValue); // Update the displayed text input immediately
3084
+ // --- Validation and Conversion Logic ---
3085
+ if (rawValue) {
3086
+ var newDate = new Date(rawValue);
3087
+ if (!isNaN(newDate.getTime())) {
3088
+ // If valid, update the Date object state
3089
+ if (setValue)
3090
+ setValue(rawValue);
3091
+ return;
3092
+ }
3093
+ }
3094
+ // If the string is empty or invalid, set the Date object state to null
3095
+ if (setValue)
3096
+ setValue('');
3097
+ };
3098
+ var handleBlur = function () {
3099
+ setIsEditing(false);
3100
+ setDateString(value);
3101
+ };
3102
+ var input = isEditing ? (React.createElement(TextInput, { type: "text", value: dateString !== null && dateString !== void 0 ? dateString : '', onChange: handleTextChange, onBlur: handleBlur, placeholder: placeholder, size: size, inputClassName: className, autoFocus: true, actionElement: React.createElement("button", { className: "bianic-datepicker-toggle-button text-bia-coolgrey", disabled: disabled, onClick: function () {
3103
+ buttonAction && buttonAction();
3104
+ } },
3105
+ React.createElement(TbCalendar, { size: iconSize })) })) : (React.createElement(React.Fragment, null,
3106
+ React.createElement("div", { role: "button", onClick: function () { return setIsEditing(true); }, className: "bianic-text-input bianic-fgc-target w-full min-w-[185px] rounded hover:rounded-b-none hover:border-b-bia-blue focus:rounded-b-none focus-visible:outline-none disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-80 disabled:text-bia-grey-active ".concat(extendedInputClassName, " ").concat(value || nullDisplay ? 'text-bia-black' : 'text-bia-coolgrey', " ").concat(className) }, value
3107
+ ? displayDateFormatter(new Date(value))
3108
+ : nullDisplay || placeholder),
3109
+ React.createElement("div", { className: "absolute inset-y-0 flex items-center pl-3 text-bia-coolgrey ".concat(iconPosition) },
3110
+ React.createElement("button", { className: "bianic-datepicker-toggle-button", disabled: disabled, onClick: function () { return buttonAction && buttonAction(); } },
3111
+ React.createElement(TbCalendar, { size: iconSize })))));
3112
+ React.useEffect(function () {
3113
+ // Only update dateString if we are NOT currently editing.
3114
+ if (!isEditing)
3115
+ setDateString(value ? dateToInputString(new Date(value)) : '');
3116
+ }, [value, isEditing]);
3117
+ return (React.createElement("div", { className: "bianic-date-input-container bianic-fgc-container flex w-full flex-col gap-y-2 text-bia-black" },
3118
+ label && (React.createElement("label", { htmlFor: id, className: "bianic-text-input-label text-xs font-semibold ".concat(labelStatus) },
3119
+ label,
3120
+ required && React.createElement("span", { className: "p-1 text-bia-red" }, "*"))),
3121
+ React.createElement("div", { className: "relative w-full" }, input)));
3122
+ };
3123
+ var dateToInputString = function (dateObj) {
3124
+ if (!(dateObj instanceof Date) || isNaN(dateObj))
3125
+ return ''; // Return empty string for invalid dates
3126
+ // Use local time methods for consistent display/input
3127
+ var year = dateObj.getFullYear();
3128
+ var month = String(dateObj.getMonth() + 1).padStart(2, '0');
3129
+ var day = String(dateObj.getDate()).padStart(2, '0');
3130
+ return "".concat(year, "-").concat(month, "-").concat(day);
3131
+ };
3132
+ var displayDateFormatter = function (date) {
3133
+ return "".concat(date.getDate(), " ").concat(monthMap[date.getMonth()].slice(0, 3), " '").concat(date.getFullYear().toString().slice(2, 4));
3134
+ };
3135
+
3005
3136
  function DatePicker(_a) {
3006
- var value = _a.value, onChange = _a.onChange, size = _a.size, disabled = _a.disabled, _b = _a.placeholder, placeholder = _b === void 0 ? '"YYYY-MM-DD"' : _b, label = _a.label, descText = _a.descText, required = _a.required;
3137
+ var className = _a.className, value = _a.value, onChange = _a.onChange, size = _a.size, disabled = _a.disabled; _a.placeholder; var label = _a.label, minDate = _a.minDate, maxDate = _a.maxDate, required = _a.required, nullDisplay = _a.nullDisplay;
3007
3138
  // State and Ref
3008
3139
  var inputRef = React.useRef(null);
3009
3140
  var wrapperRef = React.useRef(null);
@@ -3011,114 +3142,10 @@ function DatePicker(_a) {
3011
3142
  var _c = useDetectOutsideClick(wrapperRef, false, pickerRef), isPickerOpen = _c[0], setIsPickerOpen = _c[1];
3012
3143
  return (React.createElement("div", { className: "bianic-datepicker-container relative", ref: wrapperRef },
3013
3144
  React.createElement("div", { className: "bianic-datepicker-field-container" },
3014
- React.createElement(DateInput, { ref: inputRef, placeholder: placeholder, value: value, onChange: onChange, size: size, disabled: disabled, buttonAction: function () { return setIsPickerOpen(true); }, setIsActive: setIsPickerOpen, label: label, descText: descText, required: required })),
3145
+ React.createElement(DateInputDisplay, { inputClassName: className, value: value, setValue: onChange, placeholder: "YYYY-MM-DD", nullDisplay: nullDisplay, size: size, label: label, required: required, buttonAction: function () { return setIsPickerOpen(!isPickerOpen); }, ref: inputRef, disabled: disabled })),
3015
3146
  isPickerOpen && (React.createElement("div", { className: "bianic-datepicker-calendar-container absolute left-0 w-[250px] rounded-b-radius-sm bg-bia-white px-1.5 pb-[17px] pt-[15px] shadow-md" },
3016
- React.createElement(PickerCalendar, { selectedDate: new Date(value), onDateChange: onChange, ref: pickerRef })))));
3147
+ React.createElement(PickerCalendar, { selectedDate: value, onDateChange: onChange, ref: pickerRef, minDate: minDate, maxDate: maxDate })))));
3017
3148
  }
3018
- var DateInput = function (_a) {
3019
- var className = _a.className, value = _a.value; _a.isActive; var setIsActive = _a.setIsActive, label = _a.label, id = _a.id, _b = _a.size, size = _b === void 0 ? 'md' : _b, onChange = _a.onChange, _c = _a.required, required = _c === void 0 ? false : _c, _d = _a.disabled, disabled = _d === void 0 ? false : _d, buttonAction = _a.buttonAction, readOnly = _a.readOnly, descText = _a.descText, props = __rest(_a, ["className", "value", "isActive", "setIsActive", "label", "id", "size", "onChange", "required", "disabled", "buttonAction", "readOnly", "descText"]);
3020
- var editDateFormatter = function (date) {
3021
- var localString = date.toLocaleDateString().split('/');
3022
- return localString.reverse().join('-');
3023
- };
3024
- var displayDateFormatter = function (date) {
3025
- return "".concat(date.getDate(), " ").concat(monthMap[date.getMonth()].slice(0, 3), " '").concat(date.getFullYear().toString().slice(2, 4));
3026
- };
3027
- // Convert Date to string for display
3028
- var formattedValue = value instanceof Date ? displayDateFormatter(value) : value;
3029
- var _e = React.useState(formattedValue), viewValue = _e[0], setViewValue = _e[1];
3030
- React.useRef(null);
3031
- var _f = React.useState(0); _f[0]; _f[1];
3032
- var _g = styleConfig['text'], fieldStyle = _g.fieldStyle;
3033
- var _h = sizeConfig$c[size], iconSize = _h.iconSize, fieldSize = _h.fieldSize, iconPosition = _h.iconPosition;
3034
- var borderStyle = 'border border-bia-grey-dark-10 bg-primary-white';
3035
- var extendedInputClassName = "".concat(fieldStyle, " ").concat(fieldSize, " ").concat(borderStyle, " ").concat(className);
3036
- var validateAndFormatDate = function (value) {
3037
- // 1. validate separator
3038
- var splittedDate = value.split('-');
3039
- if (splittedDate.length !== 3) {
3040
- return [1, value]; // Invalid format
3041
- }
3042
- var year = splittedDate[0];
3043
- var month = splittedDate[1];
3044
- var day = splittedDate[2];
3045
- // 2. validate year
3046
- if (!/^\d{4}$/.test(year)) {
3047
- return [2, value];
3048
- }
3049
- var parsedYear = parseInt(year, 10);
3050
- // 3. validate month digit
3051
- if (!/^\d{1,2}$/.test(month)) {
3052
- return [3, value];
3053
- }
3054
- // 4. validate month range
3055
- var parsedMonth = parseInt(month, 10);
3056
- if (parsedMonth < 1 || parsedMonth > 12) {
3057
- return [4, value];
3058
- }
3059
- var formattedMonth = String(parsedMonth).padStart(2, '0');
3060
- // 5. validate date digit
3061
- if (!/^\d{1,2}$/.test(day)) {
3062
- return [5, value];
3063
- }
3064
- // 6. validate date range
3065
- var parsedDate = parseInt(day, 10);
3066
- if (parsedDate < 1 || parsedDate > 31) {
3067
- return [6, value];
3068
- }
3069
- var formattedDay = String(parsedDate).padStart(2, '0');
3070
- // 7. validate date rightness
3071
- var dateObject = new Date(parsedYear, parsedMonth - 1, parsedDate);
3072
- if (dateObject.getFullYear() !== parsedYear ||
3073
- dateObject.getMonth() !== parsedMonth - 1 ||
3074
- dateObject.getDate() !== parsedDate) {
3075
- return [7, value];
3076
- }
3077
- // If all checks pass, the date is valid and formatted
3078
- var formattedDate = "".concat(year, "-").concat(formattedMonth, "-").concat(formattedDay);
3079
- return [0, formattedDate];
3080
- };
3081
- // Update actual value on release
3082
- var updateValue = function (newValue) {
3083
- var date = new Date(newValue); // Create a Date object from the input
3084
- if (onChange && !Number.isNaN(date.valueOf())) {
3085
- onChange(date); // Update the value if it's a valid date
3086
- }
3087
- };
3088
- var handleChange = function (event) {
3089
- var value = event.target.value;
3090
- // Regular expression to allow only numbers (0-9) and hyphens (-)
3091
- // The caret (^) matches the beginning of the string, and the dollar sign ($) matches the end.
3092
- // This ensures the *entire* string matches the pattern.
3093
- var regex = /^[0-9-]*$/;
3094
- if (regex.test(value)) {
3095
- setViewValue(value);
3096
- }
3097
- };
3098
- React.useEffect(function () {
3099
- setViewValue(formattedValue);
3100
- }, [value]);
3101
- return (React.createElement("div", { className: "bianic-date-input-container bianic-fgc-container group/form flex w-full flex-col gap-y-2 text-bia-black " },
3102
- label && (React.createElement(FormLabel, { htmlFor: id, required: required, readOnly: readOnly }, label)),
3103
- React.createElement("div", { className: "relative w-full" },
3104
- React.createElement("input", __assign({}, props, { type: "text", className: "bianic-text-input bianic-fgc-target w-full rounded read-only:pointer-events-none read-only:border-bia-grey-light-50 hover:rounded-b-none hover:border-b-bia-blue focus:rounded-b-none focus-visible:outline-none disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-80 disabled:text-bia-grey-active ".concat(extendedInputClassName), id: id, value: viewValue, disabled: disabled, onChange: handleChange, required: required, onFocus: function () {
3105
- setIsActive && setIsActive(true);
3106
- setViewValue(editDateFormatter(value));
3107
- }, onBlur: function () {
3108
- var _a = validateAndFormatDate(viewValue), status = _a[0], validatedValue = _a[1];
3109
- setViewValue(displayDateFormatter(value));
3110
- if (status !== 0) ;
3111
- else {
3112
- updateValue(validatedValue);
3113
- }
3114
- }, maxLength: 10 })),
3115
- React.createElement("div", { className: "absolute inset-y-0 flex items-center pl-3 text-bia-coolgrey ".concat(iconPosition) },
3116
- React.createElement("button", { className: "bianic-datepicker-toggle-button", disabled: disabled, onClick: function () {
3117
- buttonAction && buttonAction();
3118
- } },
3119
- React.createElement(TbCalendar, { size: iconSize })))),
3120
- descText && (React.createElement("span", { className: "desc text-xs text-primary-cool" }, descText))));
3121
- };
3122
3149
 
3123
3150
  var Node = function (_a) {
3124
3151
  var className = _a.className, _b = _a.fill, fill = _b === void 0 ? 'currentColor' : _b, _c = _a.size, size = _c === void 0 ? 20 : _c;
@@ -4094,6 +4121,7 @@ exports.MenuItem = MenuItem;
4094
4121
  exports.Modal = Modal;
4095
4122
  exports.P = P;
4096
4123
  exports.PaginationBar = PaginationBar;
4124
+ exports.PickerCalendar = PickerCalendar;
4097
4125
  exports.Pills = Pills;
4098
4126
  exports.Popover = Popover;
4099
4127
  exports.ProgressBar = ProgressBar;