@trsys-tech/matrix-library 0.4.6-alpha → 0.4.7

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.
@@ -1,63 +1,70 @@
1
- import { jsxs as d, jsx as a } from "react/jsx-runtime";
2
- import o, { useRef as F, useEffect as K } from "react";
3
- import { cn as h } from "./utils.es.js";
4
- import { Button as R } from "./button.es.js";
5
- import { ChevronDown as _, Check as A } from "@trsys-tech/matrix-icons";
6
- import { Popover as B, PopoverTrigger as O, PopoverContent as T } from "./popover.es.js";
7
- import { Command as G, CommandInput as q, CommandList as z, CommandEmpty as H, CommandItem as v, CommandGroup as J } from "./command.es.js";
8
- const $ = ({
9
- onValueChange: l,
1
+ import { jsxs as n, jsx as a } from "react/jsx-runtime";
2
+ import o, { useRef as R, useEffect as _ } from "react";
3
+ import { ChevronDown as A, XMark as B, Check as O } from "@trsys-tech/matrix-icons";
4
+ import { cn as v } from "./utils.es.js";
5
+ import { Button as T } from "./button.es.js";
6
+ import { Popover as G, PopoverTrigger as M, PopoverContent as X } from "./popover.es.js";
7
+ import { Command as q, CommandInput as z, CommandList as H, CommandEmpty as J, CommandItem as h, CommandGroup as Q } from "./command.es.js";
8
+ const re = ({
9
+ onValueChange: t,
10
10
  options: c,
11
- value: i,
11
+ value: u,
12
12
  className: x,
13
- closeOnSelect: n = !0,
14
- loading: s,
13
+ clearable: g = !1,
14
+ closeOnSelect: s = !0,
15
+ loading: d,
15
16
  disabled: w,
16
- placeholder: g = "Select an option",
17
- searchText: y = "Search...",
18
- noResultsText: C = "No results found",
19
- loadingText: k = "Loading...",
20
- emptyOptionsText: N = "No Items",
21
- showSearchInput: u = !0,
17
+ placeholder: y = "Select an option",
18
+ searchText: C = "Search...",
19
+ noResultsText: k = "No results found",
20
+ loadingText: N = "Loading...",
21
+ emptyOptionsText: P = "No Items",
22
+ showSearchInput: p = !0,
22
23
  ...L
23
24
  }) => {
24
- const [p, t] = o.useState(!1), f = F(null), [r, m] = o.useState(i), P = o.useCallback(
25
+ const [m, l] = o.useState(!1), f = R(null), [r, i] = o.useState(u), D = o.useCallback(
25
26
  (e) => {
26
- e.key === "Enter" ? t(!0) : e.key === "Backspace" && !e.currentTarget.value && (m(r), l?.(r), n && t(!1));
27
+ e.key === "Enter" ? l(!0) : e.key === "Backspace" && !e.currentTarget.value && (i(r), t?.(r), s && l(!1));
27
28
  },
28
- [r, l, n]
29
- ), D = o.useCallback(
29
+ [r, t, s]
30
+ ), E = o.useCallback(
30
31
  (e) => {
31
- m(e), l?.(e), n && t(!1);
32
+ i(e), t?.(e), s && l(!1);
32
33
  },
33
- [l, n]
34
- ), E = o.useCallback((e, j, I = [""]) => I.join("").toLocaleLowerCase().includes(j.toLocaleLowerCase()) ? 1 : 0, []), S = o.useCallback(
34
+ [t, s]
35
+ ), S = o.useCallback(
35
36
  (e) => {
36
- u || (e.preventDefault(), f.current?.focus());
37
+ e.stopPropagation(), t?.(void 0), i(void 0);
37
38
  },
38
- [u]
39
+ [t]
40
+ ), j = o.useCallback((e, F, K = [""]) => K.join("").toLocaleLowerCase().includes(F.toLocaleLowerCase()) ? 1 : 0, []), I = o.useCallback(
41
+ (e) => {
42
+ p || (e.preventDefault(), f.current?.focus());
43
+ },
44
+ [p]
39
45
  );
40
- K(() => {
41
- m(i);
42
- }, [i]);
46
+ _(() => {
47
+ i(u);
48
+ }, [u]);
43
49
  const b = r === void 0 || r === "";
44
- return /* @__PURE__ */ d(B, { open: p, onOpenChange: t, children: [
45
- /* @__PURE__ */ a(O, { asChild: !0, children: /* @__PURE__ */ a(
46
- R,
50
+ return /* @__PURE__ */ n(G, { open: m, onOpenChange: l, children: [
51
+ /* @__PURE__ */ a(M, { asChild: !0, children: /* @__PURE__ */ n(
52
+ T,
47
53
  {
48
54
  variant: "text",
49
55
  role: "combobox",
50
- "aria-expanded": p,
51
- className: h(
56
+ type: "button",
57
+ "aria-expanded": m,
58
+ className: v(
52
59
  "group flex h-8 w-full items-center justify-between whitespace-nowrap overflow-hidden rounded-sm border border-input bg-transparent px-3 py-1.5 text-sm ring-offset-background data-[placeholder]:text-muted-foreground hover:border hover:border-primary hover:bg-transparent focus:border focus:border-primary focus:outline-none focus:ring focus:ring-primary-100 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:text-text-300 disabled:border-gray-100 [&_svg]:disabled:text-text-300",
53
60
  x
54
61
  ),
55
62
  "data-value": r,
56
63
  "data-placeholder": b ? "" : void 0,
57
- loading: s,
64
+ loading: d,
58
65
  disabled: w,
59
66
  endIcon: /* @__PURE__ */ a(
60
- _,
67
+ A,
61
68
  {
62
69
  role: "button",
63
70
  "aria-label": "Expand dropdown",
@@ -65,30 +72,42 @@ const $ = ({
65
72
  }
66
73
  ),
67
74
  ...L,
68
- children: /* @__PURE__ */ a("span", { className: "text-start text-ellipsis whitespace-nowrap overflow-hidden flex-1 max-w-[calc(100%-24px)]", children: b ? s ? k : g : c.find((e) => e.value === r)?.label })
75
+ children: [
76
+ /* @__PURE__ */ a("span", { className: "text-start text-ellipsis whitespace-nowrap overflow-hidden flex-1 max-w-[calc(100%-24px)]", children: b ? d ? N : y : c.find((e) => e.value === r)?.label }),
77
+ g && r !== void 0 && r !== null ? /* @__PURE__ */ a(
78
+ "span",
79
+ {
80
+ onClick: S,
81
+ className: "p-0 rounded-sm text-xs font-normal transition-colors focus-visible:outline-none disabled:pointer-events-none disabled:bg-muted disabled:text-gray-500 text-primary hover:bg-primary-50 focus:bg-transparent focus:ring active:bg-primary-50 active:text-primary-700 [&>svg]:h-4.5 [&>svg]:w-4.5",
82
+ role: "button",
83
+ "aria-label": "Clear selection",
84
+ children: /* @__PURE__ */ a(B, {})
85
+ }
86
+ ) : null
87
+ ]
69
88
  }
70
89
  ) }),
71
- /* @__PURE__ */ a(T, { className: "w-auto p-0", align: "start", onEscapeKeyDown: () => t(!1), onOpenAutoFocus: S, children: /* @__PURE__ */ d(
72
- G,
90
+ /* @__PURE__ */ a(X, { className: "w-auto p-0", align: "start", onEscapeKeyDown: () => l(!1), onOpenAutoFocus: I, children: /* @__PURE__ */ n(
91
+ q,
73
92
  {
74
93
  className: "w-[--radix-popper-anchor-width] focus-visible:outline-none",
75
- filter: E,
76
- defaultValue: r !== void 0 ? String(r) : void 0,
94
+ filter: j,
95
+ defaultValue: r != null ? String(r) : void 0,
77
96
  ref: f,
78
97
  children: [
79
- u && /* @__PURE__ */ a(q, { placeholder: y, onKeyDown: P }),
80
- /* @__PURE__ */ d(z, { children: [
81
- !s && /* @__PURE__ */ a(H, { children: C }),
82
- !s && !c.length ? /* @__PURE__ */ a(v, { value: "8fdcaeb67c8ad943c80fe54c3b1059b700d9254389a38a4a1fc39a6eee7564623", disabled: !0, children: N }) : null,
83
- /* @__PURE__ */ a(J, { children: c.map((e) => /* @__PURE__ */ d(
84
- v,
98
+ p && /* @__PURE__ */ a(z, { placeholder: C, onKeyDown: D }),
99
+ /* @__PURE__ */ n(H, { children: [
100
+ !d && /* @__PURE__ */ a(J, { children: k }),
101
+ !d && !c.length ? /* @__PURE__ */ a(h, { value: "8fdcaeb67c8ad943c80fe54c3b1059b700d9254389a38a4a1fc39a6eee7564623", disabled: !0, children: P }) : null,
102
+ /* @__PURE__ */ a(Q, { children: c.map((e) => /* @__PURE__ */ n(
103
+ h,
85
104
  {
86
105
  value: e.value,
87
106
  keywords: [e.label],
88
- onSelect: D,
107
+ onSelect: E,
89
108
  children: [
90
109
  e.label,
91
- /* @__PURE__ */ a(A, { className: h("ml-auto", r === e.value ? "opacity-100" : "opacity-0") })
110
+ /* @__PURE__ */ a(O, { className: v("ml-auto", r === e.value ? "opacity-100" : "opacity-0") })
92
111
  ]
93
112
  },
94
113
  String(e.value)
@@ -100,6 +119,6 @@ const $ = ({
100
119
  ] });
101
120
  };
102
121
  export {
103
- $ as Combobox
122
+ re as Combobox
104
123
  };
105
124
  //# sourceMappingURL=combobox.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"combobox.es.js","sources":["../src/components/combobox/Combobox.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport React, { useEffect, useRef } from \"react\";\r\n\r\nimport { cn } from \"../../lib/utils\";\r\nimport { Button } from \"../button/Button\";\r\nimport { Check, ChevronDown } from \"@trsys-tech/matrix-icons\";\r\nimport { Popover, PopoverContent, PopoverTrigger } from \"../popover/Popover\";\r\nimport { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from \"../command/Command\";\r\n\r\ntype ComboboxProps<T extends string | number> = React.HTMLAttributes<HTMLButtonElement> & {\r\n /**\r\n * The options to display in the combobox.\r\n * Each option should have a label and a value.\r\n * The label is what is displayed in the combobox.\r\n * The value is what is returned when the option is selected.\r\n */\r\n options: { label: string; value: T }[];\r\n\r\n /**\r\n * The value of the combobox.\r\n */\r\n value?: T;\r\n\r\n /**\r\n * A function that is called when the value of the combobox changes.\r\n */\r\n onValueChange?: (value: T) => void;\r\n\r\n /**\r\n * Placeholder text to be displayed when no values are selected.\r\n * @default \"Select an option\"\r\n */\r\n placeholder?: string;\r\n\r\n /**\r\n * The modality of the popover. When set to true, interaction with outside elements\r\n * will be disabled and only popover content will be visible to screen readers.\r\n * Optional\r\n * @default false\r\n */\r\n modalPopover?: boolean;\r\n\r\n /**\r\n * The text to display in the search input.\r\n * @default \"Search...\"\r\n */\r\n searchText?: string;\r\n\r\n /**\r\n * The text to display when no results are found.\r\n * @default \"No results found\"\r\n */\r\n noResultsText?: string;\r\n\r\n /**\r\n * Whether the popover should close when an option is selected.\r\n * @default true\r\n */\r\n closeOnSelect?: boolean;\r\n\r\n /**\r\n * Whether the combobox is loading.\r\n * @default false\r\n */\r\n loading?: boolean;\r\n\r\n /**\r\n * Whether the combobox is disabled.\r\n * @default false\r\n */\r\n disabled?: boolean;\r\n\r\n /**\r\n * The text to display when the combobox is loading.\r\n * @default \"Loading...\"\r\n */\r\n loadingText?: string;\r\n\r\n /**\r\n * The text to display when there are no options.\r\n * @default \"No Items\"\r\n */\r\n emptyOptionsText?: string;\r\n\r\n /**\r\n * Whether to show the search input.\r\n * @default true\r\n */\r\n showSearchInput?: boolean;\r\n};\r\n\r\nconst Combobox = <T extends string | number>({\r\n onValueChange,\r\n options,\r\n value,\r\n className,\r\n closeOnSelect = true,\r\n loading,\r\n disabled,\r\n placeholder = \"Select an option\",\r\n searchText = \"Search...\",\r\n noResultsText = \"No results found\",\r\n loadingText = \"Loading...\",\r\n emptyOptionsText = \"No Items\",\r\n showSearchInput = true,\r\n ...props\r\n}: ComboboxProps<T>) => {\r\n const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);\r\n const commandRef = useRef<HTMLDivElement>(null);\r\n\r\n const [currentSelectedValue, setCurrentSelectedValue] = React.useState<T | undefined>(value);\r\n\r\n const handleInputKeyDown = React.useCallback(\r\n (event: React.KeyboardEvent<HTMLInputElement>) => {\r\n if (event.key === \"Enter\") {\r\n setIsPopoverOpen(true);\r\n } else if (event.key === \"Backspace\" && !event.currentTarget.value) {\r\n setCurrentSelectedValue(currentSelectedValue);\r\n onValueChange?.(currentSelectedValue!);\r\n if (closeOnSelect) setIsPopoverOpen(false);\r\n }\r\n },\r\n [currentSelectedValue, onValueChange, closeOnSelect],\r\n );\r\n\r\n const handleSelect = React.useCallback(\r\n (currentValue: T) => {\r\n setCurrentSelectedValue(currentValue);\r\n onValueChange?.(currentValue);\r\n if (closeOnSelect) setIsPopoverOpen(false);\r\n },\r\n [onValueChange, closeOnSelect],\r\n );\r\n\r\n const handleFilter = React.useCallback((value: string, search: string, keywords: string[] = [\"\"]) => {\r\n return keywords.join(\"\").toLocaleLowerCase().includes(search.toLocaleLowerCase()) ? 1 : 0;\r\n }, []);\r\n\r\n // when search input is not shown, we need to focus on the command manually to enable keyboard navigation\r\n const handleOpenAutoFocus = React.useCallback(\r\n (e: Event) => {\r\n if (!showSearchInput) {\r\n e.preventDefault();\r\n commandRef.current?.focus();\r\n }\r\n },\r\n [showSearchInput],\r\n );\r\n\r\n useEffect(() => {\r\n setCurrentSelectedValue(value);\r\n }, [value]);\r\n\r\n const showPlaceholder = currentSelectedValue === undefined || currentSelectedValue === \"\";\r\n\r\n return (\r\n <Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>\r\n <PopoverTrigger asChild>\r\n <Button\r\n variant=\"text\"\r\n role=\"combobox\"\r\n aria-expanded={isPopoverOpen}\r\n className={cn(\r\n \"group flex h-8 w-full items-center justify-between whitespace-nowrap overflow-hidden rounded-sm border border-input bg-transparent px-3 py-1.5 text-sm ring-offset-background data-[placeholder]:text-muted-foreground hover:border hover:border-primary hover:bg-transparent focus:border focus:border-primary focus:outline-none focus:ring focus:ring-primary-100 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:text-text-300 disabled:border-gray-100 [&_svg]:disabled:text-text-300\",\r\n className,\r\n )}\r\n data-value={currentSelectedValue}\r\n data-placeholder={showPlaceholder ? \"\" : undefined}\r\n loading={loading}\r\n disabled={disabled}\r\n endIcon={\r\n <ChevronDown\r\n role=\"button\"\r\n aria-label=\"Expand dropdown\"\r\n className=\"!h-4.5 !w-4.5 cursor-pointer group-data-[state=open]:rotate-180 transition-transform ms-auto\"\r\n />\r\n }\r\n {...props}\r\n >\r\n <span className=\"text-start text-ellipsis whitespace-nowrap overflow-hidden flex-1 max-w-[calc(100%-24px)]\">\r\n {!showPlaceholder ? options.find(option => option.value === currentSelectedValue)?.label : loading ? loadingText : placeholder}\r\n </span>\r\n </Button>\r\n </PopoverTrigger>\r\n <PopoverContent className=\"w-auto p-0\" align=\"start\" onEscapeKeyDown={() => setIsPopoverOpen(false)} onOpenAutoFocus={handleOpenAutoFocus}>\r\n <Command\r\n className=\"w-[--radix-popper-anchor-width] focus-visible:outline-none\"\r\n filter={handleFilter}\r\n defaultValue={currentSelectedValue !== undefined ? String(currentSelectedValue) : undefined} // highlight selected value on open\r\n ref={commandRef}\r\n >\r\n {showSearchInput && <CommandInput placeholder={searchText} onKeyDown={handleInputKeyDown} />}\r\n <CommandList>\r\n {!loading && <CommandEmpty>{noResultsText}</CommandEmpty>}\r\n {!loading && !options.length ? (\r\n <CommandItem value=\"8fdcaeb67c8ad943c80fe54c3b1059b700d9254389a38a4a1fc39a6eee7564623\" disabled>\r\n {emptyOptionsText}\r\n </CommandItem>\r\n ) : null}\r\n <CommandGroup>\r\n {options.map(option => (\r\n <CommandItem\r\n key={String(option.value)}\r\n value={option.value}\r\n keywords={[option.label]}\r\n onSelect={handleSelect as React.ComponentProps<typeof CommandItem>[\"onSelect\"]}\r\n >\r\n {option.label}\r\n <Check className={cn(\"ml-auto\", currentSelectedValue === option.value ? \"opacity-100\" : \"opacity-0\")} />\r\n </CommandItem>\r\n ))}\r\n </CommandGroup>\r\n </CommandList>\r\n </Command>\r\n </PopoverContent>\r\n </Popover>\r\n );\r\n};\r\nexport { Combobox, type ComboboxProps };\r\n"],"names":["Combobox","onValueChange","options","value","className","closeOnSelect","loading","disabled","placeholder","searchText","noResultsText","loadingText","emptyOptionsText","showSearchInput","props","isPopoverOpen","setIsPopoverOpen","React","commandRef","useRef","currentSelectedValue","setCurrentSelectedValue","handleInputKeyDown","event","handleSelect","currentValue","handleFilter","search","keywords","handleOpenAutoFocus","useEffect","showPlaceholder","jsxs","Popover","jsx","PopoverTrigger","Button","cn","ChevronDown","option","PopoverContent","Command","CommandInput","CommandList","CommandEmpty","CommandItem","CommandGroup","Check"],"mappings":";;;;;;;AA4FA,MAAMA,IAAW,CAA4B;AAAA,EAC3C,eAAAC;AAAA,EACA,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,eAAAC,IAAgB;AAAA,EAChB,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,YAAAC,IAAa;AAAA,EACb,eAAAC,IAAgB;AAAA,EAChB,aAAAC,IAAc;AAAA,EACd,kBAAAC,IAAmB;AAAA,EACnB,iBAAAC,IAAkB;AAAA,EAClB,GAAGC;AACL,MAAwB;AACtB,QAAM,CAACC,GAAeC,CAAgB,IAAIC,EAAM,SAAS,EAAK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AAA,gBAET,UAAA;AAAA,kBAAOe,EAAA;AAAA,kBACR,gBAAAL,EAACa,GAAM,EAAA,WAAWV,EAAG,WAAWjB,MAAyBmB,EAAO,QAAQ,gBAAgB,WAAW,EAAG,CAAA;AAAA,gBAAA;AAAA,cAAA;AAAA,cANjG,OAAOA,EAAO,KAAK;AAAA,YAAA,CAQ3B,EACH,CAAA;AAAA,UAAA,EACF,CAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,EAEJ,CAAA;AAAA,EAAA,GACF;AAEJ;"}
1
+ {"version":3,"file":"combobox.es.js","sources":["../src/components/combobox/Combobox.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport React, { useEffect, useRef } from \"react\";\r\nimport { Check, ChevronDown, XMark } from \"@trsys-tech/matrix-icons\";\r\n\r\nimport { cn } from \"../../lib/utils\";\r\nimport { Button } from \"../button/Button\";\r\nimport { Popover, PopoverContent, PopoverTrigger } from \"../popover/Popover\";\r\nimport { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from \"../command/Command\";\r\n\r\ntype ComboboxProps<T extends string | number> = React.HTMLAttributes<HTMLButtonElement> & {\r\n /**\r\n * The options to display in the combobox.\r\n * Each option should have a label and a value.\r\n * The label is what is displayed in the combobox.\r\n * The value is what is returned when the option is selected.\r\n */\r\n options: { label: string; value: T }[];\r\n\r\n /**\r\n * The value of the combobox.\r\n */\r\n value?: T;\r\n\r\n /**\r\n * A function that is called when the value of the combobox changes.\r\n */\r\n onValueChange?: (value: T) => void;\r\n\r\n /**\r\n * Placeholder text to be displayed when no values are selected.\r\n * @default \"Select an option\"\r\n */\r\n placeholder?: string;\r\n\r\n /**\r\n * The modality of the popover. When set to true, interaction with outside elements\r\n * will be disabled and only popover content will be visible to screen readers.\r\n * Optional\r\n * @default false\r\n */\r\n modalPopover?: boolean;\r\n\r\n /**\r\n * The text to display in the search input.\r\n * @default \"Search...\"\r\n */\r\n searchText?: string;\r\n\r\n /**\r\n * The text to display when no results are found.\r\n * @default \"No results found\"\r\n */\r\n noResultsText?: string;\r\n\r\n /**\r\n * Whether the popover should close when an option is selected.\r\n * @default true\r\n */\r\n closeOnSelect?: boolean;\r\n\r\n /**\r\n * Whether the combobox is loading.\r\n * @default false\r\n */\r\n loading?: boolean;\r\n\r\n /**\r\n * Whether the combobox is disabled.\r\n * @default false\r\n */\r\n disabled?: boolean;\r\n\r\n /**\r\n * The text to display when the combobox is loading.\r\n * @default \"Loading...\"\r\n */\r\n loadingText?: string;\r\n\r\n /**\r\n * The text to display when there are no options.\r\n * @default \"No Items\"\r\n */\r\n emptyOptionsText?: string;\r\n\r\n /**\r\n * Whether to show the search input.\r\n * @default true\r\n */\r\n showSearchInput?: boolean;\r\n\r\n /**\r\n * Whether to show the clear button.\r\n * @default false\r\n */\r\n clearable?: boolean;\r\n};\r\n\r\nconst Combobox = <T extends string | number>({\r\n onValueChange,\r\n options,\r\n value,\r\n className,\r\n clearable = false,\r\n closeOnSelect = true,\r\n loading,\r\n disabled,\r\n placeholder = \"Select an option\",\r\n searchText = \"Search...\",\r\n noResultsText = \"No results found\",\r\n loadingText = \"Loading...\",\r\n emptyOptionsText = \"No Items\",\r\n showSearchInput = true,\r\n ...props\r\n}: ComboboxProps<T>) => {\r\n const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);\r\n const commandRef = useRef<HTMLDivElement>(null);\r\n\r\n const [currentSelectedValue, setCurrentSelectedValue] = React.useState<T | undefined>(value);\r\n\r\n const handleInputKeyDown = React.useCallback(\r\n (event: React.KeyboardEvent<HTMLInputElement>) => {\r\n if (event.key === \"Enter\") {\r\n setIsPopoverOpen(true);\r\n } else if (event.key === \"Backspace\" && !event.currentTarget.value) {\r\n setCurrentSelectedValue(currentSelectedValue);\r\n onValueChange?.(currentSelectedValue!);\r\n if (closeOnSelect) setIsPopoverOpen(false);\r\n }\r\n },\r\n [currentSelectedValue, onValueChange, closeOnSelect],\r\n );\r\n\r\n const handleSelect = React.useCallback(\r\n (currentValue: T) => {\r\n setCurrentSelectedValue(currentValue);\r\n onValueChange?.(currentValue);\r\n if (closeOnSelect) setIsPopoverOpen(false);\r\n },\r\n [onValueChange, closeOnSelect],\r\n );\r\n\r\n const handleClear = React.useCallback(\r\n (e: React.MouseEvent) => {\r\n e.stopPropagation();\r\n onValueChange?.(undefined as unknown as T);\r\n setCurrentSelectedValue(undefined);\r\n },\r\n [onValueChange],\r\n );\r\n\r\n const handleFilter = React.useCallback((value: string, search: string, keywords: string[] = [\"\"]) => {\r\n return keywords.join(\"\").toLocaleLowerCase().includes(search.toLocaleLowerCase()) ? 1 : 0;\r\n }, []);\r\n\r\n // when search input is not shown, we need to focus on the command manually to enable keyboard navigation\r\n const handleOpenAutoFocus = React.useCallback(\r\n (e: Event) => {\r\n if (!showSearchInput) {\r\n e.preventDefault();\r\n commandRef.current?.focus();\r\n }\r\n },\r\n [showSearchInput],\r\n );\r\n\r\n useEffect(() => {\r\n setCurrentSelectedValue(value);\r\n }, [value]);\r\n\r\n const showPlaceholder = currentSelectedValue === undefined || currentSelectedValue === \"\";\r\n\r\n return (\r\n <Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>\r\n <PopoverTrigger asChild>\r\n <Button\r\n variant=\"text\"\r\n role=\"combobox\"\r\n type=\"button\"\r\n aria-expanded={isPopoverOpen}\r\n className={cn(\r\n \"group flex h-8 w-full items-center justify-between whitespace-nowrap overflow-hidden rounded-sm border border-input bg-transparent px-3 py-1.5 text-sm ring-offset-background data-[placeholder]:text-muted-foreground hover:border hover:border-primary hover:bg-transparent focus:border focus:border-primary focus:outline-none focus:ring focus:ring-primary-100 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:text-text-300 disabled:border-gray-100 [&_svg]:disabled:text-text-300\",\r\n className,\r\n )}\r\n data-value={currentSelectedValue}\r\n data-placeholder={showPlaceholder ? \"\" : undefined}\r\n loading={loading}\r\n disabled={disabled}\r\n endIcon={\r\n <ChevronDown\r\n role=\"button\"\r\n aria-label=\"Expand dropdown\"\r\n className=\"!h-4.5 !w-4.5 cursor-pointer group-data-[state=open]:rotate-180 transition-transform ms-auto\"\r\n />\r\n }\r\n {...props}\r\n >\r\n <span className=\"text-start text-ellipsis whitespace-nowrap overflow-hidden flex-1 max-w-[calc(100%-24px)]\">\r\n {!showPlaceholder ? options.find(option => option.value === currentSelectedValue)?.label : loading ? loadingText : placeholder}\r\n </span>\r\n {clearable && currentSelectedValue !== undefined && currentSelectedValue !== null ? (\r\n <span\r\n onClick={handleClear}\r\n className=\"p-0 rounded-sm text-xs font-normal transition-colors focus-visible:outline-none disabled:pointer-events-none disabled:bg-muted disabled:text-gray-500 text-primary hover:bg-primary-50 focus:bg-transparent focus:ring active:bg-primary-50 active:text-primary-700 [&>svg]:h-4.5 [&>svg]:w-4.5\"\r\n role=\"button\"\r\n aria-label=\"Clear selection\"\r\n >\r\n <XMark />\r\n </span>\r\n ) : null}\r\n </Button>\r\n </PopoverTrigger>\r\n <PopoverContent className=\"w-auto p-0\" align=\"start\" onEscapeKeyDown={() => setIsPopoverOpen(false)} onOpenAutoFocus={handleOpenAutoFocus}>\r\n <Command\r\n className=\"w-[--radix-popper-anchor-width] focus-visible:outline-none\"\r\n filter={handleFilter}\r\n defaultValue={currentSelectedValue !== undefined && currentSelectedValue !== null ? String(currentSelectedValue) : undefined} // highlight selected value on open\r\n ref={commandRef}\r\n >\r\n {showSearchInput && <CommandInput placeholder={searchText} onKeyDown={handleInputKeyDown} />}\r\n <CommandList>\r\n {!loading && <CommandEmpty>{noResultsText}</CommandEmpty>}\r\n {!loading && !options.length ? (\r\n <CommandItem value=\"8fdcaeb67c8ad943c80fe54c3b1059b700d9254389a38a4a1fc39a6eee7564623\" disabled>\r\n {emptyOptionsText}\r\n </CommandItem>\r\n ) : null}\r\n <CommandGroup>\r\n {options.map(option => (\r\n <CommandItem\r\n key={String(option.value)}\r\n value={option.value}\r\n keywords={[option.label]}\r\n onSelect={handleSelect as React.ComponentProps<typeof CommandItem>[\"onSelect\"]}\r\n >\r\n {option.label}\r\n <Check className={cn(\"ml-auto\", currentSelectedValue === option.value ? \"opacity-100\" : \"opacity-0\")} />\r\n </CommandItem>\r\n ))}\r\n </CommandGroup>\r\n </CommandList>\r\n </Command>\r\n </PopoverContent>\r\n </Popover>\r\n );\r\n};\r\nexport { Combobox, type ComboboxProps };\r\n"],"names":["Combobox","onValueChange","options","value","className","clearable","closeOnSelect","loading","disabled","placeholder","searchText","noResultsText","loadingText","emptyOptionsText","showSearchInput","props","isPopoverOpen","setIsPopoverOpen","React","commandRef","useRef","currentSelectedValue","setCurrentSelectedValue","handleInputKeyDown","event","handleSelect","currentValue","handleClear","handleFilter","search","keywords","handleOpenAutoFocus","useEffect","showPlaceholder","jsxs","Popover","jsx","PopoverTrigger","Button","cn","ChevronDown","option","XMark","PopoverContent","Command","CommandInput","CommandList","CommandEmpty","CommandItem","CommandGroup","Check"],"mappings":";;;;;;;AAkGA,MAAMA,KAAW,CAA4B;AAAA,EAC3C,eAAAC;AAAA,EACA,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,eAAAC,IAAgB;AAAA,EAChB,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,YAAAC,IAAa;AAAA,EACb,eAAAC,IAAgB;AAAA,EAChB,aAAAC,IAAc;AAAA,EACd,kBAAAC,IAAmB;AAAA,EACnB,iBAAAC,IAAkB;AAAA,EAClB,GAAGC;AACL,MAAwB;AACtB,QAAM,CAACC,GAAeC,CAAgB,IAAIC,EAAM,SAAS,EAAK,GACxDC,IAAaC,EAAuB,IAAI,GAExC,CAACC,GAAsBC,CAAuB,IAAIJ,EAAM,SAAwBf,CAAK,GAErFoB,IAAqBL,EAAM;AAAA,IAC/B,CAACM,MAAiD;AAC5C,MAAAA,EAAM,QAAQ,UAChBP,EAAiB,EAAI,IACZO,EAAM,QAAQ,eAAe,CAACA,EAAM,cAAc,UAC3DF,EAAwBD,C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gBAAAuB,EAAAa,GAAA,EACE,UAAQ/C,EAAA,IAAI,CACXuC,MAAA,gBAAAP;AAAA,cAACc;AAAA,cAAA;AAAA,gBAEC,OAAOP,EAAO;AAAA,gBACd,UAAU,CAACA,EAAO,KAAK;AAAA,gBACvB,UAAUhB;AAAA,gBAET,UAAA;AAAA,kBAAOgB,EAAA;AAAA,kBACR,gBAAAL,EAACc,GAAM,EAAA,WAAWX,EAAG,WAAWlB,MAAyBoB,EAAO,QAAQ,gBAAgB,WAAW,EAAG,CAAA;AAAA,gBAAA;AAAA,cAAA;AAAA,cANjG,OAAOA,EAAO,KAAK;AAAA,YAAA,CAQ3B,EACH,CAAA;AAAA,UAAA,EACF,CAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,EAEJ,CAAA;AAAA,EAAA,GACF;AAEJ;"}
@@ -70,7 +70,12 @@ type ComboboxProps<T extends string | number> = React.HTMLAttributes<HTMLButtonE
70
70
  * @default true
71
71
  */
72
72
  showSearchInput?: boolean;
73
+ /**
74
+ * Whether to show the clear button.
75
+ * @default false
76
+ */
77
+ clearable?: boolean;
73
78
  };
74
- declare const Combobox: <T extends string | number>({ onValueChange, options, value, className, closeOnSelect, loading, disabled, placeholder, searchText, noResultsText, loadingText, emptyOptionsText, showSearchInput, ...props }: ComboboxProps<T>) => import("react/jsx-runtime").JSX.Element;
79
+ declare const Combobox: <T extends string | number>({ onValueChange, options, value, className, clearable, closeOnSelect, loading, disabled, placeholder, searchText, noResultsText, loadingText, emptyOptionsText, showSearchInput, ...props }: ComboboxProps<T>) => import("react/jsx-runtime").JSX.Element;
75
80
  export { Combobox, type ComboboxProps };
76
81
  //# sourceMappingURL=Combobox.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Combobox.d.ts","sourceRoot":"","sources":["../../../src/components/combobox/Combobox.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAQjD,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG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AO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,EAAE,CAAC;IAEvC;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,CAAC;IAEV;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAEnC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,QAAA,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,+LAgBxC,aAAa,CAAC,CAAC,CAAC,4CAmIlB,CAAC;AACF,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,CAAC"}
@@ -11,6 +11,7 @@ type FormComboboxProps<TFieldValues extends FieldValues, TName extends FieldPath
11
11
  loadingText?: string;
12
12
  emptyOptionsText?: string;
13
13
  showSearchInput?: boolean;
14
+ clearable?: boolean;
14
15
  placeholder?: string;
15
16
  required?: boolean;
16
17
  readOnly?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"FormCombobox.d.ts","sourceRoot":"","sources":["../../../src/components/form-combobox/FormCombobox.tsx"],"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AAO,CAAC;IACnB,SAAS,CAAC,EAAE;QACV,cAAc,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;QAChG,gBAAgB,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,oBAAoB,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC;QAC1G,aAAa,CAAC,EAAE,IAAI,CAClB,KAAK,CAAC,wBAAwB,CAAC,OAAO,QAAQ,CAAC,EAC/C,SAAS,GAAG,OAAO,GAAG,eAAe,GAAG,SAAS,GAAG,aAAa,GAAG,kBAAkB,GAAG,aAAa,GAAG,UAAU,GAAG,iBAAiB,CACxI,CAAC;KACH,CAAC;CACH,CAAC;AAEJ,QAAA,MAAM,YAAY,GAAI,YAAY,SAAS,WAAW,EAAE,KAAK,SAAS,SAAS,CAAC,YAAY,CAAC,mCACpF,iBAAiB,CAAC,YAAY,EAAE,KAAK,CAAC,4CA4D9C,CAAC;AACF,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,CAAC"}
@@ -1,61 +1,63 @@
1
- import { jsx as o, jsxs as s } from "react/jsx-runtime";
2
- import { FormField as P, FormItem as I, FormLabel as j, FormControl as v, FormMessage as y } from "./form.es.js";
3
- import { Combobox as L } from "./combobox.es.js";
4
- const V = (n) => {
1
+ import { jsx as e, jsxs as a } from "react/jsx-runtime";
2
+ import { FormField as I, FormItem as j, FormLabel as v, FormControl as y, FormMessage as L } from "./form.es.js";
3
+ import { Combobox as M } from "./combobox.es.js";
4
+ const q = (s) => {
5
5
  const {
6
- name: a,
6
+ name: n,
7
7
  control: t,
8
- defaultValue: m,
8
+ clearable: m = !1,
9
+ defaultValue: d,
9
10
  disabled: r,
10
- readOnly: d,
11
- rules: i,
12
- shouldUnregister: p,
13
- label: b,
14
- options: c,
15
- loading: u,
16
- loadingText: h,
17
- emptyOptionsText: x,
18
- showSearchInput: g,
11
+ readOnly: i,
12
+ rules: p,
13
+ shouldUnregister: b,
14
+ label: c,
15
+ options: u,
16
+ loading: h,
17
+ loadingText: x,
18
+ emptyOptionsText: g,
19
+ showSearchInput: f,
19
20
  placeholder: F,
20
- slotProps: e,
21
- required: f,
22
- ...C
23
- } = n;
24
- return /* @__PURE__ */ o(
25
- P,
21
+ slotProps: o,
22
+ required: C,
23
+ ...P
24
+ } = s;
25
+ return /* @__PURE__ */ e(
26
+ I,
26
27
  {
27
28
  control: t,
28
- name: a,
29
- defaultValue: m,
29
+ name: n,
30
+ defaultValue: d,
30
31
  disabled: r,
31
- rules: i,
32
- shouldUnregister: p,
33
- render: ({ field: l }) => /* @__PURE__ */ s(I, { ...C, children: [
34
- /* @__PURE__ */ s(j, { ...e?.formLabelProps ?? {}, children: [
35
- b,
36
- f && /* @__PURE__ */ o("span", { className: "text-danger text-sm leading-4", children: "*" })
32
+ rules: p,
33
+ shouldUnregister: b,
34
+ render: ({ field: l }) => /* @__PURE__ */ a(j, { ...P, children: [
35
+ /* @__PURE__ */ a(v, { ...o?.formLabelProps ?? {}, children: [
36
+ c,
37
+ C && /* @__PURE__ */ e("span", { className: "text-danger text-sm leading-4", children: "*" })
37
38
  ] }),
38
- /* @__PURE__ */ o(v, { children: /* @__PURE__ */ o(
39
- L,
39
+ /* @__PURE__ */ e(y, { children: /* @__PURE__ */ e(
40
+ M,
40
41
  {
41
- options: c,
42
+ options: u,
42
43
  value: l.value,
43
44
  onValueChange: l.onChange,
44
- loading: u,
45
- loadingText: h,
46
- emptyOptionsText: x,
45
+ loading: h,
46
+ loadingText: x,
47
+ emptyOptionsText: g,
47
48
  placeholder: F,
48
- disabled: r || d,
49
- showSearchInput: g,
50
- ...e?.comboboxProps ?? {}
49
+ disabled: r || i,
50
+ showSearchInput: f,
51
+ clearable: m,
52
+ ...o?.comboboxProps ?? {}
51
53
  }
52
54
  ) }),
53
- /* @__PURE__ */ o(y, { ...e?.formMessageProps ?? {} })
55
+ /* @__PURE__ */ e(L, { ...o?.formMessageProps ?? {} })
54
56
  ] })
55
57
  }
56
58
  );
57
59
  };
58
60
  export {
59
- V as FormCombobox
61
+ q as FormCombobox
60
62
  };
61
63
  //# sourceMappingURL=formcombobox.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"formcombobox.es.js","sources":["../src/components/form-combobox/FormCombobox.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport { ControllerProps, FieldPath, FieldValues } from \"react-hook-form\";\r\n\r\nimport { FormControl, FormField, FormItem, FormLabel, FormMessage } from \"../form/Form\";\r\nimport { Combobox } from \"../combobox/Combobox\";\r\n\r\ntype FormComboboxProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<\r\n ControllerProps<TFieldValues, TName>,\r\n \"render\"\r\n> &\r\n React.ComponentProps<typeof FormItem> & {\r\n label: string;\r\n options: { value: string | number; label: string }[];\r\n loading?: boolean;\r\n loadingText?: string;\r\n emptyOptionsText?: string;\r\n showSearchInput?: boolean;\r\n placeholder?: string;\r\n required?: boolean;\r\n readOnly?: boolean;\r\n slotProps?: {\r\n formLabelProps?: React.HTMLAttributes<HTMLLabelElement> & React.RefAttributes<HTMLLabelElement>;\r\n formMessageProps?: React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>;\r\n comboboxProps?: Omit<\r\n React.ComponentPropsWithoutRef<typeof Combobox>,\r\n \"options\" | \"value\" | \"onValueChange\" | \"loading\" | \"loadingText\" | \"emptyOptionsText\" | \"placeholder\" | \"disabled\" | \"showSearchInput\"\r\n >;\r\n };\r\n };\r\n\r\nconst FormCombobox = <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(\r\n props: FormComboboxProps<TFieldValues, TName>,\r\n) => {\r\n const {\r\n name,\r\n control,\r\n defaultValue,\r\n disabled,\r\n readOnly,\r\n rules,\r\n shouldUnregister,\r\n label,\r\n options,\r\n loading,\r\n loadingText,\r\n emptyOptionsText,\r\n showSearchInput,\r\n placeholder,\r\n slotProps,\r\n required,\r\n ...formItemProps\r\n } = props;\r\n\r\n return (\r\n <FormField\r\n control={control}\r\n name={name}\r\n defaultValue={defaultValue}\r\n disabled={disabled}\r\n rules={rules}\r\n shouldUnregister={shouldUnregister}\r\n render={({ field }) => {\r\n return (\r\n <FormItem {...formItemProps}>\r\n <FormLabel {...(slotProps?.formLabelProps ?? {})}>\r\n {label}\r\n {required && <span className=\"text-danger text-sm leading-4\">*</span>}\r\n </FormLabel>\r\n <FormControl>\r\n <Combobox\r\n options={options}\r\n value={field.value}\r\n onValueChange={field.onChange}\r\n loading={loading}\r\n loadingText={loadingText}\r\n emptyOptionsText={emptyOptionsText}\r\n placeholder={placeholder}\r\n disabled={disabled || readOnly}\r\n showSearchInput={showSearchInput}\r\n {...(slotProps?.comboboxProps ?? {})}\r\n />\r\n </FormControl>\r\n\r\n <FormMessage {...(slotProps?.formMessageProps ?? {})} />\r\n </FormItem>\r\n );\r\n }}\r\n />\r\n );\r\n};\r\nexport { FormCombobox, type FormComboboxProps };\r\n"],"names":["FormCombobox","props","name","control","defaultValue","disabled","readOnly","rules","shouldUnregister","label","options","loading","loadingText","emptyOptionsText","showSearchInput","placeholder","slotProps","required","formItemProps","jsx","FormField","field","jsxs","FormItem","FormLabel","FormControl","Combobox","FormMessage"],"mappings":";;;AA+BM,MAAAA,IAAe,CACnBC,MACG;AACG,QAAA;AAAA,IACJ,MAAAC;AAAA,IACA,SAAAC;AAAA,IACA,cAAAC;AAAA,IACA,UAAAC;AAAA,IACA,UAAAC;AAAA,IACA,OAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC;AAAA,IACA,SAAAC;AAAA,IACA,aAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,UAAAC;AAAA,IACA,GAAGC;AAAA,EAAA,IACDjB;AAGF,SAAA,gBAAAkB;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,SAAAjB;AAAA,MACA,MAAAD;AAAA,MACA,cAAAE;AAAA,MACA,UAAAC;AAAA,MACA,OAAAE;AAAA,MACA,kBAAAC;AAAA,MACA,QAAQ,CAAC,EAAE,OAAAa,QAEP,gBAAAC,EAACC,GAAU,EAAA,GAAGL,GACZ,UAAA;AAAA,QAAA,gBAAAI,EAACE,GAAW,EAAA,GAAIR,GAAW,kBAAkB,CAC1C,GAAA,UAAA;AAAA,UAAAP;AAAA,UACAQ,KAAY,gBAAAE,EAAC,QAAK,EAAA,WAAU,iCAAgC,UAAC,IAAA,CAAA;AAAA,QAAA,GAChE;AAAA,0BACCM,GACC,EAAA,UAAA,gBAAAN;AAAA,UAACO;AAAA,UAAA;AAAA,YACC,SAAAhB;AAAA,YACA,OAAOW,EAAM;AAAA,YACb,eAAeA,EAAM;AAAA,YACrB,SAAAV;AAAA,YACA,aAAAC;AAAA,YACA,kBAAAC;AAAA,YACA,aAAAE;AAAA,YACA,UAAUV,KAAYC;AAAA,YACtB,iBAAAQ;AAAA,YACC,GAAIE,GAAW,iBAAiB,CAAA;AAAA,UAAC;AAAA,QAAA,GAEtC;AAAA,0BAECW,GAAa,EAAA,GAAIX,GAAW,oBAAoB,CAAA,EAAK,CAAA;AAAA,MAAA,GACxD;AAAA,IAEJ;AAAA,EACF;AAEJ;"}
1
+ {"version":3,"file":"formcombobox.es.js","sources":["../src/components/form-combobox/FormCombobox.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport { ControllerProps, FieldPath, FieldValues } from \"react-hook-form\";\r\n\r\nimport { FormControl, FormField, FormItem, FormLabel, FormMessage } from \"../form/Form\";\r\nimport { Combobox } from \"../combobox/Combobox\";\r\n\r\ntype FormComboboxProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<\r\n ControllerProps<TFieldValues, TName>,\r\n \"render\"\r\n> &\r\n React.ComponentProps<typeof FormItem> & {\r\n label: string;\r\n options: { value: string | number; label: string }[];\r\n loading?: boolean;\r\n loadingText?: string;\r\n emptyOptionsText?: string;\r\n showSearchInput?: boolean;\r\n clearable?: boolean;\r\n placeholder?: string;\r\n required?: boolean;\r\n readOnly?: boolean;\r\n slotProps?: {\r\n formLabelProps?: React.HTMLAttributes<HTMLLabelElement> & React.RefAttributes<HTMLLabelElement>;\r\n formMessageProps?: React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>;\r\n comboboxProps?: Omit<\r\n React.ComponentPropsWithoutRef<typeof Combobox>,\r\n \"options\" | \"value\" | \"onValueChange\" | \"loading\" | \"loadingText\" | \"emptyOptionsText\" | \"placeholder\" | \"disabled\" | \"showSearchInput\"\r\n >;\r\n };\r\n };\r\n\r\nconst FormCombobox = <TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(\r\n props: FormComboboxProps<TFieldValues, TName>,\r\n) => {\r\n const {\r\n name,\r\n control,\r\n clearable = false,\r\n defaultValue,\r\n disabled,\r\n readOnly,\r\n rules,\r\n shouldUnregister,\r\n label,\r\n options,\r\n loading,\r\n loadingText,\r\n emptyOptionsText,\r\n showSearchInput,\r\n placeholder,\r\n slotProps,\r\n required,\r\n ...formItemProps\r\n } = props;\r\n\r\n return (\r\n <FormField\r\n control={control}\r\n name={name}\r\n defaultValue={defaultValue}\r\n disabled={disabled}\r\n rules={rules}\r\n shouldUnregister={shouldUnregister}\r\n render={({ field }) => {\r\n return (\r\n <FormItem {...formItemProps}>\r\n <FormLabel {...(slotProps?.formLabelProps ?? {})}>\r\n {label}\r\n {required && <span className=\"text-danger text-sm leading-4\">*</span>}\r\n </FormLabel>\r\n <FormControl>\r\n <Combobox\r\n options={options}\r\n value={field.value}\r\n onValueChange={field.onChange}\r\n loading={loading}\r\n loadingText={loadingText}\r\n emptyOptionsText={emptyOptionsText}\r\n placeholder={placeholder}\r\n disabled={disabled || readOnly}\r\n showSearchInput={showSearchInput}\r\n clearable={clearable}\r\n {...(slotProps?.comboboxProps ?? {})}\r\n />\r\n </FormControl>\r\n\r\n <FormMessage {...(slotProps?.formMessageProps ?? {})} />\r\n </FormItem>\r\n );\r\n }}\r\n />\r\n );\r\n};\r\nexport { FormCombobox, type FormComboboxProps };\r\n"],"names":["FormCombobox","props","name","control","clearable","defaultValue","disabled","readOnly","rules","shouldUnregister","label","options","loading","loadingText","emptyOptionsText","showSearchInput","placeholder","slotProps","required","formItemProps","jsx","FormField","field","jsxs","FormItem","FormLabel","FormControl","Combobox","FormMessage"],"mappings":";;;AAgCM,MAAAA,IAAe,CACnBC,MACG;AACG,QAAA;AAAA,IACJ,MAAAC;AAAA,IACA,SAAAC;AAAA,IACA,WAAAC,IAAY;AAAA,IACZ,cAAAC;AAAA,IACA,UAAAC;AAAA,IACA,UAAAC;AAAA,IACA,OAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC;AAAA,IACA,SAAAC;AAAA,IACA,aAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,UAAAC;AAAA,IACA,GAAGC;AAAA,EAAA,IACDlB;AAGF,SAAA,gBAAAmB;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,SAAAlB;AAAA,MACA,MAAAD;AAAA,MACA,cAAAG;AAAA,MACA,UAAAC;AAAA,MACA,OAAAE;AAAA,MACA,kBAAAC;AAAA,MACA,QAAQ,CAAC,EAAE,OAAAa,QAEP,gBAAAC,EAACC,GAAU,EAAA,GAAGL,GACZ,UAAA;AAAA,QAAA,gBAAAI,EAACE,GAAW,EAAA,GAAIR,GAAW,kBAAkB,CAC1C,GAAA,UAAA;AAAA,UAAAP;AAAA,UACAQ,KAAY,gBAAAE,EAAC,QAAK,EAAA,WAAU,iCAAgC,UAAC,IAAA,CAAA;AAAA,QAAA,GAChE;AAAA,0BACCM,GACC,EAAA,UAAA,gBAAA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