fis-component 0.2.2 → 0.2.3
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 +92 -13
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/components/Input/InputDate/index.d.ts +13 -1
- package/dist/cjs/types/src/components/Input/InputStepper/InputStepper.stories.d.ts +5 -0
- package/dist/esm/index.js +92 -13
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/components/Input/InputDate/index.d.ts +13 -1
- package/dist/esm/types/src/components/Input/InputStepper/InputStepper.stories.d.ts +5 -0
- package/dist/index.d.ts +11 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -73068,8 +73068,42 @@ const HiddenDatePickerSC = styled(DatePicker) `
|
|
|
73068
73068
|
z-index: -1;
|
|
73069
73069
|
`;
|
|
73070
73070
|
|
|
73071
|
+
dayjs.extend(customParseFormat);
|
|
73072
|
+
const SEPARATORS = ["/", "-", "."];
|
|
73073
|
+
/**
|
|
73074
|
+
* Builds lenient-but-strict parse formats from a display format made only of
|
|
73075
|
+
* D/M/Y tokens and separators, e.g. "MM/YYYY" -> ["MM/YYYY", "M/YYYY",
|
|
73076
|
+
* "MM-YYYY", "M-YYYY", "MM.YYYY", "M.YYYY"].
|
|
73077
|
+
*/
|
|
73078
|
+
const buildParseFormats = (format) => {
|
|
73079
|
+
if (!/^[DMY/.\- ]+$/.test(format))
|
|
73080
|
+
return [format];
|
|
73081
|
+
const digitVariants = new Set([format]);
|
|
73082
|
+
[
|
|
73083
|
+
["DD", "D"],
|
|
73084
|
+
["MM", "M"],
|
|
73085
|
+
].forEach(([full, short]) => {
|
|
73086
|
+
Array.from(digitVariants).forEach((f) => {
|
|
73087
|
+
if (f.includes(full))
|
|
73088
|
+
digitVariants.add(f.replace(full, short));
|
|
73089
|
+
});
|
|
73090
|
+
});
|
|
73091
|
+
const result = new Set();
|
|
73092
|
+
digitVariants.forEach((f) => {
|
|
73093
|
+
result.add(f);
|
|
73094
|
+
SEPARATORS.forEach((sep) => result.add(f.replace(/[/.-]/g, sep)));
|
|
73095
|
+
});
|
|
73096
|
+
return Array.from(result);
|
|
73097
|
+
};
|
|
73098
|
+
const parseDateText = (text, formats) => {
|
|
73099
|
+
const trimmed = text.trim();
|
|
73100
|
+
if (!trimmed)
|
|
73101
|
+
return null;
|
|
73102
|
+
const parsed = dayjs(trimmed, formats, true);
|
|
73103
|
+
return parsed.isValid() ? parsed : null;
|
|
73104
|
+
};
|
|
73071
73105
|
const FISInputDate$1 = React.forwardRef((props, ref) => {
|
|
73072
|
-
const { className, value, textLabel = "", iconLabel, required, message = "", disabled, negative, positive, format, onClickIconLabel, onChange, getPopupContainer, minDate, maxDate, picker = "date", allowClear = true, showToday = true, showTime = false, autoFocus = false, disabledDate, disabledTime, inputReadOnly = false, onBlur: originalOnBlur, ...restProps } = props;
|
|
73106
|
+
const { className, value, textLabel = "", iconLabel, required, message = "", disabled, negative, positive, format, onClickIconLabel, onChange, getPopupContainer, minDate, maxDate, picker = "date", allowClear = true, showToday = true, showTime = false, autoFocus = false, disabledDate, disabledTime, inputReadOnly = false, onBlur: originalOnBlur, onKeyDown: originalOnKeyDown, parseFormats, parseInput, ...restProps } = props;
|
|
73073
73107
|
const getDefaultFormat = (pickerMode) => {
|
|
73074
73108
|
switch (pickerMode) {
|
|
73075
73109
|
case "year":
|
|
@@ -73084,19 +73118,48 @@ const FISInputDate$1 = React.forwardRef((props, ref) => {
|
|
|
73084
73118
|
}
|
|
73085
73119
|
};
|
|
73086
73120
|
const finalFormat = format || getDefaultFormat(picker);
|
|
73121
|
+
const parseText = (text) => {
|
|
73122
|
+
if (parseInput) {
|
|
73123
|
+
if (!text.trim())
|
|
73124
|
+
return null;
|
|
73125
|
+
const result = parseInput(text);
|
|
73126
|
+
if (!result)
|
|
73127
|
+
return null;
|
|
73128
|
+
const d = dayjs(result);
|
|
73129
|
+
return d.isValid() ? d : null;
|
|
73130
|
+
}
|
|
73131
|
+
const formats = parseFormats
|
|
73132
|
+
? Array.isArray(parseFormats)
|
|
73133
|
+
? parseFormats
|
|
73134
|
+
: [parseFormats]
|
|
73135
|
+
: buildParseFormats(finalFormat);
|
|
73136
|
+
return parseDateText(text, formats);
|
|
73137
|
+
};
|
|
73087
73138
|
const [open, setOpen] = React.useState(false);
|
|
73088
73139
|
const [inputValue, setInputValue] = React.useState(value ? dayjs(value).format(finalFormat) : "");
|
|
73089
73140
|
const [dateValue, setDateValue] = React.useState(value ? dayjs(value) : null);
|
|
73090
73141
|
const inputRef = React.useRef(null);
|
|
73091
73142
|
const mergeRef = mergeRefs(inputRef, ref);
|
|
73092
73143
|
// Update internal state when external value changes
|
|
73144
|
+
const dateValueRef = React.useRef(dateValue);
|
|
73145
|
+
dateValueRef.current = dateValue;
|
|
73146
|
+
const formatRef = React.useRef(finalFormat);
|
|
73093
73147
|
React.useEffect(() => {
|
|
73148
|
+
const formatChanged = formatRef.current !== finalFormat;
|
|
73149
|
+
formatRef.current = finalFormat;
|
|
73150
|
+
const current = dateValueRef.current;
|
|
73094
73151
|
if (value) {
|
|
73095
73152
|
const newDayjs = dayjs(value);
|
|
73153
|
+
// Value echoed back from our own onChange while typing: keep the
|
|
73154
|
+
// user's text as-is (it is normalized on blur / Enter).
|
|
73155
|
+
if (!formatChanged && current && current.isSame(newDayjs))
|
|
73156
|
+
return;
|
|
73096
73157
|
setDateValue(newDayjs);
|
|
73097
73158
|
setInputValue(newDayjs.format(finalFormat));
|
|
73098
73159
|
}
|
|
73099
73160
|
else {
|
|
73161
|
+
if (!formatChanged && !current)
|
|
73162
|
+
return;
|
|
73100
73163
|
setDateValue(null);
|
|
73101
73164
|
setInputValue("");
|
|
73102
73165
|
}
|
|
@@ -73122,11 +73185,13 @@ const FISInputDate$1 = React.forwardRef((props, ref) => {
|
|
|
73122
73185
|
onChange?.(null);
|
|
73123
73186
|
return;
|
|
73124
73187
|
}
|
|
73125
|
-
// Try to parse the input as a date
|
|
73126
|
-
const parsedDate =
|
|
73127
|
-
if (parsedDate
|
|
73128
|
-
|
|
73129
|
-
|
|
73188
|
+
// Try to parse the input as a date (strict)
|
|
73189
|
+
const parsedDate = parseText(newInputValue);
|
|
73190
|
+
if (parsedDate) {
|
|
73191
|
+
if (!dateValue || !dateValue.isSame(parsedDate)) {
|
|
73192
|
+
setDateValue(parsedDate);
|
|
73193
|
+
onChange?.(parsedDate.toDate());
|
|
73194
|
+
}
|
|
73130
73195
|
}
|
|
73131
73196
|
// If invalid format, keep inputValue but don't update dateValue or call onChange
|
|
73132
73197
|
// This preserves the old date value like Antd DatePicker
|
|
@@ -73140,18 +73205,32 @@ const FISInputDate$1 = React.forwardRef((props, ref) => {
|
|
|
73140
73205
|
if (inputValue === "") {
|
|
73141
73206
|
return;
|
|
73142
73207
|
}
|
|
73143
|
-
|
|
73144
|
-
|
|
73145
|
-
|
|
73146
|
-
|
|
73208
|
+
normalizeInput();
|
|
73209
|
+
};
|
|
73210
|
+
// Valid text -> normalize to display format; invalid -> revert to the
|
|
73211
|
+
// current value (or clear if there is none).
|
|
73212
|
+
const normalizeInput = () => {
|
|
73213
|
+
if (inputValue === "")
|
|
73214
|
+
return;
|
|
73215
|
+
const parsedDate = parseText(inputValue);
|
|
73216
|
+
if (parsedDate) {
|
|
73217
|
+
setInputValue(parsedDate.format(finalFormat));
|
|
73218
|
+
}
|
|
73219
|
+
else if (dateValue) {
|
|
73147
73220
|
setInputValue(dateValue.format(finalFormat));
|
|
73148
73221
|
}
|
|
73149
|
-
else
|
|
73150
|
-
// If no current date and invalid input, clear input
|
|
73222
|
+
else {
|
|
73151
73223
|
setInputValue("");
|
|
73152
73224
|
}
|
|
73153
73225
|
};
|
|
73154
|
-
|
|
73226
|
+
const handleInputKeyDown = (e) => {
|
|
73227
|
+
if (e.key === "Enter") {
|
|
73228
|
+
normalizeInput();
|
|
73229
|
+
setOpen(false);
|
|
73230
|
+
}
|
|
73231
|
+
originalOnKeyDown?.(e);
|
|
73232
|
+
};
|
|
73233
|
+
return (jsxRuntime.jsxs(DivWrapperSC$2, { className: className, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel$1, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.jsxs(DivInputWrapperSC$1, { children: [jsxRuntime.jsx(FISInputField$1, { ...restProps, ref: mergeRef, typeSuffix: "icon", iconSuffix: jsxRuntime.jsx(DateIcon, {}), value: inputValue, negative: negative, disabled: disabled, placeholder: restProps.placeholder, readOnly: inputReadOnly, autoFocus: autoFocus, onFocus: () => setOpen(true), onChange: handleInputChange, onBlur: handleInputBlur, onKeyDown: handleInputKeyDown, onClickSuffix: () => setOpen(true), autoComplete: "off" }), jsxRuntime.jsx(HiddenDatePickerSC, { open: open, value: dateValue, onChange: (value) => handleChange(value), onOpenChange: handleOpenChange, format: finalFormat, getPopupContainer: getPopupContainer, minDate: minDate, maxDate: maxDate, picker: picker, allowClear: allowClear, showToday: showToday, showTime: showTime, disabledDate: disabledDate, disabledTime: disabledTime })] }), message && (jsxRuntime.jsx(DivHintWrapperSC$1, { children: jsxRuntime.jsx(SpanHintSC$3, { className: classNames({
|
|
73155
73234
|
disabled,
|
|
73156
73235
|
negative,
|
|
73157
73236
|
positive,
|