@ceed/cds 1.29.1 → 1.30.1
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/components/Calendar/utils/index.d.ts +1 -0
- package/dist/components/DatePicker/DatePicker.d.ts +4 -0
- package/dist/components/DateRangePicker/DateRangePicker.d.ts +4 -0
- package/dist/components/MonthRangePicker/MonthRangePicker.d.ts +8 -0
- package/dist/components/inputs/DatePicker.md +43 -25
- package/dist/components/inputs/DateRangePicker.md +39 -24
- package/dist/components/inputs/MonthPicker.md +52 -23
- package/dist/components/inputs/MonthRangePicker.md +37 -21
- package/dist/index.browser.js +4 -4
- package/dist/index.browser.js.map +3 -3
- package/dist/index.cjs +105 -42
- package/dist/index.js +105 -42
- package/framer/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -895,6 +895,9 @@ var getMonthName = (date, locale, options) => {
|
|
|
895
895
|
...options?.hideYear ? {} : { year: "numeric" }
|
|
896
896
|
});
|
|
897
897
|
};
|
|
898
|
+
var getShortMonthName = (date, locale) => {
|
|
899
|
+
return date.toLocaleString(locale, { month: "short" });
|
|
900
|
+
};
|
|
898
901
|
var getMonthNameFromIndex = (index, locale) => {
|
|
899
902
|
return new Date(0, index).toLocaleString(locale, { month: "short" });
|
|
900
903
|
};
|
|
@@ -2538,6 +2541,7 @@ DialogActions.displayName = "DialogActions";
|
|
|
2538
2541
|
var DialogActions_default = DialogActions;
|
|
2539
2542
|
|
|
2540
2543
|
// src/components/DatePicker/DatePicker.tsx
|
|
2544
|
+
var hasAlphabeticMonth = (format) => /MMMM|MMM/.test(format);
|
|
2541
2545
|
var CalendarButton = (0, import_joy28.styled)(IconButton_default, {
|
|
2542
2546
|
name: "DatePicker",
|
|
2543
2547
|
slot: "calendarButton"
|
|
@@ -2608,6 +2612,7 @@ var DatePickerRoot = (0, import_joy28.styled)("div", {
|
|
|
2608
2612
|
width: "100%"
|
|
2609
2613
|
});
|
|
2610
2614
|
var validValueFormat = (value, format) => {
|
|
2615
|
+
if (hasAlphabeticMonth(format)) return true;
|
|
2611
2616
|
try {
|
|
2612
2617
|
const parsedValue = parseDate(value, format);
|
|
2613
2618
|
if (parsedValue.toString() === "Invalid Date") {
|
|
@@ -2622,13 +2627,15 @@ var validValueFormat = (value, format) => {
|
|
|
2622
2627
|
return false;
|
|
2623
2628
|
}
|
|
2624
2629
|
};
|
|
2625
|
-
var formatValueString = (date, format) => {
|
|
2630
|
+
var formatValueString = (date, format, locale = "default") => {
|
|
2626
2631
|
let day = `${date.getDate()}`;
|
|
2627
2632
|
let month = `${date.getMonth() + 1}`;
|
|
2628
2633
|
const year = date.getFullYear();
|
|
2629
2634
|
if (Number(day) < 10) day = "0" + day;
|
|
2630
2635
|
if (Number(month) < 10) month = "0" + month;
|
|
2631
|
-
|
|
2636
|
+
const monthName = getMonthName(date, locale, { hideYear: true });
|
|
2637
|
+
const shortMonthName = getShortMonthName(date, locale);
|
|
2638
|
+
return format.replace(/MMMM/g, monthName).replace(/MMM/g, shortMonthName).replace(/MM/g, month).replace(/DD/g, day).replace(/YYYY/g, year.toString());
|
|
2632
2639
|
};
|
|
2633
2640
|
function parseDate(dateString, format) {
|
|
2634
2641
|
const formatParts = format.split(/[-./\s]/);
|
|
@@ -2713,6 +2720,7 @@ var DatePicker = (0, import_react20.forwardRef)((inProps, ref) => {
|
|
|
2713
2720
|
format = "YYYY/MM/DD",
|
|
2714
2721
|
displayFormat = "YYYY/MM/DD",
|
|
2715
2722
|
size,
|
|
2723
|
+
locale = "default",
|
|
2716
2724
|
inputReadOnly,
|
|
2717
2725
|
hideClearButton,
|
|
2718
2726
|
readOnly,
|
|
@@ -2727,8 +2735,9 @@ var DatePicker = (0, import_react20.forwardRef)((inProps, ref) => {
|
|
|
2727
2735
|
props.defaultValue || "",
|
|
2728
2736
|
(0, import_react20.useCallback)((value2) => onChange?.({ target: { name: props.name, value: value2 } }), [props.name, onChange])
|
|
2729
2737
|
);
|
|
2738
|
+
const isAlphabeticDisplay = hasAlphabeticMonth(displayFormat);
|
|
2730
2739
|
const [displayValue, setDisplayValue] = (0, import_react20.useState)(
|
|
2731
|
-
() => value ? formatValueString(parseDate(value, format), displayFormat) : ""
|
|
2740
|
+
() => value ? formatValueString(parseDate(value, format), displayFormat, locale) : ""
|
|
2732
2741
|
);
|
|
2733
2742
|
const [anchorEl, setAnchorEl] = (0, import_react20.useState)(null);
|
|
2734
2743
|
const open = Boolean(anchorEl);
|
|
@@ -2742,19 +2751,19 @@ var DatePicker = (0, import_react20.forwardRef)((inProps, ref) => {
|
|
|
2742
2751
|
setDisplayValue("");
|
|
2743
2752
|
return;
|
|
2744
2753
|
}
|
|
2745
|
-
const formattedValue = formatValueString(parseDate(value, format), displayFormat);
|
|
2754
|
+
const formattedValue = formatValueString(parseDate(value, format), displayFormat, locale);
|
|
2746
2755
|
if (validValueFormat(formattedValue, displayFormat) && formattedValue !== displayValue) {
|
|
2747
2756
|
setDisplayValue(formattedValue);
|
|
2748
2757
|
}
|
|
2749
|
-
}, [displayFormat, displayValue, format, value]);
|
|
2758
|
+
}, [displayFormat, displayValue, format, locale, value]);
|
|
2750
2759
|
(0, import_react20.useImperativeHandle)(ref, () => innerRef.current, [innerRef]);
|
|
2751
2760
|
const handleChange = (0, import_react20.useCallback)(
|
|
2752
2761
|
(event) => {
|
|
2753
2762
|
const value2 = event.target.value;
|
|
2754
|
-
setDisplayValue(value2 ? formatValueString(parseDate(value2, format), displayFormat) : value2);
|
|
2763
|
+
setDisplayValue(value2 ? formatValueString(parseDate(value2, format), displayFormat, locale) : value2);
|
|
2755
2764
|
setValue(value2);
|
|
2756
2765
|
},
|
|
2757
|
-
[displayFormat, format, setValue]
|
|
2766
|
+
[displayFormat, format, locale, setValue]
|
|
2758
2767
|
);
|
|
2759
2768
|
const handleDisplayInputChange = (0, import_react20.useCallback)(
|
|
2760
2769
|
(event) => {
|
|
@@ -2792,12 +2801,12 @@ var DatePicker = (0, import_react20.forwardRef)((inProps, ref) => {
|
|
|
2792
2801
|
);
|
|
2793
2802
|
const handleInputMouseDown = (0, import_react20.useCallback)(
|
|
2794
2803
|
(event) => {
|
|
2795
|
-
if (inputReadOnly) {
|
|
2804
|
+
if (inputReadOnly || isAlphabeticDisplay) {
|
|
2796
2805
|
event.preventDefault();
|
|
2797
2806
|
buttonRef.current?.focus();
|
|
2798
2807
|
}
|
|
2799
2808
|
},
|
|
2800
|
-
[inputReadOnly, buttonRef]
|
|
2809
|
+
[inputReadOnly, isAlphabeticDisplay, buttonRef]
|
|
2801
2810
|
);
|
|
2802
2811
|
const handlePresetClick = (0, import_react20.useCallback)(
|
|
2803
2812
|
(presetValue) => {
|
|
@@ -2843,12 +2852,11 @@ var DatePicker = (0, import_react20.forwardRef)((inProps, ref) => {
|
|
|
2843
2852
|
error,
|
|
2844
2853
|
slotProps: {
|
|
2845
2854
|
input: {
|
|
2846
|
-
component: TextMaskAdapter3,
|
|
2855
|
+
...isAlphabeticDisplay ? {} : { component: TextMaskAdapter3, format: displayFormat },
|
|
2847
2856
|
ref: innerRef,
|
|
2848
|
-
format: displayFormat,
|
|
2849
2857
|
sx: {
|
|
2850
2858
|
"&:hover": {
|
|
2851
|
-
cursor: inputReadOnly || readOnly ? "default" : "text"
|
|
2859
|
+
cursor: isAlphabeticDisplay || inputReadOnly || readOnly ? "default" : "text"
|
|
2852
2860
|
}
|
|
2853
2861
|
},
|
|
2854
2862
|
onMouseDown: handleInputMouseDown
|
|
@@ -2872,7 +2880,7 @@ var DatePicker = (0, import_react20.forwardRef)((inProps, ref) => {
|
|
|
2872
2880
|
),
|
|
2873
2881
|
label,
|
|
2874
2882
|
helperText,
|
|
2875
|
-
readOnly: readOnly || inputReadOnly
|
|
2883
|
+
readOnly: readOnly || inputReadOnly || isAlphabeticDisplay
|
|
2876
2884
|
}
|
|
2877
2885
|
), open && /* @__PURE__ */ import_react20.default.createElement(import_base3.ClickAwayListener, { onClickAway: () => setAnchorEl(null) }, /* @__PURE__ */ import_react20.default.createElement(
|
|
2878
2886
|
StyledPopper,
|
|
@@ -2910,7 +2918,8 @@ var DatePicker = (0, import_react20.forwardRef)((inProps, ref) => {
|
|
|
2910
2918
|
maxDate: maxDate ? new Date(maxDate) : void 0,
|
|
2911
2919
|
disableFuture,
|
|
2912
2920
|
disablePast,
|
|
2913
|
-
shouldDisableDate: shouldDisableDate ? (date) => shouldDisableDate(formatValueString(date, format)) : void 0
|
|
2921
|
+
shouldDisableDate: shouldDisableDate ? (date) => shouldDisableDate(formatValueString(date, format)) : void 0,
|
|
2922
|
+
locale
|
|
2914
2923
|
}
|
|
2915
2924
|
), !hideClearButton && /* @__PURE__ */ import_react20.default.createElement(
|
|
2916
2925
|
DialogActions_default,
|
|
@@ -4761,6 +4770,7 @@ var import_react_imask2 = require("react-imask");
|
|
|
4761
4770
|
var import_CalendarToday2 = __toESM(require("@mui/icons-material/CalendarToday"));
|
|
4762
4771
|
var import_joy36 = require("@mui/joy");
|
|
4763
4772
|
var import_base4 = require("@mui/base");
|
|
4773
|
+
var hasAlphabeticMonth2 = (format) => /MMMM|MMM/.test(format);
|
|
4764
4774
|
var CalendarButton2 = (0, import_joy36.styled)(IconButton_default, {
|
|
4765
4775
|
name: "DateRangePicker",
|
|
4766
4776
|
slot: "calendarButton"
|
|
@@ -4832,6 +4842,7 @@ var DateRangePickerRoot = (0, import_joy36.styled)("div", {
|
|
|
4832
4842
|
width: "100%"
|
|
4833
4843
|
});
|
|
4834
4844
|
var validValueFormat2 = (value, format) => {
|
|
4845
|
+
if (hasAlphabeticMonth2(format)) return true;
|
|
4835
4846
|
try {
|
|
4836
4847
|
const [date1Str, date2Str] = value.split(" - ");
|
|
4837
4848
|
if (!date1Str || !date2Str) {
|
|
@@ -4854,14 +4865,16 @@ var validValueFormat2 = (value, format) => {
|
|
|
4854
4865
|
return false;
|
|
4855
4866
|
}
|
|
4856
4867
|
};
|
|
4857
|
-
var formatValueString2 = ([date1, date2], format) => {
|
|
4868
|
+
var formatValueString2 = ([date1, date2], format, locale = "default") => {
|
|
4858
4869
|
const getStr = (date) => {
|
|
4859
4870
|
let day = `${date.getDate()}`;
|
|
4860
4871
|
let month = `${date.getMonth() + 1}`;
|
|
4861
4872
|
const year = date.getFullYear();
|
|
4862
4873
|
if (Number(day) < 10) day = "0" + day;
|
|
4863
4874
|
if (Number(month) < 10) month = "0" + month;
|
|
4864
|
-
|
|
4875
|
+
const monthName = getMonthName(date, locale, { hideYear: true });
|
|
4876
|
+
const shortMonthName = getShortMonthName(date, locale);
|
|
4877
|
+
return format.replace(/MMMM/g, monthName).replace(/MMM/g, shortMonthName).replace(/MM/g, month).replace(/DD/g, day).replace(/YYYY/g, year.toString());
|
|
4865
4878
|
};
|
|
4866
4879
|
return [getStr(date1), date2 ? getStr(date2) : ""].join(" - ");
|
|
4867
4880
|
};
|
|
@@ -4949,6 +4962,7 @@ var DateRangePicker = (0, import_react29.forwardRef)((inProps, ref) => {
|
|
|
4949
4962
|
format = "YYYY/MM/DD",
|
|
4950
4963
|
displayFormat = "YYYY/MM/DD",
|
|
4951
4964
|
size,
|
|
4965
|
+
locale = "default",
|
|
4952
4966
|
inputReadOnly,
|
|
4953
4967
|
hideClearButton,
|
|
4954
4968
|
readOnly,
|
|
@@ -4962,8 +4976,9 @@ var DateRangePicker = (0, import_react29.forwardRef)((inProps, ref) => {
|
|
|
4962
4976
|
props.defaultValue || "",
|
|
4963
4977
|
(0, import_react29.useCallback)((value2) => onChange?.({ target: { name: props.name, value: value2 } }), [props.name, onChange])
|
|
4964
4978
|
);
|
|
4979
|
+
const isAlphabeticDisplay = hasAlphabeticMonth2(displayFormat);
|
|
4965
4980
|
const [displayValue, setDisplayValue] = (0, import_react29.useState)(
|
|
4966
|
-
() => value ? formatValueString2(parseDates(value, format), displayFormat) : ""
|
|
4981
|
+
() => value ? formatValueString2(parseDates(value, format), displayFormat, locale) : ""
|
|
4967
4982
|
);
|
|
4968
4983
|
const [anchorEl, setAnchorEl] = (0, import_react29.useState)(null);
|
|
4969
4984
|
const open = Boolean(anchorEl);
|
|
@@ -4975,14 +4990,14 @@ var DateRangePicker = (0, import_react29.forwardRef)((inProps, ref) => {
|
|
|
4975
4990
|
if (value) {
|
|
4976
4991
|
try {
|
|
4977
4992
|
const dates = parseDates(value, format);
|
|
4978
|
-
const newDisplayValue = formatValueString2(dates, displayFormat);
|
|
4993
|
+
const newDisplayValue = formatValueString2(dates, displayFormat, locale);
|
|
4979
4994
|
setDisplayValue(newDisplayValue);
|
|
4980
4995
|
} catch (error2) {
|
|
4981
4996
|
}
|
|
4982
4997
|
} else {
|
|
4983
4998
|
setDisplayValue("");
|
|
4984
4999
|
}
|
|
4985
|
-
}, [displayFormat, value, format]);
|
|
5000
|
+
}, [displayFormat, locale, value, format]);
|
|
4986
5001
|
(0, import_react29.useEffect)(() => {
|
|
4987
5002
|
if (!anchorEl) {
|
|
4988
5003
|
innerRef.current?.blur();
|
|
@@ -4992,10 +5007,10 @@ var DateRangePicker = (0, import_react29.forwardRef)((inProps, ref) => {
|
|
|
4992
5007
|
const handleChange = (0, import_react29.useCallback)(
|
|
4993
5008
|
(event) => {
|
|
4994
5009
|
const value2 = event.target.value;
|
|
4995
|
-
setDisplayValue(value2 ? formatValueString2(parseDates(value2, format), displayFormat) : value2);
|
|
5010
|
+
setDisplayValue(value2 ? formatValueString2(parseDates(value2, format), displayFormat, locale) : value2);
|
|
4996
5011
|
setValue(value2);
|
|
4997
5012
|
},
|
|
4998
|
-
[displayFormat, format, setValue]
|
|
5013
|
+
[displayFormat, format, locale, setValue]
|
|
4999
5014
|
);
|
|
5000
5015
|
const handleDisplayInputChange = (0, import_react29.useCallback)(
|
|
5001
5016
|
(event) => {
|
|
@@ -5036,21 +5051,21 @@ var DateRangePicker = (0, import_react29.forwardRef)((inProps, ref) => {
|
|
|
5036
5051
|
if (props.value !== void 0) {
|
|
5037
5052
|
onChange?.({ target: { name: props.name, value: formattedValue } });
|
|
5038
5053
|
} else {
|
|
5039
|
-
setDisplayValue(formatValueString2([date1, date2], displayFormat));
|
|
5054
|
+
setDisplayValue(formatValueString2([date1, date2], displayFormat, locale));
|
|
5040
5055
|
setValue(formattedValue);
|
|
5041
5056
|
}
|
|
5042
5057
|
setAnchorEl(null);
|
|
5043
5058
|
},
|
|
5044
|
-
[props.value, props.name, onChange, setValue, setAnchorEl, format, displayFormat]
|
|
5059
|
+
[props.value, props.name, onChange, setValue, setAnchorEl, format, displayFormat, locale]
|
|
5045
5060
|
);
|
|
5046
5061
|
const handleInputMouseDown = (0, import_react29.useCallback)(
|
|
5047
5062
|
(event) => {
|
|
5048
|
-
if (inputReadOnly) {
|
|
5063
|
+
if (inputReadOnly || isAlphabeticDisplay) {
|
|
5049
5064
|
event.preventDefault();
|
|
5050
5065
|
buttonRef.current?.focus();
|
|
5051
5066
|
}
|
|
5052
5067
|
},
|
|
5053
|
-
[inputReadOnly, buttonRef]
|
|
5068
|
+
[inputReadOnly, isAlphabeticDisplay, buttonRef]
|
|
5054
5069
|
);
|
|
5055
5070
|
const handlePresetClick = (0, import_react29.useCallback)(
|
|
5056
5071
|
(presetValue) => {
|
|
@@ -5058,12 +5073,12 @@ var DateRangePicker = (0, import_react29.forwardRef)((inProps, ref) => {
|
|
|
5058
5073
|
onChange?.({ target: { name: props.name, value: presetValue } });
|
|
5059
5074
|
} else {
|
|
5060
5075
|
const dates = parseDates(presetValue, format);
|
|
5061
|
-
setDisplayValue(formatValueString2(dates, displayFormat));
|
|
5076
|
+
setDisplayValue(formatValueString2(dates, displayFormat, locale));
|
|
5062
5077
|
setValue(presetValue);
|
|
5063
5078
|
}
|
|
5064
5079
|
setAnchorEl(null);
|
|
5065
5080
|
},
|
|
5066
|
-
[props.value, props.name, onChange, setValue, setAnchorEl, format, displayFormat]
|
|
5081
|
+
[props.value, props.name, onChange, setValue, setAnchorEl, format, displayFormat, locale]
|
|
5067
5082
|
);
|
|
5068
5083
|
const isPresetDisabled = (0, import_react29.useCallback)(
|
|
5069
5084
|
(presetValue) => {
|
|
@@ -5098,12 +5113,11 @@ var DateRangePicker = (0, import_react29.forwardRef)((inProps, ref) => {
|
|
|
5098
5113
|
placeholder: `${displayFormat} - ${displayFormat}`,
|
|
5099
5114
|
slotProps: {
|
|
5100
5115
|
input: {
|
|
5101
|
-
component: TextMaskAdapter5,
|
|
5116
|
+
...isAlphabeticDisplay ? {} : { component: TextMaskAdapter5, format: displayFormat },
|
|
5102
5117
|
ref: innerRef,
|
|
5103
|
-
format: displayFormat,
|
|
5104
5118
|
sx: {
|
|
5105
5119
|
"&:hover": {
|
|
5106
|
-
cursor: inputReadOnly || readOnly ? "default" : "text"
|
|
5120
|
+
cursor: isAlphabeticDisplay || inputReadOnly || readOnly ? "default" : "text"
|
|
5107
5121
|
}
|
|
5108
5122
|
},
|
|
5109
5123
|
onMouseDown: handleInputMouseDown
|
|
@@ -5128,7 +5142,7 @@ var DateRangePicker = (0, import_react29.forwardRef)((inProps, ref) => {
|
|
|
5128
5142
|
),
|
|
5129
5143
|
label,
|
|
5130
5144
|
helperText,
|
|
5131
|
-
readOnly: readOnly || inputReadOnly
|
|
5145
|
+
readOnly: readOnly || inputReadOnly || isAlphabeticDisplay
|
|
5132
5146
|
}
|
|
5133
5147
|
), open && /* @__PURE__ */ import_react29.default.createElement(import_base4.ClickAwayListener, { onClickAway: () => setAnchorEl(null) }, /* @__PURE__ */ import_react29.default.createElement(
|
|
5134
5148
|
StyledPopper2,
|
|
@@ -5158,7 +5172,8 @@ var DateRangePicker = (0, import_react29.forwardRef)((inProps, ref) => {
|
|
|
5158
5172
|
minDate: minDate ? new Date(minDate) : void 0,
|
|
5159
5173
|
maxDate: maxDate ? new Date(maxDate) : void 0,
|
|
5160
5174
|
disableFuture,
|
|
5161
|
-
disablePast
|
|
5175
|
+
disablePast,
|
|
5176
|
+
locale
|
|
5162
5177
|
}
|
|
5163
5178
|
), !hideClearButton && /* @__PURE__ */ import_react29.default.createElement(
|
|
5164
5179
|
DialogActions_default,
|
|
@@ -5803,8 +5818,9 @@ var formatValueString3 = (date, format, locale = "default") => {
|
|
|
5803
5818
|
const year = date.getFullYear().toString();
|
|
5804
5819
|
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
|
5805
5820
|
const monthName = getMonthName(date, locale, { hideYear: true });
|
|
5821
|
+
const shortMonthName = getShortMonthName(date, locale);
|
|
5806
5822
|
const day = "01";
|
|
5807
|
-
return format.replace(/MMMM/g, monthName).replace(/MM/g, month).replace(/DD/g, day).replace(/YYYY/g, year);
|
|
5823
|
+
return format.replace(/MMMM/g, monthName).replace(/MMM/g, shortMonthName).replace(/MM/g, month).replace(/DD/g, day).replace(/YYYY/g, year);
|
|
5808
5824
|
};
|
|
5809
5825
|
function parseDate3(dateString, format) {
|
|
5810
5826
|
const dateParts = dateString.split(/[-./\s]/);
|
|
@@ -6031,6 +6047,7 @@ var import_react_imask3 = require("react-imask");
|
|
|
6031
6047
|
var import_CalendarToday4 = __toESM(require("@mui/icons-material/CalendarToday"));
|
|
6032
6048
|
var import_joy50 = require("@mui/joy");
|
|
6033
6049
|
var import_base6 = require("@mui/base");
|
|
6050
|
+
var hasAlphabeticMonth3 = (format) => /MMMM|MMM/.test(format);
|
|
6034
6051
|
var StyledPopper4 = (0, import_joy50.styled)(import_base6.Popper, {
|
|
6035
6052
|
name: "MonthRangePicker",
|
|
6036
6053
|
slot: "popper"
|
|
@@ -6054,12 +6071,14 @@ var MonthRangePickerRoot = (0, import_joy50.styled)("div", {
|
|
|
6054
6071
|
})({
|
|
6055
6072
|
width: "100%"
|
|
6056
6073
|
});
|
|
6057
|
-
var formatValueString4 = ([date1, date2], format) => {
|
|
6074
|
+
var formatValueString4 = ([date1, date2], format, locale = "default") => {
|
|
6058
6075
|
const getStr = (date) => {
|
|
6059
6076
|
let month = `${date.getMonth() + 1}`;
|
|
6060
6077
|
const year = date.getFullYear();
|
|
6061
6078
|
if (Number(month) < 10) month = "0" + month;
|
|
6062
|
-
|
|
6079
|
+
const monthName = getMonthName(date, locale, { hideYear: true });
|
|
6080
|
+
const shortMonthName = getShortMonthName(date, locale);
|
|
6081
|
+
return format.replace(/MMMM/g, monthName).replace(/MMM/g, shortMonthName).replace(/MM/g, month).replace(/YYYY/g, year.toString());
|
|
6063
6082
|
};
|
|
6064
6083
|
return [getStr(date1), date2 ? getStr(date2) : ""].join(" - ");
|
|
6065
6084
|
};
|
|
@@ -6131,18 +6150,38 @@ var MonthRangePicker = (0, import_react39.forwardRef)((inProps, ref) => {
|
|
|
6131
6150
|
sx,
|
|
6132
6151
|
className,
|
|
6133
6152
|
format = "YYYY/MM",
|
|
6153
|
+
displayFormat: displayFormatProp,
|
|
6134
6154
|
size,
|
|
6155
|
+
locale = "default",
|
|
6135
6156
|
...innerProps
|
|
6136
6157
|
} = props;
|
|
6158
|
+
const displayFormat = displayFormatProp ?? format;
|
|
6159
|
+
const isAlphabeticDisplay = hasAlphabeticMonth3(displayFormat);
|
|
6137
6160
|
const innerRef = (0, import_react39.useRef)(null);
|
|
6161
|
+
const buttonRef = (0, import_react39.useRef)(null);
|
|
6138
6162
|
const [value, setValue] = useControlledState(
|
|
6139
6163
|
props.value,
|
|
6140
6164
|
props.defaultValue || "",
|
|
6141
6165
|
(0, import_react39.useCallback)((value2) => onChange?.({ target: { name: props.name, value: value2 } }), [props.name, onChange])
|
|
6142
6166
|
);
|
|
6167
|
+
const [displayValue, setDisplayValue] = (0, import_react39.useState)(
|
|
6168
|
+
() => value ? formatValueString4(parseDates2(value), displayFormat, locale) : ""
|
|
6169
|
+
);
|
|
6143
6170
|
const [anchorEl, setAnchorEl] = (0, import_react39.useState)(null);
|
|
6144
6171
|
const open = Boolean(anchorEl);
|
|
6145
6172
|
const calendarValue = (0, import_react39.useMemo)(() => value ? parseDates2(value) : void 0, [value]);
|
|
6173
|
+
(0, import_react39.useEffect)(() => {
|
|
6174
|
+
if (value) {
|
|
6175
|
+
try {
|
|
6176
|
+
const dates = parseDates2(value);
|
|
6177
|
+
const newDisplayValue = formatValueString4(dates, displayFormat, locale);
|
|
6178
|
+
setDisplayValue(newDisplayValue);
|
|
6179
|
+
} catch {
|
|
6180
|
+
}
|
|
6181
|
+
} else {
|
|
6182
|
+
setDisplayValue("");
|
|
6183
|
+
}
|
|
6184
|
+
}, [displayFormat, locale, value]);
|
|
6146
6185
|
(0, import_react39.useEffect)(() => {
|
|
6147
6186
|
if (!anchorEl) {
|
|
6148
6187
|
innerRef.current?.blur();
|
|
@@ -6151,9 +6190,21 @@ var MonthRangePicker = (0, import_react39.forwardRef)((inProps, ref) => {
|
|
|
6151
6190
|
(0, import_react39.useImperativeHandle)(ref, () => innerRef.current, [innerRef]);
|
|
6152
6191
|
const handleChange = (0, import_react39.useCallback)(
|
|
6153
6192
|
(event) => {
|
|
6193
|
+
setDisplayValue(
|
|
6194
|
+
event.target.value ? formatValueString4(parseDates2(event.target.value), displayFormat, locale) : ""
|
|
6195
|
+
);
|
|
6154
6196
|
setValue(event.target.value);
|
|
6155
6197
|
},
|
|
6156
|
-
[setValue]
|
|
6198
|
+
[displayFormat, locale, setValue]
|
|
6199
|
+
);
|
|
6200
|
+
const handleInputMouseDown = (0, import_react39.useCallback)(
|
|
6201
|
+
(event) => {
|
|
6202
|
+
if (isAlphabeticDisplay) {
|
|
6203
|
+
event.preventDefault();
|
|
6204
|
+
buttonRef.current?.focus();
|
|
6205
|
+
}
|
|
6206
|
+
},
|
|
6207
|
+
[isAlphabeticDisplay, buttonRef]
|
|
6157
6208
|
);
|
|
6158
6209
|
const handleCalendarToggle = (0, import_react39.useCallback)(
|
|
6159
6210
|
(event) => {
|
|
@@ -6165,10 +6216,12 @@ var MonthRangePicker = (0, import_react39.forwardRef)((inProps, ref) => {
|
|
|
6165
6216
|
const handleCalendarChange = (0, import_react39.useCallback)(
|
|
6166
6217
|
([date1, date2]) => {
|
|
6167
6218
|
if (!date1 || !date2) return;
|
|
6168
|
-
|
|
6219
|
+
const formattedValue = formatValueString4([date1, date2], format);
|
|
6220
|
+
setDisplayValue(formatValueString4([date1, date2], displayFormat, locale));
|
|
6221
|
+
setValue(formattedValue);
|
|
6169
6222
|
setAnchorEl(null);
|
|
6170
6223
|
},
|
|
6171
|
-
[setValue, setAnchorEl, format]
|
|
6224
|
+
[setValue, setAnchorEl, format, displayFormat, locale]
|
|
6172
6225
|
);
|
|
6173
6226
|
return /* @__PURE__ */ import_react39.default.createElement(MonthRangePickerRoot, null, /* @__PURE__ */ import_react39.default.createElement(import_base6.FocusTrap, { open: true }, /* @__PURE__ */ import_react39.default.createElement(import_react39.default.Fragment, null, /* @__PURE__ */ import_react39.default.createElement(
|
|
6174
6227
|
Input_default,
|
|
@@ -6177,14 +6230,22 @@ var MonthRangePicker = (0, import_react39.forwardRef)((inProps, ref) => {
|
|
|
6177
6230
|
color: error ? "danger" : innerProps.color,
|
|
6178
6231
|
ref,
|
|
6179
6232
|
size,
|
|
6180
|
-
value,
|
|
6233
|
+
value: isAlphabeticDisplay ? displayValue : value,
|
|
6181
6234
|
onChange: handleChange,
|
|
6182
6235
|
disabled,
|
|
6183
6236
|
required,
|
|
6184
|
-
placeholder: `${
|
|
6237
|
+
placeholder: `${displayFormat} - ${displayFormat}`,
|
|
6185
6238
|
slotProps: {
|
|
6186
|
-
input: {
|
|
6239
|
+
input: {
|
|
6240
|
+
...isAlphabeticDisplay ? {} : { component: TextMaskAdapter7, format },
|
|
6241
|
+
ref: innerRef,
|
|
6242
|
+
...isAlphabeticDisplay ? {
|
|
6243
|
+
sx: { "&:hover": { cursor: "default" } },
|
|
6244
|
+
onMouseDown: handleInputMouseDown
|
|
6245
|
+
} : {}
|
|
6246
|
+
}
|
|
6187
6247
|
},
|
|
6248
|
+
readOnly: isAlphabeticDisplay || void 0,
|
|
6188
6249
|
error,
|
|
6189
6250
|
className,
|
|
6190
6251
|
sx: {
|
|
@@ -6195,6 +6256,7 @@ var MonthRangePicker = (0, import_react39.forwardRef)((inProps, ref) => {
|
|
|
6195
6256
|
endDecorator: /* @__PURE__ */ import_react39.default.createElement(
|
|
6196
6257
|
IconButton_default,
|
|
6197
6258
|
{
|
|
6259
|
+
ref: buttonRef,
|
|
6198
6260
|
variant: "plain",
|
|
6199
6261
|
onClick: handleCalendarToggle,
|
|
6200
6262
|
"aria-label": "Toggle Calendar",
|
|
@@ -6237,7 +6299,8 @@ var MonthRangePicker = (0, import_react39.forwardRef)((inProps, ref) => {
|
|
|
6237
6299
|
minDate: minDate ? new Date(minDate) : void 0,
|
|
6238
6300
|
maxDate: maxDate ? new Date(maxDate) : void 0,
|
|
6239
6301
|
disableFuture,
|
|
6240
|
-
disablePast
|
|
6302
|
+
disablePast,
|
|
6303
|
+
locale
|
|
6241
6304
|
}
|
|
6242
6305
|
), /* @__PURE__ */ import_react39.default.createElement(
|
|
6243
6306
|
DialogActions_default,
|