fis-component 0.0.86 → 0.0.88

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/esm/index.js CHANGED
@@ -64925,44 +64925,58 @@ const FISInputLabel = (props) => {
64925
64925
  };
64926
64926
  FISInputLabel.displayName = "FISInputLabel";
64927
64927
 
64928
+ /**
64929
+ * A utility function to merge multiple React refs into a single callback function.
64930
+ * This function accepts any number of refs as arguments and returns a callback function.
64931
+ * When the returned callback function is invoked with a DOM element or null,
64932
+ * it updates the current value of each ref accordingly.
64933
+ *
64934
+ * @template T - The type of the DOM element.
64935
+ * @param {...(Ref<T> | undefined)[]} refs - The refs to be merged.
64936
+ * @returns {(el: T | null) => void} - A callback function that updates the current value of each ref.
64937
+ */
64938
+ function mergeRefs(...refs) {
64939
+ return (el) => {
64940
+ refs.forEach((ref) => {
64941
+ if (!ref)
64942
+ return;
64943
+ if (typeof ref === "function") {
64944
+ ref(el);
64945
+ }
64946
+ else if (typeof ref === "object" && "current" in ref) {
64947
+ ref.current = el;
64948
+ }
64949
+ });
64950
+ };
64951
+ }
64952
+
64928
64953
  const FISInputText = forwardRef((props, ref) => {
64929
64954
  const { className, typeSuffix, textLabel = "", iconLabel, required, iconPrefix, sizeInput, showCount, message, negative, positive, maxLength = 500, disabled, onChange, onEnter, onKeyDown, onClickIconLabel, onClickSuffix, ...rest } = props;
64930
- // Internal ref to access DOM element when external ref is not provided
64955
+ // Internal ref to access DOM element for character count
64931
64956
  const internalRef = React__default.useRef(null);
64932
- const inputRef = ref || internalRef;
64933
- const [internalValue, setInternalValue] = React__default.useState(rest.value || rest.defaultValue || "");
64957
+ const [internalValue, setInternalValue] = React__default.useState("");
64934
64958
  // State to trigger re-render for character count (React Hook Form compatibility)
64935
64959
  const [, forceUpdate] = React__default.useReducer((x) => x + 1, 0);
64936
- // Sync internal value with controlled value prop
64937
- React__default.useEffect(() => {
64938
- if (rest.value !== undefined) {
64939
- setInternalValue(rest.value);
64940
- }
64941
- }, [rest.value]);
64942
- // Get current value for display (controlled vs uncontrolled)
64960
+ // Get current value for display (prioritize DOM for React Hook Form)
64943
64961
  const getCurrentValue = () => {
64944
- // Controlled mode: use value prop
64945
- if (rest.value !== undefined) {
64946
- return rest.value;
64947
- }
64948
- // Uncontrolled mode: use internal state, fallback to DOM value for React Hook Form
64949
- return internalValue ?? inputRef.current?.value ?? "";
64962
+ return (internalRef.current?.value ??
64963
+ rest.value ??
64964
+ internalValue ??
64965
+ "");
64950
64966
  };
64951
64967
  const handleChange = React__default.useCallback((event) => {
64952
- const newValue = event.target.value;
64953
- // Only update internal state if not controlled
64968
+ // Update internal state for uncontrolled mode
64954
64969
  if (rest.value === undefined) {
64955
- setInternalValue(newValue);
64970
+ setInternalValue(event.target.value);
64956
64971
  }
64957
64972
  else {
64958
- // Force re-render for character count when using React Hook Form
64959
- // This ensures character count updates even when value prop doesn't change
64973
+ // Force re-render only for controlled mode (React Hook Form case)
64960
64974
  forceUpdate();
64961
64975
  }
64962
64976
  if (onChange) {
64963
64977
  onChange(event);
64964
64978
  }
64965
- }, [onChange, rest.value, forceUpdate]);
64979
+ }, [onChange, rest.value]);
64966
64980
  const handleKeyPress = React__default.useCallback((event) => {
64967
64981
  if (!event)
64968
64982
  return;
@@ -64972,7 +64986,7 @@ const FISInputText = forwardRef((props, ref) => {
64972
64986
  }
64973
64987
  }
64974
64988
  }, [onEnter]);
