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/cjs/index.js CHANGED
@@ -64945,44 +64945,58 @@ const FISInputLabel = (props) => {
64945
64945
  };
64946
64946
  FISInputLabel.displayName = "FISInputLabel";
64947
64947
 
64948
+ /**
64949
+ * A utility function to merge multiple React refs into a single callback function.
64950
+ * This function accepts any number of refs as arguments and returns a callback function.
64951
+ * When the returned callback function is invoked with a DOM element or null,
64952
+ * it updates the current value of each ref accordingly.
64953
+ *
64954
+ * @template T - The type of the DOM element.
64955
+ * @param {...(Ref<T> | undefined)[]} refs - The refs to be merged.
64956
+ * @returns {(el: T | null) => void} - A callback function that updates the current value of each ref.
64957
+ */
64958
+ function mergeRefs(...refs) {
64959
+ return (el) => {
64960
+ refs.forEach((ref) => {
64961
+ if (!ref)
64962
+ return;
64963
+ if (typeof ref === "function") {
64964
+ ref(el);
64965
+ }
64966
+ else if (typeof ref === "object" && "current" in ref) {
64967
+ ref.current = el;
64968
+ }
64969
+ });
64970
+ };
64971
+ }
64972
+
64948
64973
  const FISInputText = React.forwardRef((props, ref) => {
64949
64974
  const { className, typeSuffix, textLabel = "", iconLabel, required, iconPrefix, sizeInput, showCount, message, negative, positive, maxLength = 500, disabled, onChange, onEnter, onKeyDown, onClickIconLabel, onClickSuffix, ...rest } = props;
64950
- // Internal ref to access DOM element when external ref is not provided
64975
+ // Internal ref to access DOM element for character count
64951
64976
  const internalRef = React.useRef(null);
64952
- const inputRef = ref || internalRef;
64953
- const [internalValue, setInternalValue] = React.useState(rest.value || rest.defaultValue || "");
64977
+ const [internalValue, setInternalValue] = React.useState("");
64954
64978
  // State to trigger re-render for character count (React Hook Form compatibility)
64955
64979
  const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
64956
- // Sync internal value with controlled value prop
64957
- React.useEffect(() => {
64958
- if (rest.value !== undefined) {
64959
- setInternalValue(rest.value);
64960
- }
64961
- }, [rest.value]);
64962
- // Get current value for display (controlled vs uncontrolled)
64980
+ // Get current value for display (prioritize DOM for React Hook Form)
64963
64981
  const getCurrentValue = () => {
64964
- // Controlled mode: use value prop
64965
- if (rest.value !== undefined) {
64966
- return rest.value;
64967
- }
64968
- // Uncontrolled mode: use internal state, fallback to DOM value for React Hook Form
64969
- return internalValue ?? inputRef.current?.value ?? "";
64982
+ return (internalRef.current?.value ??
64983
+ rest.value ??
64984
+ internalValue ??
64985
+ "");
64970
64986
  };
64971
64987
  const handleChange = React.useCallback((event) => {
64972
- const newValue = event.target.value;
64973
- // Only update internal state if not controlled
64988
+ // Update internal state for uncontrolled mode
64974
64989
  if (rest.value === undefined) {
64975
- setInternalValue(newValue);
64990
+ setInternalValue(event.target.value);
64976
64991
  }
64977
64992
  else {
64978
- // Force re-render for character count when using React Hook Form
64979
- // This ensures character count updates even when value prop doesn't change
64993
+ // Force re-render only for controlled mode (React Hook Form case)
64980
64994
  forceUpdate();
64981
64995
  }
64982
64996
  if (onChange) {
64983
64997
  onChange(event);
64984
64998
  }
64985
- }, [onChange, rest.value, forceUpdate]);
64999
+ }, [onChange, rest.value]);
64986
65000
  const handleKeyPress = React.useCallback((event) => {
64987
65001
  if (!event)
64988
65002
  return;
@@ -64992,7 +65006,7 @@ const FISInputText = React.forwardRef((props, ref) => {
64992
65006
  }
64993
65007
  }
64994
65008
  }, [onEnter]);
