@codefast/ui 0.3.16-canary.1 → 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 +30 -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 +169 -21
  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,116 @@
1
+ "use client";
2
+
3
+ import type { ComponentProps, JSX } from "react";
4
+
5
+ import { cn } from "#/lib/utils";
6
+ import * as HoverCardPrimitive from "@radix-ui/react-hover-card";
7
+
8
+ /* -----------------------------------------------------------------------------
9
+ * Component: HoverCard
10
+ * -------------------------------------------------------------------------- */
11
+
12
+ /**
13
+ * @since 0.3.16-canary.0
14
+ */
15
+ type HoverCardProps = ComponentProps<typeof HoverCardPrimitive.Root>;
16
+
17
+ /**
18
+ * @since 0.3.16-canary.0
19
+ */
20
+ function HoverCard({ ...props }: HoverCardProps): JSX.Element {
21
+ return <HoverCardPrimitive.Root data-slot="hover-card" {...props} />;
22
+ }
23
+
24
+ /* -----------------------------------------------------------------------------
25
+ * Component: HoverCardTrigger
26
+ * -------------------------------------------------------------------------- */
27
+
28
+ /**
29
+ * @since 0.3.16-canary.0
30
+ */
31
+ type HoverCardTriggerProps = ComponentProps<typeof HoverCardPrimitive.Trigger>;
32
+
33
+ /**
34
+ * @since 0.3.16-canary.0
35
+ */
36
+ function HoverCardTrigger({ ...props }: HoverCardTriggerProps): JSX.Element {
37
+ return <HoverCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />;
38
+ }
39
+
40
+ /* -----------------------------------------------------------------------------
41
+ * Component: HoverCardContent
42
+ * -------------------------------------------------------------------------- */
43
+
44
+ /**
45
+ * @since 0.3.16-canary.0
46
+ */
47
+ type HoverCardContentProps = ComponentProps<typeof HoverCardPrimitive.Content>;
48
+
49
+ /**
50
+ * @since 0.3.16-canary.0
51
+ */
52
+ function HoverCardContent({
53
+ align = "center",
54
+ className,
55
+ sideOffset = 4,
56
+ ...props
57
+ }: HoverCardContentProps): JSX.Element {
58
+ return (
59
+ <HoverCardPrimitive.Portal>
60
+ <HoverCardPrimitive.Content
61
+ align={align}
62
+ className={cn(
63
+ "z-50",
64
+ "min-w-32 p-4",
65
+ "rounded-lg border",
66
+ "bg-popover text-popover-foreground shadow-lg",
67
+ "ease-snappy data-open:animate-in data-open:duration-200 data-open:fade-in-0 data-open:zoom-in-95",
68
+ "data-open:data-side-top:slide-in-from-bottom-2",
69
+ "data-open:data-side-right:slide-in-from-left-2",
70
+ "data-open:data-side-bottom:slide-in-from-top-2",
71
+ "data-open:data-side-left:slide-in-from-right-2",
72
+ "data-closed:animate-out data-closed:duration-150 data-closed:fade-out-0 data-closed:zoom-out-95",
73
+ "data-closed:data-side-top:slide-out-to-bottom-2",
74
+ "data-closed:data-side-right:slide-out-to-left-2",
75
+ "data-closed:data-side-bottom:slide-out-to-top-2",
76
+ "data-closed:data-side-left:slide-out-to-right-2",
77
+ "motion-reduce:animate-none motion-reduce:transition-none motion-reduce:duration-0",
78
+ "origin-(--radix-hover-card-content-transform-origin)",
79
+ className,
80
+ )}
81
+ data-slot="hover-card-content"
82
+ sideOffset={sideOffset}
83
+ {...props}
84
+ />
85
+ </HoverCardPrimitive.Portal>
86
+ );
87
+ }
88
+
89
+ /* -----------------------------------------------------------------------------
90
+ * Component: HoverCardArrow
91
+ * -------------------------------------------------------------------------- */
92
+
93
+ /**
94
+ * @since 0.3.16-canary.0
95
+ */
96
+ type HoverCardArrowProps = ComponentProps<typeof HoverCardPrimitive.Arrow>;
97
+
98
+ /**
99
+ * @since 0.3.16-canary.0
100
+ */
101
+ function HoverCardArrow({ className, ...props }: HoverCardArrowProps): JSX.Element {
102
+ return (
103
+ <HoverCardPrimitive.Arrow
104
+ className={cn("fill-popover", className)}
105
+ data-slot="hover-card-arrow"
106
+ {...props}
107
+ />
108
+ );
109
+ }
110
+
111
+ /* -----------------------------------------------------------------------------
112
+ * Exports
113
+ * -------------------------------------------------------------------------- */
114
+
115
+ export { HoverCard, HoverCardArrow, HoverCardContent, HoverCardTrigger };
116
+ export type { HoverCardArrowProps, HoverCardContentProps, HoverCardProps, HoverCardTriggerProps };
@@ -0,0 +1,224 @@
1
+ "use client";
2
+
3
+ import type { InputGroupAddonVariants, InputGroupButtonVariants } from "#/variants/input-group";
4
+ import type { ComponentProps, JSX } from "react";
5
+
6
+ import { cn } from "#/lib/utils";
7
+
8
+ import {
9
+ inputGroupAddonVariants,
10
+ inputGroupButtonVariants,
11
+ inputGroupVariants,
12
+ } from "#/variants/input-group";
13
+
14
+ import type { ButtonProps } from "#/components/button";
15
+ import type { InputProps } from "#/components/input";
16
+ import type { TextareaProps } from "#/components/textarea";
17
+
18
+ import { Button } from "#/components/button";
19
+ import { Input } from "#/components/input";
20
+ import { Textarea } from "#/components/textarea";
21
+
22
+ /* -----------------------------------------------------------------------------
23
+ * Component: InputGroup
24
+ * -------------------------------------------------------------------------- */
25
+
26
+ /**
27
+ * @since 0.3.16-canary.0
28
+ */
29
+ type InputGroupProps = ComponentProps<"div">;
30
+
31
+ /**
32
+ * @since 0.3.16-canary.0
33
+ */
34
+ function InputGroup({ className, ...props }: InputGroupProps): JSX.Element {
35
+ return (
36
+ <div
37
+ className={inputGroupVariants({ className })}
38
+ data-slot="input-group"
39
+ role="group"
40
+ {...props}
41
+ />
42
+ );
43
+ }
44
+
45
+ /* -----------------------------------------------------------------------------
46
+ * Component: InputGroupAddon
47
+ * -------------------------------------------------------------------------- */
48
+
49
+ /**
50
+ * @since 0.3.16-canary.0
51
+ */
52
+ type InputGroupAddonProps = ComponentProps<"div"> & InputGroupAddonVariants;
53
+
54
+ /**
55
+ * @since 0.3.16-canary.0
56
+ */
57
+ function InputGroupAddon({
58
+ align = "inline-start",
59
+ className,
60
+ ...props
61
+ }: InputGroupAddonProps): JSX.Element {
62
+ return (
63
+ <div
64
+ className={cn(inputGroupAddonVariants({ align }), className)}
65
+ data-align={align}
66
+ data-slot="input-group-addon"
67
+ role="group"
68
+ onPointerDown={(event) => {
69
+ if ((event.target as HTMLElement).closest("button")) {
70
+ return;
71
+ }
72
+
73
+ event.preventDefault();
74
+
75
+ const control = event.currentTarget.parentElement?.querySelector("input, textarea");
76
+
77
+ if (control instanceof HTMLElement) {
78
+ control.focus();
79
+ }
80
+ }}
81
+ {...props}
82
+ />
83
+ );
84
+ }
85
+
86
+ /* -----------------------------------------------------------------------------
87
+ * Component: InputGroupButton
88
+ * -------------------------------------------------------------------------- */
89
+
90
+ /**
91
+ * @since 0.3.16-canary.0
92
+ */
93
+ type InputGroupButtonProps = Omit<ButtonProps, "size"> & InputGroupButtonVariants;
94
+
95
+ /**
96
+ * @since 0.3.16-canary.0
97
+ */
98
+ function InputGroupButton({
99
+ className,
100
+ size = "xs",
101
+ type = "button",
102
+ variant = "ghost",
103
+ ...props
104
+ }: InputGroupButtonProps): JSX.Element {
105
+ return (
106
+ <Button
107
+ className={cn(inputGroupButtonVariants({ size }), className)}
108
+ data-size={size}
109
+ data-slot="input-group-button"
110
+ type={type}
111
+ variant={variant}
112
+ {...props}
113
+ />
114
+ );
115
+ }
116
+
117
+ /* -----------------------------------------------------------------------------
118
+ * Component: InputGroupText
119
+ * -------------------------------------------------------------------------- */
120
+
121
+ /**
122
+ * @since 0.3.16-canary.0
123
+ */
124
+ type InputGroupTextProps = ComponentProps<"span">;
125
+
126
+ /**
127
+ * @since 0.3.16-canary.0
128
+ */
129
+ function InputGroupText({ className, ...props }: InputGroupTextProps): JSX.Element {
130
+ return (
131
+ <span
132
+ className={cn(
133
+ "flex items-center gap-2 text-sm text-muted-foreground",
134
+ "[&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
135
+ className,
136
+ )}
137
+ data-slot="input-group-text"
138
+ {...props}
139
+ />
140
+ );
141
+ }
142
+
143
+ /* -----------------------------------------------------------------------------
144
+ * Component: InputGroupInput
145
+ * -------------------------------------------------------------------------- */
146
+
147
+ /**
148
+ * @since 0.3.16-canary.0
149
+ */
150
+ type InputGroupInputProps = InputProps;
151
+
152
+ /**
153
+ * @since 0.3.16-canary.0
154
+ */
155
+ function InputGroupInput({ className, ...props }: InputGroupInputProps): JSX.Element {
156
+ return (
157
+ <Input
158
+ className={cn(
159
+ "flex-1",
160
+ "px-3 py-1",
161
+ "rounded-none border-0",
162
+ "bg-transparent shadow-none",
163
+ "focus-visible:ring-0",
164
+ "dark:bg-transparent",
165
+ className,
166
+ )}
167
+ data-slot="input-group-control"
168
+ {...props}
169
+ />
170
+ );
171
+ }
172
+
173
+ /* -----------------------------------------------------------------------------
174
+ * Component: InputGroupTextarea
175
+ * -------------------------------------------------------------------------- */
176
+
177
+ /**
178
+ * @since 0.3.16-canary.0
179
+ */
180
+ type InputGroupTextareaProps = TextareaProps;
181
+
182
+ /**
183
+ * @since 0.3.16-canary.0
184
+ */
185
+ function InputGroupTextarea({ className, ...props }: InputGroupTextareaProps): JSX.Element {
186
+ return (
187
+ <Textarea
188
+ className={cn(
189
+ "flex-1",
190
+ "py-3",
191
+ "rounded-none border-0",
192
+ "bg-transparent shadow-none",
193
+ "resize-none",
194
+ "focus-visible:ring-0",
195
+ "dark:bg-transparent",
196
+ className,
197
+ )}
198
+ data-slot="input-group-control"
199
+ {...props}
200
+ />
201
+ );
202
+ }
203
+
204
+ /* -----------------------------------------------------------------------------
205
+ * Exports
206
+ * -------------------------------------------------------------------------- */
207
+
208
+ export {
209
+ InputGroup,
210
+ InputGroupAddon,
211
+ InputGroupButton,
212
+ InputGroupInput,
213
+ InputGroupText,
214
+ InputGroupTextarea,
215
+ };
216
+
217
+ export type {
218
+ InputGroupAddonProps,
219
+ InputGroupButtonProps,
220
+ InputGroupInputProps,
221
+ InputGroupProps,
222
+ InputGroupTextareaProps,
223
+ InputGroupTextProps,
224
+ };
@@ -0,0 +1,161 @@
1
+ "use client";
2
+
3
+ import type { ComponentProps, JSX } from "react";
4
+
5
+ import { cn } from "#/lib/utils";
6
+ import { ChevronDownIcon, ChevronUpIcon } from "lucide-react";
7
+
8
+ import { buttonVariants } from "#/variants/button";
9
+ import { Spinner } from "#/components/spinner";
10
+ import * as InputNumberPrimitive from "#/primitives/input-number";
11
+
12
+ /* -----------------------------------------------------------------------------
13
+ * Component: InputNumber
14
+ * -------------------------------------------------------------------------- */
15
+
16
+ /**
17
+ * @since 0.3.16-canary.0
18
+ */
19
+ interface InputNumberProps
20
+ extends
21
+ ComponentProps<typeof InputNumberPrimitive.Field>,
22
+ ComponentProps<typeof InputNumberPrimitive.Root> {}
23
+
24
+ /**
25
+ * @since 0.3.16-canary.0
26
+ */
27
+ function InputNumber({
28
+ ariaDecrementLabel,
29
+ ariaIncrementLabel,
30
+ className,
31
+ defaultValue,
32
+ disabled,
33
+ formatOptions,
34
+ id,
35
+ loaderPosition,
36
+ loading,
37
+ max,
38
+ min,
39
+ onChange,
40
+ prefix,
41
+ readOnly,
42
+ spinner,
43
+ step,
44
+ suffix,
45
+ value,
46
+ ...props
47
+ }: InputNumberProps): JSX.Element {
48
+ return (
49
+ <InputNumberPrimitive.Root
50
+ ariaDecrementLabel={ariaDecrementLabel}
51
+ ariaIncrementLabel={ariaIncrementLabel}
52
+ className={cn(
53
+ "group peer flex h-9 w-full grow items-center gap-3 px-3 pr-0",
54
+ "rounded-lg border border-input",
55
+ "text-base",
56
+ "transition",
57
+ "motion-reduce:transition-none",
58
+ "not-has-disabled:shadow-xs",
59
+ "focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50",
60
+ "hover:not-has-disabled:not-focus-within:border-ring/60",
61
+ "focus-within:has-aria-invalid:ring-destructive/20",
62
+ "hover:not-has-disabled:not-focus-within:has-aria-invalid:border-destructive/60",
63
+ "md:text-sm",
64
+ "dark:bg-input/30",
65
+ "dark:focus-within:has-aria-invalid:ring-destructive/40",
66
+ "has-disabled:opacity-50",
67
+ "has-aria-invalid:border-destructive",
68
+ "[&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
69
+ "[&>svg]:text-muted-foreground",
70
+ className,
71
+ )}
72
+ data-slot="input-number"
73
+ defaultValue={defaultValue}
74
+ disabled={disabled}
75
+ formatOptions={formatOptions}
76
+ id={id}
77
+ loaderPosition={loaderPosition}
78
+ loading={loading}
79
+ max={max}
80
+ min={min}
81
+ prefix={prefix}
82
+ readOnly={readOnly}
83
+ spinner={spinner ?? <Spinner key="spinner" />}
84
+ step={step}
85
+ suffix={suffix}
86
+ value={value}
87
+ onChange={onChange}
88
+ >
89
+ <InputNumberPrimitive.Field
90
+ autoCapitalize="none"
91
+ autoComplete="off"
92
+ autoCorrect="off"
93
+ className={cn(
94
+ "h-9 w-full min-w-0 px-3 py-1",
95
+ "rounded-md border border-input",
96
+ "bg-transparent shadow-xs outline-none",
97
+ "text-base",
98
+ "transition-[color,box-shadow]",
99
+ "motion-reduce:transition-none",
100
+ "selection:bg-primary selection:text-primary-foreground",
101
+ "file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground",
102
+ "placeholder:text-muted-foreground",
103
+ "focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50",
104
+ "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
105
+ "aria-invalid:border-destructive aria-invalid:ring-destructive/20",
106
+ "md:text-sm",
107
+ "dark:bg-input/30",
108
+ "dark:aria-invalid:ring-destructive/40",
109
+ )}
110
+ spellCheck="false"
111
+ {...props}
112
+ />
113
+ <div
114
+ className={cn(
115
+ "order-last ml-auto grid h-full shrink-0",
116
+ "divide-y divide-input border-l border-l-input",
117
+ "transition",
118
+ "motion-reduce:transition-none",
119
+ "group-hover:not-group-focus-within:not-has-disabled:border-l-border-ring/60 group-hover:not-group-focus-within:not-has-disabled:divide-border-ring/60",
120
+ "group-focus-within:divide-ring group-focus-within:border-l-ring",
121
+ "group-has-aria-invalid:divide-destructive group-has-aria-invalid:border-l-destructive",
122
+ "group-hover:group-has-aria-invalid:not-group-focus-within:not-has-disabled:divide-destructive/60 group-hover:group-has-aria-invalid:not-group-focus-within:not-has-disabled:border-l-destructive/60",
123
+ "*:[button]:focus-visible:bg-ring/50 *:[button]:focus-visible:ring-0",
124
+ "group-has-aria-invalid:*:[button]:focus-visible:bg-destructive/20",
125
+ "dark:group-has-aria-invalid:*:[button]:focus-visible:bg-destructive/40",
126
+ )}
127
+ data-slot="input-number-buttons"
128
+ >
129
+ <InputNumberPrimitive.IncrementButton
130
+ aria-label="Increment"
131
+ className={buttonVariants({
132
+ className:
133
+ "text-muted-foreground h-auto rounded-none rounded-tr-[calc(var(--radius-lg)-1px)]",
134
+ variant: "ghost",
135
+ })}
136
+ data-slot="input-number-increment-button"
137
+ >
138
+ <ChevronUpIcon />
139
+ </InputNumberPrimitive.IncrementButton>
140
+ <InputNumberPrimitive.DecrementButton
141
+ aria-label="Decrement"
142
+ className={buttonVariants({
143
+ className:
144
+ "text-muted-foreground h-auto rounded-none rounded-br-[calc(var(--radius-lg)-1px)]",
145
+ variant: "ghost",
146
+ })}
147
+ data-slot="input-number-decrement-button"
148
+ >
149
+ <ChevronDownIcon />
150
+ </InputNumberPrimitive.DecrementButton>
151
+ </div>
152
+ </InputNumberPrimitive.Root>
153
+ );
154
+ }
155
+
156
+ /* -----------------------------------------------------------------------------
157
+ * Exports
158
+ * -------------------------------------------------------------------------- */
159
+
160
+ export { InputNumber };
161
+ export type { InputNumberProps };
@@ -0,0 +1,151 @@
1
+ "use client";
2
+
3
+ import type { ComponentProps, JSX } from "react";
4
+
5
+ import { cn } from "#/lib/utils";
6
+ import { OTPInput, OTPInputContext } from "input-otp";
7
+ import { MinusIcon } from "lucide-react";
8
+ import { use } from "react";
9
+
10
+ /* -----------------------------------------------------------------------------
11
+ * Component: InputOtp
12
+ * -------------------------------------------------------------------------- */
13
+
14
+ /**
15
+ * @since 0.3.16-canary.0
16
+ */
17
+ type InputOTPProps = ComponentProps<typeof OTPInput>;
18
+
19
+ /**
20
+ * @since 0.3.16-canary.0
21
+ */
22
+ function InputOTP({ className, containerClassName, ...props }: InputOTPProps): JSX.Element {
23
+ return (
24
+ <OTPInput
25
+ aria-label="One-time password"
26
+ className={cn(className)}
27
+ containerClassName={cn(
28
+ "flex items-center gap-2",
29
+ "has-disabled:opacity-50",
30
+ containerClassName,
31
+ )}
32
+ data-slot="input-otp"
33
+ {...props}
34
+ />
35
+ );
36
+ }
37
+
38
+ /* -----------------------------------------------------------------------------
39
+ * Component: InputOTPGroup
40
+ * -------------------------------------------------------------------------- */
41
+
42
+ /**
43
+ * @since 0.3.16-canary.0
44
+ */
45
+ type InputOTPGroupProps = ComponentProps<"div">;
46
+
47
+ /**
48
+ * @since 0.3.16-canary.0
49
+ */
50
+ function InputOTPGroup({ className, ...props }: InputOTPGroupProps): JSX.Element {
51
+ return (
52
+ <div
53
+ className={cn("flex items-center -space-x-px", className)}
54
+ data-slot="input-otp-group"
55
+ role="group"
56
+ {...props}
57
+ />
58
+ );
59
+ }
60
+
61
+ /* -----------------------------------------------------------------------------
62
+ * Component: InputOTPSlot
63
+ * -------------------------------------------------------------------------- */
64
+
65
+ /**
66
+ * @since 0.3.16-canary.0
67
+ */
68
+ interface InputOTPSlotProps extends ComponentProps<"div"> {
69
+ index: number;
70
+ }
71
+
72
+ /**
73
+ * @since 0.3.16-canary.0
74
+ */
75
+ function InputOTPSlot({ className, index, ...props }: InputOTPSlotProps): JSX.Element {
76
+ const inputOTPContext = use(OTPInputContext);
77
+ const slot = inputOTPContext.slots[index];
78
+ if (slot === undefined) {
79
+ throw new Error(`InputOTPSlot: no slot at index ${index}`);
80
+ }
81
+ const { char, hasFakeCaret, isActive } = slot;
82
+
83
+ return (
84
+ <div
85
+ className={cn(
86
+ "relative flex size-9 items-center justify-center",
87
+ "border border-input outline-hidden",
88
+ "text-sm",
89
+ "transition-all",
90
+ "motion-reduce:transition-none",
91
+ "not-has-disabled:shadow-xs",
92
+ "first:rounded-l-lg",
93
+ "last:rounded-r-lg",
94
+ "aria-invalid:border-destructive",
95
+ "dark:bg-input/30",
96
+ "data-active:z-10 data-active:border-ring data-active:ring-3 data-active:ring-ring/50",
97
+ "data-active:aria-invalid:border-destructive data-active:aria-invalid:ring-destructive/20",
98
+ "dark:data-active:aria-invalid:ring-destructive/40",
99
+ className,
100
+ )}
101
+ data-active={isActive}
102
+ data-slot="input-otp-slot"
103
+ {...props}
104
+ >
105
+ {char}
106
+ {hasFakeCaret ? (
107
+ <div
108
+ className={cn("absolute inset-0 flex items-center justify-center", "pointer-events-none")}
109
+ >
110
+ <div
111
+ className={cn(
112
+ "h-4 w-px",
113
+ "bg-foreground",
114
+ "animate-caret-blink",
115
+ "animation-duration-1000",
116
+ "motion-reduce:animate-none motion-reduce:duration-0",
117
+ )}
118
+ />
119
+ </div>
120
+ ) : null}
121
+ </div>
122
+ );
123
+ }
124
+
125
+ /* -----------------------------------------------------------------------------
126
+ * Component: InputOTPSeparator
127
+ * -------------------------------------------------------------------------- */
128
+
129
+ /**
130
+ * @since 0.3.16-canary.0
131
+ */
132
+ type InputOTPSeparatorProps = ComponentProps<"div">;
133
+
134
+ /**
135
+ * @since 0.3.16-canary.0
136
+ */
137
+ function InputOTPSeparator({ ...props }: InputOTPSeparatorProps): JSX.Element {
138
+ return (
139
+ <div data-slot="input-otp-separator" {...props}>
140
+ <MinusIcon />
141
+ </div>
142
+ );
143
+ }
144
+
145
+ /* -----------------------------------------------------------------------------
146
+ * Exports
147
+ * -------------------------------------------------------------------------- */
148
+
149
+ export { REGEXP_ONLY_CHARS, REGEXP_ONLY_DIGITS, REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp";
150
+ export { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot };
151
+ export type { InputOTPGroupProps, InputOTPProps, InputOTPSeparatorProps, InputOTPSlotProps };