@questpie/admin 0.0.1

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 (203) hide show
  1. package/.turbo/turbo-build.log +108 -0
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +556 -0
  4. package/STATUS.md +917 -0
  5. package/VALIDATION.md +602 -0
  6. package/components.json +24 -0
  7. package/dist/__tests__/setup.mjs +38 -0
  8. package/dist/__tests__/test-utils.mjs +45 -0
  9. package/dist/__tests__/vitest.d.mjs +3 -0
  10. package/dist/components/admin-app.mjs +69 -0
  11. package/dist/components/fields/array-field.mjs +190 -0
  12. package/dist/components/fields/checkbox-field.mjs +34 -0
  13. package/dist/components/fields/custom-field.mjs +32 -0
  14. package/dist/components/fields/date-field.mjs +41 -0
  15. package/dist/components/fields/datetime-field.mjs +42 -0
  16. package/dist/components/fields/email-field.mjs +37 -0
  17. package/dist/components/fields/embedded-collection.mjs +253 -0
  18. package/dist/components/fields/field-types.mjs +1 -0
  19. package/dist/components/fields/field-utils.mjs +10 -0
  20. package/dist/components/fields/field-wrapper.mjs +34 -0
  21. package/dist/components/fields/index.mjs +23 -0
  22. package/dist/components/fields/json-field.mjs +243 -0
  23. package/dist/components/fields/locale-badge.mjs +16 -0
  24. package/dist/components/fields/number-field.mjs +39 -0
  25. package/dist/components/fields/password-field.mjs +37 -0
  26. package/dist/components/fields/relation-field.mjs +104 -0
  27. package/dist/components/fields/relation-picker.mjs +229 -0
  28. package/dist/components/fields/relation-select.mjs +188 -0
  29. package/dist/components/fields/rich-text-editor/index.mjs +897 -0
  30. package/dist/components/fields/select-field.mjs +41 -0
  31. package/dist/components/fields/switch-field.mjs +34 -0
  32. package/dist/components/fields/text-field.mjs +38 -0
  33. package/dist/components/fields/textarea-field.mjs +38 -0
  34. package/dist/components/index.mjs +59 -0
  35. package/dist/components/primitives/checkbox-input.mjs +127 -0
  36. package/dist/components/primitives/date-input.mjs +303 -0
  37. package/dist/components/primitives/index.mjs +12 -0
  38. package/dist/components/primitives/number-input.mjs +104 -0
  39. package/dist/components/primitives/select-input.mjs +177 -0
  40. package/dist/components/primitives/tag-input.mjs +135 -0
  41. package/dist/components/primitives/text-input.mjs +39 -0
  42. package/dist/components/primitives/textarea-input.mjs +37 -0
  43. package/dist/components/primitives/toggle-input.mjs +31 -0
  44. package/dist/components/primitives/types.mjs +12 -0
  45. package/dist/components/ui/accordion.mjs +55 -0
  46. package/dist/components/ui/avatar.mjs +54 -0
  47. package/dist/components/ui/badge.mjs +34 -0
  48. package/dist/components/ui/button.mjs +48 -0
  49. package/dist/components/ui/card.mjs +58 -0
  50. package/dist/components/ui/checkbox.mjs +21 -0
  51. package/dist/components/ui/combobox.mjs +163 -0
  52. package/dist/components/ui/dialog.mjs +95 -0
  53. package/dist/components/ui/dropdown-menu.mjs +138 -0
  54. package/dist/components/ui/field.mjs +113 -0
  55. package/dist/components/ui/input-group.mjs +82 -0
  56. package/dist/components/ui/input.mjs +17 -0
  57. package/dist/components/ui/label.mjs +15 -0
  58. package/dist/components/ui/popover.mjs +56 -0
  59. package/dist/components/ui/scroll-area.mjs +38 -0
  60. package/dist/components/ui/select.mjs +100 -0
  61. package/dist/components/ui/separator.mjs +16 -0
  62. package/dist/components/ui/sheet.mjs +90 -0
  63. package/dist/components/ui/sidebar.mjs +387 -0
  64. package/dist/components/ui/skeleton.mjs +14 -0
  65. package/dist/components/ui/spinner.mjs +16 -0
  66. package/dist/components/ui/switch.mjs +22 -0
  67. package/dist/components/ui/table.mjs +68 -0
  68. package/dist/components/ui/tabs.mjs +48 -0
  69. package/dist/components/ui/textarea.mjs +15 -0
  70. package/dist/components/ui/tooltip.mjs +44 -0
  71. package/dist/config/component-registry.mjs +38 -0
  72. package/dist/config/index.mjs +129 -0
  73. package/dist/hooks/admin-provider.mjs +70 -0
  74. package/dist/hooks/index.mjs +7 -0
  75. package/dist/hooks/store.mjs +178 -0
  76. package/dist/hooks/use-auth.mjs +76 -0
  77. package/dist/hooks/use-collection-db.mjs +146 -0
  78. package/dist/hooks/use-collection.mjs +112 -0
  79. package/dist/hooks/use-global.mjs +46 -0
  80. package/dist/hooks/use-mobile.mjs +20 -0
  81. package/dist/lib/utils.mjs +10 -0
  82. package/dist/styles/index.css +336 -0
  83. package/dist/styles/index.mjs +1 -0
  84. package/dist/utils/index.mjs +9 -0
  85. package/dist/views/auth/auth-layout.mjs +52 -0
  86. package/dist/views/auth/forgot-password-form.mjs +148 -0
  87. package/dist/views/auth/index.mjs +6 -0
  88. package/dist/views/auth/login-form.mjs +156 -0
  89. package/dist/views/auth/reset-password-form.mjs +184 -0
  90. package/dist/views/collection/auto-form-fields.mjs +525 -0
  91. package/dist/views/collection/collection-form.mjs +91 -0
  92. package/dist/views/collection/collection-list.mjs +76 -0
  93. package/dist/views/collection/form-field.mjs +42 -0
  94. package/dist/views/collection/index.mjs +6 -0
  95. package/dist/views/common/index.mjs +4 -0
  96. package/dist/views/common/locale-switcher.mjs +39 -0
  97. package/dist/views/common/version-history.mjs +272 -0
  98. package/dist/views/index.mjs +9 -0
  99. package/dist/views/layout/admin-layout.mjs +40 -0
  100. package/dist/views/layout/admin-router.mjs +95 -0
  101. package/dist/views/layout/admin-sidebar.mjs +63 -0
  102. package/dist/views/layout/index.mjs +5 -0
  103. package/package.json +276 -0
  104. package/src/__tests__/setup.ts +44 -0
  105. package/src/__tests__/test-utils.tsx +49 -0
  106. package/src/__tests__/vitest.d.ts +9 -0
  107. package/src/components/admin-app.tsx +221 -0
  108. package/src/components/fields/array-field.tsx +237 -0
  109. package/src/components/fields/checkbox-field.tsx +47 -0
  110. package/src/components/fields/custom-field.tsx +50 -0
  111. package/src/components/fields/date-field.tsx +65 -0
  112. package/src/components/fields/datetime-field.tsx +67 -0
  113. package/src/components/fields/email-field.tsx +51 -0
  114. package/src/components/fields/embedded-collection.tsx +315 -0
  115. package/src/components/fields/field-types.ts +162 -0
  116. package/src/components/fields/field-utils.ts +6 -0
  117. package/src/components/fields/field-wrapper.tsx +52 -0
  118. package/src/components/fields/index.ts +66 -0
  119. package/src/components/fields/json-field.tsx +440 -0
  120. package/src/components/fields/locale-badge.tsx +15 -0
  121. package/src/components/fields/number-field.tsx +57 -0
  122. package/src/components/fields/password-field.tsx +51 -0
  123. package/src/components/fields/relation-field.tsx +243 -0
  124. package/src/components/fields/relation-picker.tsx +402 -0
  125. package/src/components/fields/relation-select.tsx +327 -0
  126. package/src/components/fields/rich-text-editor/index.tsx +1337 -0
  127. package/src/components/fields/select-field.tsx +61 -0
  128. package/src/components/fields/switch-field.tsx +47 -0
  129. package/src/components/fields/text-field.tsx +55 -0
  130. package/src/components/fields/textarea-field.tsx +55 -0
  131. package/src/components/index.ts +40 -0
  132. package/src/components/primitives/checkbox-input.tsx +193 -0
  133. package/src/components/primitives/date-input.tsx +401 -0
  134. package/src/components/primitives/index.ts +24 -0
  135. package/src/components/primitives/number-input.tsx +132 -0
  136. package/src/components/primitives/select-input.tsx +296 -0
  137. package/src/components/primitives/tag-input.tsx +200 -0
  138. package/src/components/primitives/text-input.tsx +49 -0
  139. package/src/components/primitives/textarea-input.tsx +46 -0
  140. package/src/components/primitives/toggle-input.tsx +36 -0
  141. package/src/components/primitives/types.ts +235 -0
  142. package/src/components/ui/accordion.tsx +72 -0
  143. package/src/components/ui/avatar.tsx +106 -0
  144. package/src/components/ui/badge.tsx +48 -0
  145. package/src/components/ui/button.tsx +53 -0
  146. package/src/components/ui/card.tsx +94 -0
  147. package/src/components/ui/checkbox.tsx +27 -0
  148. package/src/components/ui/combobox.tsx +290 -0
  149. package/src/components/ui/dialog.tsx +151 -0
  150. package/src/components/ui/dropdown-menu.tsx +254 -0
  151. package/src/components/ui/field.tsx +227 -0
  152. package/src/components/ui/input-group.tsx +149 -0
  153. package/src/components/ui/input.tsx +20 -0
  154. package/src/components/ui/label.tsx +18 -0
  155. package/src/components/ui/popover.tsx +88 -0
  156. package/src/components/ui/scroll-area.tsx +53 -0
  157. package/src/components/ui/select.tsx +192 -0
  158. package/src/components/ui/separator.tsx +23 -0
  159. package/src/components/ui/sheet.tsx +127 -0
  160. package/src/components/ui/sidebar.tsx +723 -0
  161. package/src/components/ui/skeleton.tsx +13 -0
  162. package/src/components/ui/spinner.tsx +10 -0
  163. package/src/components/ui/switch.tsx +32 -0
  164. package/src/components/ui/table.tsx +99 -0
  165. package/src/components/ui/tabs.tsx +82 -0
  166. package/src/components/ui/textarea.tsx +18 -0
  167. package/src/components/ui/tooltip.tsx +70 -0
  168. package/src/config/component-registry.ts +190 -0
  169. package/src/config/index.ts +1099 -0
  170. package/src/hooks/README.md +269 -0
  171. package/src/hooks/admin-provider.tsx +110 -0
  172. package/src/hooks/index.ts +41 -0
  173. package/src/hooks/store.ts +248 -0
  174. package/src/hooks/use-auth.ts +168 -0
  175. package/src/hooks/use-collection-db.ts +209 -0
  176. package/src/hooks/use-collection.ts +156 -0
  177. package/src/hooks/use-global.ts +69 -0
  178. package/src/hooks/use-mobile.ts +21 -0
  179. package/src/lib/utils.ts +6 -0
  180. package/src/styles/index.css +340 -0
  181. package/src/utils/index.ts +6 -0
  182. package/src/views/auth/auth-layout.tsx +77 -0
  183. package/src/views/auth/forgot-password-form.tsx +192 -0
  184. package/src/views/auth/index.ts +21 -0
  185. package/src/views/auth/login-form.tsx +229 -0
  186. package/src/views/auth/reset-password-form.tsx +232 -0
  187. package/src/views/collection/auto-form-fields.tsx +982 -0
  188. package/src/views/collection/collection-form.tsx +186 -0
  189. package/src/views/collection/collection-list.tsx +223 -0
  190. package/src/views/collection/form-field.tsx +52 -0
  191. package/src/views/collection/index.ts +15 -0
  192. package/src/views/common/index.ts +8 -0
  193. package/src/views/common/locale-switcher.tsx +45 -0
  194. package/src/views/common/version-history.tsx +406 -0
  195. package/src/views/index.ts +25 -0
  196. package/src/views/layout/admin-layout.tsx +117 -0
  197. package/src/views/layout/admin-router.tsx +206 -0
  198. package/src/views/layout/admin-sidebar.tsx +185 -0
  199. package/src/views/layout/index.ts +12 -0
  200. package/tsconfig.json +13 -0
  201. package/tsconfig.tsbuildinfo +1 -0
  202. package/tsdown.config.ts +13 -0
  203. package/vitest.config.ts +29 -0
