fis-component 0.2.2 → 0.2.4

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
@@ -64433,7 +64433,7 @@ const DivContainer$2 = styled.div `
64433
64433
  ${getTheme("com/badge/default/color-stroke/neutral")};
64434
64434
 
64435
64435
  &.solid {
64436
- border: ${getTheme("sem/dimension/stroke-width/border/md")} solid ${getTheme("com/badge/solid/background-color/neutral")};
64436
+ border: ${getTheme("com/badge/stroke-width")} solid transparent;
64437
64437
  }
64438
64438
 
64439
64439
  &.ghost {
@@ -64793,8 +64793,7 @@ const DivContainer$2 = styled.div `
64793
64793
 
64794
64794
  &.solid {
64795
64795
  background-color: ${getTheme("com/badge/solid/background-color/disable")};
64796
- border: ${getTheme("com/badge/stroke-width")} solid
64797
- ${getTheme("com/badge/disable/color-stroke")};
64796
+ border: ${getTheme("com/badge/stroke-width")} solid transparent;
64798
64797
  }
64799
64798
  `}
64800
64799
  `;
@@ -73068,8 +73067,42 @@ const HiddenDatePickerSC = styled(DatePicker) `
73068
73067
  z-index: -1;
73069
73068
  `;
73070
73069
 
73070
+ dayjs.extend(customParseFormat);
73071
+ const SEPARATORS = ["/", "-", "."];
73072
+ /**
73073
+ * Builds lenient-but-strict parse formats from a display format made only of
73074
+ * D/M/Y tokens and separators, e.g. "MM/YYYY" -> ["MM/YYYY", "M/YYYY",
73075
+ * "MM-YYYY", "M-YYYY", "MM.YYYY", "M.YYYY"].
73076
+ */
73077
+ const buildParseFormats = (format) => {
73078
+ if (!/^[DMY/.\- ]+$/.test(format))
73079
+ return [format];
73080
+ const digitVariants = new Set([format]);
73081
+ [
73082
+ ["DD", "D"],
73083
+ ["MM", "M"],
73084
+ ].forEach(([full, short]) => {
73085
+ Array.from(digitVariants).forEach((f) => {
73086
+ if (f.includes(full))
73087
+ digitVariants.add(f.replace(full, short));
73088
+ });
73089
+ });
73090
+ const result = new Set();
73091
+ digitVariants.forEach((f) => {
73092
+ result.add(f);
73093
+ SEPARATORS.forEach((sep) => result.add(f.replace(/[/.-]/g, sep)));
73094
+ });
73095
+ return Array.from(result);
73096
+ };
73097
+ const parseDateText = (text, formats) => {
73098
+ const trimmed = text.trim();
73099
+ if (!trimmed)
73100
+ return null;
73101
+ const parsed = dayjs(trimmed, formats, true);
73102
+ return parsed.isValid() ? parsed : null;
73103
+ };
73071
73104
  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;
