@bigbinary/neeto-atoms 1.0.27 → 1.0.28

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.
@@ -2656,11 +2656,42 @@ const SIZE_CONFIG = {
2656
2656
  large: { trigger: "h-10 text-sm", icon: "size-4" },
2657
2657
  };
2658
2658
 
2659
+ /** Coerce dayjs/moment-like objects or date strings to native Date. */
2660
+ const toNativeDate = (value) => {
2661
+ if (value == null)
2662
+ return null;
2663
+ if (value instanceof Date)
2664
+ return value;
2665
+ if (typeof value.toDate === "function") {
2666
+ return value.toDate();
2667
+ }
2668
+ if (typeof value === "string") {
2669
+ const parsed = new Date(value);
2670
+ if (!isNaN(parsed.getTime()))
2671
+ return parsed;
2672
+ }
2673
+ return null;
2674
+ };
2675
+ /** Coerce a single or range value to native Date(s). */
2676
+ const coerceDateValue = (value, type) => {
2677
+ if (value == null)
2678
+ return null;
2679
+ if (type === "range" && Array.isArray(value)) {
2680
+ return [toNativeDate(value[0]), toNativeDate(value[1])];
2681
+ }
2682
+ return toNativeDate(value);
2683
+ };
2684
+ /** Convert dayjs/moment format tokens to date-fns format tokens. */
2685
+ const normalizeDateFormat = (fmt) => fmt
2686
+ .replace(/YYYY/g, "yyyy")
2687
+ .replace(/YY/g, "yy")
2688
+ .replace(/DD/g, "dd")
2689
+ .replace(/\bD\b/g, "d");
2659
2690
  const formatDate = (date, formatStr) => {
2660
2691
  if (!date)
2661
2692
  return "";
2662
2693
  try {
2663
- return primitives_Calendar.format(date, formatStr);
2694
+ return primitives_Calendar.format(date, normalizeDateFormat(formatStr));
2664
2695
  }
2665
2696
  catch {
2666
2697
  return "";
@@ -2670,7 +2701,7 @@ const parseDate = (str, formatStr) => {
2670
2701
  if (!str)
2671
2702
  return null;
2672
2703
  try {
2673
- const parsed = parse(str, formatStr, new Date());
2704
+ const parsed = parse(str, normalizeDateFormat(formatStr), new Date());
2674
2705
  if (!isNaN(parsed.getTime()))
2675
2706
  return parsed;
2676
2707
  }
@@ -2727,8 +2758,8 @@ const DatePicker = React.forwardRef(({ value, defaultValue, onChange, type = "da
2727
2758
  const containerRef = React.useRef(null);
2728
2759
  const popoverContentId = React.useRef(`datepicker-popover-${generatedId}`).current;
2729
2760
  const [open, setOpen] = React.useState(false);
2730
- const [internalValue, setInternalValue] = React.useState(defaultValue ?? null);
2731
- const currentValue = value !== undefined ? value : internalValue;
2761
+ const [internalValue, setInternalValue] = React.useState(coerceDateValue(defaultValue, type) ?? null);
2762
+ const currentValue = value !== undefined ? coerceDateValue(value, type) : internalValue;
2732
2763
  const [calendarMonth, setCalendarMonth] = React.useState((type === "date"
2733
2764
  ? (value ?? defaultValue)
2734
2765
  : null) ?? new Date());
@@ -2959,4 +2990,4 @@ const DatePicker = React.forwardRef(({ value, defaultValue, onChange, type = "da
2959
2990
  DatePicker.displayName = "DatePicker";
2960
2991
 
2961
2992
  exports.DatePicker = DatePicker;
2962
- //# sourceMappingURL=DatePicker-CA113xZV.js.map
2993
+ //# sourceMappingURL=DatePicker-aFQ4yEf1.js.map