kiban-design-system 1.1.8 → 1.1.9
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/index.cjs.js +109 -38
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +109 -38
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -16171,10 +16171,43 @@ const AlphaInputDate = ({
|
|
|
16171
16171
|
year: reference.getFullYear()
|
|
16172
16172
|
};
|
|
16173
16173
|
});
|
|
16174
|
-
const
|
|
16174
|
+
const initialDateState = (() => {
|
|
16175
|
+
if (value) {
|
|
16176
|
+
const validDate = getValidDate(value);
|
|
16177
|
+
if (validDate) {
|
|
16178
|
+
const normalizedDate = normalizeDate(validDate.start);
|
|
16179
|
+
return {
|
|
16180
|
+
selectedDate: {
|
|
16181
|
+
start: normalizedDate,
|
|
16182
|
+
end: normalizedDate
|
|
16183
|
+
},
|
|
16184
|
+
inputValue: formatDate(normalizedDate) || ""
|
|
16185
|
+
};
|
|
16186
|
+
}
|
|
16187
|
+
}
|
|
16188
|
+
return {
|
|
16189
|
+
selectedDate: null,
|
|
16190
|
+
inputValue: undefined
|
|
16191
|
+
};
|
|
16192
|
+
})();
|
|
16193
|
+
const [inputValue, setInputValue] = useState(initialDateState.inputValue);
|
|
16175
16194
|
const [isErrorTooltipActive, setIsErrorTooltipActive] = useState(false);
|
|
16176
|
-
const [selectedDate, setSelectedDate] = useState();
|
|
16195
|
+
const [selectedDate, setSelectedDate] = useState(initialDateState.selectedDate);
|
|
16177
16196
|
const inputRef = useRef(null);
|
|
16197
|
+
const isInternalUpdateRef = useRef(false);
|
|
16198
|
+
const lastValueRef = useRef(initialDateState.inputValue || value);
|
|
16199
|
+
const onChangeRef = useRef(onChange);
|
|
16200
|
+
const isMountedRef = useRef(false);
|
|
16201
|
+
|
|
16202
|
+
// Actualizar la referencia de onChange cuando cambia
|
|
16203
|
+
useEffect(() => {
|
|
16204
|
+
onChangeRef.current = onChange;
|
|
16205
|
+
}, [onChange]);
|
|
16206
|
+
|
|
16207
|
+
// Marcar que el componente está montado después del primer render
|
|
16208
|
+
useEffect(() => {
|
|
16209
|
+
isMountedRef.current = true;
|
|
16210
|
+
}, []);
|
|
16178
16211
|
const className = cssClassName(COMPONENT_NAME$s);
|
|
16179
16212
|
const normalizedMinDate = useMemo(() => minDate ? normalizeDate(minDate) : undefined, [minDate]);
|
|
16180
16213
|
const normalizedMaxDate = useMemo(() => maxDate ? normalizeDate(maxDate) : undefined, [maxDate]);
|
|
@@ -16185,13 +16218,22 @@ const AlphaInputDate = ({
|
|
|
16185
16218
|
});
|
|
16186
16219
|
};
|
|
16187
16220
|
const handleDateChange = date => {
|
|
16188
|
-
|
|
16189
|
-
|
|
16190
|
-
}
|
|
16221
|
+
const normalizedDate = normalizeDate(date.start);
|
|
16222
|
+
isInternalUpdateRef.current = true;
|
|
16191
16223
|
setSelectedDate({
|
|
16192
|
-
start:
|
|
16193
|
-
end:
|
|
16224
|
+
start: normalizedDate,
|
|
16225
|
+
end: normalizedDate
|
|
16226
|
+
});
|
|
16227
|
+
setInputValue(formatDate(normalizedDate) || "");
|
|
16228
|
+
setDate({
|
|
16229
|
+
month: normalizedDate.getMonth(),
|
|
16230
|
+
year: normalizedDate.getFullYear()
|
|
16194
16231
|
});
|
|
16232
|
+
lastValueRef.current = formatDate(normalizedDate) || undefined;
|
|
16233
|
+
if (onChangeRef.current && isMountedRef.current) {
|
|
16234
|
+
onChangeRef.current(normalizedDate);
|
|
16235
|
+
}
|
|
16236
|
+
isInternalUpdateRef.current = false;
|
|
16195
16237
|
setIsPopoverActive(false);
|
|
16196
16238
|
};
|
|
16197
16239
|
const handlePaste = e => {
|
|
@@ -16237,20 +16279,39 @@ const AlphaInputDate = ({
|
|
|
16237
16279
|
onBlur();
|
|
16238
16280
|
}
|
|
16239
16281
|
};
|
|
16282
|
+
|
|
16283
|
+
// Sincronizar value externo con selectedDate (solo cuando value cambia externamente)
|
|
16240
16284
|
useEffect(() => {
|
|
16241
|
-
if (
|
|
16242
|
-
|
|
16243
|
-
setSelectedDate(validDate || null);
|
|
16285
|
+
if (isInternalUpdateRef.current) {
|
|
16286
|
+
return;
|
|
16244
16287
|
}
|
|
16245
|
-
if (
|
|
16246
|
-
|
|
16247
|
-
|
|
16248
|
-
|
|
16249
|
-
|
|
16250
|
-
|
|
16251
|
-
|
|
16288
|
+
if (value !== lastValueRef.current) {
|
|
16289
|
+
lastValueRef.current = value;
|
|
16290
|
+
if (value !== undefined && value !== null && value !== "") {
|
|
16291
|
+
const validDate = getValidDate(value);
|
|
16292
|
+
if (validDate) {
|
|
16293
|
+
const normalizedDate = normalizeDate(validDate.start);
|
|
16294
|
+
setSelectedDate({
|
|
16295
|
+
start: normalizedDate,
|
|
16296
|
+
end: normalizedDate
|
|
16297
|
+
});
|
|
16298
|
+
setInputValue(formatDate(normalizedDate) || "");
|
|
16299
|
+
setDate({
|
|
16300
|
+
month: normalizedDate.getMonth(),
|
|
16301
|
+
year: normalizedDate.getFullYear()
|
|
16302
|
+
});
|
|
16303
|
+
}
|
|
16304
|
+
} else if (!value) {
|
|
16305
|
+
const fallback = normalizedMaxDate ?? normalizeDate();
|
|
16306
|
+
setDate({
|
|
16307
|
+
month: fallback.getMonth(),
|
|
16308
|
+
year: fallback.getFullYear()
|
|
16309
|
+
});
|
|
16310
|
+
setSelectedDate(null);
|
|
16311
|
+
setInputValue("");
|
|
16312
|
+
}
|
|
16252
16313
|
}
|
|
16253
|
-
}, [value,
|
|
16314
|
+
}, [value, normalizedMaxDate]);
|
|
16254
16315
|
useEffect(() => {
|
|
16255
16316
|
if (inputRef.current) {
|
|
16256
16317
|
inputRef.current.querySelector("input")?.addEventListener("paste", handlePaste);
|
|
@@ -16261,33 +16322,43 @@ const AlphaInputDate = ({
|
|
|
16261
16322
|
}
|
|
16262
16323
|
};
|
|
16263
16324
|
}, []);
|
|
16325
|
+
|
|
16326
|
+
// Sincronizar inputValue con selectedDate cuando el usuario escribe
|
|
16264
16327
|
useEffect(() => {
|
|
16265
|
-
if (inputValue
|
|
16266
|
-
|
|
16267
|
-
if (validDate) {
|
|
16268
|
-
setSelectedDate(validDate);
|
|
16269
|
-
} else {
|
|
16270
|
-
setSelectedDate(null);
|
|
16271
|
-
}
|
|
16328
|
+
if (isInternalUpdateRef.current || inputValue === undefined || !isMountedRef.current) {
|
|
16329
|
+
return;
|
|
16272
16330
|
}
|
|
16273
|
-
|
|
16274
|
-
|
|
16275
|
-
|
|
16276
|
-
|
|
16277
|
-
|
|
16331
|
+
const validDate = getValidDate(inputValue);
|
|
16332
|
+
if (validDate) {
|
|
16333
|
+
const normalizedDate = normalizeDate(validDate.start);
|
|
16334
|
+
const formattedDate = formatDate(normalizedDate) || undefined;
|
|
16335
|
+
// Solo actualizar si el valor formateado es diferente al último valor conocido
|
|
16336
|
+
if (formattedDate !== lastValueRef.current) {
|
|
16337
|
+
isInternalUpdateRef.current = true;
|
|
16338
|
+
setSelectedDate({
|
|
16339
|
+
start: normalizedDate,
|
|
16340
|
+
end: normalizedDate
|
|
16341
|
+
});
|
|
16278
16342
|
setDate({
|
|
16279
|
-
month:
|
|
16280
|
-
year:
|
|
16343
|
+
month: normalizedDate.getMonth(),
|
|
16344
|
+
year: normalizedDate.getFullYear()
|
|
16281
16345
|
});
|
|
16282
|
-
|
|
16283
|
-
if (
|
|
16284
|
-
|
|
16346
|
+
lastValueRef.current = formattedDate;
|
|
16347
|
+
if (onChangeRef.current) {
|
|
16348
|
+
onChangeRef.current(normalizedDate);
|
|
16285
16349
|
}
|
|
16286
|
-
|
|
16287
|
-
onChange(null);
|
|
16350
|
+
isInternalUpdateRef.current = false;
|
|
16288
16351
|
}
|
|
16352
|
+
} else if (inputValue === "" && lastValueRef.current !== undefined) {
|
|
16353
|
+
isInternalUpdateRef.current = true;
|
|
16354
|
+
setSelectedDate(null);
|
|
16355
|
+
lastValueRef.current = undefined;
|
|
16356
|
+
if (onChangeRef.current) {
|
|
16357
|
+
onChangeRef.current(null);
|
|
16358
|
+
}
|
|
16359
|
+
isInternalUpdateRef.current = false;
|
|
16289
16360
|
}
|
|
16290
|
-
}, [
|
|
16361
|
+
}, [inputValue]);
|
|
16291
16362
|
useEffect(() => {
|
|
16292
16363
|
if (!selectedDate && normalizedMaxDate) {
|
|
16293
16364
|
setDate(prevDate => {
|