@brightlocal/ui-components 0.1.0

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.
Files changed (320) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +349 -0
  3. package/dist/accordion.cjs +1 -0
  4. package/dist/accordion.d.ts +32 -0
  5. package/dist/accordion.d.ts.map +1 -0
  6. package/dist/accordion.js +107 -0
  7. package/dist/alert-dialog.cjs +1 -0
  8. package/dist/alert-dialog.d.ts +15 -0
  9. package/dist/alert-dialog.d.ts.map +1 -0
  10. package/dist/alert-dialog.js +146 -0
  11. package/dist/alert.cjs +1 -0
  12. package/dist/alert.d.ts +16 -0
  13. package/dist/alert.d.ts.map +1 -0
  14. package/dist/alert.js +174 -0
  15. package/dist/aspect-ratio.cjs +1 -0
  16. package/dist/aspect-ratio.d.ts +10 -0
  17. package/dist/aspect-ratio.d.ts.map +1 -0
  18. package/dist/aspect-ratio.js +22 -0
  19. package/dist/avatar.cjs +1 -0
  20. package/dist/avatar.d.ts +11 -0
  21. package/dist/avatar.d.ts.map +1 -0
  22. package/dist/avatar.js +46 -0
  23. package/dist/badge.cjs +1 -0
  24. package/dist/badge.d.ts +19 -0
  25. package/dist/badge.d.ts.map +1 -0
  26. package/dist/badge.js +50 -0
  27. package/dist/blocks/data-table.cjs +1 -0
  28. package/dist/blocks/data-table.d.ts +303 -0
  29. package/dist/blocks/data-table.d.ts.map +1 -0
  30. package/dist/blocks/data-table.js +555 -0
  31. package/dist/blocks/sidebar.cjs +1 -0
  32. package/dist/blocks/sidebar.d.ts +744 -0
  33. package/dist/blocks/sidebar.d.ts.map +1 -0
  34. package/dist/blocks/sidebar.js +839 -0
  35. package/dist/breadcrumb.cjs +1 -0
  36. package/dist/breadcrumb.d.ts +12 -0
  37. package/dist/breadcrumb.d.ts.map +1 -0
  38. package/dist/breadcrumb.js +102 -0
  39. package/dist/button.cjs +1 -0
  40. package/dist/button.d.ts +73 -0
  41. package/dist/button.d.ts.map +1 -0
  42. package/dist/button.js +195 -0
  43. package/dist/calendar.cjs +1 -0
  44. package/dist/calendar.d.ts +28 -0
  45. package/dist/calendar.d.ts.map +1 -0
  46. package/dist/calendar.js +191 -0
  47. package/dist/card.cjs +1 -0
  48. package/dist/card.d.ts +28 -0
  49. package/dist/card.d.ts.map +1 -0
  50. package/dist/card.js +131 -0
  51. package/dist/carousel.cjs +1 -0
  52. package/dist/carousel.d.ts +21 -0
  53. package/dist/carousel.d.ts.map +1 -0
  54. package/dist/carousel.js +185 -0
  55. package/dist/centred-layout.cjs +1 -0
  56. package/dist/centred-layout.d.ts +49 -0
  57. package/dist/centred-layout.d.ts.map +1 -0
  58. package/dist/centred-layout.js +35 -0
  59. package/dist/chart.cjs +10 -0
  60. package/dist/chart.d.ts +83 -0
  61. package/dist/chart.d.ts.map +1 -0
  62. package/dist/chart.js +254 -0
  63. package/dist/checkbox.cjs +1 -0
  64. package/dist/checkbox.d.ts +15 -0
  65. package/dist/checkbox.d.ts.map +1 -0
  66. package/dist/checkbox.js +96 -0
  67. package/dist/collapsible.cjs +1 -0
  68. package/dist/collapsible.d.ts +18 -0
  69. package/dist/collapsible.d.ts.map +1 -0
  70. package/dist/collapsible.js +58 -0
  71. package/dist/combobox.cjs +1 -0
  72. package/dist/combobox.d.ts +65 -0
  73. package/dist/combobox.d.ts.map +1 -0
  74. package/dist/combobox.js +203 -0
  75. package/dist/command.cjs +1 -0
  76. package/dist/command.d.ts +44 -0
  77. package/dist/command.d.ts.map +1 -0
  78. package/dist/command.js +166 -0
  79. package/dist/context-menu.cjs +1 -0
  80. package/dist/context-menu.d.ts +42 -0
  81. package/dist/context-menu.d.ts.map +1 -0
  82. package/dist/context-menu.js +226 -0
  83. package/dist/date-picker.cjs +1 -0
  84. package/dist/date-picker.d.ts +54 -0
  85. package/dist/date-picker.d.ts.map +1 -0
  86. package/dist/date-picker.js +95 -0
  87. package/dist/dialog.cjs +1 -0
  88. package/dist/dialog.d.ts +20 -0
  89. package/dist/dialog.d.ts.map +1 -0
  90. package/dist/dialog.js +130 -0
  91. package/dist/drawer.cjs +1 -0
  92. package/dist/drawer.d.ts +22 -0
  93. package/dist/drawer.d.ts.map +1 -0
  94. package/dist/drawer.js +149 -0
  95. package/dist/dropdown-menu.cjs +1 -0
  96. package/dist/dropdown-menu.d.ts +253 -0
  97. package/dist/dropdown-menu.d.ts.map +1 -0
  98. package/dist/dropdown-menu.js +325 -0
  99. package/dist/field.cjs +1 -0
  100. package/dist/field.d.ts +21 -0
  101. package/dist/field.d.ts.map +1 -0
  102. package/dist/field.js +148 -0
  103. package/dist/global-layout.cjs +1 -0
  104. package/dist/global-layout.d.ts +60 -0
  105. package/dist/global-layout.d.ts.map +1 -0
  106. package/dist/global-layout.js +87 -0
  107. package/dist/hooks/use-mobile.cjs +1 -0
  108. package/dist/hooks/use-mobile.d.ts +2 -0
  109. package/dist/hooks/use-mobile.d.ts.map +1 -0
  110. package/dist/hooks/use-mobile.js +16 -0
  111. package/dist/hover-card.cjs +1 -0
  112. package/dist/hover-card.d.ts +43 -0
  113. package/dist/hover-card.d.ts.map +1 -0
  114. package/dist/hover-card.js +71 -0
  115. package/dist/index.cjs +1 -0
  116. package/dist/index.d.ts +61 -0
  117. package/dist/index.d.ts.map +1 -0
  118. package/dist/index.js +412 -0
  119. package/dist/input-base.cjs +1 -0
  120. package/dist/input-base.d.ts +28 -0
  121. package/dist/input-base.d.ts.map +1 -0
  122. package/dist/input-base.js +56 -0
  123. package/dist/input-group.cjs +1 -0
  124. package/dist/input-group.d.ts +26 -0
  125. package/dist/input-group.d.ts.map +1 -0
  126. package/dist/input-group.js +116 -0
  127. package/dist/input-otp.cjs +1 -0
  128. package/dist/input-otp.d.ts +45 -0
  129. package/dist/input-otp.d.ts.map +1 -0
  130. package/dist/input-otp.js +186 -0
  131. package/dist/input-password.cjs +1 -0
  132. package/dist/input-password.d.ts +38 -0
  133. package/dist/input-password.d.ts.map +1 -0
  134. package/dist/input-password.js +101 -0
  135. package/dist/input.cjs +1 -0
  136. package/dist/input.d.ts +32 -0
  137. package/dist/input.d.ts.map +1 -0
  138. package/dist/input.js +146 -0
  139. package/dist/label.cjs +1 -0
  140. package/dist/label.d.ts +12 -0
  141. package/dist/label.d.ts.map +1 -0
  142. package/dist/label.js +34 -0
  143. package/dist/lib/utils.cjs +1 -0
  144. package/dist/lib/utils.d.ts +3 -0
  145. package/dist/lib/utils.d.ts.map +1 -0
  146. package/dist/lib/utils.js +8 -0
  147. package/dist/link.cjs +1 -0
  148. package/dist/link.d.ts +29 -0
  149. package/dist/link.d.ts.map +1 -0
  150. package/dist/link.figma.d.ts +2 -0
  151. package/dist/link.figma.d.ts.map +1 -0
  152. package/dist/link.js +71 -0
  153. package/dist/logo.cjs +1 -0
  154. package/dist/logo.d.ts +25 -0
  155. package/dist/logo.d.ts.map +1 -0
  156. package/dist/logo.js +71 -0
  157. package/dist/menubar.cjs +1 -0
  158. package/dist/menubar.d.ts +106 -0
  159. package/dist/menubar.d.ts.map +1 -0
  160. package/dist/menubar.js +270 -0
  161. package/dist/navigation-menu.cjs +1 -0
  162. package/dist/navigation-menu.d.ts +108 -0
  163. package/dist/navigation-menu.d.ts.map +1 -0
  164. package/dist/navigation-menu.js +175 -0
  165. package/dist/pagination.cjs +1 -0
  166. package/dist/pagination.d.ts +81 -0
  167. package/dist/pagination.d.ts.map +1 -0
  168. package/dist/pagination.js +216 -0
  169. package/dist/popover.cjs +1 -0
  170. package/dist/popover.d.ts +8 -0
  171. package/dist/popover.d.ts.map +1 -0
  172. package/dist/popover.js +44 -0
  173. package/dist/progress.cjs +1 -0
  174. package/dist/progress.d.ts +29 -0
  175. package/dist/progress.d.ts.map +1 -0
  176. package/dist/progress.js +64 -0
  177. package/dist/radio-group.cjs +1 -0
  178. package/dist/radio-group.d.ts +33 -0
  179. package/dist/radio-group.d.ts.map +1 -0
  180. package/dist/radio-group.js +193 -0
  181. package/dist/rating.cjs +1 -0
  182. package/dist/rating.d.ts +22 -0
  183. package/dist/rating.d.ts.map +1 -0
  184. package/dist/rating.js +51 -0
  185. package/dist/resizable.cjs +1 -0
  186. package/dist/resizable.d.ts +14 -0
  187. package/dist/resizable.d.ts.map +1 -0
  188. package/dist/resizable.js +46 -0
  189. package/dist/scroll-area.cjs +1 -0
  190. package/dist/scroll-area.d.ts +12 -0
  191. package/dist/scroll-area.d.ts.map +1 -0
  192. package/dist/scroll-area.js +67 -0
  193. package/dist/select.cjs +1 -0
  194. package/dist/select.d.ts +77 -0
  195. package/dist/select.d.ts.map +1 -0
  196. package/dist/select.js +259 -0
  197. package/dist/separator.cjs +1 -0
  198. package/dist/separator.d.ts +14 -0
  199. package/dist/separator.d.ts.map +1 -0
  200. package/dist/separator.js +43 -0
  201. package/dist/sheet.cjs +1 -0
  202. package/dist/sheet.d.ts +38 -0
  203. package/dist/sheet.d.ts.map +1 -0
  204. package/dist/sheet.js +190 -0
  205. package/dist/skeleton.cjs +1 -0
  206. package/dist/skeleton.d.ts +5 -0
  207. package/dist/skeleton.d.ts.map +1 -0
  208. package/dist/skeleton.js +15 -0
  209. package/dist/slider.cjs +1 -0
  210. package/dist/slider.d.ts +19 -0
  211. package/dist/slider.d.ts.map +1 -0
  212. package/dist/slider.js +69 -0
  213. package/dist/sonner.cjs +1 -0
  214. package/dist/sonner.d.ts +188 -0
  215. package/dist/sonner.d.ts.map +1 -0
  216. package/dist/sonner.js +150 -0
  217. package/dist/split-layout.cjs +1 -0
  218. package/dist/split-layout.d.ts +42 -0
  219. package/dist/split-layout.d.ts.map +1 -0
  220. package/dist/split-layout.js +108 -0
  221. package/dist/switch.cjs +1 -0
  222. package/dist/switch.d.ts +43 -0
  223. package/dist/switch.d.ts.map +1 -0
  224. package/dist/switch.figma.d.ts +2 -0
  225. package/dist/switch.figma.d.ts.map +1 -0
  226. package/dist/switch.js +110 -0
  227. package/dist/table.cjs +1 -0
  228. package/dist/table.d.ts +95 -0
  229. package/dist/table.d.ts.map +1 -0
  230. package/dist/table.js +164 -0
  231. package/dist/tabs.cjs +1 -0
  232. package/dist/tabs.d.ts +29 -0
  233. package/dist/tabs.d.ts.map +1 -0
  234. package/dist/tabs.js +96 -0
  235. package/dist/textarea.cjs +1 -0
  236. package/dist/textarea.d.ts +23 -0
  237. package/dist/textarea.d.ts.map +1 -0
  238. package/dist/textarea.js +47 -0
  239. package/dist/toggle-group.cjs +1 -0
  240. package/dist/toggle-group.d.ts +25 -0
  241. package/dist/toggle-group.d.ts.map +1 -0
  242. package/dist/toggle-group.js +74 -0
  243. package/dist/toggle.cjs +1 -0
  244. package/dist/toggle.d.ts +44 -0
  245. package/dist/toggle.d.ts.map +1 -0
  246. package/dist/toggle.figma.d.ts +2 -0
  247. package/dist/toggle.figma.d.ts.map +1 -0
  248. package/dist/toggle.js +57 -0
  249. package/dist/tooltip.cjs +1 -0
  250. package/dist/tooltip.d.ts +66 -0
  251. package/dist/tooltip.d.ts.map +1 -0
  252. package/dist/tooltip.js +78 -0
  253. package/package.json +184 -0
  254. package/src/blocks/data-table.tsx +1166 -0
  255. package/src/blocks/sidebar.tsx +1830 -0
  256. package/src/components/.gitkeep +0 -0
  257. package/src/components/accordion.tsx +142 -0
  258. package/src/components/alert-dialog.tsx +157 -0
  259. package/src/components/alert.tsx +199 -0
  260. package/src/components/aspect-ratio.tsx +30 -0
  261. package/src/components/avatar.tsx +56 -0
  262. package/src/components/badge.tsx +72 -0
  263. package/src/components/breadcrumb.tsx +109 -0
  264. package/src/components/button.tsx +296 -0
  265. package/src/components/calendar.tsx +234 -0
  266. package/src/components/card.tsx +158 -0
  267. package/src/components/carousel.tsx +256 -0
  268. package/src/components/centred-layout.tsx +91 -0
  269. package/src/components/chart.tsx +456 -0
  270. package/src/components/checkbox.tsx +132 -0
  271. package/src/components/collapsible.tsx +68 -0
  272. package/src/components/combobox.tsx +321 -0
  273. package/src/components/command.tsx +220 -0
  274. package/src/components/context-menu.tsx +305 -0
  275. package/src/components/date-picker.tsx +155 -0
  276. package/src/components/dialog.tsx +152 -0
  277. package/src/components/drawer.tsx +168 -0
  278. package/src/components/dropdown-menu.tsx +575 -0
  279. package/src/components/field.tsx +155 -0
  280. package/src/components/global-layout.tsx +153 -0
  281. package/src/components/hover-card.tsx +121 -0
  282. package/src/components/input-base.tsx +86 -0
  283. package/src/components/input-group.tsx +158 -0
  284. package/src/components/input-otp.tsx +327 -0
  285. package/src/components/input-password.tsx +191 -0
  286. package/src/components/input.tsx +220 -0
  287. package/src/components/label.tsx +42 -0
  288. package/src/components/link.figma.tsx +71 -0
  289. package/src/components/link.tsx +105 -0
  290. package/src/components/logo.tsx +97 -0
  291. package/src/components/menubar.tsx +379 -0
  292. package/src/components/navigation-menu.tsx +324 -0
  293. package/src/components/pagination.tsx +368 -0
  294. package/src/components/popover.tsx +46 -0
  295. package/src/components/progress.tsx +100 -0
  296. package/src/components/radio-group.tsx +281 -0
  297. package/src/components/rating.tsx +87 -0
  298. package/src/components/resizable.tsx +66 -0
  299. package/src/components/scroll-area.tsx +72 -0
  300. package/src/components/select.tsx +442 -0
  301. package/src/components/separator.tsx +53 -0
  302. package/src/components/sheet.tsx +220 -0
  303. package/src/components/skeleton.tsx +17 -0
  304. package/src/components/slider.tsx +86 -0
  305. package/src/components/sonner.tsx +396 -0
  306. package/src/components/split-layout.tsx +155 -0
  307. package/src/components/switch.figma.tsx +115 -0
  308. package/src/components/switch.tsx +173 -0
  309. package/src/components/table.tsx +277 -0
  310. package/src/components/tabs.tsx +142 -0
  311. package/src/components/textarea.tsx +77 -0
  312. package/src/components/toggle-group.tsx +109 -0
  313. package/src/components/toggle.figma.tsx +81 -0
  314. package/src/components/toggle.tsx +103 -0
  315. package/src/components/tooltip.tsx +156 -0
  316. package/src/hooks/.gitkeep +0 -0
  317. package/src/hooks/use-mobile.ts +21 -0
  318. package/src/index.ts +67 -0
  319. package/src/lib/utils.ts +6 -0
  320. package/src/types/external-modules.d.ts +16 -0
