@trsys-tech/matrix-library 0.5.2-alpha.1 → 0.5.2-alpha.2
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/combobox.es.js +60 -60
- package/dist/combobox.es.js.map +1 -1
- package/dist/components/combobox/Combobox.d.ts +6 -2
- package/dist/components/combobox/Combobox.d.ts.map +1 -1
- package/dist/components/form-combobox/FormCombobox.d.ts +1 -4
- package/dist/components/form-combobox/FormCombobox.d.ts.map +1 -1
- package/dist/formcombobox.es.js.map +1 -1
- package/dist/textfield.es.js +1 -1
- package/dist/textfield.es.js.map +1 -1
- package/package.json +1 -1
package/dist/combobox.es.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import { XMark as
|
|
4
|
-
import { cn as
|
|
5
|
-
import { Button as
|
|
6
|
-
import { Popover as
|
|
7
|
-
import { Command as
|
|
8
|
-
const
|
|
9
|
-
onValueChange:
|
|
10
|
-
options:
|
|
11
|
-
value:
|
|
12
|
-
className:
|
|
1
|
+
import { jsxs as s, jsx as a } from "react/jsx-runtime";
|
|
2
|
+
import t, { useRef as A, useEffect as B, useMemo as M } from "react";
|
|
3
|
+
import { XMark as O, ChevronDown as G, Check as T } from "@trsys-tech/matrix-icons";
|
|
4
|
+
import { cn as x } from "./utils.es.js";
|
|
5
|
+
import { Button as X } from "./button.es.js";
|
|
6
|
+
import { Popover as q, PopoverTrigger as z, PopoverContent as H } from "./popover.es.js";
|
|
7
|
+
import { Command as J, CommandInput as Q, CommandList as U, CommandEmpty as W, CommandItem as w, CommandGroup as Y } from "./command.es.js";
|
|
8
|
+
const oe = ({
|
|
9
|
+
onValueChange: o,
|
|
10
|
+
options: d,
|
|
11
|
+
value: m,
|
|
12
|
+
className: y,
|
|
13
13
|
clearable: g = !1,
|
|
14
|
-
closeOnSelect:
|
|
15
|
-
loading:
|
|
16
|
-
disabled:
|
|
17
|
-
placeholder:
|
|
18
|
-
searchText:
|
|
19
|
-
noResultsText:
|
|
20
|
-
loadingText:
|
|
14
|
+
closeOnSelect: i = !0,
|
|
15
|
+
loading: n,
|
|
16
|
+
disabled: C,
|
|
17
|
+
placeholder: p = "Select an option",
|
|
18
|
+
searchText: k = "Search...",
|
|
19
|
+
noResultsText: N = "No results found",
|
|
20
|
+
loadingText: b = "Loading...",
|
|
21
21
|
emptyOptionsText: P = "No Items",
|
|
22
|
-
showSearchInput:
|
|
22
|
+
showSearchInput: f = !0,
|
|
23
23
|
modalPopover: L,
|
|
24
24
|
...D
|
|
25
25
|
}) => {
|
|
26
|
-
const [
|
|
26
|
+
const [v, l] = t.useState(!1), h = A(null), [r, c] = t.useState(m), E = t.useCallback(
|
|
27
27
|
(e) => {
|
|
28
|
-
e.key === "Enter" ? l(!0) : e.key === "Backspace" && !e.currentTarget.value && (
|
|
28
|
+
e.key === "Enter" ? l(!0) : e.key === "Backspace" && !e.currentTarget.value && (c(r), o?.(r), i && l(!1));
|
|
29
29
|
},
|
|
30
|
-
[r,
|
|
31
|
-
), S =
|
|
30
|
+
[r, o, i]
|
|
31
|
+
), S = t.useCallback(
|
|
32
32
|
(e) => {
|
|
33
|
-
|
|
33
|
+
c(e), o?.(e), i && l(!1);
|
|
34
34
|
},
|
|
35
|
-
[
|
|
36
|
-
), j =
|
|
35
|
+
[o, i]
|
|
36
|
+
), j = t.useCallback(
|
|
37
37
|
(e) => {
|
|
38
|
-
e.stopPropagation(),
|
|
38
|
+
e.stopPropagation(), o?.(void 0), c(void 0);
|
|
39
39
|
},
|
|
40
|
-
[
|
|
41
|
-
), I =
|
|
40
|
+
[o]
|
|
41
|
+
), I = t.useCallback((e, R, _ = [""]) => _.join("").toLocaleLowerCase().includes(R.toLocaleLowerCase()) ? 1 : 0, []), F = t.useCallback(
|
|
42
42
|
(e) => {
|
|
43
|
-
|
|
43
|
+
f || (e.preventDefault(), h.current?.focus());
|
|
44
44
|
},
|
|
45
|
-
[
|
|
45
|
+
[f]
|
|
46
46
|
);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}, [
|
|
50
|
-
const
|
|
51
|
-
return /* @__PURE__ */
|
|
52
|
-
/* @__PURE__ */ a(
|
|
53
|
-
|
|
47
|
+
B(() => {
|
|
48
|
+
c(m);
|
|
49
|
+
}, [m]);
|
|
50
|
+
const u = r === void 0 || r === "", K = M(() => u && n ? b : u ? p : d.find((e) => e.value === r)?.label || p, [u, r, d, p, n, b]);
|
|
51
|
+
return /* @__PURE__ */ s(q, { open: v, onOpenChange: l, modal: L, children: [
|
|
52
|
+
/* @__PURE__ */ a(z, { asChild: !0, children: /* @__PURE__ */ s(
|
|
53
|
+
X,
|
|
54
54
|
{
|
|
55
55
|
variant: "text",
|
|
56
56
|
role: "combobox",
|
|
57
57
|
type: "button",
|
|
58
|
-
"aria-expanded":
|
|
59
|
-
className:
|
|
58
|
+
"aria-expanded": v,
|
|
59
|
+
className: x(
|
|
60
60
|
"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-xs 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",
|
|
61
|
-
|
|
61
|
+
y
|
|
62
62
|
),
|
|
63
63
|
"data-value": r,
|
|
64
|
-
"data-placeholder":
|
|
65
|
-
loading:
|
|
66
|
-
disabled:
|
|
64
|
+
"data-placeholder": u ? "" : void 0,
|
|
65
|
+
loading: n,
|
|
66
|
+
disabled: C,
|
|
67
67
|
endIcon: /* @__PURE__ */ a(
|
|
68
|
-
|
|
68
|
+
G,
|
|
69
69
|
{
|
|
70
70
|
role: "button",
|
|
71
71
|
"aria-label": "Expand dropdown",
|
|
@@ -74,7 +74,7 @@ const ae = ({
|
|
|
74
74
|
),
|
|
75
75
|
...D,
|
|
76
76
|
children: [
|
|
77
|
-
/* @__PURE__ */ a("span", { className: "text-start text-ellipsis whitespace-nowrap overflow-hidden flex-1 max-w-[calc(100%-24px)]", children:
|
|
77
|
+
/* @__PURE__ */ a("span", { className: "text-start text-ellipsis whitespace-nowrap overflow-hidden flex-1 max-w-[calc(100%-24px)]", children: K }),
|
|
78
78
|
g && r !== void 0 && r !== null ? /* @__PURE__ */ a(
|
|
79
79
|
"span",
|
|
80
80
|
{
|
|
@@ -82,33 +82,33 @@ const ae = ({
|
|
|
82
82
|
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",
|
|
83
83
|
role: "button",
|
|
84
84
|
"aria-label": "Clear selection",
|
|
85
|
-
children: /* @__PURE__ */ a(
|
|
85
|
+
children: /* @__PURE__ */ a(O, {})
|
|
86
86
|
}
|
|
87
87
|
) : null
|
|
88
88
|
]
|
|
89
89
|
}
|
|
90
90
|
) }),
|
|
91
|
-
/* @__PURE__ */ a(
|
|
92
|
-
|
|
91
|
+
/* @__PURE__ */ a(H, { className: "w-auto p-0", align: "start", onEscapeKeyDown: () => l(!1), onOpenAutoFocus: F, children: /* @__PURE__ */ s(
|
|
92
|
+
J,
|
|
93
93
|
{
|
|
94
94
|
className: "w-[--radix-popper-anchor-width] focus-visible:outline-none",
|
|
95
95
|
filter: I,
|
|
96
96
|
defaultValue: r != null ? String(r) : void 0,
|
|
97
|
-
ref:
|
|
97
|
+
ref: h,
|
|
98
98
|
children: [
|
|
99
|
-
|
|
100
|
-
/* @__PURE__ */
|
|
101
|
-
!
|
|
102
|
-
!
|
|
103
|
-
/* @__PURE__ */ a(
|
|
104
|
-
|
|
99
|
+
f && /* @__PURE__ */ a(Q, { placeholder: k, onKeyDown: E }),
|
|
100
|
+
/* @__PURE__ */ s(U, { children: [
|
|
101
|
+
!n && /* @__PURE__ */ a(W, { children: N }),
|
|
102
|
+
!n && !d.length ? /* @__PURE__ */ a(w, { value: "8fdcaeb67c8ad943c80fe54c3b1059b700d9254389a38a4a1fc39a6eee7564623", disabled: !0, children: P }) : null,
|
|
103
|
+
/* @__PURE__ */ a(Y, { children: d.map((e) => /* @__PURE__ */ s(
|
|
104
|
+
w,
|
|
105
105
|
{
|
|
106
106
|
value: e.value,
|
|
107
|
-
keywords: [e.label],
|
|
107
|
+
keywords: "keyword" in e ? [e.keyword] : [e.label],
|
|
108
108
|
onSelect: S,
|
|
109
109
|
children: [
|
|
110
110
|
e.label,
|
|
111
|
-
/* @__PURE__ */ a(T, { className:
|
|
111
|
+
/* @__PURE__ */ a(T, { className: x("ml-auto", r === e.value ? "opacity-100" : "opacity-0") })
|
|
112
112
|
]
|
|
113
113
|
},
|
|
114
114
|
String(e.value)
|
|
@@ -120,6 +120,6 @@ const ae = ({
|
|
|
120
120
|
] });
|
|
121
121
|
};
|
|
122
122
|
export {
|
|
123
|
-
|
|
123
|
+
oe as Combobox
|
|
124
124
|
};
|
|
125
125
|
//# sourceMappingURL=combobox.es.js.map
|
package/dist/combobox.es.js.map
CHANGED
|
@@ -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\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 modalPopover,\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} modal={modalPopover}>\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-xs 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","modalPopover","props","isPopoverOpen","setIsPopoverOpen","React","commandRef","useRef","currentSelectedValue","setCurrentSelectedValue","handleInputKeyDown","event","handleSelect","currentValue","handleClear","handleFilter","search","keywords","handleOpenAutoFocus","useEffect","showPlaceholder","Popover","jsx","PopoverTrigger","jsxs","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;AA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GAAG,iBAAiBc,GACpH,UAAA,gBAAAM;AAAA,MAACO;AAAA,MAAA;AAAA,QACC,WAAU;AAAA,QACV,QAAQhB;AAAA,QACR,cAAoDP,KAAyB,OAAO,OAAOA,CAAoB,IAAI;AAAA,QACnH,KAAKF;AAAA,QAEJ,UAAA;AAAA,UAAAN,KAAmB,gBAAAsB,EAACU,GAAA,EAAa,aAAapC,GAAY,WAAWc,GAAoB;AAAA,4BACzFuB,GAAA,EACE,UAAA;AAAA,YAAA,CAACxC,KAAW,gBAAA6B,EAACY,GAAA,EAAc,UAAArC,EAAA,CAAc;AAAA,YACzC,CAACJ,KAAW,CAACL,EAAQ,SACpB,gBAAAkC,EAACa,GAAA,EAAY,OAAM,qEAAoE,UAAQ,IAC5F,UAAApC,EAAA,CACH,IACE;AAAA,YACJ,gBAAAuB,EAACc,GAAA,EACE,UAAAhD,EAAQ,IAAI,CAAAwC,MACX,gBAAAJ;AAAA,cAACW;AAAA,cAAA;AAAA,gBAEC,OAAOP,EAAO;AAAA,gBACd,UAAU,CAACA,EAAO,KAAK;AAAA,gBACvB,UAAUhB;AAAA,gBAET,UAAA;AAAA,kBAAAgB,EAAO;AAAA,kBACR,gBAAAN,EAACe,GAAA,EAAM,WAAWX,EAAG,WAAWlB,MAAyBoB,EAAO,QAAQ,gBAAgB,WAAW,EAAA,CAAG;AAAA,gBAAA;AAAA,cAAA;AAAA,cANjG,OAAOA,EAAO,KAAK;AAAA,YAAA,CAQ3B,EAAA,CACH;AAAA,UAAA,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,EACF,CACF;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, useMemo, 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 } | { label: React.ReactElement; value: T; keyword: string })[];\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 modalPopover,\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 const label = useMemo(() => {\r\n if (showPlaceholder && loading) return loadingText;\r\n if (showPlaceholder) return placeholder;\r\n return options.find(option => option.value === currentSelectedValue)?.label || placeholder;\r\n }, [showPlaceholder, currentSelectedValue, options, placeholder, loading, loadingText]);\r\n\r\n return (\r\n <Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen} modal={modalPopover}>\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-xs 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)]\">{label}</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={\"keyword\" in option ? [option.keyword] : [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","modalPopover","props","isPopoverOpen","setIsPopoverOpen","React","commandRef","useRef","currentSelectedValue","setCurrentSelectedValue","handleInputKeyDown","event","handleSelect","currentValue","handleClear","handleFilter","search","keywords","handleOpenAutoFocus","useEffect","showPlaceholder","label","useMemo","option","Popover","jsx","PopoverTrigger","jsxs","Button","cn","ChevronDown","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,cAAAC;AAAA,EACA,GAAGC;AACL,MAAwB;AACtB,QAAM,CAACC,GAAeC,CAAgB,IAAIC,EAAM,SAAS,EAAK,GACxDC,IAAaC,EAAuB,IAAI,GAExC,CAACC,GAAsBC,CAAuB,IAAIJ,EAAM,SAAwBhB,CAAK,GAErFqB,IAAqBL,EAAM;AAAA,IAC/B,CAACM,MAAiD;AAChD,MAAIA,EAAM,QAAQ,UAChBP,EAAiB,EAAI,IACZO,EAAM,QAAQ,eAAe,CAACA,EAAM,cAAc,UAC3DF,EAAwBD,CAAoB,GAC5CrB,IAAgBqB,CAAqB,GACjChB,OAAgC,EAAK;AAAA,IAE7C;AAAA,IACA,CAACgB,GAAsBrB,GAAeK,CAAa;AAAA,EAAA,GAG/CoB,IAAeP,EAAM;AAAA,IACzB,CAACQ,MAAoB;AACnB,MAAAJ,EAAwBI,CAAY,GACpC1B,IAAgB0B,CAAY,GACxBrB,OAAgC,EAAK;AAAA,IAC3C;AAAA,IACA,CAACL,GAAeK,CAAa;AAAA,EAAA,GAGzBsB,IAAcT,EAAM;AAAA,IAC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AChE,UAAUX;AAAA,gBAET,UAAA;AAAA,kBAAAW,EAAO;AAAA,kBACR,gBAAAE,EAACc,GAAA,EAAM,WAAWV,EAAG,WAAWrB,MAAyBe,EAAO,QAAQ,gBAAgB,WAAW,EAAA,CAAG;AAAA,gBAAA;AAAA,cAAA;AAAA,cANjG,OAAOA,EAAO,KAAK;AAAA,YAAA,CAQ3B,EAAA,CACH;AAAA,UAAA,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,EACF,CACF;AAAA,EAAA,GACF;AAEJ;"}
|
|
@@ -6,10 +6,14 @@ type ComboboxProps<T extends string | number> = React.HTMLAttributes<HTMLButtonE
|
|
|
6
6
|
* The label is what is displayed in the combobox.
|
|
7
7
|
* The value is what is returned when the option is selected.
|
|
8
8
|
*/
|
|
9
|
-
options: {
|
|
9
|
+
options: ({
|
|
10
10
|
label: string;
|
|
11
11
|
value: T;
|
|
12
|
-
}
|
|
12
|
+
} | {
|
|
13
|
+
label: React.ReactElement;
|
|
14
|
+
value: T;
|
|
15
|
+
keyword: string;
|
|
16
|
+
})[];
|
|
13
17
|
/**
|
|
14
18
|
* The value of the combobox.
|
|
15
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Combobox.d.ts","sourceRoot":"","sources":["../../../src/components/combobox/Combobox.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"Combobox.d.ts","sourceRoot":"","sources":["../../../src/components/combobox/Combobox.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAqC,MAAM,OAAO,CAAC;AAQ1D,KAAK,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,iBAAiB,CAAC,GAAG;IACxF;;;;;OAKG;IACH,OAAO,EAAE,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,CAAC,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC;QAAC,KAAK,EAAE,CAAC,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,CAAC;IAEpG;;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,6MAiBxC,aAAa,CAAC,CAAC,CAAC,4CAuIlB,CAAC;AACF,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,CAAC"}
|
|
@@ -3,10 +3,7 @@ import { FormItem } from '../form/Form';
|
|
|
3
3
|
import { Combobox } from '../combobox/Combobox';
|
|
4
4
|
type FormComboboxProps<TFieldValues extends FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = Omit<ControllerProps<TFieldValues, TName>, "render"> & React.ComponentProps<typeof FormItem> & {
|
|
5
5
|
label: string;
|
|
6
|
-
options:
|
|
7
|
-
value: string | number;
|
|
8
|
-
label: string;
|
|
9
|
-
}[];
|
|
6
|
+
options: React.ComponentProps<typeof Combobox>["options"];
|
|
10
7
|
loading?: boolean;
|
|
11
8
|
loadingText?: string;
|
|
12
9
|
emptyOptionsText?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormCombobox.d.ts","sourceRoot":"","sources":["../../../src/components/form-combobox/FormCombobox.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE1E,OAAO,EAA0B,QAAQ,EAA0B,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,KAAK,iBAAiB,CAAC,YAAY,SAAS,WAAW,EAAE,KAAK,SAAS,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,IAAI,IAAI,CAC9H,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC,EACpC,QAAQ,CACT,GACC,KAAK,CAAC,cAAc,CAAC,OAAO,QAAQ,CAAC,GAAG;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE
|
|
1
|
+
{"version":3,"file":"FormCombobox.d.ts","sourceRoot":"","sources":["../../../src/components/form-combobox/FormCombobox.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE1E,OAAO,EAA0B,QAAQ,EAA0B,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,KAAK,iBAAiB,CAAC,YAAY,SAAS,WAAW,EAAE,KAAK,SAAS,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,IAAI,IAAI,CAC9H,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC,EACpC,QAAQ,CACT,GACC,KAAK,CAAC,cAAc,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Content":["\"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:
|
|
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: React.ComponentProps<typeof Combobox>[\"options\"];\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":";;;AAgCA,MAAMA,IAAe,CACnBC,MACG;AACH,QAAM;AAAA,IACJ,MAAAC;AAAA,IACA,SAAAC;AAAA,IACA,WAAAC,IAAY;AAAA,IACZ,cAAAC;AAAA,IACA,UAAAC;AAAA,IACA,UAAA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?? {},
|
|
34
34
|
className: n(
|
|
35
|
-
"focus:outline-none w-full h-full py-1 rounded-sm file:border-0
|
|
35
|
+
"focus:outline-none w-full h-full py-1 rounded-sm file:border-0 bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-text-300",
|
|
36
36
|
r ? "ps-1 pe-3" : "px-3",
|
|
37
37
|
t?.inputProps?.className
|
|
38
38
|
)
|
package/dist/textfield.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textfield.es.js","sources":["../src/components/text-field/TextField.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\nimport { tv, VariantProps } from \"tailwind-variants\";\r\n\r\nimport { cn } from \"../../lib/utils\";\r\n\r\nconst textFieldVariants = tv({\r\n base: [\r\n \"flex items-center w-full rounded-sm border border-input text-text bg-transparent p-0 text-xs [&_input]:text-xs font-medium transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground\",\r\n \"placeholder:text-text-300 hover:border-primary-400 focus-within:border-primary-400 focus-within:outline-none focus-within:ring focus-within:ring-primary-100\",\r\n \"aria-disabled:text-text-300 aria-disabled:bg-gray-100 aria-disabled:border-gray-100\",\r\n ],\r\n variants: {\r\n size: {\r\n sm: \"h-7\",\r\n md: \"h-8\",\r\n lg: \"h-11\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n },\r\n});\r\n\r\ninterface TextFieldProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof textFieldVariants> {\r\n type?: React.HTMLInputTypeAttribute;\r\n disabled?: boolean;\r\n suffix?: React.ReactNode;\r\n endAdornment?: React.ReactNode;\r\n startAdornment?: React.ReactNode;\r\n onChange?: React.ChangeEventHandler<HTMLInputElement>;\r\n value?: string | number;\r\n defaultValue?: string | number;\r\n slotProps?: {\r\n inputProps?: React.InputHTMLAttributes<HTMLInputElement>;\r\n };\r\n}\r\n\r\nconst TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(\r\n ({ className, slotProps, suffix, endAdornment, startAdornment, size, value, onChange, defaultValue, type, disabled, ...props }, ref) => {\r\n return (\r\n <div {...props} className={cn(textFieldVariants({ size, className }))} aria-disabled={disabled}>\r\n {startAdornment}\r\n <input\r\n type={type}\r\n ref={ref}\r\n onChange={onChange}\r\n value={value}\r\n defaultValue={defaultValue}\r\n disabled={disabled}\r\n {...(slotProps?.inputProps ?? {})}\r\n className={cn(\r\n \"focus:outline-none w-full h-full py-1 rounded-sm file:border-0
|
|
1
|
+
{"version":3,"file":"textfield.es.js","sources":["../src/components/text-field/TextField.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\nimport { tv, VariantProps } from \"tailwind-variants\";\r\n\r\nimport { cn } from \"../../lib/utils\";\r\n\r\nconst textFieldVariants = tv({\r\n base: [\r\n \"flex items-center w-full rounded-sm border border-input text-text bg-transparent p-0 text-xs [&_input]:text-xs font-medium transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground\",\r\n \"placeholder:text-text-300 hover:border-primary-400 focus-within:border-primary-400 focus-within:outline-none focus-within:ring focus-within:ring-primary-100\",\r\n \"aria-disabled:text-text-300 aria-disabled:bg-gray-100 aria-disabled:border-gray-100\",\r\n ],\r\n variants: {\r\n size: {\r\n sm: \"h-7\",\r\n md: \"h-8\",\r\n lg: \"h-11\",\r\n },\r\n },\r\n defaultVariants: {\r\n size: \"md\",\r\n },\r\n});\r\n\r\ninterface TextFieldProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof textFieldVariants> {\r\n type?: React.HTMLInputTypeAttribute;\r\n disabled?: boolean;\r\n suffix?: React.ReactNode;\r\n endAdornment?: React.ReactNode;\r\n startAdornment?: React.ReactNode;\r\n onChange?: React.ChangeEventHandler<HTMLInputElement>;\r\n value?: string | number;\r\n defaultValue?: string | number;\r\n slotProps?: {\r\n inputProps?: React.InputHTMLAttributes<HTMLInputElement>;\r\n };\r\n}\r\n\r\nconst TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(\r\n ({ className, slotProps, suffix, endAdornment, startAdornment, size, value, onChange, defaultValue, type, disabled, ...props }, ref) => {\r\n return (\r\n <div {...props} className={cn(textFieldVariants({ size, className }))} aria-disabled={disabled}>\r\n {startAdornment}\r\n <input\r\n type={type}\r\n ref={ref}\r\n onChange={onChange}\r\n value={value}\r\n defaultValue={defaultValue}\r\n disabled={disabled}\r\n {...(slotProps?.inputProps ?? {})}\r\n className={cn(\r\n \"focus:outline-none w-full h-full py-1 rounded-sm file:border-0 bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-text-300\",\r\n !startAdornment ? \"px-3\" : \"ps-1 pe-3\",\r\n slotProps?.inputProps?.className,\r\n )}\r\n />\r\n {typeof suffix === \"string\" || typeof suffix === \"number\" ? (\r\n <span className=\"inline-flex items-center px-2 text-xs font-medium text-primary bg-primary-50 m-0.5 rounded-sm\">{suffix}</span>\r\n ) : (\r\n suffix\r\n )}\r\n {endAdornment}\r\n </div>\r\n );\r\n },\r\n);\r\nTextField.displayName = \"TextField\";\r\n\r\nexport { TextField, type TextFieldProps };\r\n"],"names":["textFieldVariants","tv","TextField","React","className","slotProps","suffix","endAdornment","startAdornment","size","value","onChange","defaultValue","type","disabled","props","ref","jsxs","cn","jsx"],"mappings":";;;;AAOA,MAAMA,IAAoBC,EAAG;AAAA,EAC3B,MAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAAA,EAEF,UAAU;AAAA,IACR,MAAM;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,IAAA;AAAA,EACN;AAAA,EAEF,iBAAiB;AAAA,IACf,MAAM;AAAA,EAAA;AAEV,CAAC,GAgBKC,IAAYC,EAAM;AAAA,EACtB,CAAC,EAAE,WAAAC,GAAW,WAAAC,GAAW,QAAAC,GAAQ,cAAAC,GAAc,gBAAAC,GAAgB,MAAAC,GAAM,OAAAC,GAAO,UAAAC,GAAU,cAAAC,GAAc,MAAAC,GAAM,UAAAC,GAAU,GAAGC,EAAA,GAASC,MAE5H,gBAAAC,EAAC,OAAA,EAAK,GAAGF,GAAO,WAAWG,EAAGlB,EAAkB,EAAE,MAAAS,GAAM,WAAAL,EAAA,CAAW,CAAC,GAAG,iBAAeU,GACnF,UAAA;AAAA,IAAAN;AAAA,IACD,gBAAAW;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,MAAAN;AAAA,QACA,KAAAG;AAAA,QACA,UAAAL;AAAA,QACA,OAAAD;AAAA,QACA,cAAAE;AAAA,QACA,UAAAE;AAAA,QACC,GAAIT,GAAW,cAAc,CAAA;AAAA,QAC9B,WAAWa;AAAA,UACT;AAAA,UACCV,IAA0B,cAAT;AAAA,UAClBH,GAAW,YAAY;AAAA,QAAA;AAAA,MACzB;AAAA,IAAA;AAAA,IAED,OAAOC,KAAW,YAAY,OAAOA,KAAW,WAC/C,gBAAAa,EAAC,QAAA,EAAK,WAAU,iGAAiG,UAAAb,EAAA,CAAO,IAExHA;AAAA,IAEDC;AAAA,EAAA,GACH;AAGN;AACAL,EAAU,cAAc;"}
|