@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.js CHANGED
@@ -28011,6 +28011,32 @@ function useLazyDropdown(config) {
28011
28011
  if (debounceTimer.current) clearTimeout(debounceTimer.current);
28012
28012
  };
28013
28013
  }, []);
28014
+ const createNewOption = async (label) => {
28015
+ if (!configRef.current.apiUrl) return null;
28016
+ const axiosClient = configRef.current.axiosInstance ?? import_axios.default;
28017
+ const apiUrl = configRef.current.apiUrl;
28018
+ const urlObj = new URL(
28019
+ apiUrl,
28020
+ typeof window !== "undefined" ? window.location.origin : "http://localhost"
28021
+ );
28022
+ const queryParams = {};
28023
+ urlObj.searchParams.forEach((value, key) => {
28024
+ queryParams[key] = value;
28025
+ });
28026
+ const body = {
28027
+ ...queryParams,
28028
+ [configRef.current.dataLabel]: label
28029
+ };
28030
+ const res = await axiosClient.post(urlObj.origin + urlObj.pathname, body, {
28031
+ withCredentials: true
28032
+ });
28033
+ if (res.data?.success && Array.isArray(res.data.data) && res.data.data.length > 0) {
28034
+ const fetched = transformToOptions(res.data.data);
28035
+ setOptions((prev) => uniqueOptions([...fetched, ...prev]));
28036
+ return fetched[0];
28037
+ }
28038
+ return null;
28039
+ };
28014
28040
  return {
28015
28041
  options,
28016
28042
  loading,
@@ -28018,7 +28044,8 @@ function useLazyDropdown(config) {
28018
28044
  loadMore,
28019
28045
  search,
28020
28046
  reset,
28021
- loadPage
28047
+ loadPage,
28048
+ createNewOption
28022
28049
  };
28023
28050
  }
28024
28051
 
@@ -28039,7 +28066,8 @@ function LazySelectDropdown({
28039
28066
  dataKey = "id",
28040
28067
  dataLabel = "name",
28041
28068
  errorMessage,
28042
- axiosInstance
28069
+ axiosInstance,
28070
+ enableAddNewOption = false
28043
28071
  }) {
28044
28072
  const [isOpen, setIsOpen] = (0, import_react20.useState)(false);
28045
28073
  const [searchTerm, setSearchTerm] = (0, import_react20.useState)("");
@@ -28052,7 +28080,8 @@ function LazySelectDropdown({
28052
28080
  loadMore,
28053
28081
  search,
28054
28082
  reset,
28055
- loadPage
28083
+ loadPage,
28084
+ createNewOption
28056
28085
  } = useLazyDropdown({
28057
28086
  enabled: true,
28058
28087
  dataSource: source || "",
@@ -28110,6 +28139,15 @@ function LazySelectDropdown({
28110
28139
  reset();
28111
28140
  search("");
28112
28141
  };
28142
+ const handleAddNewOption = async (newOption) => {
28143
+ const option = await createNewOption(newOption);
28144
+ if (option) {
28145
+ onChange?.(option.value, id || "");
28146
+ setIsOpen(false);
28147
+ setSearchTerm("");
28148
+ reset();
28149
+ }
28150
+ };
28113
28151
  return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { ref: dropdownRef, className: "relative w-full", children: [
28114
28152
  /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
28115
28153
  "input",
@@ -28179,7 +28217,19 @@ function LazySelectDropdown({
28179
28217
  ] }) : "Scroll for more..."
28180
28218
  }
28181
28219
  )
28182
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: "px-3 py-4 text-sm text-center text-gray-500", children: searchTerm ? `No results for "${searchTerm}"` : "No options available" })
28220
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: "px-3 py-4 text-sm text-center text-gray-500", children: [
28221
+ searchTerm ? `No results for "${searchTerm}"` : "No options available",
28222
+ enableAddNewOption && searchTerm && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
28223
+ "div",
28224
+ {
28225
+ onClick: () => {
28226
+ handleAddNewOption(searchTerm);
28227
+ },
28228
+ className: "mt-2 px-3 py-2 bg-green-50 hover:bg-green-100 cursor-pointer text-green-700 rounded text-sm",
28229
+ children: `Add "${searchTerm}"`
28230
+ }
28231
+ )
28232
+ ] })
28183
28233
  }
28184
28234
  ) })
28185
28235
  ] });
@@ -28859,14 +28909,20 @@ function DateTimePicker({
28859
28909
  }, [date, mode]);
28860
28910
  const isInputDisabled = isDisabled || !isEditable;
