@monolith-forensics/monolith-ui 1.2.109 → 1.2.111
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.
|
@@ -193,9 +193,10 @@ const InputSegment = styled.div `
|
|
|
193
193
|
}
|
|
194
194
|
`;
|
|
195
195
|
const DateInput = forwardRef(({ className, style = {}, defaultValue, value, format = "YYYY-MM-DD HH:mm:ss", label, description, arrow = true, size = "sm", variant = "outlined", clearable = false, required = false, onChange = () => { }, min, max, error, enableCalendar = false, utc = false, closeOnSelect = true, disabled = false, }, _ref) => {
|
|
196
|
-
|
|
196
|
+
// Determine controlled status only once at mount
|
|
197
|
+
const isControlled = useRef(value !== undefined);
|
|
197
198
|
const [unControlledValue, setUncontrolledValue] = useState(defaultValue);
|
|
198
|
-
const _value = isControlled ? value : unControlledValue;
|
|
199
|
+
const _value = isControlled.current ? value : unControlledValue;
|
|
199
200
|
const [selectedSegment, setSelectedSegment] = useState();
|
|
200
201
|
const [isOpen, setIsOpen] = useState(false);
|
|
201
202
|
// Check if format is date only and does not include time
|
|
@@ -351,7 +352,10 @@ const DateInput = forwardRef(({ className, style = {}, defaultValue, value, form
|
|
|
351
352
|
setUncontrolledValue((prev) => {
|
|
352
353
|
if (!(selectedSegment === null || selectedSegment === void 0 ? void 0 : selectedSegment.momentType))
|
|
353
354
|
return prev;
|
|
354
|
-
|
|
355
|
+
// if prev is null, use undefined - passing null to moment returns a null moment value
|
|
356
|
+
const momentValue = utc
|
|
357
|
+
? moment.utc(prev || undefined)
|
|
358
|
+
: moment(prev || undefined);
|
|
355
359
|
let newValue = moment(momentValue)
|
|
356
360
|
.set(selectedSegment.momentType, parseInt(tempValue, 10) -
|
|
357
361
|
(selectedSegment.type === "month" ? 1 : 0))
|
|
@@ -206,7 +206,8 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
|
|
|
206
206
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
207
207
|
const theme = useTheme();
|
|
208
208
|
const isObjectArray = (_a = Object.keys((data === null || data === void 0 ? void 0 : data[0]) || {})) === null || _a === void 0 ? void 0 : _a.includes("label");
|
|
209
|
-
|
|
209
|
+
// Determine controlled status only once at mount
|
|
210
|
+
const isControlled = useRef(value !== undefined);
|
|
210
211
|
const resolvedOptions = data.map((item) => ({
|
|
211
212
|
value: isObjectArray ? item.value : item,
|
|
212
213
|
label: isObjectArray ? item.label : item,
|
|
@@ -231,7 +232,7 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
|
|
|
231
232
|
* Get the correct value based on whether the component is controlled or not
|
|
232
233
|
* if controlled, use the controlled value, otherwise use the resolved value
|
|
233
234
|
*/
|
|
234
|
-
const _value = isControlled ? resolvedValue : valueState;
|
|
235
|
+
const _value = isControlled.current ? resolvedValue : valueState;
|
|
235
236
|
const [inputValue, setInputValue] = useState(typeof _value === "object" ? (_value === null || _value === void 0 ? void 0 : _value.label) || "" : _value || "");
|
|
236
237
|
const [isOpen, setIsOpen] = useState(false);
|
|
237
238
|
const [searchValue, setSearchValue] = useState("");
|
|
@@ -342,7 +343,7 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
|
|
|
342
343
|
setInputValue("");
|
|
343
344
|
setIsOpen(false);
|
|
344
345
|
handleChangeSelection(null);
|
|
345
|
-
!isControlled && setValueState(null);
|
|
346
|
+
!isControlled.current && setValueState(null);
|
|
346
347
|
setSearchValue("");
|
|
347
348
|
searchFn === null || searchFn === void 0 ? void 0 : searchFn("");
|
|
348
349
|
update();
|
|
@@ -356,7 +357,7 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
|
|
|
356
357
|
setIsOpen(false);
|
|
357
358
|
};
|
|
358
359
|
const handleChangeSelection = useCallback((option) => {
|
|
359
|
-
!isControlled && setValueState(option);
|
|
360
|
+
!isControlled.current && setValueState(option);
|
|
360
361
|
onChange === null || onChange === void 0 ? void 0 : onChange(option === null || option === void 0 ? void 0 : option.value, option);
|
|
361
362
|
}, [onChange]);
|
|
362
363
|
const handleAddItem = useCallback((newItem) => {
|
|
@@ -396,7 +397,7 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
|
|
|
396
397
|
else if (index < filteredItems.length - 1) {
|
|
397
398
|
newItem = filteredItems[index + 1];
|
|
398
399
|
}
|
|
399
|
-
!isControlled && setValueState(newItem);
|
|
400
|
+
!isControlled.current && setValueState(newItem);
|
|
400
401
|
onChange === null || onChange === void 0 ? void 0 : onChange(newItem.value, newItem);
|
|
401
402
|
return;
|
|
402
403
|
}
|
|
@@ -417,7 +418,7 @@ DropDownProps = {}, debounceTime = 150, sort = false, disabled = false, }) => {
|
|
|
417
418
|
else if (index > 0) {
|
|
418
419
|
newItem = filteredItems[index - 1];
|
|
419
420
|
}
|
|
420
|
-
!isControlled && setValueState(newItem);
|
|
421
|
+
!isControlled.current && setValueState(newItem);
|
|
421
422
|
onChange === null || onChange === void 0 ? void 0 : onChange(newItem.value, newItem);
|
|
422
423
|
return;
|
|
423
424
|
}
|