64975
- return (jsxs(DivContainerSC$6, { className: className, children: [(textLabel || iconLabel) && (jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsx(FISInputField, { ...rest, ref: inputRef, typeSuffix: typeSuffix, sizeInput: sizeInput, iconPrefix: iconPrefix, onKeyPress: handleKeyPress, onChange: handleChange, disabled: disabled, negative: negative, maxLength: maxLength, onClickSuffix: onClickSuffix }), (message || showCount) && (jsxs(DivHintWrapperSC$1, { children: [jsx(SpanHintSC$3, { className: classNames({
64989
+ return (jsxs(DivContainerSC$6, { className: className, children: [(textLabel || iconLabel) && (jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsx(FISInputField, { ...rest, ref: mergeRefs(ref, internalRef), typeSuffix: typeSuffix, sizeInput: sizeInput, iconPrefix: iconPrefix, onKeyPress: handleKeyPress, onChange: handleChange, disabled: disabled, negative: negative, maxLength: maxLength, onClickSuffix: onClickSuffix }), (message || showCount) && (jsxs(DivHintWrapperSC$1, { children: [jsx(SpanHintSC$3, { className: classNames({
64976
64990
  disabled: disabled,
64977
64991
  negative: negative,
64978
64992
  positive: positive,
@@ -66009,13 +66023,26 @@ styled.div `
66009
66023
  const FISInputArea = forwardRef((props, ref) => {
66010
66024
  const { className, required = false, textLabel = "", iconLabel, iconSuffix, disabled = false, readOnly = false, negative, message, positive, maxLength = 50, showCount, size = "md", fixedWidth, onClickIconLabel, onClickIconSuffix, onChange, onEnter, ...rest } = props;
66011
66025
  const [internalValue, setInternalValue] = React__default.useState("");
66026
+ // State to trigger re-render for character count (React Hook Form compatibility)
66027
+ const [, forceUpdate] = React__default.useReducer((x) => x + 1, 0);
66012
66028
  const inputRef = React__default.useRef(null);
66029
+ // Get current value for display (prioritize DOM for React Hook Form)
66030
+ const getCurrentValue = () => {
66031
+ return (inputRef.current?.value ?? rest.value ?? internalValue ?? "");
66032
+ };
66013
66033
  const handleChange = React__default.useCallback((event) => {
66014
- setInternalValue(event.target.value);
66034
+ // Update internal state for uncontrolled mode
66035
+ if (rest.value === undefined) {
66036
+ setInternalValue(event.target.value);
66037
+ }
66038
+ else {
66039
+ // Force re-render only for controlled mode (React Hook Form case)
66040
+ forceUpdate();
66041
+ }
66015
66042
  if (onChange) {
66016
66043
  onChange(event);
66017
66044
  }
66018
- }, [onChange]);
66045
+ }, [onChange, rest.value]);
66019
66046
  const handleKeyPress = React__default.useCallback((event) => {
66020
66047
  if (!event)
66021
66048
  return;
@@ -66025,28 +66052,6 @@ const FISInputArea = forwardRef((props, ref) => {
66025
66052
  }
66026
66053
  }
66027
66054
  }, [onEnter]);
66028
- useImperativeHandle(ref, () => {
66029
- const inputElement = inputRef.current;
66030
- return {
66031
- ...inputElement,
66032
- focus: () => {
66033
- if (inputRef.current) {
66034
- inputRef.current.focus();
66035
- }
66036
- },
66037
- blur: () => {
66038
- if (inputRef.current) {
66039
- inputRef.current.blur();
66040
- }
66041
- },
66042
- clear: () => {
66043
- if (inputRef.current) {
66044
- inputRef.current.value = "";
66045
- setInternalValue("");
66046
- }
66047
- },
66048
- };
66049
- });
66050
66055
  const handleResize = (e) => {
66051
66056
  e.preventDefault();
66052
66057
  e.stopPropagation();
@@ -66087,7 +66092,7 @@ const FISInputArea = forwardRef((props, ref) => {
66087
66092
  "input-area-lg": size === "lg",
66088
66093
  "input-area-icon": iconSuffix,
66089
66094
  negative,
66090
- }), style: { width: fixedWidth ? `${fixedWidth}px` : "auto" }, children: [jsx(TextAreaSC, { ...rest, onChange: handleChange, onKeyDown: handleKeyPress, ref: inputRef, disabled: disabled, className: classNames({
66095
+ }), style: { width: fixedWidth ? `${fixedWidth}px` : "auto" }, children: [jsx(TextAreaSC, { ...rest, onChange: handleChange, onKeyDown: handleKeyPress, ref: mergeRefs(ref, inputRef), disabled: disabled, className: classNames({
66091
66096
  negative,
66092
66097
  "input-area-lg": size === "lg",
66093
66098
  "input-area-icon": iconSuffix,
@@ -66098,8 +66103,8 @@ const FISInputArea = forwardRef((props, ref) => {
66098
66103
  negative,
66099
66104
  positive,
66100
66105
  }), children: message ? message : "" }), jsx(DivCountSC, { children: showCount && maxLength > 0 && (jsxs("span", { className: classNames("text-area__count", {
66101
- negative: internalValue.length > maxLength,
66102
- }), children: [internalValue?.replaceAll("\n", "")?.length, "/", maxLength] })) })] })] }));
66106
+ negative: getCurrentValue()?.length > maxLength,
66107
+ }), children: [getCurrentValue()?.length, "/", maxLength] })) })] })] }));
66103
66108
  });
66104
66109
  FISInputArea.displayName = "FISInputArea";
66105
66110
 
@@ -71253,31 +71258,6 @@ const HiddenDatePickerSC = styled(DatePicker) `
71253
71258
  z-index: -1;
71254
71259
  `;
71255
71260
 
71256
- /**
71257
- * A utility function to merge multiple React refs into a single callback function.
71258
- * This function accepts any number of refs as arguments and returns a callback function.
71259
- * When the returned callback function is invoked with a DOM element or null,
71260
- * it updates the current value of each ref accordingly.
71261
- *
71262
- * @template T - The type of the DOM element.
71263
- * @param {...(Ref<T> | undefined)[]} refs - The refs to be merged.
71264
- * @returns {(el: T | null) => void} - A callback function that updates the current value of each ref.
71265
- */
71266
- function mergeRefs(...refs) {
71267
- return (el) => {
71268
- refs.forEach((ref) => {
71269
- if (!ref)
71270
- return;
71271
- if (typeof ref === "function") {
71272
- ref(el);
71273
- }
71274
- else if (typeof ref === "object" && "current" in ref) {
71275
- ref.current = el;
71276
- }
71277
- });
71278
- };
71279
- }
71280
-
71281
71261
  const FISInputDate = forwardRef((props, ref) => {
71282
71262
  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, inputReadOnly = false, ...restProps } = props;
71283
71263
  const getDefaultFormat = (pickerMode) => {