@@ -0,0 +1,296 @@
1
+ "use client";
2
+
3
+ import { useState, useCallback, useMemo, useEffect, useRef } from "react";
4
+ import { Check, CircleNotch } from "@phosphor-icons/react";
5
+ import {
6
+ Select,
7
+ SelectContent,
8
+ SelectItem,
9
+ SelectTrigger,
10
+ SelectValue,
11
+ } from "../ui/select";
12
+ import {
13
+ Combobox,
14
+ ComboboxInput,
15
+ ComboboxContent,
16
+ ComboboxList,
17
+ ComboboxItem,
18
+ ComboboxEmpty,
19
+ ComboboxChips,
20
+ ComboboxChip,
21
+ ComboboxChipsInput,
22
+ useComboboxAnchor,
23
+ } from "../ui/combobox";
24
+ import { cn } from "../../lib/utils";
25
+ import type { SelectInputProps, SelectOption } from "./types";
26
+ import { flattenOptions } from "./types";
27
+
28
+ /**
29
+ * Select Input Primitive
30
+ *
31
+ * A unified select component that supports:
32
+ * - Single select (dropdown)
33
+ * - Multi-select (chips)
34
+ * - Static options
35
+ * - Dynamic loading via loadOptions
36
+ * - Search/filtering
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * // Single select with static options
41
+ * <SelectInput
42
+ * value={status}
43
+ * onChange={setStatus}
44
+ * options={[
45
+ * { value: "active", label: "Active" },
46
+ * { value: "inactive", label: "Inactive" },
47
+ * ]}
48
+ * />
49
+ *
50
+ * // Multi-select with dynamic loading
51
+ * <SelectInput
52
+ * value={selectedTags}
53
+ * onChange={setSelectedTags}
54
+ * multiple
55
+ * loadOptions={async (search) => {
56
+ * const res = await fetch(`/api/tags?search=${search}`)
57
+ * return res.json()
58
+ * }}
59
+ * />
60
+ * ```
61
+ */
62
+ export function SelectInput<TValue extends string = string>({
63
+ value,
64
+ onChange,
65
+ options: staticOptions = [],
66
+ loadOptions,
67
+ multiple = false,
68
+ clearable = true,
69
+ maxSelections,
70
+ debounceMs = 300,
71
+ loading: externalLoading = false,
72
+ emptyMessage = "No options found",
73
+ placeholder = "Select...",
74
+ disabled,
75
+ className,
76
+ id,
77
+ "aria-invalid": ariaInvalid,
78
+ }: SelectInputProps<TValue>) {
79
+ const [search, setSearch] = useState("");
80
+ const [dynamicOptions, setDynamicOptions] = useState<SelectOption<TValue>[]>(
81
+ [],
82
+ );
83
+ const [isLoading, setIsLoading] = useState(false);
84
+ const debounceRef = useRef<ReturnType<typeof setTimeout>>(null);
85
+ const anchorRef = useComboboxAnchor();
86
+
87
+ // Flatten static options
88
+ const flatStaticOptions = useMemo(
89
+ () => flattenOptions(staticOptions),
90
+ [staticOptions],
91
+ );
92
+
93
+ // Merge static and dynamic options
94
+ const allOptions = useMemo(() => {
95
+ if (loadOptions) {
96
+ return dynamicOptions;
97
+ }
98
+ return flatStaticOptions;
99
+ }, [loadOptions, dynamicOptions, flatStaticOptions]);
100
+
101
+ // Filter options by search (for static options)
102
+ const filteredOptions = useMemo(() => {
103
+ if (loadOptions) {
104
+ return allOptions; // Dynamic options are already filtered by server
105
+ }
106
+ if (!search) {
107
+ return allOptions;
108
+ }
109
+ return allOptions.filter((opt) =>
110
+ opt.label.toLowerCase().includes(search.toLowerCase()),
111
+ );
112
+ }, [allOptions, search, loadOptions]);
113
+
114
+ // Load dynamic options
115
+ useEffect(() => {
116
+ if (!loadOptions) return;
117
+
118
+ if (debounceRef.current) {
119
+ clearTimeout(debounceRef.current);
120
+ }
121
+
122
+ debounceRef.current = setTimeout(async () => {
123
+ setIsLoading(true);
124
+ try {
125
+ const results = await loadOptions(search);
126
+ setDynamicOptions(results);
127
+ } catch (error) {
128
+ console.error("Failed to load options:", error);
129
+ setDynamicOptions([]);
130
+ } finally {
131
+ setIsLoading(false);
132
+ }
133
+ }, debounceMs);
134
+
135
+ return () => {
136
+ if (debounceRef.current) {
137
+ clearTimeout(debounceRef.current);
138
+ }
139
+ };
140
+ }, [search, loadOptions, debounceMs]);
141
+
142
+ // Get label for a value
143
+ const getLabel = useCallback(
144
+ (val: TValue): string => {
145
+ const option = allOptions.find((opt) => opt.value === val);
146
+ return option?.label ?? String(val);
147
+ },
148
+ [allOptions],
149
+ );
150
+
151
+ // Normalize value to array for internal handling
152
+ const selectedValues = useMemo((): TValue[] => {
153
+ if (value === null || value === undefined) return [];
154
+ return Array.isArray(value) ? value : [value];
155
+ }, [value]);
156
+
157
+ // Handle selection for multi-select
158
+ const handleMultiSelect = useCallback(
159
+ (selectedValue: TValue) => {
160
+ const currentValues = selectedValues;
161
+ const isSelected = currentValues.includes(selectedValue);
162
+
163
+ if (isSelected) {
164
+ // Remove
165
+ const newValues = currentValues.filter((v) => v !== selectedValue);
166
+ onChange(newValues as TValue & (TValue | TValue[] | null));
167
+ } else {
168
+ // Add (check max)
169
+ if (maxSelections && currentValues.length >= maxSelections) return;
170
+ const newValues = [...currentValues, selectedValue];
171
+ onChange(newValues as TValue & (TValue | TValue[] | null));
172
+ }
173
+ },
174
+ [selectedValues, onChange, maxSelections],
175
+ );
176
+
177
+ // Handle removal (for multi-select chips)
178
+ const handleRemove = useCallback(
179
+ (removedValue: TValue) => {
180
+ const newValues = selectedValues.filter((v) => v !== removedValue);
181
+ onChange(newValues as TValue & (TValue | TValue[] | null));
182
+ },
183
+ [selectedValues, onChange],
184
+ );
185
+
186
+ const showLoading = isLoading || externalLoading;
187
+
188
+ // ==========================================================================
189
+ // Single Select (using shadcn Select) - only for static options
190
+ // ==========================================================================
191
+ if (!multiple && !loadOptions) {
192
+ return (
193
+ <Select
194
+ value={selectedValues[0] ?? ""}
195
+ onValueChange={(val) =>
196
+ onChange(val as TValue & (TValue | TValue[] | null))
197
+ }
198
+ disabled={disabled}
199
+ >
200
+ <SelectTrigger
201
+ id={id}
202
+ className={cn("w-full", className)}
203
+ aria-invalid={ariaInvalid}
204
+ >
205
+ <SelectValue>
206
+ {selectedValues[0] ? getLabel(selectedValues[0]) : placeholder}
207
+ </SelectValue>
208
+ </SelectTrigger>
209
+ <SelectContent>
210
+ {filteredOptions.map((option) => (
211
+ <SelectItem
212
+ key={String(option.value)}
213
+ value={String(option.value)}
214
+ disabled={option.disabled}
215
+ >
216
+ {option.icon}
217
+ {option.label}
218
+ </SelectItem>
219
+ ))}
220
+ </SelectContent>
221
+ </Select>
222
+ );
223
+ }
224
+
225
+ // ==========================================================================
226
+ // Multi-Select or Dynamic Loading (using Combobox)
227
+ // ==========================================================================
228
+ return (
229
+ <Combobox
230
+ value={multiple ? undefined : (selectedValues[0] ?? null)}
231
+ onValueChange={(val) => {
232
+ if (val !== null && val !== undefined) {
233
+ if (multiple) {
234
+ handleMultiSelect(val as TValue);
235
+ } else {
236
+ onChange(val as TValue & (TValue | TValue[] | null));
237
+ }
238
+ }
239
+ }}
240
+ disabled={disabled}
241
+ >
242
+ {multiple ? (
243
+ // Multi-select with chips
244
+ <ComboboxChips
245
+ ref={anchorRef}
246
+ className={cn(className)}
247
+ aria-invalid={ariaInvalid}
248
+ >
249
+ {selectedValues.map((val) => (
250
+ <ComboboxChip key={String(val)}>{getLabel(val)}</ComboboxChip>
251
+ ))}
252
+ <ComboboxChipsInput
253
+ placeholder={selectedValues.length === 0 ? placeholder : undefined}
254
+ value={search}
255
+ onChange={(e) => setSearch(e.target.value)}
256
+ />
257
+ </ComboboxChips>
258
+ ) : (
259
+ // Single select with search
260
+ <ComboboxInput
261
+ id={id}
262
+ placeholder={placeholder}
263
+ value={search}
264
+ onChange={(e) => setSearch(e.target.value)}
265
+ className={cn(className)}
266
+ aria-invalid={ariaInvalid}
267
+ showClear={clearable && selectedValues.length > 0}
268
+ />
269
+ )}
270
+
271
+ <ComboboxContent anchor={multiple ? anchorRef : undefined}>
272
+ {showLoading && (
273
+ <div className="flex items-center justify-center py-4">
274
+ <CircleNotch className="size-4 animate-spin text-muted-foreground" />
275
+ </div>
276
+ )}
277
+ <ComboboxList>
278
+ {filteredOptions.map((option) => (
279
+ <ComboboxItem
280
+ key={String(option.value)}
281
+ value={option.value}
282
+ disabled={option.disabled}
283
+ >
284
+ {option.icon}
285
+ {option.label}
286
+ {multiple && selectedValues.includes(option.value) && (
287
+ <Check className="ml-auto size-3.5" />
288
+ )}
289
+ </ComboboxItem>
290
+ ))}
291
+ </ComboboxList>
292
+ <ComboboxEmpty>{emptyMessage}</ComboboxEmpty>
293
+ </ComboboxContent>
294
+ </Combobox>
295
+ );
296
+ }
@@ -0,0 +1,200 @@
1
+ "use client";
2
+
3
+ import { useState, useCallback, KeyboardEvent } from "react";
4
+ import { X } from "@phosphor-icons/react";
5
+ import { Badge } from "../ui/badge";
6
+ import { cn } from "../../lib/utils";
7
+ import type { TagInputProps } from "./types";
8
+
9
+ /**
10
+ * Tag Input Primitive
11
+ *
12
+ * An input for creating and managing tags/chips.
13
+ * Supports validation patterns, max tags, and autocomplete suggestions.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * // Basic usage
18
+ * <TagInput
19
+ * value={tags}
20
+ * onChange={setTags}
21
+ * placeholder="Add tags..."
22
+ * />
23
+ *
24
+ * // With suggestions and validation
25
+ * <TagInput
26
+ * value={emails}
27
+ * onChange={setEmails}
28
+ * suggestions={["user@example.com", "admin@example.com"]}
29
+ * pattern={/^[^\s@]+@[^\s@]+\.[^\s@]+$/}
30
+ * maxTags={5}
31
+ * />
32
+ * ```
33
+ */
34
+ export function TagInput({
35
+ value,
36
+ onChange,
37
+ suggestions = [],
38
+ maxTags,
39
+ allowDuplicates = false,
40
+ pattern,
41
+ placeholder = "Type and press Enter...",
42
+ disabled,
43
+ className,
44
+ id,
45
+ "aria-invalid": ariaInvalid,
46
+ }: TagInputProps) {
47
+ const [inputValue, setInputValue] = useState("");
48
+ const [showSuggestions, setShowSuggestions] = useState(false);
49
+
50
+ const addTag = useCallback(
51
+ (tag: string) => {
52
+ const trimmed = tag.trim();
53
+ if (!trimmed) return;
54
+
55
+ // Check max tags
56
+ if (maxTags && value.length >= maxTags) return;
57
+
58
+ // Check duplicates
59
+ if (!allowDuplicates && value.includes(trimmed)) return;
60
+
61
+ // Check pattern
62
+ if (pattern && !pattern.test(trimmed)) return;
63
+
64
+ onChange([...value, trimmed]);
65
+ setInputValue("");
66
+ setShowSuggestions(false);
67
+ },
68
+ [value, onChange, maxTags, allowDuplicates, pattern],
69
+ );
70
+
71
+ const removeTag = useCallback(
72
+ (index: number) => {
73
+ if (disabled) return;
74
+ const newTags = value.filter((_, i) => i !== index);
75
+ onChange(newTags);
76
+ },
77
+ [value, onChange, disabled],
78
+ );
79
+
80
+ const handleKeyDown = useCallback(
81
+ (e: KeyboardEvent<HTMLInputElement>) => {
82
+ if (e.key === "Enter") {
83
+ e.preventDefault();
84
+ addTag(inputValue);
85
+ } else if (e.key === "Backspace" && !inputValue && value.length > 0) {
86
+ removeTag(value.length - 1);
87
+ } else if (e.key === "Escape") {
88
+ setShowSuggestions(false);
89
+ }
90
+ },
91
+ [inputValue, value, addTag, removeTag],
92
+ );
93
+
94
+ const handleInputChange = useCallback(
95
+ (e: React.ChangeEvent<HTMLInputElement>) => {
96
+ const newValue = e.target.value;
97
+ setInputValue(newValue);
98
+ setShowSuggestions(newValue.length > 0 && suggestions.length > 0);
99
+ },
100
+ [suggestions],
101
+ );
102
+
103
+ const filteredSuggestions = suggestions.filter(
104
+ (suggestion) =>
105
+ suggestion.toLowerCase().includes(inputValue.toLowerCase()) &&
106
+ (allowDuplicates || !value.includes(suggestion)),
107
+ );
108
+
109
+ const canAddMore = !maxTags || value.length < maxTags;
110
+
111
+ return (
112
+ <div className={cn("relative", className)}>
113
+ <div
114
+ className={cn(
115
+ "flex flex-wrap gap-1.5 min-h-9 w-full border border-input bg-background px-3 py-2",
116
+ "focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
117
+ ariaInvalid && "border-destructive ring-destructive/20",
118
+ disabled && "cursor-not-allowed opacity-50",
119
+ )}
120
+ >
121
+ {value.map((tag, index) => (
122
+ <Badge
123
+ key={`${tag}-${index}`}
124
+ variant="secondary"
125
+ className="gap-1 pr-1"
126
+ >
127
+ {tag}
128
+ {!disabled && (
129
+ <button
130
+ type="button"
131
+ onClick={() => removeTag(index)}
132
+ className="ml-1 rounded-full p-0.5 hover:bg-muted-foreground/20"
133
+ aria-label={`Remove ${tag}`}
134
+ >
135
+ <X className="size-3" />
136
+ </button>
137
+ )}
138
+ </Badge>
139
+ ))}
140
+ {canAddMore && (
141
+ <input
142
+ id={id}
143
+ type="text"
144
+ value={inputValue}
145
+ onChange={handleInputChange}
146
+ onKeyDown={handleKeyDown}
147
+ onFocus={() =>
148
+ setShowSuggestions(
149
+ inputValue.length > 0 && suggestions.length > 0,
150
+ )
151
+ }
152
+ onBlur={() => {
153
+ // Delay to allow click on suggestion
154
+ setTimeout(() => setShowSuggestions(false), 150);
155
+ }}
156
+ placeholder={value.length === 0 ? placeholder : undefined}
157
+ disabled={disabled}
158
+ aria-invalid={ariaInvalid}
159
+ className={cn(
160
+ "flex-1 min-w-[120px] bg-transparent text-sm outline-none placeholder:text-muted-foreground",
161
+ "disabled:cursor-not-allowed",
162
+ )}
163
+ />
164
+ )}
165
+ </div>
166
+
167
+ {/* Suggestions dropdown */}
168
+ {showSuggestions && filteredSuggestions.length > 0 && (
169
+ <div
170
+ className={cn(
171
+ "absolute z-50 mt-1 w-full border border-input bg-popover shadow-md",
172
+ "max-h-[200px] overflow-auto",
173
+ )}
174
+ >
175
+ {filteredSuggestions.map((suggestion, index) => (
176
+ <button
177
+ key={suggestion}
178
+ type="button"
179
+ onClick={() => addTag(suggestion)}
180
+ className={cn(
181
+ "w-full px-3 py-2 text-left text-sm",
182
+ "hover:bg-accent hover:text-accent-foreground",
183
+ "focus:bg-accent focus:text-accent-foreground focus:outline-none",
184
+ )}
185
+ >
186
+ {suggestion}
187
+ </button>
188
+ ))}
189
+ </div>
190
+ )}
191
+
192
+ {/* Helper text for max tags */}
193
+ {maxTags && (
194
+ <p className="mt-1 text-xs text-muted-foreground">
195
+ {value.length} / {maxTags} tags
196
+ </p>
197
+ )}
198
+ </div>
199
+ );
200
+ }
@@ -0,0 +1,49 @@
1
+ import { Input } from "../ui/input";
2
+ import { cn } from "../../lib/utils";
3
+ import type { TextInputProps } from "./types";
4
+
5
+ /**
6
+ * Text Input Primitive
7
+ *
8
+ * A basic text input with value/onChange pattern.
9
+ * Supports different input types: text, email, password, url, tel, search.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * <TextInput
14
+ * value={email}
15
+ * onChange={setEmail}
16
+ * type="email"
17
+ * placeholder="Enter email"
18
+ * />
19
+ * ```
20
+ */
21
+ export function TextInput({
22
+ value,
23
+ onChange,
24
+ type = "text",
25
+ placeholder,
26
+ disabled,
27
+ readOnly,
28
+ maxLength,
29
+ autoComplete,
30
+ className,
31
+ id,
32
+ "aria-invalid": ariaInvalid,
33
+ }: TextInputProps) {
34
+ return (
35
+ <Input
36
+ id={id}
37
+ type={type}
38
+ value={value}
39
+ onChange={(e) => onChange(e.target.value)}
40
+ placeholder={placeholder}
41
+ disabled={disabled}
42
+ readOnly={readOnly}
43
+ maxLength={maxLength}
44
+ autoComplete={autoComplete}
45
+ aria-invalid={ariaInvalid}
46
+ className={cn(className)}
47
+ />
48
+ );
49
+ }
@@ -0,0 +1,46 @@
1
+ import { Textarea } from "../ui/textarea";
2
+ import { cn } from "../../lib/utils";
3
+ import type { TextareaInputProps } from "./types";
4
+
5
+ /**
6
+ * Textarea Input Primitive
7
+ *
8
+ * A multi-line text input.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <TextareaInput
13
+ * value={description}
14
+ * onChange={setDescription}
15
+ * rows={4}
16
+ * placeholder="Enter description..."
17
+ * />
18
+ * ```
19
+ */
20
+ export function TextareaInput({
21
+ value,
22
+ onChange,
23
+ rows = 3,
24
+ maxLength,
25
+ placeholder,
26
+ disabled,
27
+ readOnly,
28
+ className,
29
+ id,
30
+ "aria-invalid": ariaInvalid,
31
+ }: TextareaInputProps) {
32
+ return (
33
+ <Textarea
34
+ id={id}
35
+ value={value}
36
+ onChange={(e) => onChange(e.target.value)}
37
+ rows={rows}
38
+ maxLength={maxLength}
39
+ placeholder={placeholder}
40
+ disabled={disabled}
41
+ readOnly={readOnly}
42
+ aria-invalid={ariaInvalid}
43
+ className={cn(className)}
44
+ />
45
+ );
46
+ }
@@ -0,0 +1,36 @@
1
+ import { Switch } from "../ui/switch";
2
+ import { cn } from "../../lib/utils";
3
+ import type { ToggleInputProps } from "./types";
4
+
5
+ /**
6
+ * Toggle Input Primitive
7
+ *
8
+ * A switch/toggle for boolean values.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <ToggleInput
13
+ * value={isActive}
14
+ * onChange={setIsActive}
15
+ * />
16
+ * ```
17
+ */
18
+ export function ToggleInput({
19
+ value,
20
+ onChange,
21
+ disabled,
22
+ className,
23
+ id,
24
+ "aria-invalid": ariaInvalid,
25
+ }: ToggleInputProps) {
26
+ return (
27
+ <Switch
28
+ id={id}
29
+ checked={value}
30
+ onCheckedChange={onChange}
31
+ disabled={disabled}
32
+ aria-invalid={ariaInvalid}
33
+ className={cn(className)}
34
+ />
35
+ );
36
+ }