64995
- return (jsxRuntime.jsxs(DivContainerSC$6, { className: className, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.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) && (jsxRuntime.jsxs(DivHintWrapperSC$1, { children: [jsxRuntime.jsx(SpanHintSC$3, { className: classNames({
65009
+ return (jsxRuntime.jsxs(DivContainerSC$6, { className: className, children: [(textLabel || iconLabel) && (jsxRuntime.jsx(FISInputLabel, { textLabel: textLabel, required: required, iconLabel: iconLabel, onClickIconLabel: onClickIconLabel })), jsxRuntime.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) && (jsxRuntime.jsxs(DivHintWrapperSC$1, { children: [jsxRuntime.jsx(SpanHintSC$3, { className: classNames({
64996
65010
  disabled: disabled,
64997
65011
  negative: negative,
64998
65012
  positive: positive,
@@ -66029,13 +66043,26 @@ styled.div `
66029
66043
  const FISInputArea = React.forwardRef((props, ref) => {
66030
66044
  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;
66031
66045
  const [internalValue, setInternalValue] = React.useState("");
66046
+ // State to trigger re-render for character count (React Hook Form compatibility)
66047
+ const [, forceUpdate] = React.useReducer((x) => x + 1, 0);
66032
66048
  const inputRef = React.useRef(null);
66049
+ // Get current value for display (prioritize DOM for React Hook Form)
66050
+ const getCurrentValue = () => {
66051
+ return (inputRef.current?.value ?? rest.value ?? internalValue ?? "");
66052
+ };
66033
66053
  const handleChange = React.useCallback((event) => {
66034
- setInternalValue(event.target.value);
66054
+ // Update internal state for uncontrolled mode
66055
+ if (rest.value === undefined) {
66056
+ setInternalValue(event.target.value);
66057
+ }
66058
+ else {
66059
+ // Force re-render only for controlled mode (React Hook Form case)
66060
+ forceUpdate();
66061
+ }
66035
66062
  if (onChange) {
66036
66063
  onChange(event);
66037
66064
  }
66038
- }, [onChange]);
66065
+ }, [onChange, rest.value]);
66039
66066
  const handleKeyPress = React.useCallback((event) => {
66040
66067
  if (!event)
66041
66068
  return;
@@ -66045,28 +66072,6 @@ const FISInputArea = React.forwardRef((props, ref) => {
66045
66072
  }
66046
66073
  }
66047
66074
  }, [onEnter]);
66048
- React.useImperativeHandle(ref, () => {
66049
- const inputElement = inputRef.current;
66050
- return {
66051
- ...inputElement,
66052
- focus: () => {
66053
- if (inputRef.current) {
66054
- inputRef.current.focus();
66055
- }
66056
- },
66057
- blur: () => {
66058
- if (inputRef.current) {
66059
- inputRef.current.blur();
66060
- }
66061
- },
66062
- clear: () => {
66063
- if (inputRef.current) {
66064
- inputRef.current.value = "";
66065
- setInternalValue("");
66066
- }
66067
- },
66068
- };
66069
- });
66070
66075
  const handleResize = (e) => {
66071
66076
  e.preventDefault();
66072
66077
  e.stopPropagation();
@@ -66107,7 +66112,7 @@ const FISInputArea = React.forwardRef((props, ref) => {
66107
66112
  "input-area-lg": size === "lg",
66108
66113
  "input-area-icon": iconSuffix,
66109
66114
  negative,
66110
- }), style: { width: fixedWidth ? `${fixedWidth}px` : "auto" }, children: [jsxRuntime.jsx(TextAreaSC, { ...rest, onChange: handleChange, onKeyDown: handleKeyPress, ref: inputRef, disabled: disabled, className: classNames({
66115
+ }), style: { width: fixedWidth ? `${fixedWidth}px` : "auto" }, children: [jsxRuntime.jsx(TextAreaSC, { ...rest, onChange: handleChange, onKeyDown: handleKeyPress, ref: mergeRefs(ref, inputRef), disabled: disabled, className: classNames({
66111
66116
  negative,
66112
66117
  "input-area-lg": size === "lg",
66113
66118
  "input-area-icon": iconSuffix,
@@ -66118,8 +66123,8 @@ const FISInputArea = React.forwardRef((props, ref) => {
66118
66123
  negative,
66119
66124
  positive,
66120
66125
  }), children: message ? message : "" }), jsxRuntime.jsx(DivCountSC, { children: showCount && maxLength > 0 && (jsxRuntime.jsxs("span", { className: classNames("text-area__count", {
66121
- negative: internalValue.length > maxLength,
66122
- }), children: [internalValue?.replaceAll("\n", "")?.length, "/", maxLength] })) })] })] }));
66126
+ negative: getCurrentValue()?.length > maxLength,
66127
+ }), children: [getCurrentValue()?.length, "/", maxLength] })) })] })] }));
66123
66128
  });
66124
66129
  FISInputArea.displayName = "FISInputArea";
66125
66130
 
@@ -71273,31 +71278,6 @@ const HiddenDatePickerSC = styled(DatePicker) `
71273
71278
  z-index: -1;
71274
71279
  `;
71275
71280
 
71276
- /**
71277
- * A utility function to merge multiple React refs into a single callback function.
71278
- * This function accepts any number of refs as arguments and returns a callback function.
71279
- * When the returned callback function is invoked with a DOM element or null,
71280
- * it updates the current value of each ref accordingly.
71281
- *
71282
- * @template T - The type of the DOM element.
71283
- * @param {...(Ref<T> | undefined)[]} refs - The refs to be merged.
71284
- * @returns {(el: T | null) => void} - A callback function that updates the current value of each ref.
71285
- */
71286
- function mergeRefs(...refs) {
71287
- return (el) => {
71288
- refs.forEach((ref) => {
71289
- if (!ref)
71290
- return;
71291
- if (typeof ref === "function") {
71292
- ref(el);
71293
- }
71294
- else if (typeof ref === "object" && "current" in ref) {
71295
- ref.current = el;
71296
- }
71297
- });
71298
- };
71299
- }
71300
-
71301
71281
  const FISInputDate = React.forwardRef((props, ref) => {
71302
71282
  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;
71303
71283
  const getDefaultFormat = (pickerMode) => {