@ceed/ads 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.
@@ -1,3 +1,3 @@
1
1
  export declare function useControlledState<T>(controlledValue: T | undefined, defaultValue: T, onChange?: (value: T) => void, options?: {
2
2
  disableStrict?: boolean;
3
- }): [T, (value: T | ((prev: T) => T)) => void];
3
+ }): [T, (value: T | ((prev: T) => T)) => void, boolean];
package/dist/index.cjs CHANGED
@@ -405,25 +405,26 @@ var IconButton_default = IconButton;
405
405
  var import_react5 = require("react");
406
406
  function useControlledState(controlledValue, defaultValue, onChange, options) {
407
407
  const { current: isControlled } = (0, import_react5.useRef)(controlledValue !== void 0);
408
- const [displayValue, setDisplayValue] = (0, import_react5.useState)(
408
+ const [internalValue, setInternalValue] = (0, import_react5.useState)(
409
409
  controlledValue ?? defaultValue
410
410
  );
411
+ const displayValue = isControlled ? controlledValue : internalValue;
411
412
  (0, import_react5.useEffect)(() => {
412
413
  if (isControlled) {
413
- setDisplayValue(controlledValue ?? defaultValue);
414
+ setInternalValue(controlledValue);
414
415
  }
415
- }, [controlledValue, defaultValue, isControlled]);
416
+ }, [isControlled, controlledValue]);
416
417
  const handleChange = (0, import_react5.useCallback)(
417
418
  (value) => {
418
419
  const newValue = typeof value === "function" ? value(displayValue) : value;
419
- if (options?.disableStrict || !isControlled) {
420
- setDisplayValue(newValue);
420
+ if (!isControlled) {
421
+ setInternalValue(newValue);
421
422
  }
422
423
  onChange?.(newValue);
423
424
  },
424
- [isControlled, onChange, displayValue, options]
425
+ [isControlled, onChange, displayValue]
425
426
  );
426
- return [displayValue, handleChange];
427
+ return [displayValue, handleChange, isControlled];
427
428
  }
428
429
 
429
430
  // src/components/Autocomplete/Autocomplete.tsx
@@ -5054,7 +5055,6 @@ var MonthPicker = (0, import_react33.forwardRef)(
5054
5055
  * NOTE: 현재 CalendarDate는 YYYY-MM-DD로 개발하고 있어 date를 포함하여 value를 관리한다.
5055
5056
  * @see https://ecubelabs.atlassian.net/wiki/spaces/SW/pages/1938784349/Date#CalendarDate
5056
5057
  * @see https://github.com/Ecube-Labs/hds/pull/145
5057
- *
5058
5058
  */
5059
5059
  format = "YYYY/MM/DD",
5060
5060
  displayFormat = "YYYY/MM",
@@ -5064,7 +5064,7 @@ var MonthPicker = (0, import_react33.forwardRef)(
5064
5064
  } = props;
5065
5065
  const innerRef = (0, import_react33.useRef)(null);
5066
5066
  const buttonRef = (0, import_react33.useRef)(null);
5067
- const [value, setValue] = useControlledState(
5067
+ const [value, setValue, isControlled] = useControlledState(
5068
5068
  props.value,
5069
5069
  props.defaultValue || "",
5070
5070
  (0, import_react33.useCallback)(
@@ -5073,8 +5073,23 @@ var MonthPicker = (0, import_react33.forwardRef)(
5073
5073
  ),
5074
5074
  { disableStrict: true }
5075
5075
  );
5076
+ const getFormattedDisplayValue = (0, import_react33.useCallback)(
5077
+ (inputValue) => {
5078
+ if (!inputValue) return "";
5079
+ try {
5080
+ return formatValueString3(
5081
+ parseDate3(inputValue, format),
5082
+ displayFormat,
5083
+ locale
5084
+ );
5085
+ } catch (e) {
5086
+ return inputValue;
5087
+ }
5088
+ },
5089
+ [format, displayFormat, locale]
5090
+ );
5076
5091
  const [displayValue, setDisplayValue] = (0, import_react33.useState)(
5077
- () => value ? formatValueString3(parseDate3(value, format), displayFormat, locale) : ""
5092
+ () => getFormattedDisplayValue(value)
5078
5093
  );
5079
5094
  const [anchorEl, setAnchorEl] = (0, import_react33.useState)(null);
5080
5095
  const open = Boolean(anchorEl);
@@ -5087,26 +5102,17 @@ var MonthPicker = (0, import_react33.forwardRef)(
5087
5102
  innerRef
5088
5103
  ]);
5089
5104
  (0, import_react33.useEffect)(() => {
5090
- if (value === "") {
5091
- setDisplayValue("");
5092
- return;
5093
- }
5094
- const formattedValue = formatValueString3(
5095
- parseDate3(value, format),
5096
- displayFormat,
5097
- locale
5098
- );
5099
- setDisplayValue(formattedValue);
5100
- }, [displayFormat, format, value]);
5105
+ setDisplayValue(getFormattedDisplayValue(value));
5106
+ }, [value, getFormattedDisplayValue]);
5101
5107
  const handleChange = (0, import_react33.useCallback)(
5102
5108
  (event) => {
5103
- const value2 = event.target.value;
5104
- setDisplayValue(
5105
- value2 ? formatValueString3(parseDate3(value2, format), displayFormat, locale) : value2
5106
- );
5107
- setValue(value2);
5109
+ const newValue = event.target.value;
5110
+ setValue(newValue);
5111
+ if (!isControlled) {
5112
+ setDisplayValue(getFormattedDisplayValue(newValue));
5113
+ }
5108
5114
  },
5109
- [displayFormat, format, setValue, locale]
5115
+ [setValue, getFormattedDisplayValue, isControlled]
5110
5116
  );