73105
+ 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
73106
  const getDefaultFormat = (pickerMode) => {
73074
73107
  switch (pickerMode) {
73075
73108
  case "year":
@@ -73084,19 +73117,48 @@ const FISInputDate$1 = React.forwardRef((props, ref) => {
73084
73117
  }
73085
73118
  };
73086
73119
  const finalFormat = format || getDefaultFormat(picker);
73120
+ const parseText = (text) => {
73121
+ if (parseInput) {
73122
+ if (!text.trim())
73123
+ return null;
73124
+ const result = parseInput(text);
73125
+ if (!result)
73126
+ return null;
73127
+ const d = dayjs(result);
73128
+ return d.isValid() ? d : null;
73129
+ }
73130
+ const formats = parseFormats
73131
+ ? Array.isArray(parseFormats)
73132
+ ? parseFormats
73133
+ : [parseFormats]
73134
+ : buildParseFormats(finalFormat);
73135
+ return parseDateText(text, formats);
73136
+ };
73087
73137
  const [open, setOpen] = React.useState(false);
73088
73138
  const [inputValue, setInputValue] = React.useState(value ? dayjs(value).format(finalFormat) : "");
73089
73139
  const [dateValue, setDateValue] = React.useState(value ? dayjs(value) : null);
73090
73140
  const inputRef = React.useRef(null);
73091
73141
  const mergeRef = mergeRefs(inputRef, ref);
73092
73142
  // Update internal state when external value changes
73143
+ const dateValueRef = React.useRef(dateValue);
73144
+ dateValueRef.current = dateValue;
73145
+ const formatRef = React.useRef(finalFormat);
73093
73146
  React.useEffect(() => {
73147
+ const formatChanged = formatRef.current !== finalFormat;
73148
+ formatRef.current = finalFormat;
73149
+ const current = dateValueRef.current;
73094
73150
  if (value) {
73095
73151
  const newDayjs = dayjs(value);
73152
+ // Value echoed back from our own onChange while typing: keep the
73153
+ // user's text as-is (it is normalized on blur / Enter).
73154
+ if (!formatChanged && current && current.isSame(newDayjs))
73155
+ return;
73096
73156
  setDateValue(newDayjs);
73097
73157
  setInputValue(newDayjs.format(finalFormat));
73098
73158
  }
73099
73159
  else {
73160
+ if (!formatChanged && !current)
73161
+ return;
73100
73162
  setDateValue(null);
73101
73163
  setInputValue("");
73102
73164
  }
@@ -73122,11 +73184,13 @@ const FISInputDate$1 = React.forwardRef((props, ref) => {
73122
73184
  onChange?.(null);
73123
73185
  return;
73124
73186
  }
73125
- // Try to parse the input as a date
73126
- const parsedDate = dayjs(newInputValue, finalFormat);
73127
- if (parsedDate.isValid()) {
73128
- setDateValue(parsedDate);
73129
- onChange?.(parsedDate.toDate());
73187
+ // Try to parse the input as a date (strict)
73188
+ const parsedDate = parseText(newInputValue);
73189
+ if (parsedDate) {
73190
+ if (!dateValue || !dateValue.isSame(parsedDate)) {
73191
+ setDateValue(parsedDate);
73192
+ onChange?.(parsedDate.toDate());
73193
+ }
73130
73194
  }
73131
73195
  // If invalid format, keep inputValue but don't update dateValue or call onChange
73132
73196
  // This preserves the old date value like Antd DatePicker
@@ -73140,18 +73204,32 @@ const FISInputDate$1 = React.forwardRef((props, ref) => {
73140
73204
  if (inputValue === "") {
73141
73205
  return;
73142
73206
  }
73143
- // On blur, if input format is invalid, revert to the current date value's formatted string
73144
- const parsedDate = dayjs(inputValue, finalFormat);
73145
- if (!parsedDate.isValid() && dateValue) {
73146
- // Revert to formatted current date value
73207
+ normalizeInput();
73208
+ };
73209
+ // Valid text -> normalize to display format; invalid -> revert to the
73210
+ // current value (or clear if there is none).
73211
+ const normalizeInput = () => {
73212
+ if (inputValue === "")
73213
+ return;
73214
+ const parsedDate = parseText(inputValue);
73215
+ if (parsedDate) {
73216
+ setInputValue(parsedDate.format(finalFormat));
73217
+ }
73218
+ else if (dateValue) {
73147
73219
  setInputValue(dateValue.format(finalFormat));
73148
73220
  }
73149
- else if (!parsedDate.isValid() && !dateValue) {
73150
- // If no current date and invalid input, clear input
73221
+ else {
73151
73222
  setInputValue("");
73152
73223
  }
73153
73224
  };
73154
- 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, 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({
73225
+ const handleInputKeyDown = (e) => {
73226
+ if (e.key === "Enter") {
73227
+ normalizeInput();
73228
+ setOpen(false);
73229
+ }
73230
+ originalOnKeyDown?.(e);
73231
+ };
73232
+ 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
73233
  disabled,
73156
73234
  negative,
73157
73235
  positive,