@algorithm-shift/design-system 1.2.969 → 1.2.970

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.mjs CHANGED
@@ -27916,6 +27916,32 @@ function useLazyDropdown(config) {
27916
27916
  if (debounceTimer.current) clearTimeout(debounceTimer.current);
27917
27917
  };
27918
27918
  }, []);
27919
+ const createNewOption = async (label) => {
27920
+ if (!configRef.current.apiUrl) return null;
27921
+ const axiosClient = configRef.current.axiosInstance ?? axios;
27922
+ const apiUrl = configRef.current.apiUrl;
27923
+ const urlObj = new URL(
27924
+ apiUrl,
27925
+ typeof window !== "undefined" ? window.location.origin : "http://localhost"
27926
+ );
27927
+ const queryParams = {};
27928
+ urlObj.searchParams.forEach((value, key) => {
27929
+ queryParams[key] = value;
27930
+ });
27931
+ const body = {
27932
+ ...queryParams,
27933
+ [configRef.current.dataLabel]: label
27934
+ };
27935
+ const res = await axiosClient.post(urlObj.origin + urlObj.pathname, body, {
27936
+ withCredentials: true
27937
+ });
27938
+ if (res.data?.success && Array.isArray(res.data.data) && res.data.data.length > 0) {
27939
+ const fetched = transformToOptions(res.data.data);
27940
+ setOptions((prev) => uniqueOptions([...fetched, ...prev]));
27941
+ return fetched[0];
27942
+ }
27943
+ return null;
27944
+ };
27919
27945
  return {
27920
27946
  options,
27921
27947
  loading,
@@ -27923,7 +27949,8 @@ function useLazyDropdown(config) {
27923
27949
  loadMore,
27924
27950
  search,
27925
27951
  reset,
27926
- loadPage
27952
+ loadPage,
27953
+ createNewOption
27927
27954
  };
27928
27955
  }
27929
27956
 
@@ -27944,7 +27971,8 @@ function LazySelectDropdown({
27944
27971
  dataKey = "id",
27945
27972
  dataLabel = "name",
27946
27973
  errorMessage,
27947
- axiosInstance
27974
+ axiosInstance,
27975
+ enableAddNewOption = false
27948
27976
  }) {
27949
27977
  const [isOpen, setIsOpen] = useState5(false);
27950
27978
  const [searchTerm, setSearchTerm] = useState5("");
@@ -27957,7 +27985,8 @@ function LazySelectDropdown({
27957
27985
  loadMore,
27958
27986
  search,
27959
27987
  reset,
27960
- loadPage
27988
+ loadPage,
27989
+ createNewOption
27961
27990
  } = useLazyDropdown({
27962
27991
  enabled: true,
27963
27992
  dataSource: source || "",
@@ -28015,6 +28044,15 @@ function LazySelectDropdown({
28015
28044
  reset();
28016
28045
  search("");
28017
28046
  };
28047
+ const handleAddNewOption = async (newOption) => {
28048
+ const option = await createNewOption(newOption);
28049
+ if (option) {
28050
+ onChange?.(option.value, id || "");
28051
+ setIsOpen(false);
28052
+ setSearchTerm("");
28053
+ reset();
28054
+ }
28055
+ };
28018
28056
  return /* @__PURE__ */ jsxs18("div", { ref: dropdownRef, className: "relative w-full", children: [
28019
28057
  /* @__PURE__ */ jsx36(
28020
28058
  "input",
@@ -28084,7 +28122,19 @@ function LazySelectDropdown({
28084
28122
  ] }) : "Scroll for more..."
28085
28123
  }
28086
28124
  )
28087
- ] }) : /* @__PURE__ */ jsx36("div", { className: "px-3 py-4 text-sm text-center text-gray-500", children: searchTerm ? `No results for "${searchTerm}"` : "No options available" })
28125
+ ] }) : /* @__PURE__ */ jsxs18("div", { className: "px-3 py-4 text-sm text-center text-gray-500", children: [
28126
+ searchTerm ? `No results for "${searchTerm}"` : "No options available",
28127
+ enableAddNewOption && searchTerm && /* @__PURE__ */ jsx36(
28128
+ "div",
28129
+ {
28130
+ onClick: () => {
28131
+ handleAddNewOption(searchTerm);
28132
+ },
28133
+ className: "mt-2 px-3 py-2 bg-green-50 hover:bg-green-100 cursor-pointer text-green-700 rounded text-sm",
28134
+ children: `Add "${searchTerm}"`
28135
+ }
28136
+ )
28137
+ ] })
28088
28138
  }
28089
28139
  ) })
28090
28140
  ] });
@@ -28764,14 +28814,20 @@ function DateTimePicker({
28764
28814
  }, [date, mode]);
28765
28815
  const isInputDisabled = isDisabled || !isEditable;