5111
5117
  const handleCalendarToggle = (0, import_react33.useCallback)(
5112
5118
  (event) => {
package/dist/index.js CHANGED
@@ -313,25 +313,26 @@ var IconButton_default = IconButton;
313
313
  import { useState, useCallback, useEffect, useRef } from "react";
314
314
  function useControlledState(controlledValue, defaultValue, onChange, options) {
315
315
  const { current: isControlled } = useRef(controlledValue !== void 0);
316
- const [displayValue, setDisplayValue] = useState(
316
+ const [internalValue, setInternalValue] = useState(
317
317
  controlledValue ?? defaultValue
318
318
  );
319
+ const displayValue = isControlled ? controlledValue : internalValue;
319
320
  useEffect(() => {
320
321
  if (isControlled) {
321
- setDisplayValue(controlledValue ?? defaultValue);
322
+ setInternalValue(controlledValue);
322
323
  }
323
- }, [controlledValue, defaultValue, isControlled]);
324
+ }, [isControlled, controlledValue]);
324
325
  const handleChange = useCallback(
325
326
  (value) => {
326
327
  const newValue = typeof value === "function" ? value(displayValue) : value;
327
- if (options?.disableStrict || !isControlled) {
328
- setDisplayValue(newValue);
328
+ if (!isControlled) {
329
+ setInternalValue(newValue);
329
330
  }
330
331
  onChange?.(newValue);
331
332
  },
332
- [isControlled, onChange, displayValue, options]
333
+ [isControlled, onChange, displayValue]
333
334
  );
334
- return [displayValue, handleChange];
335
+ return [displayValue, handleChange, isControlled];
335
336
  }
336
337
 
337
338
  // src/components/Autocomplete/Autocomplete.tsx
@@ -5041,7 +5042,6 @@ var MonthPicker = forwardRef9(
5041
5042
  * NOTE: 현재 CalendarDate는 YYYY-MM-DD로 개발하고 있어 date를 포함하여 value를 관리한다.
5042
5043
  * @see https://ecubelabs.atlassian.net/wiki/spaces/SW/pages/1938784349/Date#CalendarDate
5043
5044
  * @see https://github.com/Ecube-Labs/hds/pull/145
5044
- *
5045
5045
  */
5046
5046
  format = "YYYY/MM/DD",
5047
5047
  displayFormat = "YYYY/MM",
@@ -5051,7 +5051,7 @@ var MonthPicker = forwardRef9(
5051
5051
  } = props;
5052
5052
  const innerRef = useRef7(null);
5053
5053
  const buttonRef = useRef7(null);
5054
- const [value, setValue] = useControlledState(
5054
+ const [value, setValue, isControlled] = useControlledState(
5055
5055
  props.value,
5056
5056
  props.defaultValue || "",
5057
5057
  useCallback12(
@@ -5060,8 +5060,23 @@ var MonthPicker = forwardRef9(
5060
5060
  ),
5061
5061
  { disableStrict: true }
5062
5062
  );
5063
+ const getFormattedDisplayValue = useCallback12(
5064
+ (inputValue) => {
5065
+ if (!inputValue) return "";
5066
+ try {
5067
+ return formatValueString3(
5068
+ parseDate3(inputValue, format),
5069
+ displayFormat,
5070
+ locale
5071
+ );
5072
+ } catch (e) {
5073
+ return inputValue;
5074
+ }
5075
+ },
5076
+ [format, displayFormat, locale]
5077
+ );
5063
5078
  const [displayValue, setDisplayValue] = useState10(
5064
- () => value ? formatValueString3(parseDate3(value, format), displayFormat, locale) : ""
5079
+ () => getFormattedDisplayValue(value)
5065
5080
  );
5066
5081
  const [anchorEl, setAnchorEl] = useState10(null);
5067
5082
  const open = Boolean(anchorEl);
@@ -5074,26 +5089,17 @@ var MonthPicker = forwardRef9(
5074
5089
  innerRef
5075
5090
  ]);
5076
5091
  useEffect9(() => {
5077
- if (value === "") {
5078
- setDisplayValue("");
5079
- return;
5080
- }
5081
- const formattedValue = formatValueString3(
5082
- parseDate3(value, format),
5083
- displayFormat,
5084
- locale
5085
- );
5086
- setDisplayValue(formattedValue);
5087
- }, [displayFormat, format, value]);
5092
+ setDisplayValue(getFormattedDisplayValue(value));
5093
+ }, [value, getFormattedDisplayValue]);
5088
5094
  const handleChange = useCallback12(
5089
5095
  (event) => {
5090
- const value2 = event.target.value;
5091
- setDisplayValue(
5092
- value2 ? formatValueString3(parseDate3(value2, format), displayFormat, locale) : value2
5093
- );
5094
- setValue(value2);
5096
+ const newValue = event.target.value;
5097
+ setValue(newValue);
5098
+ if (!isControlled) {
5099
+ setDisplayValue(getFormattedDisplayValue(newValue));
5100
+ }
5095
5101
  },
5096
- [displayFormat, format, setValue, locale]
5102
+ [setValue, getFormattedDisplayValue, isControlled]
5097
5103
  );
5098
5104
  const handleCalendarToggle = useCallback12(
5099
5105
  (event) => {