@ceed/ads 1.5.5 → 1.5.6-next.2

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 @@
1
- export declare function useControlledState<T>(controlledValue: T | undefined, defaultValue: T, onChange?: (value: T) => void, options?: {
2
- disableStrict?: boolean;
3
- }): [T, (value: T | ((prev: T) => T)) => void];
1
+ export declare function useControlledState<T>(controlledValue: T | undefined, defaultValue: T, onChange?: (value: T) => void): [T, (value: T | ((prev: T) => T)) => void, boolean];
package/dist/index.cjs CHANGED
@@ -403,27 +403,28 @@ var IconButton_default = IconButton;
403
403
 
404
404
  // src/hooks/use-controlled-state/index.ts
405
405
  var import_react5 = require("react");
406
- function useControlledState(controlledValue, defaultValue, onChange, options) {
406
+ function useControlledState(controlledValue, defaultValue, onChange) {
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
@@ -2363,8 +2364,7 @@ var DatePicker = (0, import_react19.forwardRef)(
2363
2364
  (0, import_react19.useCallback)(
2364
2365
  (value2) => onChange?.({ target: { name: props.name, value: value2 } }),
2365
2366
  [props.name, onChange]
2366
- ),
2367
- { disableStrict: true }
2367
+ )
2368
2368
  );
2369
2369
  const [displayValue, setDisplayValue] = (0, import_react19.useState)(
2370
2370
  () => value ? formatValueString(parseDate(value, format), displayFormat) : ""
@@ -4141,8 +4141,7 @@ var DateRangePicker = (0, import_react26.forwardRef)(
4141
4141
  (0, import_react26.useCallback)(
4142
4142
  (value2) => onChange?.({ target: { name: props.name, value: value2 } }),
4143
4143
  [props.name, onChange]
4144
- ),
4145
- { disableStrict: true }
4144
+ )
4146
4145
  );
4147
4146
  const [anchorEl, setAnchorEl] = (0, import_react26.useState)(null);
4148
4147
  const open = Boolean(anchorEl);
@@ -5054,7 +5053,6 @@ var MonthPicker = (0, import_react33.forwardRef)(
5054
5053
  * NOTE: 현재 CalendarDate는 YYYY-MM-DD로 개발하고 있어 date를 포함하여 value를 관리한다.
5055
5054
  * @see https://ecubelabs.atlassian.net/wiki/spaces/SW/pages/1938784349/Date#CalendarDate
5056
5055
  * @see https://github.com/Ecube-Labs/hds/pull/145
5057
- *
5058
5056
  */
5059
5057
  format = "YYYY/MM/DD",
5060
5058
  displayFormat = "YYYY/MM",
@@ -5064,17 +5062,31 @@ var MonthPicker = (0, import_react33.forwardRef)(
5064
5062
  } = props;
5065
5063
  const innerRef = (0, import_react33.useRef)(null);
5066
5064
  const buttonRef = (0, import_react33.useRef)(null);
5067
- const [value, setValue] = useControlledState(
5065
+ const [value, setValue, isControlled] = useControlledState(
5068
5066
  props.value,
5069
5067
  props.defaultValue || "",
5070
5068
  (0, import_react33.useCallback)(
5071
5069
  (value2) => onChange?.({ target: { name: props.name, value: value2 } }),
5072
5070
  [props.name, onChange]
5073
- ),
5074
- { disableStrict: true }
5071
+ )
5072
+ );
5073
+ const getFormattedDisplayValue = (0, import_react33.useCallback)(
5074
+ (inputValue) => {
5075
+ if (!inputValue) return "";
5076
+ try {
5077
+ return formatValueString3(
5078
+ parseDate3(inputValue, format),
5079
+ displayFormat,
5080
+ locale
5081
+ );
5082
+ } catch (e) {
5083
+ return inputValue;
5084
+ }
5085
+ },
5086
+ [format, displayFormat, locale]
5075
5087
  );
5076
5088
  const [displayValue, setDisplayValue] = (0, import_react33.useState)(
5077
- () => value ? formatValueString3(parseDate3(value, format), displayFormat, locale) : ""
5089
+ () => getFormattedDisplayValue(value)
5078
5090
  );
5079
5091
  const [anchorEl, setAnchorEl] = (0, import_react33.useState)(null);
5080
5092
  const open = Boolean(anchorEl);
@@ -5087,26 +5099,17 @@ var MonthPicker = (0, import_react33.forwardRef)(
5087
5099
  innerRef
5088
5100
  ]);
5089
5101
  (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]);
5102
+ setDisplayValue(getFormattedDisplayValue(value));
5103
+ }, [value, getFormattedDisplayValue]);
5101
5104
  const handleChange = (0, import_react33.useCallback)(
5102
5105
  (event) => {
5103
- const value2 = event.target.value;
5104
- setDisplayValue(
5105
- value2 ? formatValueString3(parseDate3(value2, format), displayFormat, locale) : value2
5106
- );
5107
- setValue(value2);
5106
+ const newValue = event.target.value;
5107
+ setValue(newValue);
5108
+ if (!isControlled) {
5109
+ setDisplayValue(getFormattedDisplayValue(newValue));
5110
+ }
5108
5111
  },
5109
- [displayFormat, format, setValue, locale]
5112
+ [setValue, getFormattedDisplayValue, isControlled]
5110
5113
  );