28766
28816
  const [calendarMonthState, setCalendarMonthState] = React6.useState(() => {
28767
- return date ? new Date(date.getFullYear(), date.getMonth()) : new Date(year, 0);
28817
+ const currentMonth = (/* @__PURE__ */ new Date()).getMonth();
28818
+ return date ? new Date(date.getFullYear(), date.getMonth()) : new Date(year, currentMonth);
28768
28819
  });
28769
28820
  React6.useEffect(() => {
28770
28821
  setCalendarMonthState(new Date(year, calendarMonthState.getMonth()));
28771
28822
  }, [year]);
28823
+ const handleToday = () => {
28824
+ const today = /* @__PURE__ */ new Date();
28825
+ const selectedYearDate = new Date(year, today.getMonth(), today.getDate());
28826
+ updateDateTime(selectedYearDate);
28827
+ };
28772
28828
  return /* @__PURE__ */ jsxs24("div", { className: "flex flex-col", children: [
28773
28829
  /* @__PURE__ */ jsxs24(Popover, { children: [
28774
- /* @__PURE__ */ jsx45(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx45(
28830
+ /* @__PURE__ */ jsx45(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs24(
28775
28831
  Button,
28776
28832
  {
28777
28833
  type: "button",
@@ -28787,17 +28843,28 @@ function DateTimePicker({
28787
28843
  borderColor: props.errorMessage ? "#f87171" : style?.borderColor
28788
28844
  },
28789
28845
  disabled: isInputDisabled,
28790
- children: displayValue || placeholder
28846
+ children: [
28847
+ displayValue || placeholder,
28848
+ /* @__PURE__ */ jsx45(Calendar1, { className: "absolute right-2 top-2" })
28849
+ ]
28791
28850
  }
28792
28851
  ) }),
28793
- /* @__PURE__ */ jsx45(PopoverContent, { className: "w-auto text-sm p-2", align: "start", style: { fontSize: "0.75rem" }, children: /* @__PURE__ */ jsxs24("div", { className: "flex flex-col gap-1", children: [
28852
+ /* @__PURE__ */ jsx45(PopoverContent, { className: "w-auto text-sm p-2", align: "start", children: /* @__PURE__ */ jsxs24("div", { className: "flex flex-col gap-1", children: [
28794
28853
  (mode === "date" || mode === "datetime") && /* @__PURE__ */ jsxs24(Fragment16, { children: [
28795
28854
  /* @__PURE__ */ jsxs24("div", { className: "flex items-center justify-between gap-1", children: [
28796
- /* @__PURE__ */ jsx45("label", { className: "text-xs text-muted-foreground", children: "Year" }),
28855
+ /* @__PURE__ */ jsx45(
28856
+ "label",
28857
+ {
28858
+ className: "text-xs text-blue-600 font-bold cursor-pointer",
28859
+ role: "presentation",
28860
+ onClick: handleToday,
28861
+ children: "Today"
28862
+ }
28863
+ ),
28797
28864
  /* @__PURE__ */ jsx45(
28798
28865
  "select",
28799
28866
  {
28800
- className: "h-8 rounded border bg-background px-2 text-sm",
28867
+ className: "h-8 rounded border bg-background px-2 text-xs",
28801
28868
  value: year,
28802
28869
  onChange: (e) => setYear(Number(e.target.value)),
28803
28870
  disabled: isInputDisabled || isReadonly,
@@ -28818,7 +28885,8 @@ function DateTimePicker({
28818
28885
  if (maxDate && d > maxDate) return true;
28819
28886
  return false;
28820
28887
  },
28821
- initialFocus: true
28888
+ className: "p-[10px]",
28889
+ autoFocus: true
28822
28890
  }
28823
28891
  ) })
28824
28892
  ] }),
@@ -28827,7 +28895,7 @@ function DateTimePicker({
28827
28895
  /* @__PURE__ */ jsx45(
28828
28896
  "select",
28829
28897
  {
28830
- className: "h-8 rounded border bg-background px-2 text-sm",
28898
+ className: "h-8 rounded border bg-background px-2 text-xs",
28831
28899
  value: displayHours,
28832
28900
  onChange: handleHoursChange,
28833
28901
  disabled: isInputDisabled || isReadonly,
@@ -28838,7 +28906,7 @@ function DateTimePicker({
28838
28906
  /* @__PURE__ */ jsx45(
28839
28907
  "select",
28840
28908
  {
28841
- className: "h-8 rounded border bg-background px-2 text-sm",
28909
+ className: "h-8 rounded border bg-background px-2 text-xs",
28842
28910
  value: minutes,
28843
28911
  onChange: handleMinutesChange,
28844
28912
  disabled: isInputDisabled || isReadonly,
@@ -28851,7 +28919,7 @@ function DateTimePicker({
28851
28919
  /* @__PURE__ */ jsxs24(
28852
28920
  "select",
28853
28921
  {
28854
- className: "h-8 rounded border bg-background px-2 text-sm",
28922
+ className: "h-8 rounded border bg-background px-2 text-xs",
28855
28923
  value: amPm,
28856
28924
  onChange: handleAmPmChange,
28857
28925
  disabled: isInputDisabled || isReadonly,