@@ -0,0 +1,321 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { CheckIcon, ChevronsUpDownIcon, ChevronDownIcon } from "lucide-react";
5
+ import { cva, type VariantProps } from "class-variance-authority";
6
+
7
+ import { cn } from "@brightlocal/ui-components/lib/utils";
8
+ import {
9
+ Popover,
10
+ PopoverContent,
11
+ PopoverTrigger,
12
+ } from "@brightlocal/ui-components/popover";
13
+ import {
14
+ Command,
15
+ CommandEmpty,
16
+ CommandGroup,
17
+ CommandInput,
18
+ CommandItem,
19
+ CommandList,
20
+ } from "@brightlocal/ui-components/command";
21
+
22
+ /**
23
+ * Visual style variants for Combobox
24
+ */
25
+ export enum ComboboxVariant {
26
+ /** Default variant with standard combobox styling */
27
+ DEFAULT = "default",
28
+ /** Variant with group label showing category above selection */
29
+ WITH_GROUP_LABEL = "withGroupLabel",
30
+ }
31
+
32
+ /**
33
+ * Size variants for Combobox
34
+ */
35
+ export enum ComboboxSize {
36
+ /** Standard size (36px height) */
37
+ DEFAULT = "default",
38
+ /** Large size (48px height) */
39
+ LG = "lg",
40
+ }
41
+
42
+ export interface ComboboxItem {
43
+ /** Unique value for the item */
44
+ value: string;
45
+ /** Display label for the item */
46
+ label: string;
47
+ /** Optional group/category for the item */
48
+ group?: string;
49
+ }
50
+
51
+ const comboboxTriggerVariants = cva(
52
+ [
53
+ // Base layout
54
+ "relative flex w-full items-center justify-between gap-2",
55
+ "px-3 py-2",
56
+
57
+ // Base appearance
58
+ "border border-border rounded-lg outline-none transition-all",
59
+ "bg-neutral-50 border-neutral-300",
60
+ "dark:bg-white/5 dark:border-white/15",
61
+
62
+ // Typography
63
+ "text-sm font-normal font-sans text-foreground",
64
+
65
+ // Placeholder state
66
+ "data-[placeholder]:text-muted-foreground",
67
+
68
+ // Focus state (keyboard navigation only - not on click)
69
+ "focus-visible:outline-none focus-visible:border-ring dark:focus-visible:border-neutral-500 focus-visible:bg-background",
70
+ "focus-visible:shadow-default",
71
+
72
+ // Open dropdown state
73
+ "data-[state=open]:border-ring",
74
+
75
+ // Disabled state
76
+ "disabled:cursor-not-allowed disabled:opacity-50",
77
+
78
+ // Icon styles
79
+ "[&_svg]:pointer-events-none [&_svg]:shrink-0",
80
+ "[&_svg:not([class*='size-'])]:size-4",
81
+ "[&_svg:not([class*='text-'])]:text-muted-foreground",
82
+ ],
83
+ {
84
+ variants: {
85
+ variant: {
86
+ default: ["h-9", "py-2"],
87
+ withGroupLabel: ["h-12", "py-2", "flex-col", "items-start"],
88
+ },
89
+ size: {
90
+ default: [],
91
+ lg: [],
92
+ },
93
+ },
94
+ compoundVariants: [
95
+ {
96
+ variant: "withGroupLabel",
97
+ size: "lg",
98
+ className: "h-12",
99
+ },
100
+ ],
101
+ defaultVariants: {
102
+ variant: "default",
103
+ size: "default",
104
+ },
105
+ }
106
+ );
107
+
108
+ interface ComboboxProps extends VariantProps<typeof comboboxTriggerVariants> {
109
+ /** Data hook for automated testing (REQUIRED) */
110
+ dataHook: string;
111
+ /** Tracking element identifier for analytics */
112
+ trackingEl?: string;
113
+ /** Tracking label for analytics context */
114
+ trackingLabel?: string;
115
+ /** Array of items to display in the combobox */
116
+ items: ComboboxItem[];
117
+ /** Currently selected value */
118
+ value?: string;
119
+ /** Callback when selection changes */
120
+ onValueChange?: (value: string) => void;
121
+ /** Placeholder text when no value is selected */
122
+ placeholder?: string;
123
+ /** Group label text (only for withGroupLabel variant) */
124
+ groupLabel?: string;
125
+ /** Label text displayed above the combobox */
126
+ label?: string;
127
+ /** Description text displayed below the combobox */
128
+ description?: string;
129
+ /** Disabled state */
130
+ disabled?: boolean;
131
+ /** Empty state message when no results found */
132
+ emptyMessage?: string;
133
+ /** Search placeholder text */
134
+ searchPlaceholder?: string;
135
+ /** Custom className for the trigger button */
136
+ className?: string;
137
+ }
138
+
139
+ const Combobox = React.forwardRef<HTMLButtonElement, ComboboxProps>(
140
+ (
141
+ {
142
+ variant = ComboboxVariant.DEFAULT,
143
+ size = ComboboxSize.DEFAULT,
144
+ dataHook,
145
+ trackingEl,
146
+ trackingLabel,
147
+ items,
148
+ value,
149
+ onValueChange,
150
+ placeholder = "Select an option...",
151
+ groupLabel,
152
+ label,
153
+ description,
154
+ disabled,
155
+ emptyMessage = "No results found.",
156
+ searchPlaceholder = "Search...",
157
+ className,
158
+ },
159
+ ref
160
+ ) => {
161
+ const [open, setOpen] = React.useState(false);
162
+
163
+ const selectedItem = items.find((item) => item.value === value);
164
+
165
+ // Group items by their group property for withGroupLabel variant
166
+ const groupedItems = React.useMemo(() => {
167
+ if (variant !== ComboboxVariant.WITH_GROUP_LABEL) {
168
+ return { "": items };
169
+ }
170
+
171
+ return items.reduce(
172
+ (acc, item) => {
173
+ const group = item.group || "";
174
+ if (!acc[group]) {
175
+ acc[group] = [];
176
+ }
177
+ acc[group].push(item);
178
+ return acc;
179
+ },
180
+ {} as Record<string, ComboboxItem[]>
181
+ );
182
+ }, [items, variant]);
183
+
184
+ const handleSelect = (currentValue: string) => {
185
+ const newValue = currentValue === value ? "" : currentValue;
186
+ onValueChange?.(newValue);
187
+ setOpen(false);
188
+ };
189
+
190
+ return (
191
+ <div
192
+ className="flex w-full flex-col gap-2"
193
+ data-slot="combobox-container"
194
+ >
195
+ {label && (
196
+ <label
197
+ className="text-foreground text-sm leading-none font-medium"
198
+ data-slot="combobox-label"
199
+ >
200
+ {label}
201
+ </label>
202
+ )}
203
+
204
+ <Popover open={open} onOpenChange={setOpen}>
205
+ <PopoverTrigger asChild>
206
+ <button
207
+ ref={ref}
208
+ aria-expanded={open}
209
+ aria-haspopup="listbox"
210
+ aria-label={label || placeholder}
211
+ className={cn(
212
+ comboboxTriggerVariants({
213
+ variant:
214
+ selectedItem && variant === ComboboxVariant.WITH_GROUP_LABEL
215
+ ? ComboboxVariant.WITH_GROUP_LABEL
216
+ : ComboboxVariant.DEFAULT,
217
+ size,
218
+ }),
219
+ className
220
+ )}
221
+ data-hook={dataHook}
222
+ data-slot="combobox-trigger"
223
+ data-tracking-el={trackingEl || `combobox-${variant}`}
224
+ data-tracking-label={trackingLabel}
225
+ disabled={disabled}
226
+ type="button"
227
+ >
228
+ {variant === ComboboxVariant.WITH_GROUP_LABEL && selectedItem ? (
229
+ <>
230
+ <div className="flex w-full flex-col items-start gap-0.5">
231
+ {groupLabel && (
232
+ <span className="text-muted-foreground text-xs leading-none font-normal">
233
+ {groupLabel}
234
+ </span>
235
+ )}
236
+ <span className="text-foreground overflow-hidden text-sm leading-5 font-medium text-ellipsis whitespace-nowrap">
237
+ {selectedItem.label}
238
+ </span>
239
+ </div>
240
+ <ChevronDownIcon className="size-4 shrink-0 opacity-50" />
241
+ </>
242
+ ) : (
243
+ <>
244
+ <span className="text-foreground overflow-hidden text-ellipsis whitespace-nowrap">
245
+ {selectedItem ? selectedItem.label : placeholder}
246
+ </span>
247
+ <ChevronsUpDownIcon className="size-4 shrink-0 opacity-50" />
248
+ </>
249
+ )}
250
+ </button>
251
+ </PopoverTrigger>
252
+
253
+ <PopoverContent
254
+ align="start"
255
+ className="w-[var(--radix-popover-trigger-width)] p-0"
256
+ >
257
+ <Command data-slot="combobox-command">
258
+ <CommandInput placeholder={searchPlaceholder} />
259
+ <CommandList>
260
+ <CommandEmpty>{emptyMessage}</CommandEmpty>
261
+ {variant === ComboboxVariant.WITH_GROUP_LABEL &&
262
+ Object.keys(groupedItems).length > 1 ? (
263
+ Object.entries(groupedItems).map(([group, groupItems]) => (
264
+ <CommandGroup key={group} heading={group}>
265
+ {groupItems.map((item) => (
266
+ <CommandItem
267
+ key={item.value}
268
+ value={item.value}
269
+ onSelect={handleSelect}
270
+ >
271
+ <CheckIcon
272
+ className={cn(
273
+ "mr-2 size-4",
274
+ value === item.value ? "opacity-100" : "opacity-0"
275
+ )}
276
+ />
277
+ {item.label}
278
+ </CommandItem>
279
+ ))}
280
+ </CommandGroup>
281
+ ))
282
+ ) : (
283
+ <CommandGroup>
284
+ {items.map((item) => (
285
+ <CommandItem
286
+ key={item.value}
287
+ value={item.value}
288
+ onSelect={handleSelect}
289
+ >
290
+ <CheckIcon
291
+ className={cn(
292
+ "mr-2 size-4",
293
+ value === item.value ? "opacity-100" : "opacity-0"
294
+ )}
295
+ />
296
+ {item.label}
297
+ </CommandItem>
298
+ ))}
299
+ </CommandGroup>
300
+ )}
301
+ </CommandList>
302
+ </Command>
303
+ </PopoverContent>
304
+ </Popover>
305
+
306
+ {description && (
307
+ <p
308
+ className="text-muted-foreground text-sm leading-5 font-normal"
309
+ data-slot="combobox-description"
310
+ >
311
+ {description}
312
+ </p>
313
+ )}
314
+ </div>
315
+ );
316
+ }
317
+ );
318
+
319
+ Combobox.displayName = "Combobox";
320
+
321
+ export { Combobox, type ComboboxProps };
@@ -0,0 +1,220 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { Command as CommandPrimitive } from "cmdk";
5
+ import { SearchIcon } from "lucide-react";
6
+
7
+ import { cn } from "@brightlocal/ui-components/lib/utils";
8
+
9
+ export interface CommandProps extends React.ComponentProps<
10
+ typeof CommandPrimitive
11
+ > {
12
+ dataHook?: string;
13
+ trackingEl?: string;
14
+ trackingLabel?: string;
15
+ }
16
+
17
+ function Command({
18
+ className,
19
+ dataHook,
20
+ trackingEl,
21
+ trackingLabel,
22
+ ...props
23
+ }: CommandProps) {
24
+ return (
25
+ <CommandPrimitive
26
+ className={cn(
27
+ "bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",
28
+ className
29
+ )}
30
+ data-hook={dataHook}
31
+ data-slot="command"
32
+ data-tracking-el={trackingEl}
33
+ data-tracking-label={trackingLabel}
34
+ {...props}
35
+ />
36
+ );
37
+ }
38
+
39
+ export interface CommandInputProps extends React.ComponentProps<
40
+ typeof CommandPrimitive.Input
41
+ > {
42
+ dataHook?: string;
43
+ trackingEl?: string;
44
+ trackingLabel?: string;
45
+ }
46
+
47
+ function CommandInput({
48
+ className,
49
+ dataHook,
50
+ trackingEl,
51
+ trackingLabel,
52
+ ...props
53
+ }: CommandInputProps) {
54
+ return (
55
+ <div
56
+ className="flex items-center gap-2 border-b px-3"
57
+ data-hook={dataHook}
58
+ data-slot="command-input-wrapper"
59
+ >
60
+ <SearchIcon className="size-4 shrink-0 opacity-50" />
61
+ <CommandPrimitive.Input
62
+ className={cn(
63
+ "placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
64
+ className
65
+ )}
66
+ data-slot="command-input"
67
+ data-tracking-el={trackingEl}
68
+ data-tracking-label={trackingLabel}
69
+ {...props}
70
+ />
71
+ </div>
72
+ );
73
+ }
74
+
75
+ export interface CommandListProps extends React.ComponentProps<
76
+ typeof CommandPrimitive.List
77
+ > {
78
+ dataHook?: string;
79
+ }
80
+
81
+ function CommandList({ className, dataHook, ...props }: CommandListProps) {
82
+ return (
83
+ <CommandPrimitive.List
84
+ className={cn(
85
+ "max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
86
+ className
87
+ )}
88
+ data-hook={dataHook}
89
+ data-slot="command-list"
90
+ {...props}
91
+ />
92
+ );
93
+ }
94
+
95
+ export interface CommandEmptyProps extends React.ComponentProps<
96
+ typeof CommandPrimitive.Empty
97
+ > {
98
+ dataHook?: string;
99
+ }
100
+
101
+ function CommandEmpty({ dataHook, ...props }: CommandEmptyProps) {
102
+ return (
103
+ <CommandPrimitive.Empty
104
+ className="py-6 text-center text-sm"
105
+ data-hook={dataHook}
106
+ data-slot="command-empty"
107
+ {...props}
108
+ />
109
+ );
110
+ }
111
+
112
+ export interface CommandGroupProps extends React.ComponentProps<
113
+ typeof CommandPrimitive.Group
114
+ > {
115
+ dataHook?: string;
116
+ }
117
+
118
+ function CommandGroup({ className, dataHook, ...props }: CommandGroupProps) {
119
+ return (
120
+ <CommandPrimitive.Group
121
+ className={cn(
122
+ "text-foreground [&_[cmdk-group-heading]]:text-muted-foreground overflow-hidden p-1 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium",
123
+ className
124
+ )}
125
+ data-hook={dataHook}
126
+ data-slot="command-group"
127
+ {...props}
128
+ />
129
+ );
130
+ }
131
+
132
+ export interface CommandSeparatorProps extends React.ComponentProps<
133
+ typeof CommandPrimitive.Separator
134
+ > {
135
+ dataHook?: string;
136
+ }
137
+
138
+ function CommandSeparator({
139
+ className,
140
+ dataHook,
141
+ ...props
142
+ }: CommandSeparatorProps) {
143
+ return (
144
+ <CommandPrimitive.Separator
145
+ className={cn("bg-border -mx-1 h-px", className)}
146
+ data-hook={dataHook}
147
+ data-slot="command-separator"
148
+ {...props}
149
+ />
150
+ );
151
+ }
152
+
153
+ export interface CommandItemProps extends React.ComponentProps<
154
+ typeof CommandPrimitive.Item
155
+ > {
156
+ dataHook?: string;
157
+ trackingEl?: string;
158
+ trackingLabel?: string;
159
+ }
160
+
161
+ function CommandItem({
162
+ className,
163
+ dataHook,
164
+ trackingEl,
165
+ trackingLabel,
166
+ ...props
167
+ }: CommandItemProps) {
168
+ return (
169
+ <CommandPrimitive.Item
170
+ className={cn(
171
+ "data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
172
+ className
173
+ )}
174
+ data-hook={dataHook}
175
+ data-slot="command-item"
176
+ data-tracking-el={trackingEl}
177
+ data-tracking-label={trackingLabel}
178
+ {...props}
179
+ />
180
+ );
181
+ }
182
+
183
+ export interface CommandShortcutProps extends React.ComponentProps<"span"> {
184
+ dataHook?: string;
185
+ trackingEl?: string;
186
+ trackingLabel?: string;
187
+ }
188
+
189
+ function CommandShortcut({
190
+ className,
191
+ dataHook,
192
+ trackingEl,
193
+ trackingLabel,
194
+ ...props
195
+ }: CommandShortcutProps) {
196
+ return (
197
+ <span
198
+ className={cn(
199
+ "text-muted-foreground ml-auto text-xs tracking-widest",
200
+ className
201
+ )}
202
+ data-hook={dataHook}
203
+ data-slot="command-shortcut"
204
+ data-tracking-el={trackingEl}
205
+ data-tracking-label={trackingLabel}
206
+ {...props}
207
+ />
208
+ );
209
+ }
210
+
211
+ export {
212
+ Command,
213
+ CommandEmpty,
214
+ CommandGroup,
215
+ CommandInput,
216
+ CommandItem,
217
+ CommandList,
218
+ CommandSeparator,
219
+ CommandShortcut,
220
+ };