5111
5114
  const handleCalendarToggle = (0, import_react33.useCallback)(
5112
5115
  (event) => {
@@ -5358,8 +5361,7 @@ var MonthRangePicker = (0, import_react34.forwardRef)(
5358
5361
  (0, import_react34.useCallback)(
5359
5362
  (value2) => onChange?.({ target: { name: props.name, value: value2 } }),
5360
5363
  [props.name, onChange]
5361
- ),
5362
- { disableStrict: true }
5364
+ )
5363
5365
  );
5364
5366
  const [anchorEl, setAnchorEl] = (0, import_react34.useState)(null);
5365
5367
  const open = Boolean(anchorEl);
package/dist/index.js CHANGED
@@ -311,27 +311,28 @@ var IconButton_default = IconButton;
311
311
 
312
312
  // src/hooks/use-controlled-state/index.ts
313
313
  import { useState, useCallback, useEffect, useRef } from "react";
314
- function useControlledState(controlledValue, defaultValue, onChange, options) {
314
+ function useControlledState(controlledValue, defaultValue, onChange) {
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
@@ -2314,8 +2315,7 @@ var DatePicker = forwardRef6(
2314
2315
  useCallback7(
2315
2316
  (value2) => onChange?.({ target: { name: props.name, value: value2 } }),
2316
2317
  [props.name, onChange]
2317
- ),
2318
- { disableStrict: true }
2318
+ )
2319
2319
  );
2320
2320
  const [displayValue, setDisplayValue] = useState5(
2321
2321
  () => value ? formatValueString(parseDate(value, format), displayFormat) : ""
@@ -4106,8 +4106,7 @@ var DateRangePicker = forwardRef8(
4106
4106
  useCallback10(
4107
4107
  (value2) => onChange?.({ target: { name: props.name, value: value2 } }),
4108
4108
  [props.name, onChange]
4109
- ),
4110
- { disableStrict: true }
4109
+ )
4111
4110
  );
4112
4111
  const [anchorEl, setAnchorEl] = useState7(null);
4113
4112
  const open = Boolean(anchorEl);
@@ -5041,7 +5040,6 @@ var MonthPicker = forwardRef9(
5041
5040
  * NOTE: 현재 CalendarDate는 YYYY-MM-DD로 개발하고 있어 date를 포함하여 value를 관리한다.
5042
5041
  * @see https://ecubelabs.atlassian.net/wiki/spaces/SW/pages/1938784349/Date#CalendarDate
5043
5042
  * @see https://github.com/Ecube-Labs/hds/pull/145
5044
- *
5045
5043
  */
5046
5044
  format = "YYYY/MM/DD",
5047
5045
  displayFormat = "YYYY/MM",
@@ -5051,17 +5049,31 @@ var MonthPicker = forwardRef9(
5051
5049
  } = props;
5052
5050
  const innerRef = useRef7(null);
5053
5051
  const buttonRef = useRef7(null);
5054
- const [value, setValue] = useControlledState(
5052
+ const [value, setValue, isControlled] = useControlledState(
5055
5053
  props.value,
5056
5054
  props.defaultValue || "",
5057
5055
  useCallback12(
5058
5056
  (value2) => onChange?.({ target: { name: props.name, value: value2 } }),
5059
5057
  [props.name, onChange]
5060
- ),
5061
- { disableStrict: true }
5058
+ )
5059
+ );
5060
+ const getFormattedDisplayValue = useCallback12(
5061
+ (inputValue) => {
5062
+ if (!inputValue) return "";
5063
+ try {
5064
+ return formatValueString3(
5065
+ parseDate3(inputValue, format),
5066
+ displayFormat,
5067
+ locale
5068
+ );
5069
+ } catch (e) {
5070
+ return inputValue;
5071
+ }
5072
+ },
5073
+ [format, displayFormat, locale]
5062
5074
  );
5063
5075
  const [displayValue, setDisplayValue] = useState10(
5064
- () => value ? formatValueString3(parseDate3(value, format), displayFormat, locale) : ""
5076
+ () => getFormattedDisplayValue(value)
5065
5077
  );
5066
5078
  const [anchorEl, setAnchorEl] = useState10(null);
5067
5079
  const open = Boolean(anchorEl);
@@ -5074,26 +5086,17 @@ var MonthPicker = forwardRef9(
5074
5086
  innerRef
5075
5087
  ]);
5076
5088
  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]);
5089
+ setDisplayValue(getFormattedDisplayValue(value));
5090
+ }, [value, getFormattedDisplayValue]);
5088
5091
  const handleChange = useCallback12(
5089
5092
  (event) => {
5090
- const value2 = event.target.value;
5091
- setDisplayValue(
5092
- value2 ? formatValueString3(parseDate3(value2, format), displayFormat, locale) : value2
5093
- );
5094
- setValue(value2);
5093
+ const newValue = event.target.value;
5094
+ setValue(newValue);
5095
+ if (!isControlled) {
5096
+ setDisplayValue(getFormattedDisplayValue(newValue));
5097
+ }
5095
5098
  },
5096
- [displayFormat, format, setValue, locale]
5099
+ [setValue, getFormattedDisplayValue, isControlled]
5097
5100
  );
5098
5101
  const handleCalendarToggle = useCallback12(
5099
5102
  (event) => {
@@ -5353,8 +5356,7 @@ var MonthRangePicker = forwardRef10(
5353
5356
  useCallback13(
5354
5357
  (value2) => onChange?.({ target: { name: props.name, value: value2 } }),
5355
5358
  [props.name, onChange]
5356
- ),
5357
- { disableStrict: true }
5359
+ )
5358
5360
  );
5359
5361
  const [anchorEl, setAnchorEl] = useState11(null);
5360
5362
  const open = Boolean(anchorEl);