@underverse-ui/underverse 0.1.21 → 0.1.22

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.d.cts CHANGED
@@ -660,7 +660,7 @@ declare const ScrollArea: React$1.ForwardRefExoticComponent<ScrollAreaProps & Re
660
660
  interface DatePickerProps {
661
661
  id?: string;
662
662
  value?: Date;
663
- onChange: (date: Date) => void;
663
+ onChange: (date: Date | undefined) => void;
664
664
  placeholder?: string;
665
665
  className?: string;
666
666
  disabled?: boolean;
package/dist/index.d.ts CHANGED
@@ -660,7 +660,7 @@ declare const ScrollArea: React$1.ForwardRefExoticComponent<ScrollAreaProps & Re
660
660
  interface DatePickerProps {
661
661
  id?: string;
662
662
  value?: Date;
663
- onChange: (date: Date) => void;
663
+ onChange: (date: Date | undefined) => void;
664
664
  placeholder?: string;
665
665
  className?: string;
666
666
  disabled?: boolean;
package/dist/index.js CHANGED
@@ -4417,7 +4417,7 @@ ScrollArea.displayName = "ScrollArea";
4417
4417
  import * as React21 from "react";
4418
4418
  import { useId as useId3 } from "react";
4419
4419
  import { createPortal as createPortal7 } from "react-dom";
4420
- import { Calendar, ChevronLeft as ChevronLeft2, ChevronRight as ChevronRight3 } from "lucide-react";
4420
+ import { Calendar, ChevronLeft as ChevronLeft2, ChevronRight as ChevronRight3, X as XIcon } from "lucide-react";
4421
4421
  import { useTranslations as useTranslations5, useLocale } from "next-intl";
4422
4422
 
4423
4423
  // ../../lib/utils/date.ts
@@ -4621,6 +4621,7 @@ var DatePicker = ({
4621
4621
  const [dropdownPosition, setDropdownPosition] = React21.useState(null);
4622
4622
  const [viewDate, setViewDate] = React21.useState(value || /* @__PURE__ */ new Date());
4623
4623
  const triggerRef = React21.useRef(null);
4624
+ const dropdownRef = React21.useRef(null);
4624
4625
  useShadCNAnimations();
4625
4626
  const calculatePosition = React21.useCallback(() => {
4626
4627
  if (!triggerRef.current) return null;
@@ -4646,15 +4647,24 @@ var DatePicker = ({
4646
4647
  window.removeEventListener("scroll", handler, true);
4647
4648
  };
4648
4649
  }, [isOpen, calculatePosition]);
4650
+ React21.useEffect(() => {
4651
+ if (value) {
4652
+ setViewDate(value);
4653
+ } else {
4654
+ setViewDate(/* @__PURE__ */ new Date());
4655
+ }
4656
+ }, [value]);
4649
4657
  React21.useEffect(() => {
4650
4658
  if (!isOpen) return;
4651
4659
  const handleClickOutside = (event) => {
4652
4660
  const target = event.target;
4653
- if (triggerRef.current && !triggerRef.current.contains(target)) {
4654
- const dropdown = document.querySelector("[data-datepicker]");
4655
- if (dropdown && !dropdown.contains(target)) {
4656
- setIsOpen(false);
4657
- }
4661
+ const trigger = triggerRef.current;
4662
+ const dropdown = dropdownRef.current;
4663
+ if (!trigger || !dropdown) return;
4664
+ const clickedOutsideTrigger = !trigger.contains(target);
4665
+ const clickedOutsideDropdown = !dropdown.contains(target);
4666
+ if (clickedOutsideTrigger && clickedOutsideDropdown) {
4667
+ setIsOpen(false);
4658
4668
  }
4659
4669
  };
4660
4670
  const handleEscape = (event) => {
@@ -4670,11 +4680,18 @@ var DatePicker = ({
4670
4680
  };
4671
4681
  }, [isOpen]);
4672
4682
  const handleDateSelect = (date) => {
4673
- onChange(date);
4683
+ let selectedDate;
4684
+ if (value && (value.getHours() !== 0 || value.getMinutes() !== 0 || value.getSeconds() !== 0)) {
4685
+ selectedDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), value.getHours(), value.getMinutes(), value.getSeconds());
4686
+ } else {
4687
+ const now = /* @__PURE__ */ new Date();
4688
+ selectedDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), now.getHours(), now.getMinutes(), now.getSeconds());
4689
+ }
4690
+ onChange(selectedDate);
4674
4691
  setIsOpen(false);
4675
4692
  };
4676
4693
  const formatDateDisplay = (date) => {
4677
- return locale === "vi" /* VI */ ? formatDate(date) : formatDateShort(date);
4694
+ return formatDate(date);
4678
4695
  };
4679
4696
  const getDaysInMonth = (date) => {
4680
4697
  return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
@@ -4735,7 +4752,8 @@ var DatePicker = ({
4735
4752
  top: dropdownPosition?.top || 0,
4736
4753
  left: dropdownPosition?.left || 0,
4737
4754
  width: size === "sm" ? dropdownPosition?.width || 224 : dropdownPosition?.width || 256,
4738
- zIndex: 9999
4755
+ zIndex: 9999,
4756
+ pointerEvents: "none"
4739
4757
  },
4740
4758
  "data-state": isOpen ? "open" : "closed",
4741
4759
  className: cn(
@@ -4746,11 +4764,13 @@ var DatePicker = ({
4746
4764
  children: /* @__PURE__ */ jsxs23(
4747
4765
  "div",
4748
4766
  {
4767
+ ref: dropdownRef,
4749
4768
  className: cn(
4750
4769
  "rounded-md border bg-popover text-popover-foreground shadow-md",
4751
4770
  "backdrop-blur-sm bg-popover/95 border-border/60",
4752
4771
  size === "sm" ? "p-3 w-56" : "p-4 w-64"
4753
4772
  ),
4773
+ style: { pointerEvents: "auto" },
4754
4774
  children: [
4755
4775
  /* @__PURE__ */ jsxs23("div", { className: "flex items-center justify-between mb-4", children: [
4756
4776
  /* @__PURE__ */ jsx27(Button_default, { variant: "ghost", size: "sm", onClick: () => navigateMonth("prev"), className: "p-1 h-auto", children: /* @__PURE__ */ jsx27(ChevronLeft2, { className: "h-4 w-4" }) }),
@@ -4758,7 +4778,20 @@ var DatePicker = ({
4758
4778
  /* @__PURE__ */ jsx27(Button_default, { variant: "ghost", size: "sm", onClick: () => navigateMonth("next"), className: "p-1 h-auto", children: /* @__PURE__ */ jsx27(ChevronRight3, { className: "h-4 w-4" }) })
4759
4779
  ] }),
4760
4780
  /* @__PURE__ */ jsx27("div", { className: cn("grid grid-cols-7 gap-1", size === "sm" ? "mb-1" : "mb-2"), children: (weekdayLabels || ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]).map((day) => /* @__PURE__ */ jsx27("div", { className: cn("text-muted-foreground text-center font-medium", size === "sm" ? "text-[10px] py-0.5" : "text-xs py-1"), children: day }, day)) }),
4761
- /* @__PURE__ */ jsx27("div", { className: "grid grid-cols-7 gap-1", children: renderCalendar() })
4781
+ /* @__PURE__ */ jsx27("div", { className: "grid grid-cols-7 gap-1", children: renderCalendar() }),
4782
+ /* @__PURE__ */ jsx27("div", { className: "flex items-center justify-end mt-2", children: /* @__PURE__ */ jsx27(
4783
+ Button_default,
4784
+ {
4785
+ variant: "outline",
4786
+ size: "sm",
4787
+ onClick: () => {
4788
+ onChange(void 0);
4789
+ setIsOpen(false);
4790
+ setViewDate(/* @__PURE__ */ new Date());
4791
+ },
4792
+ children: clearLabel || t("clear")
4793
+ }
4794
+ ) })
4762
4795
  ]
4763
4796
  }
4764
4797
  )
@@ -4816,6 +4849,31 @@ var DatePicker = ({
4816
4849
  ),
4817
4850
  children: [
4818
4851
  /* @__PURE__ */ jsx27("span", { className: cn("truncate", !value && "text-muted-foreground"), children: value ? formatDateDisplay(value) : placeholder || t("placeholder") }),
4852
+ value && /* @__PURE__ */ jsx27(
4853
+ "span",
4854
+ {
4855
+ role: "button",
4856
+ "aria-label": clearLabel || t("clear"),
4857
+ tabIndex: 0,
4858
+ onClick: (e) => {
4859
+ e.preventDefault();
4860
+ e.stopPropagation();
4861
+ onChange(void 0);
4862
+ setViewDate(/* @__PURE__ */ new Date());
4863
+ },
4864
+ onKeyDown: (e) => {
4865
+ if (e.key === "Enter" || e.key === " ") {
4866
+ e.preventDefault();
4867
+ e.stopPropagation();
4868
+ onChange(void 0);
4869
+ setViewDate(/* @__PURE__ */ new Date());
4870
+ }
4871
+ },
4872
+ className: "absolute right-8 inline-flex items-center justify-center rounded-sm text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors cursor-pointer",
4873
+ style: { width: 20, height: 20 },
4874
+ children: /* @__PURE__ */ jsx27(XIcon, { className: "h-3.5 w-3.5" })
4875
+ }
4876
+ ),
4819
4877
  /* @__PURE__ */ jsx27(Calendar, { className: "h-4 w-4 text-muted-foreground ml-2" })
4820
4878
  ]
4821
4879
  }