@mtes-mct/monitor-ui 4.0.1 → 4.0.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/CHANGELOG.md +14 -0
- package/cypress/index.js +50 -53
- package/cypress/index.js.map +1 -1
- package/fields/MultiSelect.d.ts +1 -3
- package/fields/Select.d.ts +1 -1
- package/hooks/useFieldControl.d.ts +9 -0
- package/index.js +84 -108
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/utils/getRsuiteValueFromOptionValue.d.ts +2 -0
package/index.js
CHANGED
|
@@ -2841,7 +2841,6 @@ p.disabled ? p.theme.color.lightGray : p.hasError ? p.theme.color.maximumRed : p
|
|
|
2841
2841
|
margin-bottom: 4px;
|
|
2842
2842
|
`;
|
|
2843
2843
|
|
|
2844
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
2845
2844
|
function Legend({ disabled = false, hasError = false, isHidden = false, ...nativeProps }) {
|
|
2846
2845
|
return jsx(StyledLabel, { as: "legend", disabled: disabled, hasError: hasError, isHidden: isHidden, ...nativeProps });
|
|
2847
2846
|
}
|
|
@@ -3491,9 +3490,7 @@ const useClickOutsideEffect = (zoneRefOrzoneRefs, action, baseContainer) => {
|
|
|
3491
3490
|
}, [baseContainer, handleClickOutside]);
|
|
3492
3491
|
};
|
|
3493
3492
|
|
|
3494
|
-
function useFieldUndefineEffect(
|
|
3495
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
3496
|
-
disabled, onChange, onDisable) {
|
|
3493
|
+
function useFieldUndefineEffect(disabled, onChange, onDisable) {
|
|
3497
3494
|
useEffect(() => {
|
|
3498
3495
|
if (!disabled) {
|
|
3499
3496
|
return;
|
|
@@ -20718,8 +20715,7 @@ var lodash = {
|
|
|
20718
20715
|
* @see https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
|
|
20719
20716
|
*/
|
|
20720
20717
|
function useForceUpdate() {
|
|
20721
|
-
|
|
20722
|
-
const [_, forceUpdate] = useReducer(x => x + 1, 0);
|
|
20718
|
+
const [, forceUpdate] = useReducer(x => x + 1, 0);
|
|
20723
20719
|
const forceDebouncedUpdate = useMemo(() => lodashExports.throttle(forceUpdate, 500), [forceUpdate]);
|
|
20724
20720
|
return { forceDebouncedUpdate, forceUpdate };
|
|
20725
20721
|
}
|
|
@@ -20737,7 +20733,7 @@ const getPseudoRandomString = () => Math.random().toString(36).slice(2);
|
|
|
20737
20733
|
function useKey(deps) {
|
|
20738
20734
|
const keyRef = useRef(getPseudoRandomString());
|
|
20739
20735
|
const prevDeps = usePrevious(deps);
|
|
20740
|
-
if (
|
|
20736
|
+
if (lodashExports.isEqual(deps, prevDeps)) {
|
|
20741
20737
|
return keyRef.current;
|
|
20742
20738
|
}
|
|
20743
20739
|
keyRef.current = getPseudoRandomString();
|
|
@@ -21393,9 +21389,7 @@ const StyledNumberInput = styled.input `
|
|
|
21393
21389
|
}
|
|
21394
21390
|
`;
|
|
21395
21391
|
|
|
21396
|
-
function DateInputWithRef({ baseContainer, defaultValue,
|
|
21397
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
21398
|
-
disabled = false, isCompact, isEndDate = false, isForcedFocused, isLight, isStartDate = false, onBack, onChange, onClick, onNext, onPrevious }, ref) {
|
|
21392
|
+
function DateInputWithRef({ baseContainer, defaultValue, disabled = false, isCompact, isEndDate = false, isForcedFocused, isLight, isStartDate = false, onBack, onChange, onClick, onNext, onPrevious }, ref) {
|
|
21399
21393
|
const boxRef = useRef();
|
|
21400
21394
|
const dayInputRef = useRef();
|
|
21401
21395
|
const monthInputRef = useRef();
|
|
@@ -21579,9 +21573,7 @@ const Option = styled.div `
|
|
|
21579
21573
|
}
|
|
21580
21574
|
`;
|
|
21581
21575
|
|
|
21582
|
-
function TimeInputWithRef({ baseContainer, defaultValue,
|
|
21583
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
21584
|
-
disabled = false, isCompact, isEndDate = false, isLight, isStartDate = false, minutesRange = 15, onBack, onChange, onFocus, onNext, onPrevious }, ref) {
|
|
21576
|
+
function TimeInputWithRef({ baseContainer, defaultValue, disabled = false, isCompact, isEndDate = false, isLight, isStartDate = false, minutesRange = 15, onBack, onChange, onFocus, onNext, onPrevious }, ref) {
|
|
21585
21577
|
const boxRef = useRef();
|
|
21586
21578
|
const hourInputRef = useRef();
|
|
21587
21579
|
const minuteInputRef = useRef();
|
|
@@ -21693,9 +21685,7 @@ const InputGroup = styled.div `
|
|
|
21693
21685
|
}
|
|
21694
21686
|
`;
|
|
21695
21687
|
|
|
21696
|
-
function DatePicker({ baseContainer, defaultValue,
|
|
21697
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
21698
|
-
disabled = false, error, isCompact = false, isHistorical = false, isLabelHidden = false, isLight = false, isStringDate = false, label, minutesRange = 15, onChange, withTime = false, ...nativeProps }) {
|
|
21688
|
+
function DatePicker({ baseContainer, defaultValue, disabled = false, error, isCompact = false, isHistorical = false, isLabelHidden = false, isLight = false, isStringDate = false, label, minutesRange = 15, onChange, withTime = false, ...nativeProps }) {
|
|
21699
21689
|
const boxRef = useRef();
|
|
21700
21690
|
const dateInputRef = useRef();
|
|
21701
21691
|
const timeInputRef = useRef();
|
|
@@ -22016,9 +22006,7 @@ var DateRangePosition;
|
|
|
22016
22006
|
DateRangePosition["START"] = "START";
|
|
22017
22007
|
})(DateRangePosition || (DateRangePosition = {}));
|
|
22018
22008
|
|
|
22019
|
-
function DateRangePicker({ baseContainer, defaultValue,
|
|
22020
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22021
|
-
disabled = false, error, isCompact = false, isHistorical = false, isLabelHidden = false, isLight = false, isStringDate = false, label, minutesRange = 15, onChange, withTime = false, ...nativeProps }) {
|
|
22009
|
+
function DateRangePicker({ baseContainer, defaultValue, disabled = false, error, isCompact = false, isHistorical = false, isLabelHidden = false, isLight = false, isStringDate = false, label, minutesRange = 15, onChange, withTime = false, ...nativeProps }) {
|
|
22022
22010
|
const startDateInputRef = useRef();
|
|
22023
22011
|
const startTimeInputRef = useRef();
|
|
22024
22012
|
const endDateInputRef = useRef();
|
|
@@ -22207,9 +22195,7 @@ const Field = styled.span `
|
|
|
22207
22195
|
}};
|
|
22208
22196
|
`;
|
|
22209
22197
|
|
|
22210
|
-
function MultiCheckbox({ value = [],
|
|
22211
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22212
|
-
disabled = false, error, isInline = false, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, name, onChange, options }) {
|
|
22198
|
+
function MultiCheckbox({ value = [], disabled = false, error, isInline = false, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, name, onChange, options }) {
|
|
22213
22199
|
// This tracks the component internal value which allows us to react to value changes after each checkbox toggling
|
|
22214
22200
|
const [internalValue, setInternalValue] = useState(value);
|
|
22215
22201
|
// and compare it with an eventual external value change (via the `value` prop)
|
|
@@ -22272,55 +22258,69 @@ const ChecboxesBox = styled.div `
|
|
|
22272
22258
|
`}
|
|
22273
22259
|
`;
|
|
22274
22260
|
|
|
22261
|
+
function useFieldControl(value, onChange, props) {
|
|
22262
|
+
const { disabled, isUndefinedWhenDisabled } = props;
|
|
22263
|
+
// This tracks the component internal value which allows us to react to value changes after the checkbox toggling
|
|
22264
|
+
const internalValueRef = useRef(value);
|
|
22265
|
+
// and compare it with an eventual external value change (via the `value` prop)
|
|
22266
|
+
const previousValue = usePrevious(value);
|
|
22267
|
+
const { forceUpdate } = useForceUpdate();
|
|
22268
|
+
const controlledValue = isUndefinedWhenDisabled && disabled ? undefined : internalValueRef.current;
|
|
22269
|
+
const controlledOnChange = useCallback((nextValue) => {
|
|
22270
|
+
internalValueRef.current = nextValue;
|
|
22271
|
+
if (onChange) {
|
|
22272
|
+
onChange(nextValue);
|
|
22273
|
+
}
|
|
22274
|
+
}, [onChange]);
|
|
22275
|
+
// We update the `internalValue` each time the `value` prop is updated
|
|
22276
|
+
useEffect(() => {
|
|
22277
|
+
if (lodashExports.isEqual(value, previousValue)) {
|
|
22278
|
+
return;
|
|
22279
|
+
}
|
|
22280
|
+
internalValueRef.current = value;
|
|
22281
|
+
forceUpdate();
|
|
22282
|
+
}, [forceUpdate, previousValue, value]);
|
|
22283
|
+
return { controlledOnChange, controlledValue };
|
|
22284
|
+
}
|
|
22285
|
+
|
|
22286
|
+
function getRsuiteValueFromOptionValue(optionValue, optionValueKey) {
|
|
22287
|
+
return optionValue !== undefined ? String(optionValueKey ? optionValue[optionValueKey] : optionValue) : undefined;
|
|
22288
|
+
}
|
|
22289
|
+
|
|
22275
22290
|
function getRsuiteDataFromOptions(options, optionValueKey) {
|
|
22276
|
-
const getDataValueFromOptionValue = (value) => String(optionValueKey ? value[optionValueKey] : value);
|
|
22277
22291
|
return options.map(({ value, ...rest }) => ({
|
|
22278
22292
|
...rest,
|
|
22279
22293
|
optionValue: value,
|
|
22280
|
-
value:
|
|
22294
|
+
value: getRsuiteValueFromOptionValue(value, optionValueKey)
|
|
22281
22295
|
}));
|
|
22282
22296
|
}
|
|
22283
22297
|
|
|
22284
|
-
|
|
22285
|
-
* Add the provided `item` in a collection if this collection doesn't include it or remove it if this collection does.
|
|
22286
|
-
*
|
|
22287
|
-
* This is useful with object collections and polymorphic types.
|
|
22288
|
-
*/
|
|
22289
|
-
function toggleInCollection(item, collection) {
|
|
22290
|
-
const isInCollection = includes(item, collection);
|
|
22291
|
-
return isInCollection ? reject(equals(item), collection) : [...collection, item];
|
|
22292
|
-
}
|
|
22293
|
-
|
|
22294
|
-
function MultiSelect({ baseContainer, error, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, onChange, options, optionValueKey,
|
|
22295
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22296
|
-
searchable = false, value, ...originalProps }) {
|
|
22298
|
+
function MultiSelect({ baseContainer, disabled = false, error, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, onChange, options, optionValueKey, searchable = false, value, ...originalProps }) {
|
|
22297
22299
|
// eslint-disable-next-line no-null/no-null
|
|
22298
22300
|
const boxRef = useRef(null);
|
|
22299
|
-
const selectedOptionValuesRef = useRef(value || []);
|
|
22300
22301
|
const [isOpen, setIsOpen] = useState(false);
|
|
22301
|
-
const controlledValue =
|
|
22302
|
+
const { controlledOnChange, controlledValue } = useFieldControl(value, onChange, {
|
|
22303
|
+
disabled,
|
|
22304
|
+
isUndefinedWhenDisabled
|
|
22305
|
+
});
|
|
22306
|
+
const controlledRsuiteValue = useMemo(() => (controlledValue || []).map(controlledValueItem => getRsuiteValueFromOptionValue(controlledValueItem, optionValueKey)), [controlledValue, optionValueKey]);
|
|
22302
22307
|
const controlledError = useMemo(() => normalizeString(error), [error]);
|
|
22303
22308
|
const data = useMemo(() => getRsuiteDataFromOptions(options, optionValueKey), [options, optionValueKey]);
|
|
22304
22309
|
const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
|
|
22305
|
-
const key = useKey([
|
|
22310
|
+
const key = useKey([disabled, originalProps.name, value]);
|
|
22306
22311
|
const { forceUpdate } = useForceUpdate();
|
|
22307
22312
|
const close = useCallback(() => {
|
|
22308
22313
|
setIsOpen(false);
|
|
22309
22314
|
}, []);
|
|
22310
|
-
const
|
|
22311
|
-
|
|
22312
|
-
|
|
22313
|
-
|
|
22314
|
-
|
|
22315
|
-
|
|
22316
|
-
|
|
22317
|
-
|
|
22318
|
-
|
|
22319
|
-
if (onChange) {
|
|
22320
|
-
const normalizedNextValue = !nextValues.length ? undefined : nextValues;
|
|
22321
|
-
onChange(normalizedNextValue);
|
|
22322
|
-
}
|
|
22323
|
-
}, [onChange]);
|
|
22315
|
+
const handleChange = useCallback((nextOptionRsuiteValues) => {
|
|
22316
|
+
const nextValue = nextOptionRsuiteValues
|
|
22317
|
+
? options
|
|
22318
|
+
.filter(option => nextOptionRsuiteValues.includes(optionValueKey ? option.value[optionValueKey] : String(option.value)))
|
|
22319
|
+
.map(option => option.value)
|
|
22320
|
+
: [];
|
|
22321
|
+
const normalizedNextValue = !nextValue.length ? undefined : nextValue;
|
|
22322
|
+
controlledOnChange(normalizedNextValue);
|
|
22323
|
+
}, [controlledOnChange, options, optionValueKey]);
|
|
22324
22324
|
const renderMenuItem = useCallback((node) => jsx("span", { title: String(node), children: String(node) }), []);
|
|
22325
22325
|
const toggle = useCallback((event) => {
|
|
22326
22326
|
let targetElement = event.target;
|
|
@@ -22335,14 +22335,14 @@ searchable = false, value, ...originalProps }) {
|
|
|
22335
22335
|
setIsOpen(!isOpen);
|
|
22336
22336
|
}
|
|
22337
22337
|
}, [isOpen]);
|
|
22338
|
-
useFieldUndefineEffect(isUndefinedWhenDisabled &&
|
|
22338
|
+
useFieldUndefineEffect(isUndefinedWhenDisabled && disabled, onChange);
|
|
22339
22339
|
useClickOutsideEffect(boxRef, close, baseContainer);
|
|
22340
22340
|
useEffect(() => {
|
|
22341
22341
|
forceUpdate();
|
|
22342
22342
|
}, [forceUpdate]);
|
|
22343
|
-
return (jsxs(Field$2, { children: [jsx(Label, { disabled:
|
|
22343
|
+
return (jsxs(Field$2, { 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,
|
|
22344
22344
|
// Since we customized `ItemDataType` type by adding `optionValue`, we have an optional vs required conflict
|
|
22345
|
-
|
|
22345
|
+
onChange: handleChange, onClick: toggle, open: isOpen, renderMenuItem: renderMenuItem, searchable: searchable, value: controlledRsuiteValue, ...originalProps }, key)) }), hasError && jsx(FieldError, { children: controlledError })] }));
|
|
22346
22346
|
}
|
|
22347
22347
|
const Box$4 = styled.div `
|
|
22348
22348
|
position: relative;
|
|
@@ -22465,30 +22465,18 @@ const Box$4 = styled.div `
|
|
|
22465
22465
|
}
|
|
22466
22466
|
`;
|
|
22467
22467
|
|
|
22468
|
-
function MultiRadio({
|
|
22469
|
-
|
|
22470
|
-
disabled
|
|
22471
|
-
|
|
22472
|
-
|
|
22473
|
-
// and compare it with an eventual external value change (via the `value` prop)
|
|
22474
|
-
const previousValue = usePrevious(value);
|
|
22475
|
-
// to decide which on is the source of "truth" in `controlledValue` (the last one to be changed is the true value)
|
|
22476
|
-
const controlledValue = useMemo(() => {
|
|
22477
|
-
// If the `value` has changed, `value` takes precedence,
|
|
22478
|
-
// otherwise we can use our current internal value
|
|
22479
|
-
const nextControlledValue = lodashExports.isEqual(value, previousValue) ? internalValue : value;
|
|
22480
|
-
return !isUndefinedWhenDisabled || !disabled ? nextControlledValue : undefined;
|
|
22481
|
-
}, [disabled, internalValue, isUndefinedWhenDisabled, previousValue, value]);
|
|
22468
|
+
function MultiRadio({ disabled = false, error, isInline = false, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, name, onChange, options, value }) {
|
|
22469
|
+
const { controlledOnChange, controlledValue } = useFieldControl(value, onChange, {
|
|
22470
|
+
disabled,
|
|
22471
|
+
isUndefinedWhenDisabled
|
|
22472
|
+
});
|
|
22482
22473
|
const controlledError = useMemo(() => normalizeString(error), [error]);
|
|
22483
22474
|
const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
|
|
22484
|
-
const key = useKey([
|
|
22475
|
+
const key = useKey([disabled, name, value]);
|
|
22485
22476
|
const handleChange = useCallback((nextOptionValue, isChecked) => {
|
|
22486
22477
|
const nextCheckedOptionValue = isChecked ? nextOptionValue : undefined;
|
|
22487
|
-
|
|
22488
|
-
|
|
22489
|
-
onChange(nextCheckedOptionValue);
|
|
22490
|
-
}
|
|
22491
|
-
}, [onChange]);
|
|
22478
|
+
controlledOnChange(nextCheckedOptionValue);
|
|
22479
|
+
}, [controlledOnChange]);
|
|
22492
22480
|
useFieldUndefineEffect(isUndefinedWhenDisabled && disabled, onChange);
|
|
22493
22481
|
return (jsxs(Fieldset, { 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)))) }), hasError && jsx(FieldError, { children: controlledError })] }, key));
|
|
22494
22482
|
}
|
|
@@ -22530,9 +22518,7 @@ const CheckboxesBox = styled.div `
|
|
|
22530
22518
|
`}
|
|
22531
22519
|
`;
|
|
22532
22520
|
|
|
22533
|
-
function MultiZoneEditor({ addButtonLabel, defaultValue = [],
|
|
22534
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22535
|
-
disabled = false, error, initialZone, isLabelHidden = false, isLight = false, label, labelPropName, onAdd, onCenter, onChange, onDelete, onEdit }) {
|
|
22521
|
+
function MultiZoneEditor({ addButtonLabel, defaultValue = [], disabled = false, error, initialZone, isLabelHidden = false, isLight = false, label, labelPropName, onAdd, onCenter, onChange, onDelete, onEdit }) {
|
|
22536
22522
|
const prevDefaultValueRef = useRef(defaultValue);
|
|
22537
22523
|
const [zones, setZones] = useState(defaultValue);
|
|
22538
22524
|
const controlledError = useMemo(() => normalizeString(error), [error]);
|
|
@@ -22642,9 +22628,7 @@ function isNumeric(val) {
|
|
|
22642
22628
|
}
|
|
22643
22629
|
|
|
22644
22630
|
// TODO This field should return undefined when cleared (i.e.: Select all & Backspace/Delete)
|
|
22645
|
-
function DDCoordinatesInput({ coordinates,
|
|
22646
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
22647
|
-
disabled = false, onChange }) {
|
|
22631
|
+
function DDCoordinatesInput({ coordinates, disabled = false, onChange }) {
|
|
22648
22632
|
const latitudeInputRef = useRef();
|
|
22649
22633
|
const longitudeInputRef = useRef();
|
|
22650
22634
|
const [latitudeError, setLatitudeError] = useState('');
|
|
@@ -32638,9 +32622,7 @@ const coordinatesAreDistinct = (nextCoordinates, coordinates) => {
|
|
|
32638
32622
|
// Open issue: https://github.com/uNmAnNeR/imaskjs/issues/761
|
|
32639
32623
|
const UntypedIMaskInput = IMaskInput;
|
|
32640
32624
|
// TODO This field should return undefined when cleared (i.e.: Select all & Backspace/Delete)
|
|
32641
|
-
function DMDCoordinatesInput({ coordinates, coordinatesFormat,
|
|
32642
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
32643
|
-
disabled = false, onChange }) {
|
|
32625
|
+
function DMDCoordinatesInput({ coordinates, coordinatesFormat, disabled = false, onChange }) {
|
|
32644
32626
|
const [error, setError] = useState('');
|
|
32645
32627
|
const [value, setValue] = useState('');
|
|
32646
32628
|
useEffect(() => {
|
|
@@ -32712,9 +32694,7 @@ const Box$2 = styled.div `
|
|
|
32712
32694
|
text-align: left;
|
|
32713
32695
|
`;
|
|
32714
32696
|
|
|
32715
|
-
function DMSCoordinatesInput({ coordinates, coordinatesFormat,
|
|
32716
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
32717
|
-
disabled = false, onChange }) {
|
|
32697
|
+
function DMSCoordinatesInput({ coordinates, coordinatesFormat, disabled = false, onChange }) {
|
|
32718
32698
|
/** Convert the coordinates to the [latitude, longitude] string format */
|
|
32719
32699
|
const defaultValue = useMemo(() => {
|
|
32720
32700
|
if (!coordinates?.length || !coordinatesFormat) {
|
|
@@ -32741,9 +32721,7 @@ const Box$1 = styled.div `
|
|
|
32741
32721
|
|
|
32742
32722
|
const noop = () => { };
|
|
32743
32723
|
|
|
32744
|
-
function CoordinatesInput({ coordinatesFormat, defaultValue,
|
|
32745
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
32746
|
-
error, isLabelHidden = false, isLight = false, label, onChange = noop, ...nativeProps }) {
|
|
32724
|
+
function CoordinatesInput({ coordinatesFormat, defaultValue, error, isLabelHidden = false, isLight = false, label, onChange = noop, ...nativeProps }) {
|
|
32747
32725
|
const controlledError = useMemo(() => normalizeString(error), [error]);
|
|
32748
32726
|
const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
|
|
32749
32727
|
const getCoordinatesInput = useCallback(() => {
|
|
@@ -32772,32 +32750,30 @@ const StyledFieldset = styled(Fieldset) `
|
|
|
32772
32750
|
}
|
|
32773
32751
|
`;
|
|
32774
32752
|
|
|
32775
|
-
function Select({ baseContainer, error, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, onChange, options, optionValueKey,
|
|
32776
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
32777
|
-
searchable = false, value, ...originalProps }) {
|
|
32753
|
+
function Select({ baseContainer, disabled = false, error, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, onChange, options, optionValueKey, searchable = false, value, ...originalProps }) {
|
|
32778
32754
|
// eslint-disable-next-line no-null/no-null
|
|
32779
32755
|
const boxRef = useRef(null);
|
|
32780
32756
|
const [isOpen, setIsOpen] = useState(false);
|
|
32781
32757
|
const { forceUpdate } = useForceUpdate();
|
|
32782
|
-
const controlledValue =
|
|
32758
|
+
const { controlledOnChange, controlledValue } = useFieldControl(value, onChange, {
|
|
32759
|
+
disabled,
|
|
32760
|
+
isUndefinedWhenDisabled
|
|
32761
|
+
});
|
|
32762
|
+
const controlledRsuiteValue = useMemo(() => getRsuiteValueFromOptionValue(controlledValue, optionValueKey), [controlledValue, optionValueKey]);
|
|
32783
32763
|
const controlledError = useMemo(() => normalizeString(error), [error]);
|
|
32784
32764
|
const data = useMemo(() => getRsuiteDataFromOptions(options, optionValueKey), [options, optionValueKey]);
|
|
32785
32765
|
const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
|
|
32786
|
-
const key = useKey([
|
|
32766
|
+
const key = useKey([disabled, originalProps.name, value]);
|
|
32787
32767
|
const close = useCallback(() => {
|
|
32788
32768
|
setIsOpen(false);
|
|
32789
32769
|
}, []);
|
|
32790
32770
|
const handleClean = useCallback(() => {
|
|
32791
|
-
|
|
32792
|
-
|
|
32793
|
-
}
|
|
32794
|
-
}, [onChange]);
|
|
32771
|
+
controlledOnChange(undefined);
|
|
32772
|
+
}, [controlledOnChange]);
|
|
32795
32773
|
const handleSelect = useCallback((_, selectedItem) => {
|
|
32796
32774
|
close();
|
|
32797
|
-
|
|
32798
|
-
|
|
32799
|
-
}
|
|
32800
|
-
}, [close, onChange]);
|
|
32775
|
+
controlledOnChange(selectedItem.optionValue);
|
|
32776
|
+
}, [close, controlledOnChange]);
|
|
32801
32777
|
const renderMenuItem = useCallback((node) => jsx("span", { title: String(node), children: String(node) }), []);
|
|
32802
32778
|
const toggle = useCallback((event) => {
|
|
32803
32779
|
let targetElement = event.target;
|
|
@@ -32814,14 +32790,14 @@ searchable = false, value, ...originalProps }) {
|
|
|
32814
32790
|
setIsOpen(!isOpen);
|
|
32815
32791
|
}
|
|
32816
32792
|
}, [isOpen]);
|
|
32817
|
-
useFieldUndefineEffect(isUndefinedWhenDisabled &&
|
|
32793
|
+
useFieldUndefineEffect(isUndefinedWhenDisabled && disabled, onChange);
|
|
32818
32794
|
useClickOutsideEffect(boxRef, close, baseContainer);
|
|
32819
32795
|
useEffect(() => {
|
|
32820
32796
|
forceUpdate();
|
|
32821
32797
|
}, [forceUpdate]);
|
|
32822
|
-
return (jsxs(Field$2, { children: [jsx(Label, { disabled:
|
|
32798
|
+
return (jsxs(Field$2, { 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,
|
|
32823
32799
|
// Since we customized `ItemDataType` type by adding `optionValue`, we have an optional vs required conflict
|
|
32824
|
-
onSelect: handleSelect, open: isOpen, renderMenuItem: renderMenuItem, searchable: searchable, value:
|
|
32800
|
+
onSelect: handleSelect, open: isOpen, renderMenuItem: renderMenuItem, searchable: searchable, value: controlledRsuiteValue, ...originalProps }, key)) }), hasError && jsx(FieldError, { children: controlledError })] }));
|
|
32825
32801
|
}
|
|
32826
32802
|
const StyledSelectPicker = styled(SelectPicker) `
|
|
32827
32803
|
> .rs-picker-toggle {
|