@ceed/cds 1.5.5 → 1.5.6-next.1
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/hooks/use-controlled-state/index.d.ts +1 -1
- package/dist/index.cjs +33 -27
- package/dist/index.js +33 -27
- package/framer/index.js +37 -37
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -408,25 +408,26 @@ var IconButton_default = IconButton;
|
|
|
408
408
|
var import_react5 = require("react");
|
|
409
409
|
function useControlledState(controlledValue, defaultValue, onChange, options) {
|
|
410
410
|
const { current: isControlled } = (0, import_react5.useRef)(controlledValue !== void 0);
|
|
411
|
-
const [
|
|
411
|
+
const [internalValue, setInternalValue] = (0, import_react5.useState)(
|
|
412
412
|
controlledValue ?? defaultValue
|
|
413
413
|
);
|
|
414
|
+
const displayValue = isControlled ? controlledValue : internalValue;
|
|
414
415
|
(0, import_react5.useEffect)(() => {
|
|
415
416
|
if (isControlled) {
|
|
416
|
-
|
|
417
|
+
setInternalValue(controlledValue);
|
|
417
418
|
}
|
|
418
|
-
}, [
|
|
419
|
+
}, [isControlled, controlledValue]);
|
|
419
420
|
const handleChange = (0, import_react5.useCallback)(
|
|
420
421
|
(value) => {
|
|
421
422
|
const newValue = typeof value === "function" ? value(displayValue) : value;
|
|
422
|
-
if (
|
|
423
|
-
|
|
423
|
+
if (!isControlled) {
|
|
424
|
+
setInternalValue(newValue);
|
|
424
425
|
}
|
|
425
426
|
onChange?.(newValue);
|
|
426
427
|
},
|
|
427
|
-
[isControlled, onChange, displayValue
|
|
428
|
+
[isControlled, onChange, displayValue]
|
|
428
429
|
);
|
|
429
|
-
return [displayValue, handleChange];
|
|
430
|
+
return [displayValue, handleChange, isControlled];
|
|
430
431
|
}
|
|
431
432
|
|
|
432
433
|
// src/components/Autocomplete/Autocomplete.tsx
|
|
@@ -4616,7 +4617,6 @@ var MonthPicker = (0, import_react33.forwardRef)(
|
|
|
4616
4617
|
* NOTE: 현재 CalendarDate는 YYYY-MM-DD로 개발하고 있어 date를 포함하여 value를 관리한다.
|
|
4617
4618
|
* @see https://ecubelabs.atlassian.net/wiki/spaces/SW/pages/1938784349/Date#CalendarDate
|
|
4618
4619
|
* @see https://github.com/Ecube-Labs/hds/pull/145
|
|
4619
|
-
*
|
|
4620
4620
|
*/
|
|
4621
4621
|
format = "YYYY/MM/DD",
|
|
4622
4622
|
displayFormat = "YYYY/MM",
|
|
@@ -4626,7 +4626,7 @@ var MonthPicker = (0, import_react33.forwardRef)(
|
|
|
4626
4626
|
} = props;
|
|
4627
4627
|
const innerRef = (0, import_react33.useRef)(null);
|
|
4628
4628
|
const buttonRef = (0, import_react33.useRef)(null);
|
|
4629
|
-
const [value, setValue] = useControlledState(
|
|
4629
|
+
const [value, setValue, isControlled] = useControlledState(
|
|
4630
4630
|
props.value,
|
|
4631
4631
|
props.defaultValue || "",
|
|
4632
4632
|
(0, import_react33.useCallback)(
|
|
@@ -4635,8 +4635,23 @@ var MonthPicker = (0, import_react33.forwardRef)(
|
|
|
4635
4635
|
),
|
|
4636
4636
|
{ disableStrict: true }
|
|
4637
4637
|
);
|
|
4638
|
+
const getFormattedDisplayValue = (0, import_react33.useCallback)(
|
|
4639
|
+
(inputValue) => {
|
|
4640
|
+
if (!inputValue) return "";
|
|
4641
|
+
try {
|
|
4642
|
+
return formatValueString3(
|
|
4643
|
+
parseDate3(inputValue, format),
|
|
4644
|
+
displayFormat,
|
|
4645
|
+
locale
|
|
4646
|
+
);
|
|
4647
|
+
} catch (e) {
|
|
4648
|
+
return inputValue;
|
|
4649
|
+
}
|
|
4650
|
+
},
|
|
4651
|
+
[format, displayFormat, locale]
|
|
4652
|
+
);
|
|
4638
4653
|
const [displayValue, setDisplayValue] = (0, import_react33.useState)(
|
|
4639
|
-
() =>
|
|
4654
|
+
() => getFormattedDisplayValue(value)
|
|
4640
4655
|
);
|
|
4641
4656
|
const [anchorEl, setAnchorEl] = (0, import_react33.useState)(null);
|
|
4642
4657
|
const open = Boolean(anchorEl);
|
|
@@ -4649,26 +4664,17 @@ var MonthPicker = (0, import_react33.forwardRef)(
|
|
|
4649
4664
|
innerRef
|
|
4650
4665
|
]);
|
|
4651
4666
|
(0, import_react33.useEffect)(() => {
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
return;
|
|
4655
|
-
}
|
|
4656
|
-
const formattedValue = formatValueString3(
|
|
4657
|
-
parseDate3(value, format),
|
|
4658
|
-
displayFormat,
|
|
4659
|
-
locale
|
|
4660
|
-
);
|
|
4661
|
-
setDisplayValue(formattedValue);
|
|
4662
|
-
}, [displayFormat, format, value]);
|
|
4667
|
+
setDisplayValue(getFormattedDisplayValue(value));
|
|
4668
|
+
}, [value, getFormattedDisplayValue]);
|
|
4663
4669
|
const handleChange = (0, import_react33.useCallback)(
|
|
4664
4670
|
(event) => {
|
|
4665
|
-
const
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4671
|
+
const newValue = event.target.value;
|
|
4672
|
+
setValue(newValue);
|
|
4673
|
+
if (!isControlled) {
|
|
4674
|
+
setDisplayValue(getFormattedDisplayValue(newValue));
|
|
4675
|
+
}
|
|
4670
4676
|
},
|
|
4671
|
-
[
|
|
4677
|
+
[setValue, getFormattedDisplayValue, isControlled]
|
|
4672
4678
|
);
|
|
4673
4679
|
const handleCalendarToggle = (0, import_react33.useCallback)(
|
|
4674
4680
|
(event) => {
|
package/dist/index.js
CHANGED
|
@@ -327,25 +327,26 @@ var IconButton_default = IconButton;
|
|
|
327
327
|
import { useState, useCallback, useEffect, useRef } from "react";
|
|
328
328
|
function useControlledState(controlledValue, defaultValue, onChange, options) {
|
|
329
329
|
const { current: isControlled } = useRef(controlledValue !== void 0);
|
|
330
|
-
const [
|
|
330
|
+
const [internalValue, setInternalValue] = useState(
|
|
331
331
|
controlledValue ?? defaultValue
|
|
332
332
|
);
|
|
333
|
+
const displayValue = isControlled ? controlledValue : internalValue;
|
|
333
334
|
useEffect(() => {
|
|
334
335
|
if (isControlled) {
|
|
335
|
-
|
|
336
|
+
setInternalValue(controlledValue);
|
|
336
337
|
}
|
|
337
|
-
}, [
|
|
338
|
+
}, [isControlled, controlledValue]);
|
|
338
339
|
const handleChange = useCallback(
|
|
339
340
|
(value) => {
|
|
340
341
|
const newValue = typeof value === "function" ? value(displayValue) : value;
|
|
341
|
-
if (
|
|
342
|
-
|
|
342
|
+
if (!isControlled) {
|
|
343
|
+
setInternalValue(newValue);
|
|
343
344
|
}
|
|
344
345
|
onChange?.(newValue);
|
|
345
346
|
},
|
|
346
|
-
[isControlled, onChange, displayValue
|
|
347
|
+
[isControlled, onChange, displayValue]
|
|
347
348
|
);
|
|
348
|
-
return [displayValue, handleChange];
|
|
349
|
+
return [displayValue, handleChange, isControlled];
|
|
349
350
|
}
|
|
350
351
|
|
|
351
352
|
// src/components/Autocomplete/Autocomplete.tsx
|
|
@@ -4612,7 +4613,6 @@ var MonthPicker = forwardRef9(
|
|
|
4612
4613
|
* NOTE: 현재 CalendarDate는 YYYY-MM-DD로 개발하고 있어 date를 포함하여 value를 관리한다.
|
|
4613
4614
|
* @see https://ecubelabs.atlassian.net/wiki/spaces/SW/pages/1938784349/Date#CalendarDate
|
|
4614
4615
|
* @see https://github.com/Ecube-Labs/hds/pull/145
|
|
4615
|
-
*
|
|
4616
4616
|
*/
|
|
4617
4617
|
format = "YYYY/MM/DD",
|
|
4618
4618
|
displayFormat = "YYYY/MM",
|
|
@@ -4622,7 +4622,7 @@ var MonthPicker = forwardRef9(
|
|
|
4622
4622
|
} = props;
|
|
4623
4623
|
const innerRef = useRef6(null);
|
|
4624
4624
|
const buttonRef = useRef6(null);
|
|
4625
|
-
const [value, setValue] = useControlledState(
|
|
4625
|
+
const [value, setValue, isControlled] = useControlledState(
|
|
4626
4626
|
props.value,
|
|
4627
4627
|
props.defaultValue || "",
|
|
4628
4628
|
useCallback11(
|
|
@@ -4631,8 +4631,23 @@ var MonthPicker = forwardRef9(
|
|
|
4631
4631
|
),
|
|
4632
4632
|
{ disableStrict: true }
|
|
4633
4633
|
);
|
|
4634
|
+
const getFormattedDisplayValue = useCallback11(
|
|
4635
|
+
(inputValue) => {
|
|
4636
|
+
if (!inputValue) return "";
|
|
4637
|
+
try {
|
|
4638
|
+
return formatValueString3(
|
|
4639
|
+
parseDate3(inputValue, format),
|
|
4640
|
+
displayFormat,
|
|
4641
|
+
locale
|
|
4642
|
+
);
|
|
4643
|
+
} catch (e) {
|
|
4644
|
+
return inputValue;
|
|
4645
|
+
}
|
|
4646
|
+
},
|
|
4647
|
+
[format, displayFormat, locale]
|
|
4648
|
+
);
|
|
4634
4649
|
const [displayValue, setDisplayValue] = useState9(
|
|
4635
|
-
() =>
|
|
4650
|
+
() => getFormattedDisplayValue(value)
|
|
4636
4651
|
);
|
|
4637
4652
|
const [anchorEl, setAnchorEl] = useState9(null);
|
|
4638
4653
|
const open = Boolean(anchorEl);
|
|
@@ -4645,26 +4660,17 @@ var MonthPicker = forwardRef9(
|
|
|
4645
4660
|
innerRef
|
|
4646
4661
|
]);
|
|
4647
4662
|
useEffect8(() => {
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
return;
|
|
4651
|
-
}
|
|
4652
|
-
const formattedValue = formatValueString3(
|
|
4653
|
-
parseDate3(value, format),
|
|
4654
|
-
displayFormat,
|
|
4655
|
-
locale
|
|
4656
|
-
);
|
|
4657
|
-
setDisplayValue(formattedValue);
|
|
4658
|
-
}, [displayFormat, format, value]);
|
|
4663
|
+
setDisplayValue(getFormattedDisplayValue(value));
|
|
4664
|
+
}, [value, getFormattedDisplayValue]);
|
|
4659
4665
|
const handleChange = useCallback11(
|
|
4660
4666
|
(event) => {
|
|
4661
|
-
const
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4667
|
+
const newValue = event.target.value;
|
|
4668
|
+
setValue(newValue);
|
|
4669
|
+
if (!isControlled) {
|
|
4670
|
+
setDisplayValue(getFormattedDisplayValue(newValue));
|
|
4671
|
+
}
|
|
4666
4672
|
},
|
|
4667
|
-
[
|
|
4673
|
+
[setValue, getFormattedDisplayValue, isControlled]
|
|
4668
4674
|
);
|
|
4669
4675
|
const handleCalendarToggle = useCallback11(
|
|
4670
4676
|
(event) => {
|