@codefast/ui 0.3.16-canary.2 → 0.3.16-canary.3

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 (223) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +1 -1
  3. package/dist/components/accordion.mjs +2 -2
  4. package/dist/components/alert-dialog.d.mts +1 -1
  5. package/dist/components/alert-dialog.mjs +4 -4
  6. package/dist/components/alert.d.mts +3 -13
  7. package/dist/components/alert.mjs +3 -23
  8. package/dist/components/badge.d.mts +3 -15
  9. package/dist/components/badge.mjs +2 -44
  10. package/dist/components/breadcrumb.mjs +1 -1
  11. package/dist/components/button-group.d.mts +3 -13
  12. package/dist/components/button-group.mjs +3 -24
  13. package/dist/components/button.d.mts +3 -25
  14. package/dist/components/button.mjs +2 -72
  15. package/dist/components/calendar.mjs +2 -1
  16. package/dist/components/carousel.d.mts +1 -2
  17. package/dist/components/chart.d.mts +2 -4
  18. package/dist/components/checkbox.mjs +2 -2
  19. package/dist/components/context-menu.mjs +2 -2
  20. package/dist/components/dialog.d.mts +1 -1
  21. package/dist/components/dialog.mjs +4 -4
  22. package/dist/components/drawer.d.mts +1 -1
  23. package/dist/components/drawer.mjs +2 -2
  24. package/dist/components/dropdown-menu.mjs +2 -2
  25. package/dist/components/empty.d.mts +3 -13
  26. package/dist/components/empty.mjs +3 -18
  27. package/dist/components/field.d.mts +3 -14
  28. package/dist/components/field.mjs +3 -32
  29. package/dist/components/form.d.mts +2 -4
  30. package/dist/components/hover-card.mjs +1 -1
  31. package/dist/components/input-group.d.mts +4 -31
  32. package/dist/components/input-group.mjs +3 -90
  33. package/dist/components/input-number.mjs +4 -4
  34. package/dist/components/input-otp.mjs +2 -2
  35. package/dist/components/input.mjs +1 -1
  36. package/dist/components/item.d.mts +4 -29
  37. package/dist/components/item.mjs +3 -56
  38. package/dist/components/menubar.mjs +2 -2
  39. package/dist/components/native-select.mjs +1 -1
  40. package/dist/components/navigation-menu.d.mts +1 -6
  41. package/dist/components/navigation-menu.mjs +8 -15
  42. package/dist/components/pagination.d.mts +1 -1
  43. package/dist/components/pagination.mjs +1 -1
  44. package/dist/components/popover.mjs +1 -1
  45. package/dist/components/progress-circle.d.mts +3 -47
  46. package/dist/components/progress-circle.mjs +2 -47
  47. package/dist/components/progress.mjs +1 -1
  48. package/dist/components/radio-group.mjs +1 -1
  49. package/dist/components/radio.mjs +1 -1
  50. package/dist/components/scroll-area.d.mts +3 -19
  51. package/dist/components/scroll-area.mjs +4 -61
  52. package/dist/components/select.d.mts +1 -1
  53. package/dist/components/select.mjs +3 -3
  54. package/dist/components/separator.d.mts +3 -18
  55. package/dist/components/separator.mjs +3 -23
  56. package/dist/components/sheet.d.mts +6 -18
  57. package/dist/components/sheet.mjs +6 -49
  58. package/dist/components/sidebar.d.mts +4 -19
  59. package/dist/components/sidebar.mjs +10 -46
  60. package/dist/components/skeleton.mjs +1 -1
  61. package/dist/components/slider.mjs +1 -1
  62. package/dist/components/spinner.mjs +1 -1
  63. package/dist/components/switch.mjs +2 -2
  64. package/dist/components/table.mjs +1 -1
  65. package/dist/components/tabs.mjs +1 -1
  66. package/dist/components/textarea.mjs +1 -1
  67. package/dist/components/toggle-group.d.mts +3 -2
  68. package/dist/components/toggle-group.mjs +1 -1
  69. package/dist/components/toggle.d.mts +2 -21
  70. package/dist/components/toggle.mjs +2 -39
  71. package/dist/components/tooltip.mjs +1 -1
  72. package/dist/index.d.mts +31 -16
  73. package/dist/index.mjs +30 -15
  74. package/dist/lib/utils.d.mts +1 -12
  75. package/dist/lib/utils.mjs +1 -9
  76. package/dist/primitives/checkbox-group.d.mts +1 -2
  77. package/dist/primitives/input-number.d.mts +1 -2
  78. package/dist/primitives/input.d.mts +1 -2
  79. package/dist/primitives/progress-circle.d.mts +1 -2
  80. package/dist/variants/alert.d.mts +18 -0
  81. package/dist/variants/alert.mjs +25 -0
  82. package/dist/variants/badge.d.mts +20 -0
  83. package/dist/variants/badge.mjs +46 -0
  84. package/dist/variants/button-group.d.mts +18 -0
  85. package/dist/variants/button-group.mjs +26 -0
  86. package/dist/variants/button.d.mts +30 -0
  87. package/dist/variants/button.mjs +76 -0
  88. package/dist/variants/empty.d.mts +18 -0
  89. package/dist/variants/empty.mjs +20 -0
  90. package/dist/variants/field.d.mts +19 -0
  91. package/dist/variants/field.mjs +34 -0
  92. package/dist/variants/input-group.d.mts +43 -0
  93. package/dist/variants/input-group.mjs +93 -0
  94. package/dist/variants/item.d.mts +37 -0
  95. package/dist/variants/item.mjs +60 -0
  96. package/dist/variants/navigation-menu.d.mts +13 -0
  97. package/dist/variants/navigation-menu.mjs +12 -0
  98. package/dist/variants/progress-circle.d.mts +52 -0
  99. package/dist/variants/progress-circle.mjs +49 -0
  100. package/dist/variants/scroll-area.d.mts +24 -0
  101. package/dist/variants/scroll-area.mjs +63 -0
  102. package/dist/variants/separator.d.mts +23 -0
  103. package/dist/variants/separator.mjs +25 -0
  104. package/dist/variants/sheet.d.mts +20 -0
  105. package/dist/variants/sheet.mjs +50 -0
  106. package/dist/variants/sidebar.d.mts +23 -0
  107. package/dist/variants/sidebar.mjs +42 -0
  108. package/dist/variants/toggle.d.mts +23 -0
  109. package/dist/variants/toggle.mjs +43 -0
  110. package/package.json +168 -20
  111. package/src/components/accordion.tsx +156 -0
  112. package/src/components/alert-dialog.tsx +314 -0
  113. package/src/components/alert.tsx +86 -0
  114. package/src/components/aspect-ratio.tsx +28 -0
  115. package/src/components/avatar.tsx +84 -0
  116. package/src/components/badge.tsx +38 -0
  117. package/src/components/breadcrumb.tsx +197 -0
  118. package/src/components/button-group.tsx +107 -0
  119. package/src/components/button.tsx +66 -0
  120. package/src/components/calendar.tsx +277 -0
  121. package/src/components/card.tsx +175 -0
  122. package/src/components/carousel.tsx +367 -0
  123. package/src/components/chart.tsx +587 -0
  124. package/src/components/checkbox-cards.tsx +92 -0
  125. package/src/components/checkbox-group.tsx +83 -0
  126. package/src/components/checkbox.tsx +65 -0
  127. package/src/components/collapsible.tsx +60 -0
  128. package/src/components/command.tsx +311 -0
  129. package/src/components/context-menu.tsx +489 -0
  130. package/src/components/dialog.tsx +295 -0
  131. package/src/components/drawer.tsx +271 -0
  132. package/src/components/dropdown-menu.tsx +498 -0
  133. package/src/components/empty.tsx +169 -0
  134. package/src/components/field.tsx +362 -0
  135. package/src/components/form.tsx +300 -0
  136. package/src/components/hover-card.tsx +116 -0
  137. package/src/components/input-group.tsx +224 -0
  138. package/src/components/input-number.tsx +161 -0
  139. package/src/components/input-otp.tsx +151 -0
  140. package/src/components/input-password.tsx +74 -0
  141. package/src/components/input-search.tsx +98 -0
  142. package/src/components/input.tsx +52 -0
  143. package/src/components/item.tsx +280 -0
  144. package/src/components/kbd.tsx +59 -0
  145. package/src/components/label.tsx +44 -0
  146. package/src/components/menubar.tsx +531 -0
  147. package/src/components/native-select.tsx +96 -0
  148. package/src/components/navigation-menu.tsx +295 -0
  149. package/src/components/pagination.tsx +204 -0
  150. package/src/components/popover.tsx +139 -0
  151. package/src/components/progress-circle.tsx +203 -0
  152. package/src/components/progress.tsx +54 -0
  153. package/src/components/radio-cards.tsx +85 -0
  154. package/src/components/radio-group.tsx +79 -0
  155. package/src/components/radio.tsx +61 -0
  156. package/src/components/resizable.tsx +99 -0
  157. package/src/components/scroll-area.tsx +115 -0
  158. package/src/components/select.tsx +319 -0
  159. package/src/components/separator.tsx +74 -0
  160. package/src/components/sheet.tsx +278 -0
  161. package/src/components/sidebar.tsx +1056 -0
  162. package/src/components/skeleton.tsx +37 -0
  163. package/src/components/slider.tsx +95 -0
  164. package/src/components/sonner.tsx +47 -0
  165. package/src/components/spinner.tsx +75 -0
  166. package/src/components/switch.tsx +66 -0
  167. package/src/components/table.tsx +200 -0
  168. package/src/components/tabs.tsx +128 -0
  169. package/src/components/textarea.tsx +49 -0
  170. package/src/components/toggle-group.tsx +141 -0
  171. package/src/components/toggle.tsx +39 -0
  172. package/src/components/tooltip.tsx +141 -0
  173. package/src/css/amber.css +59 -22
  174. package/src/css/blue.css +59 -22
  175. package/src/css/cyan.css +59 -22
  176. package/src/css/emerald.css +59 -22
  177. package/src/css/fuchsia.css +59 -22
  178. package/src/css/gray.css +59 -22
  179. package/src/css/green.css +59 -22
  180. package/src/css/indigo.css +59 -22
  181. package/src/css/lime.css +59 -22
  182. package/src/css/neutral.css +59 -22
  183. package/src/css/orange.css +59 -22
  184. package/src/css/pink.css +59 -22
  185. package/src/css/preset.css +32 -13
  186. package/src/css/purple.css +59 -22
  187. package/src/css/red.css +59 -22
  188. package/src/css/rose.css +59 -22
  189. package/src/css/sky.css +59 -22
  190. package/src/css/slate.css +59 -22
  191. package/src/css/stone.css +59 -22
  192. package/src/css/teal.css +59 -22
  193. package/src/css/violet.css +59 -22
  194. package/src/css/yellow.css +59 -22
  195. package/src/css/zinc.css +59 -22
  196. package/src/hooks/use-animated-value.ts +97 -0
  197. package/src/hooks/use-copy-to-clipboard.ts +63 -0
  198. package/src/hooks/use-is-mobile.ts +27 -0
  199. package/src/hooks/use-media-query.ts +71 -0
  200. package/src/hooks/use-mutation-observer.ts +54 -0
  201. package/src/hooks/use-pagination.ts +166 -0
  202. package/src/index.ts +720 -0
  203. package/src/lib/utils.ts +5 -0
  204. package/src/primitives/checkbox-group.tsx +360 -0
  205. package/src/primitives/input-number.tsx +1013 -0
  206. package/src/primitives/input.tsx +243 -0
  207. package/src/primitives/progress-circle.tsx +537 -0
  208. package/src/variants/alert.ts +45 -0
  209. package/src/variants/badge.ts +66 -0
  210. package/src/variants/button-group.ts +49 -0
  211. package/src/variants/button.ts +93 -0
  212. package/src/variants/empty.ts +43 -0
  213. package/src/variants/field.ts +50 -0
  214. package/src/variants/input-group.ts +132 -0
  215. package/src/variants/item.ts +90 -0
  216. package/src/variants/navigation-menu.ts +32 -0
  217. package/src/variants/progress-circle.ts +47 -0
  218. package/src/variants/scroll-area.ts +79 -0
  219. package/src/variants/separator.ts +41 -0
  220. package/src/variants/sheet.ts +70 -0
  221. package/src/variants/sidebar.ts +61 -0
  222. package/src/variants/toggle.ts +59 -0
  223. package/dist/node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/clsx.d.mts +0 -6
