@mtes-mct/monitor-ui 5.3.2 → 5.3.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/index.js CHANGED
@@ -3574,9 +3574,18 @@ const useClickOutsideEffect = (zoneRefOrzoneRefs, action, baseContainer) => {
3574
3574
  }, [baseContainer, handleClickOutside]);
3575
3575
  };
3576
3576
 
3577
+ function usePrevious(value) {
3578
+ const ref = useRef();
3579
+ useEffect(() => {
3580
+ ref.current = value;
3581
+ }, [value]); // Only re-run if value changes
3582
+ return ref.current;
3583
+ }
3584
+
3577
3585
  function useFieldUndefineEffect(disabled, onChange, onDisable) {
3586
+ const wasDisabled = usePrevious(disabled);
3578
3587
  useEffect(() => {
3579
- if (!disabled) {
3588
+ if (!disabled || disabled === wasDisabled) {
3580
3589
  return;
3581
3590
  }
3582
3591
  if (onDisable) {
@@ -3585,7 +3594,7 @@ function useFieldUndefineEffect(disabled, onChange, onDisable) {
3585
3594
  if (onChange) {
3586
3595
  onChange(undefined);
3587
3596
  }
3588
- }, [disabled, onChange, onDisable]);
3597
+ }, [disabled, onChange, onDisable, wasDisabled]);
3589
3598
  }
3590
3599
 
3591
3600
  var lodashExports = {};
@@ -20804,14 +20813,6 @@ function useForceUpdate() {
20804
20813
  return { forceDebouncedUpdate, forceUpdate };
20805
20814
  }
20806
20815
 
20807
- function usePrevious(value) {
20808
- const ref = useRef();
20809
- useEffect(() => {
20810
- ref.current = value;
20811
- }, [value]); // Only re-run if value changes
20812
- return ref.current;
20813
- }
20814
-
20815
20816
  const getPseudoRandomString = () => Math.random().toString(36).slice(2);
20816
20817
 
20817
20818
  function useKey(deps) {
@@ -20979,34 +20980,17 @@ const Box$c = styled.div `
20979
20980
  `;
20980
20981
 
20981
20982
  function Checkbox({ checked = false, error, isErrorMessageHidden = false, isUndefinedWhenDisabled = false, label, onChange, ...originalProps }) {
20982
- const { forceUpdate } = useForceUpdate();
20983
- // This tracks the component internal value which allows us to react to value changes after the checkbox toggling
20984
- const [internalChecked, setInternalChecked] = useState(checked);
20985
- // and compare it with an eventual external value change (via the `value` prop)
20986
- const previousChecked = usePrevious(checked);
20987
- // to decide which on is the source of "truth" in `controlledValue` (the last one to be changed is the true value)
20988
- // eslint-disable-next-line @typescript-eslint/naming-convention
20989
- const controlledChecked = useMemo(() => {
20990
- // If the `value` has changed, `value` takes precedence,
20991
- // otherwise we can use our current internal value
20992
- const nextControlledChecked = checked === previousChecked ? internalChecked : checked;
20993
- return !isUndefinedWhenDisabled || !originalProps.disabled ? nextControlledChecked : undefined;
20994
- }, [checked, internalChecked, isUndefinedWhenDisabled, originalProps.disabled, previousChecked]);
20995
20983
  const controlledError = useMemo(() => normalizeString(error), [error]);
20996
20984
  const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
20997
20985
  const key = getPseudoRandomString();
20998
20986
  const handleChange = useCallback((_, isChecked) => {
20999
- setInternalChecked(isChecked);
21000
- // We have to force the update since a state with the same value wouldn't re-render
21001
- // which generates conflicting behaviors
21002
- // when `value` prop is changed to a value that is equal to the current internal value
21003
- forceUpdate();
21004
- if (onChange) {
21005
- onChange(isChecked);
20987
+ if (!onChange) {
20988
+ return;
21006
20989
  }
21007
- }, [forceUpdate, onChange]);
20990
+ onChange(isChecked);
20991
+ }, [onChange]);
21008
20992
  useFieldUndefineEffect(isUndefinedWhenDisabled && originalProps.disabled, onChange);
21009
- return (jsxs(Field$2, { className: "Field-Checkbox", children: [jsx(StyledCheckbox, { checked: controlledChecked, id: originalProps.name, onChange: handleChange, ...originalProps, children: label }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
20993
+ return (jsxs(Field$2, { className: "Field-Checkbox", children: [jsx(StyledCheckbox, { checked: checked, id: originalProps.name, onChange: handleChange, ...originalProps, children: label }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
21010
20994
  }
21011
20995
  const StyledCheckbox = styled(Checkbox$1) `
21012
20996
  > .rs-checkbox-checker {
@@ -22486,52 +22470,22 @@ const Field = styled.span `
22486
22470
  }};
22487
22471
  `;
22488
22472
 
22489
- function useFieldControl(value, onChange, props) {
22490
- const { disabled, isUndefinedWhenDisabled } = props;
22491
- // This tracks the component internal value which allows us to react to value changes after the checkbox toggling
22492
- const internalValueRef = useRef(value);
22493
- // and compare it with an eventual external value change (via the `value` prop)
22494
- const previousValue = usePrevious(value);
22495
- const { forceUpdate } = useForceUpdate();
22496
- const controlledValue = isUndefinedWhenDisabled && disabled ? undefined : internalValueRef.current;
22497
- const controlledOnChange = useCallback((nextValue) => {
22498
- internalValueRef.current = nextValue;
22499
- if (onChange) {
22500
- onChange(nextValue);
22501
- }
22502
- }, [onChange]);
22503
- const setInternalValue = useCallback((nextValue) => {
22504
- internalValueRef.current = nextValue;
22505
- forceUpdate();
22506
- }, [forceUpdate]);
22507
- // We update the `internalValue` each time the `value` prop is updated
22508
- useEffect(() => {
22509
- if (lodashExports.isEqual(value, previousValue)) {
22510
- return;
22511
- }
22512
- internalValueRef.current = value;
22513
- forceUpdate();
22514
- }, [forceUpdate, previousValue, value]);
22515
- return { controlledOnChange, controlledValue, setInternalValue };
22516
- }
22517
-
22518
22473
  function MultiCheckbox({ disabled = false, error, isErrorMessageHidden = false, isInline = false, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, name, onChange, options, value }) {
22519
- const { controlledOnChange, controlledValue } = useFieldControl(value, onChange, {
22520
- disabled,
22521
- isUndefinedWhenDisabled
22522
- });
22523
22474
  const controlledError = useMemo(() => normalizeString(error), [error]);
22524
22475
  const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
22525
- const key = useKey([controlledValue, disabled, name]);
22476
+ const key = useKey([value, disabled, name]);
22526
22477
  const handleChange = useCallback((nextOptionValue, isChecked) => {
22478
+ if (!onChange) {
22479
+ return;
22480
+ }
22527
22481
  const nextCheckedOptionValues = isChecked
22528
- ? [...(controlledValue || []), nextOptionValue]
22529
- : reject(equals(nextOptionValue))(controlledValue || []);
22482
+ ? [...(value || []), nextOptionValue]
22483
+ : reject(equals(nextOptionValue))(value || []);
22530
22484
  const normalizedNextValue = nextCheckedOptionValues.length ? nextCheckedOptionValues : undefined;
22531
- controlledOnChange(normalizedNextValue);
22532
- }, [controlledOnChange, controlledValue]);
22485
+ onChange(normalizedNextValue);
22486
+ }, [onChange, value]);
22533
22487
  useFieldUndefineEffect(isUndefinedWhenDisabled && disabled, onChange);
22534
- return (jsxs(Fieldset, { className: "Field-MultiCheckbox", disabled: disabled, hasError: hasError, isLegendHidden: isLabelHidden, isLight: isLight, legend: label, children: [jsx(ChecboxesBox, { "$hasError": hasError, "$isInline": isInline, children: options.map((option, index) => (jsx(Checkbox, { checked: includes(option.value, controlledValue || []), disabled: disabled, label: option.label, name: `${name}${index}`, onChange: (isChecked) => handleChange(option.value, isChecked) }, JSON.stringify(option.value)))) }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
22488
+ return (jsxs(Fieldset, { className: "Field-MultiCheckbox", disabled: disabled, hasError: hasError, isLegendHidden: isLabelHidden, isLight: isLight, legend: label, children: [jsx(ChecboxesBox, { "$hasError": hasError, "$isInline": isInline, children: options.map((option, index) => (jsx(Checkbox, { checked: includes(option.value, value || []), disabled: disabled, label: option.label, name: `${name}${index}`, onChange: (isChecked) => handleChange(option.value, isChecked) }, JSON.stringify(option.value)))) }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
22535
22489
  }
22536
22490
  const ChecboxesBox = styled.div `
22537
22491
  color: ${p => p.theme.color.gunMetal};
@@ -22585,28 +22539,27 @@ function MultiSelect({ baseContainer, disabled = false, error, isErrorMessageHid
22585
22539
  // eslint-disable-next-line no-null/no-null
22586
22540
  const boxRef = useRef(null);
22587
22541
  const [isOpen, setIsOpen] = useState(false);
22588
- const { controlledOnChange, controlledValue } = useFieldControl(value, onChange, {
22589
- disabled,
22590
- isUndefinedWhenDisabled
22591
- });
22592
- const controlledRsuiteValue = useMemo(() => (controlledValue || []).map(controlledValueItem => getRsuiteValueFromOptionValue(controlledValueItem, optionValueKey)), [controlledValue, optionValueKey]);
22593
22542
  const controlledError = useMemo(() => normalizeString(error), [error]);
22594
22543
  const data = useMemo(() => getRsuiteDataFromOptions(options, optionValueKey), [options, optionValueKey]);
22595
22544
  const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
22596
22545
  const key = useKey([disabled, originalProps.name, value]);
22546
+ const rsuiteValue = useMemo(() => (value || []).map(valueItem => getRsuiteValueFromOptionValue(valueItem, optionValueKey)), [optionValueKey, value]);
22597
22547
  const { forceUpdate } = useForceUpdate();
22598
22548
  const close = useCallback(() => {
22599
22549
  setIsOpen(false);
22600
22550
  }, []);
22601
22551
  const handleChange = useCallback((nextOptionRsuiteValues) => {
22552
+ if (!onChange) {
22553
+ return;
22554
+ }
22602
22555
  const nextValue = nextOptionRsuiteValues
22603
22556
  ? options
22604
22557
  .filter(option => nextOptionRsuiteValues.includes(optionValueKey ? option.value[optionValueKey] : String(option.value)))
22605
22558
  .map(option => option.value)
22606
22559
  : [];
22607
22560
  const normalizedNextValue = !nextValue.length ? undefined : nextValue;
22608
- controlledOnChange(normalizedNextValue);
22609
- }, [controlledOnChange, options, optionValueKey]);
22561
+ onChange(normalizedNextValue);
22562
+ }, [onChange, options, optionValueKey]);
22610
22563
  const renderMenuItem = useCallback((node) => jsx("span", { title: String(node), children: String(node) }), []);
22611
22564
  const toggle = useCallback((event) => {
22612
22565
  let targetElement = event.target;
@@ -22628,7 +22581,7 @@ function MultiSelect({ baseContainer, disabled = false, error, isErrorMessageHid
22628
22581
  }, [forceUpdate]);
22629
22582
  return (jsxs(Field$2, { className: "Field-MultiSelect", children: [jsx(Label, { disabled: disabled, hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(Box$4, { ref: boxRef, "$hasError": hasError, "$isActive": isOpen, "$isLight": isLight, onClick: toggle, children: boxRef.current && (jsx(TagPicker, { container: boxRef.current, data: data, disabled: disabled, id: originalProps.name,
22630
22583
  // Since we customized `ItemDataType` type by adding `optionValue`, we have an optional vs required conflict
22631
- onChange: handleChange, onClick: toggle, open: isOpen, renderMenuItem: renderMenuItem, searchable: searchable, value: controlledRsuiteValue, ...originalProps }, key)) }), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
22584
+ onChange: handleChange, onClick: toggle, open: isOpen, renderMenuItem: renderMenuItem, searchable: searchable, value: rsuiteValue, ...originalProps }, key)) }), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
22632
22585
  }
22633
22586
  const Box$4 = styled.div `
22634
22587
  position: relative;
@@ -22752,19 +22705,18 @@ const Box$4 = styled.div `
22752
22705
  `;
22753
22706
 
22754
22707
  function MultiRadio({ disabled = false, error, isErrorMessageHidden = false, isInline = false, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, name, onChange, options, value }) {
22755
- const { controlledOnChange, controlledValue } = useFieldControl(value, onChange, {
22756
- disabled,
22757
- isUndefinedWhenDisabled
22758
- });
22759
22708
  const controlledError = useMemo(() => normalizeString(error), [error]);
22760
22709
  const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
22761
- const key = useKey([controlledValue, disabled, name]);
22710
+ const key = useKey([value, disabled, name]);
22762
22711
  const handleChange = useCallback((nextOptionValue, isChecked) => {
22712
+ if (!onChange) {
22713
+ return;
22714
+ }
22763
22715
  const nextCheckedOptionValue = isChecked ? nextOptionValue : undefined;
22764
- controlledOnChange(nextCheckedOptionValue);
22765
- }, [controlledOnChange]);
22716
+ onChange(nextCheckedOptionValue);
22717
+ }, [onChange]);
22766
22718
  useFieldUndefineEffect(isUndefinedWhenDisabled && disabled, onChange);
22767
- return (jsxs(Fieldset, { className: "Field-MultiRadio", disabled: disabled, hasError: hasError, isLegendHidden: isLabelHidden, isLight: isLight, legend: label, children: [jsx(CheckboxesBox, { "$isInline": isInline, children: options.map(option => (jsx(Radio, { checked: equals(option.value, controlledValue), disabled: disabled, name: name, onChange: (_, isChecked) => handleChange(option.value, isChecked), children: option.label }, JSON.stringify(option.value)))) }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
22719
+ return (jsxs(Fieldset, { className: "Field-MultiRadio", disabled: disabled, hasError: hasError, isLegendHidden: isLabelHidden, isLight: isLight, legend: label, children: [jsx(CheckboxesBox, { "$isInline": isInline, children: options.map(option => (jsx(Radio, { checked: equals(option.value, value), disabled: disabled, name: name, onChange: (_, isChecked) => handleChange(option.value, isChecked), children: option.label }, JSON.stringify(option.value)))) }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
22768
22720
  }
22769
22721
  const CheckboxesBox = styled.div `
22770
22722
  color: ${p => p.theme.color.gunMetal};
@@ -22877,7 +22829,6 @@ const Link = styled.a `
22877
22829
  `;
22878
22830
 
22879
22831
  function NumberInput({ error, isErrorMessageHidden = false, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, onChange, value, ...originalProps }) {
22880
- const controlledValue = useMemo(() => (!isUndefinedWhenDisabled || !originalProps.disabled ? value : undefined), [isUndefinedWhenDisabled, originalProps.disabled, value]);
22881
22832
  const controlledError = useMemo(() => normalizeString(error), [error]);
22882
22833
  const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
22883
22834
  const key = useKey([originalProps.disabled, originalProps.name]);
@@ -22891,7 +22842,7 @@ function NumberInput({ error, isErrorMessageHidden = false, isLabelHidden = fals
22891
22842
  onChange(normalizedNextValue);
22892
22843
  }, [onChange]);
22893
22844
  useFieldUndefineEffect(isUndefinedWhenDisabled && originalProps.disabled, onChange);
22894
- return (jsxs(Field$2, { className: "Field-NumberInput", children: [jsx(Label, { disabled: originalProps.disabled, hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(StyledInput$2, { "$hasError": hasError, "$isLight": isLight, id: originalProps.name, onChange: handleChange, type: "number", value: controlledValue, ...originalProps }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
22845
+ return (jsxs(Field$2, { className: "Field-NumberInput", children: [jsx(Label, { disabled: originalProps.disabled, hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(StyledInput$2, { "$hasError": hasError, "$isLight": isLight, id: originalProps.name, onChange: handleChange, type: "number", value: value, ...originalProps }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
22895
22846
  }
22896
22847
  const StyledInput$2 = styled(Input) `
22897
22848
  background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)};
@@ -33041,25 +32992,26 @@ function Select({ baseContainer, disabled = false, error, isErrorMessageHidden =
33041
32992
  const boxRef = useRef(null);
33042
32993
  const [isOpen, setIsOpen] = useState(false);
33043
32994
  const { forceUpdate } = useForceUpdate();
33044
- const { controlledOnChange, controlledValue } = useFieldControl(value, onChange, {
33045
- disabled,
33046
- isUndefinedWhenDisabled
33047
- });
33048
- const controlledRsuiteValue = useMemo(() => getRsuiteValueFromOptionValue(controlledValue, optionValueKey), [controlledValue, optionValueKey]);
33049
32995
  const controlledError = useMemo(() => normalizeString(error), [error]);
33050
32996
  const data = useMemo(() => getRsuiteDataFromOptions(options, optionValueKey), [options, optionValueKey]);
33051
32997
  const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
33052
32998
  const key = useKey([disabled, originalProps.name, value]);
32999
+ const rsuiteValue = useMemo(() => getRsuiteValueFromOptionValue(value, optionValueKey), [value, optionValueKey]);
33053
33000
  const close = useCallback(() => {
33054
33001
  setIsOpen(false);
33055
33002
  }, []);
33056
33003
  const handleClean = useCallback(() => {
33057
- controlledOnChange(undefined);
33058
- }, [controlledOnChange]);
33004
+ if (!onChange) {
33005
+ return;
33006
+ }
33007
+ onChange(undefined);
33008
+ }, [onChange]);
33059
33009
  const handleSelect = useCallback((_, selectedItem) => {
33060
33010
  close();
33061
- controlledOnChange(selectedItem.optionValue);
33062
- }, [close, controlledOnChange]);
33011
+ if (onChange) {
33012
+ onChange(selectedItem.optionValue);
33013
+ }
33014
+ }, [close, onChange]);
33063
33015
  const renderMenuItem = useCallback((node) => jsx("span", { title: String(node), children: String(node) }), []);
33064
33016
  const toggle = useCallback((event) => {
33065
33017
  let targetElement = event.target;
@@ -33083,7 +33035,7 @@ function Select({ baseContainer, disabled = false, error, isErrorMessageHidden =
33083
33035
  }, [forceUpdate]);
33084
33036
  return (jsxs(Field$2, { className: "Field-Select", children: [jsx(Label, { disabled: disabled, hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(Box, { ref: boxRef, onClick: toggle, children: boxRef.current && (jsx(StyledSelectPicker, { "$isLight": isLight, container: boxRef.current, data: data, disabled: disabled, id: originalProps.name, onClean: handleClean,
33085
33037
  // Since we customized `ItemDataType` type by adding `optionValue`, we have an optional vs required conflict
33086
- onSelect: handleSelect, open: isOpen, renderMenuItem: renderMenuItem, searchable: searchable, value: controlledRsuiteValue, ...originalProps }, key)) }), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
33038
+ onSelect: handleSelect, open: isOpen, renderMenuItem: renderMenuItem, searchable: searchable, value: rsuiteValue, ...originalProps }, key)) }), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
33087
33039
  }
33088
33040
  const StyledSelectPicker = styled(SelectPicker) `
33089
33041
  > .rs-picker-toggle {
@@ -33168,7 +33120,6 @@ const Box = styled.div `
33168
33120
 
33169
33121
  function Textarea({ error, isErrorMessageHidden = false, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, onChange, rows = 3, value, ...originalProps }) {
33170
33122
  const inputRef = useRef();
33171
- const controlledValue = useMemo(() => (!isUndefinedWhenDisabled || !originalProps.disabled ? value : undefined), [isUndefinedWhenDisabled, originalProps.disabled, value]);
33172
33123
  const controlledError = useMemo(() => normalizeString(error), [error]);
33173
33124
  const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
33174
33125
  const key = useKey([originalProps.disabled, originalProps.name]);
@@ -33181,7 +33132,7 @@ function Textarea({ error, isErrorMessageHidden = false, isLabelHidden = false,
33181
33132
  onChange(normalizedNextValue);
33182
33133
  }, [onChange]);
33183
33134
  useFieldUndefineEffect(isUndefinedWhenDisabled && originalProps.disabled, onChange);
33184
- return (jsxs(Field$2, { className: "Field-Textarea", children: [jsx(Label, { disabled: originalProps.disabled, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(StyledInput$1, { ref: inputRef, "$isLight": isLight, as: "textarea", id: originalProps.name, onChange: handleChange, rows: rows, value: controlledValue, ...originalProps }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
33135
+ return (jsxs(Field$2, { className: "Field-Textarea", children: [jsx(Label, { disabled: originalProps.disabled, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(StyledInput$1, { ref: inputRef, "$isLight": isLight, as: "textarea", id: originalProps.name, onChange: handleChange, rows: rows, value: value, ...originalProps }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
33185
33136
  }
33186
33137
  const StyledInput$1 = styled(Input) `
33187
33138
  background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)};
@@ -33196,7 +33147,6 @@ const StyledInput$1 = styled(Input) `
33196
33147
  `;
33197
33148
 
33198
33149
  function TextInput({ error, isErrorMessageHidden = false, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, onChange, value, ...originalProps }) {
33199
- const controlledValue = useMemo(() => (!isUndefinedWhenDisabled || !originalProps.disabled ? value : undefined), [isUndefinedWhenDisabled, originalProps.disabled, value]);
33200
33150
  const controlledError = useMemo(() => normalizeString(error), [error]);
33201
33151
  const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
33202
33152
  const key = useKey([originalProps.disabled, originalProps.name]);
@@ -33208,7 +33158,7 @@ function TextInput({ error, isErrorMessageHidden = false, isLabelHidden = false,
33208
33158
  onChange(normalizedNextValue);
33209
33159
  }, [onChange]);
33210
33160
  useFieldUndefineEffect(isUndefinedWhenDisabled && originalProps.disabled, onChange);
33211
- return (jsxs(Field$2, { className: "Field-TextInput", children: [jsx(Label, { disabled: originalProps.disabled, hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(StyledInput, { "$hasError": hasError, "$isLight": isLight, id: originalProps.name, onChange: handleChange, type: "text", value: controlledValue, ...originalProps }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
33161
+ return (jsxs(Field$2, { className: "Field-TextInput", children: [jsx(Label, { disabled: originalProps.disabled, hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsx(StyledInput, { "$hasError": hasError, "$isLight": isLight, id: originalProps.name, onChange: handleChange, type: "text", value: value, ...originalProps }, key), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
33212
33162
  }
33213
33163
  const StyledInput = styled(Input) `
33214
33164
  background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)};
@@ -33339,5 +33289,26 @@ function FormikTextInput({ name, ...originalProps }) {
33339
33289
  return jsx(TextInput, { error: meta.error, name: name, onChange: handleChange, value: field.value, ...originalProps });
33340
33290
  }
33341
33291
 
33342
- export { Accent, Button, Checkbox, CoordinatesFormat, CoordinatesInput, DatePicker, DateRangePicker, Dropdown, Field$2 as Field, Fieldset, FormikCheckbox, FormikCoordinatesInput, FormikDatePicker, FormikDateRangePicker, FormikEffect, FormikMultiCheckbox, FormikMultiRadio, FormikMultiSelect, FormikNumberInput, FormikSearch, FormikSelect, FormikTextInput, FormikTextarea, GlobalStyle, index as Icon, IconButton, Label, Legend, MultiCheckbox, MultiRadio, MultiSelect, MultiZoneEditor, NumberInput, OPENLAYERS_PROJECTION, OnlyFontGlobalStyle, Search, Select, SingleTag, Size, THEME, Tag, TagBullet, TagGroup, TextInput, Textarea, ThemeProvider, WSG84_PROJECTION, coordinatesAreDistinct, customDayjs, getCoordinates, getLocalizedDayjs, getPseudoRandomString, getUtcizedDayjs, isNumeric, noop, stopMouseEventPropagation, useClickOutsideEffect, useForceUpdate, useKey, usePrevious };
33292
+ function useFieldControl(value, onChange, defaultValueWhenUndefined) {
33293
+ const previousValue = usePrevious(value);
33294
+ const [internalValue, setInternalValue] = useState(value);
33295
+ const controlledValue = internalValue === undefined && defaultValueWhenUndefined !== undefined ? defaultValueWhenUndefined : internalValue;
33296
+ // We keep track of the field value changes via `internalValue`
33297
+ const controlledOnChange = useCallback((nextValue) => {
33298
+ setInternalValue(nextValue);
33299
+ if (onChange) {
33300
+ onChange(nextValue);
33301
+ }
33302
+ }, [onChange]);
33303
+ // And we override `internalValue` each time the `value` prop is updated
33304
+ useEffect(() => {
33305
+ if (lodashExports.isEqual(value, previousValue)) {
33306
+ return;
33307
+ }
33308
+ setInternalValue(value);
33309
+ }, [previousValue, value]);
33310
+ return { controlledOnChange, controlledValue };
33311
+ }
33312
+
33313
+ export { Accent, Button, Checkbox, CoordinatesFormat, CoordinatesInput, DatePicker, DateRangePicker, Dropdown, Field$2 as Field, Fieldset, FormikCheckbox, FormikCoordinatesInput, FormikDatePicker, FormikDateRangePicker, FormikEffect, FormikMultiCheckbox, FormikMultiRadio, FormikMultiSelect, FormikNumberInput, FormikSearch, FormikSelect, FormikTextInput, FormikTextarea, GlobalStyle, index as Icon, IconButton, Label, Legend, MultiCheckbox, MultiRadio, MultiSelect, MultiZoneEditor, NumberInput, OPENLAYERS_PROJECTION, OnlyFontGlobalStyle, Search, Select, SingleTag, Size, THEME, Tag, TagBullet, TagGroup, TextInput, Textarea, ThemeProvider, WSG84_PROJECTION, coordinatesAreDistinct, customDayjs, getCoordinates, getLocalizedDayjs, getPseudoRandomString, getUtcizedDayjs, isNumeric, noop, stopMouseEventPropagation, useClickOutsideEffect, useFieldControl, useForceUpdate, useKey, usePrevious };
33343
33314
  //# sourceMappingURL=index.js.map