28861
28911
  const [calendarMonthState, setCalendarMonthState] = React6.useState(() => {
28862
- return date ? new Date(date.getFullYear(), date.getMonth()) : new Date(year, 0);
28912
+ const currentMonth = (/* @__PURE__ */ new Date()).getMonth();
28913
+ return date ? new Date(date.getFullYear(), date.getMonth()) : new Date(year, currentMonth);
28863
28914
  });
28864
28915
  React6.useEffect(() => {
28865
28916
  setCalendarMonthState(new Date(year, calendarMonthState.getMonth()));
28866
28917
  }, [year]);
28918
+ const handleToday = () => {
28919
+ const today = /* @__PURE__ */ new Date();
28920
+ const selectedYearDate = new Date(year, today.getMonth(), today.getDate());
28921
+ updateDateTime(selectedYearDate);
28922
+ };
28867
28923
  return /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "flex flex-col", children: [
28868
28924
  /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(Popover, { children: [
28869
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
28925
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
28870
28926
  Button,
28871
28927
  {
28872
28928
  type: "button",
@@ -28882,17 +28938,28 @@ function DateTimePicker({
28882
28938
  borderColor: props.errorMessage ? "#f87171" : style?.borderColor
28883
28939
  },
28884
28940
  disabled: isInputDisabled,
28885
- children: displayValue || placeholder
28941
+ children: [
28942
+ displayValue || placeholder,
28943
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(Calendar1, { className: "absolute right-2 top-2" })
28944
+ ]
28886
28945
  }
28887
28946
  ) }),
28888
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(PopoverContent, { className: "w-auto text-sm p-2", align: "start", style: { fontSize: "0.75rem" }, children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "flex flex-col gap-1", children: [
28947
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(PopoverContent, { className: "w-auto text-sm p-2", align: "start", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "flex flex-col gap-1", children: [
28889
28948
  (mode === "date" || mode === "datetime") && /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(import_jsx_runtime45.Fragment, { children: [
28890
28949
  /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "flex items-center justify-between gap-1", children: [
28891
- /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("label", { className: "text-xs text-muted-foreground", children: "Year" }),
28950
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
28951
+ "label",
28952
+ {
28953
+ className: "text-xs text-blue-600 font-bold cursor-pointer",
28954
+ role: "presentation",
28955
+ onClick: handleToday,
28956
+ children: "Today"
28957
+ }
28958
+ ),
28892
28959
  /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
28893
28960
  "select",
28894
28961
  {
28895
- className: "h-8 rounded border bg-background px-2 text-sm",
28962
+ className: "h-8 rounded border bg-background px-2 text-xs",
28896
28963
  value: year,
28897
28964
  onChange: (e) => setYear(Number(e.target.value)),
28898
28965
  disabled: isInputDisabled || isReadonly,
@@ -28913,7 +28980,8 @@ function DateTimePicker({
28913
28980
  if (maxDate && d > maxDate) return true;
28914
28981
  return false;
28915
28982
  },
28916
- initialFocus: true
28983
+ className: "p-[10px]",
28984
+ autoFocus: true
28917
28985
  }
28918
28986
  ) })
28919
28987
  ] }),
@@ -28922,7 +28990,7 @@ function DateTimePicker({
28922
28990
  /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
28923
28991
  "select",
28924
28992
  {
28925
- className: "h-8 rounded border bg-background px-2 text-sm",
28993
+ className: "h-8 rounded border bg-background px-2 text-xs",
28926
28994
  value: displayHours,
28927
28995
  onChange: handleHoursChange,
28928
28996
  disabled: isInputDisabled || isReadonly,
@@ -28933,7 +29001,7 @@ function DateTimePicker({
28933
29001
  /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
28934
29002
  "select",
28935
29003
  {
28936
- className: "h-8 rounded border bg-background px-2 text-sm",
29004
+ className: "h-8 rounded border bg-background px-2 text-xs",
28937
29005
  value: minutes,
28938
29006
  onChange: handleMinutesChange,
28939
29007
  disabled: isInputDisabled || isReadonly,
@@ -28946,7 +29014,7 @@ function DateTimePicker({
28946
29014
  /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
28947
29015
  "select",
28948
29016
  {
28949
- className: "h-8 rounded border bg-background px-2 text-sm",
29017
+ className: "h-8 rounded border bg-background px-2 text-xs",
28950
29018
  value: amPm,
28951
29019
  onChange: handleAmPmChange,
28952
29020
  disabled: isInputDisabled || isReadonly,