@@ -0,0 +1,243 @@
1
+ import type { Scope } from "@radix-ui/react-context";
2
+ import type {
3
+ ComponentProps,
4
+ JSX,
5
+ PointerEventHandler,
6
+ PropsWithChildren,
7
+ ReactNode,
8
+ RefObject,
9
+ } from "react";
10
+
11
+ import { useComposedRefs } from "@radix-ui/react-compose-refs";
12
+ import { createContextScope } from "@radix-ui/react-context";
13
+ import { useRef } from "react";
14
+
15
+ /* -----------------------------------------------------------------------------
16
+ * Component: Input
17
+ * -------------------------------------------------------------------------- */
18
+
19
+ const INPUT_NAME = "Input";
20
+
21
+ /**
22
+ * Type for adding scope to component props
23
+ */
24
+ type ScopedProps<P> = P & {
25
+ /**
26
+ * Scope for the Input component context
27
+ */
28
+ __scopeInput?: Scope;
29
+ };
30
+
31
+ const [createInputContext, createInputScope] = createContextScope(INPUT_NAME);
32
+
33
+ /**
34
+ * Context value for the Input component
35
+ */
36
+ interface InputContextValue {
37
+ /**
38
+ * Reference to the input element
39
+ */
40
+ inputRef: RefObject<HTMLInputElement | null>;
41
+
42
+ /**
43
+ * Whether the input is disabled
44
+ */
45
+ disabled?: boolean;
46
+
47
+ /**
48
+ * Whether the input is in read-only mode
49
+ */
50
+ readOnly?: boolean;
51
+ }
52
+
53
+ const [InputContextProvider, useInputContext] = createInputContext<InputContextValue>(INPUT_NAME);
54
+
55
+ /**
56
+ * Props for styling and appearance of the Input component
57
+ */
58
+ interface InputVisualProps {
59
+ /**
60
+ * CSS class name for the input container
61
+ */
62
+ className?: string;
63
+
64
+ /**
65
+ * Element to display before the input
66
+ */
67
+ prefix?: ReactNode;
68
+
69
+ /**
70
+ * Custom spinner element for loading state
71
+ */
72
+ spinner?: ReactNode;
73
+
74
+ /**
75
+ * Element to display after the input
76
+ */
77
+ suffix?: ReactNode;
78
+ }
79
+
80
+ /**
81
+ * Props for the behavior and state of the Input component
82
+ */
83
+ interface InputBehaviorProps {
84
+ /**
85
+ * Whether the input is disabled
86
+ */
87
+ disabled?: boolean;
88
+
89
+ /**
90
+ * Position of the loading spinner - either before or after the input
91
+ */
92
+ loaderPosition?: "prefix" | "suffix";
93
+
94
+ /**
95
+ * Whether the input is in the loading state
96
+ */
97
+ loading?: boolean;
98
+
99
+ /**
100
+ * Whether the input is in read-only mode
101
+ */
102
+ readOnly?: boolean;
103
+ }
104
+
105
+ /**
106
+ * Combined props for the Input component
107
+ *
108
+ * @since 0.3.16-canary.0
109
+ */
110
+ type InputProps = PropsWithChildren<InputBehaviorProps & InputVisualProps>;
111
+
112
+ /**
113
+ * @since 0.3.16-canary.0
114
+ */
115
+ function Input(inputProps: ScopedProps<InputProps>): JSX.Element {
116
+ const {
117
+ __scopeInput,
118
+ children,
119
+ disabled,
120
+ loaderPosition = "prefix",
121
+ loading,
122
+ prefix,
123
+ readOnly,
124
+ spinner,
125
+ suffix,
126
+ ...props
127
+ } = inputProps;
128
+
129
+ /**
130
+ * Reference to the input element
131
+ */
132
+ const inputRef = useRef<HTMLInputElement>(null);
133
+
134
+ /**
135
+ * Handles pointer down events on the input container
136
+ * Focuses the input element when clicking on the container
137
+ *
138
+ * @param event - The pointer event object
139
+ */
140
+ const handlePointerDown: PointerEventHandler<HTMLDivElement> = (event) => {
141
+ const target = event.target as HTMLElement;
142
+
143
+ // Skip handling when clicking directly on input, links, buttons, or other interactive elements
144
+ // This prevents interference with native input/link/button behavior
145
+ if (target.tagName.toLowerCase() === "input" || target.closest("input, a, button")) {
146
+ event.stopPropagation();
147
+
148
+ return;
149
+ }
150
+
151
+ const inputElement = inputRef.current;
152
+
153
+ if (!inputElement) {
154
+ return;
155
+ }
156
+
157
+ // Key solution: If input already has focus, only prevent default behavior
158
+ // This prevents the focus from being lost when clicking on the container padding
159
+ // and eliminates the flickering effect
160
+ if (document.activeElement === inputElement) {
161
+ event.preventDefault();
162
+
163
+ return;
164
+ }
165
+
166
+ // Only attempt to focus the input if it's not already focused
167
+ requestAnimationFrame(() => {
168
+ // Special handling for file inputs - trigger the file selection dialog
169
+ if (inputElement.type === "file") {
170
+ inputElement.click();
171
+
172
+ return;
173
+ }
174
+
175
+ // Only focus the input if it doesn't already have focus
176
+ // This avoids unnecessary re-focusing which can cause UI flickers
177
+ if (document.activeElement !== inputElement) {
178
+ inputElement.focus();
179
+ }
180
+ });
181
+ };
182
+
183
+ return (
184
+ <InputContextProvider
185
+ disabled={disabled}
186
+ inputRef={inputRef}
187
+ readOnly={readOnly}
188
+ scope={__scopeInput}
189
+ >
190
+ <div
191
+ data-disabled={disabled}
192
+ data-readonly={readOnly}
193
+ role="presentation"
194
+ onPointerDown={handlePointerDown}
195
+ {...props}
196
+ >
197
+ {loading && loaderPosition === "prefix" ? spinner : prefix}
198
+ {children}
199
+ {loading && loaderPosition === "suffix" ? spinner : suffix}
200
+ </div>
201
+ </InputContextProvider>
202
+ );
203
+ }
204
+
205
+ /* -----------------------------------------------------------------------------
206
+ * Component: InputField
207
+ * -------------------------------------------------------------------------- */
208
+
209
+ const INPUT_FIELD_NAME = "InputField";
210
+
211
+ /**
212
+ * Props for the InputField component
213
+ *
214
+ * @since 0.3.16-canary.0
215
+ */
216
+ type InputFieldProps = ComponentProps<"input">;
217
+
218
+ /**
219
+ * @since 0.3.16-canary.0
220
+ */
221
+ function InputField({ __scopeInput, ...props }: ScopedProps<InputFieldProps>): JSX.Element {
222
+ /**
223
+ * Context values from parent Input component
224
+ */
225
+ const { disabled, inputRef, readOnly } = useInputContext(INPUT_FIELD_NAME, __scopeInput);
226
+
227
+ /**
228
+ * Combined ref that syncs with the parent's inputRef
229
+ */
230
+ const composedInputRef = useComposedRefs(inputRef);
231
+
232
+ return (
233
+ <input ref={composedInputRef} disabled={disabled} readOnly={readOnly} type="text" {...props} />
234
+ );
235
+ }
236
+
237
+ /* -----------------------------------------------------------------------------
238
+ * Exports
239
+ * -------------------------------------------------------------------------- */
240
+
241
+ export { createInputScope, InputField as Field, Input, InputField, Input as Root };
242
+
243
+ export type { InputFieldProps, InputProps };