warqadui 0.0.23 → 0.0.24

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
@@ -1877,7 +1877,7 @@ var Textarea = (0, import_react11.forwardRef)(
1877
1877
  );
1878
1878
 
1879
1879
  // src/components/Fields/searchApi.tsx
1880
- var import_react13 = __toESM(require("react"));
1880
+ var import_react13 = require("react");
1881
1881
  var import_react_dom2 = require("react-dom");
1882
1882
  var import_lucide_react8 = require("lucide-react");
1883
1883
 
@@ -2063,7 +2063,7 @@ var useSearchApiContext = () => {
2063
2063
  };
2064
2064
  var SearchApi = (0, import_react13.forwardRef)(
2065
2065
  (props, _) => {
2066
- const { form, name, onChange, value, children } = props;
2066
+ const { form, name, onChange, value, children, ...restProps } = props;
2067
2067
  if (form && name) {
2068
2068
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2069
2069
  import_react_hook_form5.Controller,
@@ -2073,7 +2073,9 @@ var SearchApi = (0, import_react13.forwardRef)(
2073
2073
  render: ({ field }) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2074
2074
  SearchApiRoot,
2075
2075
  {
2076
- ...props,
2076
+ ...restProps,
2077
+ form,
2078
+ name,
2077
2079
  currentValue: field.value !== void 0 && field.value !== "" ? field.value : value,
2078
2080
  onChangeHandler: (val) => {
2079
2081
  field.onChange(val);
@@ -2089,7 +2091,9 @@ var SearchApi = (0, import_react13.forwardRef)(
2089
2091
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2090
2092
  SearchApiRoot,
2091
2093
  {
2092
- ...props,
2094
+ ...restProps,
2095
+ form,
2096
+ name,
2093
2097
  currentValue: value,
2094
2098
  onChangeHandler: onChange || (() => {
2095
2099
  }),
@@ -2343,7 +2347,7 @@ var SearchApiRoot = ({
2343
2347
  obj,
2344
2348
  error: message
2345
2349
  };
2346
- const hasChildren = import_react13.default.Children.count(children) > 0;
2350
+ const hasChildren = !!children;
2347
2351
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(SearchApiContext.Provider, { value: valueCtx, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
2348
2352
  "div",
2349
2353
  {
@@ -2390,7 +2394,8 @@ var SearchApiTrigger = (0, import_react13.forwardRef)(
2390
2394
  clearSelection,
2391
2395
  selectedValue,
2392
2396
  variant,
2393
- inputRef
2397
+ inputRef,
2398
+ searchTerm
2394
2399
  } = useSearchApiContext();
2395
2400
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "relative", ref: dropdownAnchorRef, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
2396
2401
  "div",
@@ -2403,7 +2408,9 @@ var SearchApiTrigger = (0, import_react13.forwardRef)(
2403
2408
  onClick: () => {
2404
2409
  if (disabled) return;
2405
2410
  inputRef.current?.focus();
2406
- setIsOpen(true);
2411
+ if (searchTerm.trim()) {
2412
+ setIsOpen(true);
2413
+ }
2407
2414
  },
2408
2415
  ...props,
2409
2416
  children: [
@@ -2471,7 +2478,8 @@ var SearchApiInput = (0, import_react13.forwardRef)(
2471
2478
  };
2472
2479
  const handleKeyDown = (e) => {
2473
2480
  if (!isOpen) {
2474
- if (e.key === "ArrowDown" || e.key === "Enter") setIsOpen(true);
2481
+ if ((e.key === "ArrowDown" || e.key === "Enter") && searchTerm.trim())
2482
+ setIsOpen(true);
2475
2483
  return;
2476
2484
  }
2477
2485
  switch (e.key) {
@@ -2510,10 +2518,20 @@ var SearchApiInput = (0, import_react13.forwardRef)(
2510
2518
  className: `block w-full bg-transparent border-none focus:ring-0 py-1 focus:outline-none text-sm placeholder-gray-400 dark:placeholder-zinc-500 ${!isOpen && selectedValue ? "opacity-0" : "opacity-100"} ${variant === "ghost" ? "h-full" : "h-9"} ${className}`,
2511
2519
  placeholder: !selectedValue ? placeholder : "",
2512
2520
  value: searchTerm,
2513
- onChange: (e) => setSearchTerm(e.target.value),
2521
+ onChange: (e) => {
2522
+ const val = e.target.value;
2523
+ setSearchTerm(val);
2524
+ if (val.trim()) {
2525
+ setIsOpen(true);
2526
+ } else {
2527
+ setIsOpen(false);
2528
+ }
2529
+ },
2514
2530
  onFocus: () => {
2515
2531
  setIsFocused(true);
2516
- setIsOpen(true);
2532
+ if (searchTerm.trim()) {
2533
+ setIsOpen(true);
2534
+ }
2517
2535
  },
2518
2536
  onKeyDown: handleKeyDown,
2519
2537
  disabled,
@@ -2580,7 +2598,7 @@ var SearchApiContent = (0, import_react13.forwardRef)(
2580
2598
  isLoading && options.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "p-4 text-center text-sm text-gray-500", children: [
2581
2599
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_lucide_react8.Loader2, { className: "h-5 w-5 animate-spin mx-auto mb-2" }),
2582
2600
  "Loading options..."
2583
- ] }) : import_react13.default.Children.count(children) > 0 ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "py-1", children }) : /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "p-4 text-center text-sm text-gray-500", children: searchTerm ? `No results for "${searchTerm}"` : "No options available" })
2601
+ ] }) : children ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "py-1", children }) : /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "p-4 text-center text-sm text-gray-500", children: searchTerm ? `No results for "${searchTerm}"` : "No options available" })
2584
2602
  ]
2585
2603
  }
2586
2604
  ),
package/dist/index.mjs CHANGED
@@ -1811,7 +1811,7 @@ var Textarea = forwardRef4(
1811
1811
  );
1812
1812
 
1813
1813
  // src/components/Fields/searchApi.tsx
1814
- import React7, {
1814
+ import {
1815
1815
  createContext as createContext4,
1816
1816
  useContext as useContext4,
1817
1817
  useState as useState12,
@@ -2004,7 +2004,7 @@ var useSearchApiContext = () => {
2004
2004
  };
2005
2005
  var SearchApi = forwardRef5(
2006
2006
  (props, _) => {
2007
- const { form, name, onChange, value, children } = props;
2007
+ const { form, name, onChange, value, children, ...restProps } = props;
2008
2008
  if (form && name) {
2009
2009
  return /* @__PURE__ */ jsx20(
2010
2010
  Controller5,
@@ -2014,7 +2014,9 @@ var SearchApi = forwardRef5(
2014
2014
  render: ({ field }) => /* @__PURE__ */ jsx20(
2015
2015
  SearchApiRoot,
2016
2016
  {
2017
- ...props,
2017
+ ...restProps,
2018
+ form,
2019
+ name,
2018
2020
  currentValue: field.value !== void 0 && field.value !== "" ? field.value : value,
2019
2021
  onChangeHandler: (val) => {
2020
2022
  field.onChange(val);
@@ -2030,7 +2032,9 @@ var SearchApi = forwardRef5(
2030
2032
  return /* @__PURE__ */ jsx20(
2031
2033
  SearchApiRoot,
2032
2034
  {
2033
- ...props,
2035
+ ...restProps,
2036
+ form,
2037
+ name,
2034
2038
  currentValue: value,
2035
2039
  onChangeHandler: onChange || (() => {
2036
2040
  }),
@@ -2284,7 +2288,7 @@ var SearchApiRoot = ({
2284
2288
  obj,
2285
2289
  error: message
2286
2290
  };
2287
- const hasChildren = React7.Children.count(children) > 0;
2291
+ const hasChildren = !!children;
2288
2292
  return /* @__PURE__ */ jsx20(SearchApiContext.Provider, { value: valueCtx, children: /* @__PURE__ */ jsxs15(
2289
2293
  "div",
2290
2294
  {
@@ -2331,7 +2335,8 @@ var SearchApiTrigger = forwardRef5(
2331
2335
  clearSelection,
2332
2336
  selectedValue,
2333
2337
  variant,
2334
- inputRef
2338
+ inputRef,
2339
+ searchTerm
2335
2340
  } = useSearchApiContext();
2336
2341
  return /* @__PURE__ */ jsx20("div", { className: "relative", ref: dropdownAnchorRef, children: /* @__PURE__ */ jsxs15(
2337
2342
  "div",
@@ -2344,7 +2349,9 @@ var SearchApiTrigger = forwardRef5(
2344
2349
  onClick: () => {
2345
2350
  if (disabled) return;
2346
2351
  inputRef.current?.focus();
2347
- setIsOpen(true);
2352
+ if (searchTerm.trim()) {
2353
+ setIsOpen(true);
2354
+ }
2348
2355
  },
2349
2356
  ...props,
2350
2357
  children: [
@@ -2412,7 +2419,8 @@ var SearchApiInput = forwardRef5(
2412
2419
  };
2413
2420
  const handleKeyDown = (e) => {
2414
2421
  if (!isOpen) {
2415
- if (e.key === "ArrowDown" || e.key === "Enter") setIsOpen(true);
2422
+ if ((e.key === "ArrowDown" || e.key === "Enter") && searchTerm.trim())
2423
+ setIsOpen(true);
2416
2424
  return;
2417
2425
  }
2418
2426
  switch (e.key) {
@@ -2451,10 +2459,20 @@ var SearchApiInput = forwardRef5(
2451
2459
  className: `block w-full bg-transparent border-none focus:ring-0 py-1 focus:outline-none text-sm placeholder-gray-400 dark:placeholder-zinc-500 ${!isOpen && selectedValue ? "opacity-0" : "opacity-100"} ${variant === "ghost" ? "h-full" : "h-9"} ${className}`,
2452
2460
  placeholder: !selectedValue ? placeholder : "",
2453
2461
  value: searchTerm,
2454
- onChange: (e) => setSearchTerm(e.target.value),
2462
+ onChange: (e) => {
2463
+ const val = e.target.value;
2464
+ setSearchTerm(val);
2465
+ if (val.trim()) {
2466
+ setIsOpen(true);
2467
+ } else {
2468
+ setIsOpen(false);
2469
+ }
2470
+ },
2455
2471
  onFocus: () => {
2456
2472
  setIsFocused(true);
2457
- setIsOpen(true);
2473
+ if (searchTerm.trim()) {
2474
+ setIsOpen(true);
2475
+ }
2458
2476
  },
2459
2477
  onKeyDown: handleKeyDown,
2460
2478
  disabled,
@@ -2521,7 +2539,7 @@ var SearchApiContent = forwardRef5(
2521
2539
  isLoading && options.length === 0 ? /* @__PURE__ */ jsxs15("div", { className: "p-4 text-center text-sm text-gray-500", children: [
2522
2540
  /* @__PURE__ */ jsx20(Loader22, { className: "h-5 w-5 animate-spin mx-auto mb-2" }),
2523
2541
  "Loading options..."
2524
- ] }) : React7.Children.count(children) > 0 ? /* @__PURE__ */ jsx20("div", { className: "py-1", children }) : /* @__PURE__ */ jsx20("div", { className: "p-4 text-center text-sm text-gray-500", children: searchTerm ? `No results for "${searchTerm}"` : "No options available" })
2542
+ ] }) : children ? /* @__PURE__ */ jsx20("div", { className: "py-1", children }) : /* @__PURE__ */ jsx20("div", { className: "p-4 text-center text-sm text-gray-500", children: searchTerm ? `No results for "${searchTerm}"` : "No options available" })
2525
2543
  ]
2526
2544
  }
2527
2545
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "warqadui",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",