@luxfi/ui 6.1.2 → 7.0.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 (240) hide show
  1. package/dist/accordion.cjs +213 -0
  2. package/dist/accordion.d.cts +74 -0
  3. package/dist/accordion.d.ts +74 -0
  4. package/dist/accordion.js +186 -0
  5. package/dist/alert.cjs +553 -0
  6. package/dist/alert.d.cts +30 -0
  7. package/dist/alert.d.ts +30 -0
  8. package/dist/alert.js +531 -0
  9. package/dist/avatar.cjs +149 -0
  10. package/dist/avatar.d.cts +25 -0
  11. package/dist/avatar.d.ts +25 -0
  12. package/dist/avatar.js +125 -0
  13. package/dist/badge.cjs +611 -0
  14. package/dist/badge.d.cts +23 -0
  15. package/dist/badge.d.ts +23 -0
  16. package/dist/badge.js +589 -0
  17. package/dist/bank.cjs +272 -0
  18. package/dist/bank.d.cts +76 -0
  19. package/dist/bank.d.ts +76 -0
  20. package/dist/bank.js +258 -0
  21. package/dist/button.cjs +689 -0
  22. package/dist/button.d.cts +52 -0
  23. package/dist/button.d.ts +52 -0
  24. package/dist/button.js +664 -0
  25. package/dist/checkbox.cjs +265 -0
  26. package/dist/checkbox.d.cts +31 -0
  27. package/dist/checkbox.d.ts +31 -0
  28. package/dist/checkbox.js +241 -0
  29. package/dist/close-button.cjs +73 -0
  30. package/dist/close-button.d.cts +9 -0
  31. package/dist/close-button.d.ts +9 -0
  32. package/dist/close-button.js +51 -0
  33. package/dist/collapsible.cjs +702 -0
  34. package/dist/collapsible.d.cts +23 -0
  35. package/dist/collapsible.d.ts +23 -0
  36. package/dist/collapsible.js +679 -0
  37. package/dist/color-mode.cjs +96 -0
  38. package/dist/color-mode.d.cts +25 -0
  39. package/dist/color-mode.d.ts +25 -0
  40. package/dist/color-mode.js +72 -0
  41. package/dist/dialog.cjs +279 -0
  42. package/dist/dialog.d.cts +66 -0
  43. package/dist/dialog.d.ts +66 -0
  44. package/dist/dialog.js +246 -0
  45. package/dist/drawer.cjs +207 -0
  46. package/dist/drawer.d.cts +36 -0
  47. package/dist/drawer.d.ts +36 -0
  48. package/dist/drawer.js +175 -0
  49. package/dist/empty-state.cjs +93 -0
  50. package/dist/empty-state.d.cts +13 -0
  51. package/dist/empty-state.d.ts +13 -0
  52. package/dist/empty-state.js +71 -0
  53. package/dist/expiration-selector.cjs +138 -0
  54. package/dist/expiration-selector.d.cts +16 -0
  55. package/dist/expiration-selector.d.ts +16 -0
  56. package/dist/expiration-selector.js +116 -0
  57. package/dist/field.cjs +183 -0
  58. package/dist/field.d.cts +24 -0
  59. package/dist/field.d.ts +24 -0
  60. package/dist/field.js +160 -0
  61. package/dist/greeks-display.cjs +114 -0
  62. package/dist/greeks-display.d.cts +14 -0
  63. package/dist/greeks-display.d.ts +14 -0
  64. package/dist/greeks-display.js +92 -0
  65. package/dist/heading.cjs +46 -0
  66. package/dist/heading.d.cts +10 -0
  67. package/dist/heading.d.ts +10 -0
  68. package/dist/heading.js +40 -0
  69. package/dist/icon-button.cjs +491 -0
  70. package/dist/icon-button.d.cts +33 -0
  71. package/dist/icon-button.d.ts +33 -0
  72. package/dist/icon-button.js +470 -0
  73. package/dist/image.cjs +572 -0
  74. package/dist/image.d.cts +57 -0
  75. package/dist/image.d.ts +57 -0
  76. package/dist/image.js +551 -0
  77. package/dist/index.cjs +7316 -0
  78. package/dist/index.d.cts +58 -0
  79. package/dist/index.d.ts +58 -0
  80. package/dist/index.js +7137 -0
  81. package/dist/input-group.cjs +155 -0
  82. package/dist/input-group.d.cts +17 -0
  83. package/dist/input-group.d.ts +17 -0
  84. package/dist/input-group.js +133 -0
  85. package/dist/input.cjs +65 -0
  86. package/dist/input.d.cts +11 -0
  87. package/dist/input.d.ts +11 -0
  88. package/dist/input.js +59 -0
  89. package/dist/link.cjs +630 -0
  90. package/dist/link.d.cts +37 -0
  91. package/dist/link.d.ts +37 -0
  92. package/dist/link.js +606 -0
  93. package/dist/menu.cjs +305 -0
  94. package/dist/menu.d.cts +84 -0
  95. package/dist/menu.d.ts +84 -0
  96. package/dist/menu.js +269 -0
  97. package/dist/option-chain.cjs +221 -0
  98. package/dist/option-chain.d.cts +37 -0
  99. package/dist/option-chain.d.ts +37 -0
  100. package/dist/option-chain.js +199 -0
  101. package/dist/option-position.cjs +164 -0
  102. package/dist/option-position.d.cts +29 -0
  103. package/dist/option-position.d.ts +29 -0
  104. package/dist/option-position.js +142 -0
  105. package/dist/pin-input.cjs +182 -0
  106. package/dist/pin-input.d.cts +25 -0
  107. package/dist/pin-input.d.ts +25 -0
  108. package/dist/pin-input.js +160 -0
  109. package/dist/pnl-diagram.cjs +453 -0
  110. package/dist/pnl-diagram.d.cts +11 -0
  111. package/dist/pnl-diagram.d.ts +11 -0
  112. package/dist/pnl-diagram.js +431 -0
  113. package/dist/popover.cjs +327 -0
  114. package/dist/popover.d.cts +73 -0
  115. package/dist/popover.d.ts +73 -0
  116. package/dist/popover.js +294 -0
  117. package/dist/progress-circle.cjs +152 -0
  118. package/dist/progress-circle.d.cts +47 -0
  119. package/dist/progress-circle.d.ts +47 -0
  120. package/dist/progress-circle.js +128 -0
  121. package/dist/progress.cjs +117 -0
  122. package/dist/progress.d.cts +28 -0
  123. package/dist/progress.d.ts +28 -0
  124. package/dist/progress.js +94 -0
  125. package/dist/provider.cjs +62 -0
  126. package/dist/provider.d.cts +7 -0
  127. package/dist/provider.d.ts +7 -0
  128. package/dist/provider.js +40 -0
  129. package/dist/radio.cjs +177 -0
  130. package/dist/radio.d.cts +53 -0
  131. package/dist/radio.d.ts +53 -0
  132. package/dist/radio.js +153 -0
  133. package/dist/rating.cjs +80 -0
  134. package/dist/rating.d.cts +14 -0
  135. package/dist/rating.d.ts +14 -0
  136. package/dist/rating.js +58 -0
  137. package/dist/select.cjs +791 -0
  138. package/dist/select.d.cts +130 -0
  139. package/dist/select.d.ts +130 -0
  140. package/dist/select.js +757 -0
  141. package/dist/separator.cjs +57 -0
  142. package/dist/separator.d.cts +13 -0
  143. package/dist/separator.d.ts +13 -0
  144. package/dist/separator.js +51 -0
  145. package/dist/skeleton.cjs +370 -0
  146. package/dist/skeleton.d.cts +60 -0
  147. package/dist/skeleton.d.ts +60 -0
  148. package/dist/skeleton.js +346 -0
  149. package/dist/slider.cjs +138 -0
  150. package/dist/slider.d.cts +24 -0
  151. package/dist/slider.d.ts +24 -0
  152. package/dist/slider.js +115 -0
  153. package/dist/strategy-builder.cjs +373 -0
  154. package/dist/strategy-builder.d.cts +26 -0
  155. package/dist/strategy-builder.d.ts +26 -0
  156. package/dist/strategy-builder.js +351 -0
  157. package/dist/switch.cjs +163 -0
  158. package/dist/switch.d.cts +27 -0
  159. package/dist/switch.d.ts +27 -0
  160. package/dist/switch.js +140 -0
  161. package/dist/table.cjs +1044 -0
  162. package/dist/table.d.cts +107 -0
  163. package/dist/table.d.ts +107 -0
  164. package/dist/table.js +1013 -0
  165. package/dist/tabs.cjs +240 -0
  166. package/dist/tabs.d.cts +78 -0
  167. package/dist/tabs.d.ts +78 -0
  168. package/dist/tabs.js +213 -0
  169. package/dist/tag.cjs +651 -0
  170. package/dist/tag.d.cts +21 -0
  171. package/dist/tag.d.ts +21 -0
  172. package/dist/tag.js +628 -0
  173. package/dist/textarea.cjs +65 -0
  174. package/dist/textarea.d.cts +11 -0
  175. package/dist/textarea.d.ts +11 -0
  176. package/dist/textarea.js +59 -0
  177. package/dist/toaster.cjs +99 -0
  178. package/dist/toaster.d.cts +29 -0
  179. package/dist/toaster.d.ts +29 -0
  180. package/dist/toaster.js +96 -0
  181. package/dist/tooltip.cjs +171 -0
  182. package/dist/tooltip.d.cts +39 -0
  183. package/dist/tooltip.d.ts +39 -0
  184. package/dist/tooltip.js +148 -0
  185. package/dist/utils.cjs +11 -0
  186. package/dist/utils.d.cts +5 -0
  187. package/dist/utils.d.ts +5 -0
  188. package/dist/utils.js +9 -0
  189. package/package.json +284 -85
  190. package/src/accordion.tsx +285 -0
  191. package/src/alert.tsx +221 -0
  192. package/src/avatar.tsx +174 -0
  193. package/src/badge.tsx +158 -0
  194. package/src/bank.tsx +325 -0
  195. package/src/button.tsx +411 -0
  196. package/src/checkbox.tsx +307 -0
  197. package/src/close-button.tsx +51 -0
  198. package/src/collapsible.tsx +126 -0
  199. package/src/color-mode.tsx +125 -0
  200. package/src/dialog.tsx +356 -0
  201. package/src/drawer.tsx +186 -0
  202. package/src/empty-state.tsx +97 -0
  203. package/src/expiration-selector.tsx +163 -0
  204. package/src/field.tsx +202 -0
  205. package/src/greeks-display.tsx +138 -0
  206. package/src/heading.tsx +55 -0
  207. package/src/icon-button.tsx +192 -0
  208. package/src/image.tsx +280 -0
  209. package/src/index.ts +268 -0
  210. package/src/input-group.tsx +159 -0
  211. package/src/input.tsx +60 -0
  212. package/src/link.tsx +326 -0
  213. package/src/menu.tsx +471 -0
  214. package/src/option-chain.tsx +261 -0
  215. package/src/option-position.tsx +200 -0
  216. package/src/pin-input.tsx +187 -0
  217. package/src/pnl-diagram.tsx +458 -0
  218. package/src/popover.tsx +400 -0
  219. package/src/progress-circle.tsx +180 -0
  220. package/src/progress.tsx +109 -0
  221. package/src/provider.tsx +12 -0
  222. package/src/radio.tsx +175 -0
  223. package/src/rating.tsx +79 -0
  224. package/src/select.tsx +696 -0
  225. package/src/separator.tsx +59 -0
  226. package/src/skeleton.tsx +302 -0
  227. package/src/slider.tsx +152 -0
  228. package/src/strategy-builder.tsx +466 -0
  229. package/src/switch.tsx +158 -0
  230. package/src/table.tsx +621 -0
  231. package/src/tabs.tsx +354 -0
  232. package/src/tag.tsx +159 -0
  233. package/src/textarea.tsx +60 -0
  234. package/src/toaster.tsx +117 -0
  235. package/src/tokens.css +438 -0
  236. package/src/tooltip.tsx +184 -0
  237. package/src/utils/cn.ts +7 -0
  238. package/src/utils.ts +6 -0
  239. package/tokens.css +438 -0
  240. package/README.md +0 -109
package/src/index.ts ADDED
@@ -0,0 +1,268 @@
1
+ export { cn } from './utils';
2
+
3
+ export {
4
+ AccordionRoot,
5
+ AccordionItem,
6
+ AccordionItemTrigger,
7
+ AccordionItemContent,
8
+ useAccordion,
9
+ } from './accordion';
10
+
11
+ export { Alert } from './alert';
12
+ export type { AlertProps } from './alert';
13
+
14
+ export { Avatar, AvatarGroup } from './avatar';
15
+ export type { AvatarProps } from './avatar';
16
+
17
+ export { Badge } from './badge';
18
+ export type { BadgeProps } from './badge';
19
+
20
+ export {
21
+ Button,
22
+ ButtonGroup,
23
+ ButtonGroupRadio,
24
+ buttonVariants,
25
+ } from './button';
26
+ export type { ButtonProps, ButtonGroupProps, ButtonGroupRadioProps } from './button';
27
+
28
+ export { Checkbox, CheckboxGroup } from './checkbox';
29
+ export type { CheckboxProps, CheckboxGroupProps } from './checkbox';
30
+
31
+ export { CloseButton } from './close-button';
32
+ export type { CloseButtonProps } from './close-button';
33
+
34
+ export { CollapsibleDetails, CollapsibleList } from './collapsible';
35
+
36
+ export { ColorModeProvider, useColorMode, useColorModeValue } from './color-mode';
37
+ export type { ColorMode } from './color-mode';
38
+
39
+ export {
40
+ DialogRoot,
41
+ DialogContent,
42
+ DialogCloseTrigger,
43
+ DialogHeader,
44
+ DialogBody,
45
+ DialogFooter,
46
+ DialogBackdrop,
47
+ DialogTitle,
48
+ DialogDescription,
49
+ DialogTrigger,
50
+ DialogActionTrigger,
51
+ } from './dialog';
52
+
53
+ export {
54
+ DrawerRoot,
55
+ DrawerContent,
56
+ DrawerCloseTrigger,
57
+ DrawerTrigger,
58
+ DrawerHeader,
59
+ DrawerBody,
60
+ DrawerFooter,
61
+ DrawerTitle,
62
+ DrawerDescription,
63
+ DrawerActionTrigger,
64
+ } from './drawer';
65
+
66
+ export { EmptyState } from './empty-state';
67
+ export type { EmptyStateProps } from './empty-state';
68
+
69
+ export { Field } from './field';
70
+ export type { FieldProps } from './field';
71
+
72
+ export { Heading } from './heading';
73
+ export type { HeadingProps } from './heading';
74
+
75
+ export { IconButton } from './icon-button';
76
+ export type { IconButtonProps } from './icon-button';
77
+
78
+ export { Image } from './image';
79
+ export type { ImageProps } from './image';
80
+
81
+ export { Input } from './input';
82
+ export type { InputProps } from './input';
83
+
84
+ export { InputGroup } from './input-group';
85
+ export type { InputGroupProps } from './input-group';
86
+
87
+ export { Link, LinkBox, LinkOverlay, LinkExternalIcon } from './link';
88
+ export type { LinkProps } from './link';
89
+
90
+ export {
91
+ MenuRoot,
92
+ MenuTrigger,
93
+ MenuContent,
94
+ MenuItem,
95
+ MenuItemText,
96
+ MenuSeparator,
97
+ MenuItemGroup,
98
+ MenuCheckboxItem,
99
+ MenuRadioItemGroup,
100
+ MenuRadioItem,
101
+ MenuTriggerItem,
102
+ MenuArrow,
103
+ } from './menu';
104
+
105
+ export { PinInput } from './pin-input';
106
+
107
+ export {
108
+ PopoverRoot,
109
+ PopoverTrigger,
110
+ PopoverContent,
111
+ PopoverArrow,
112
+ PopoverCloseTrigger,
113
+ PopoverCloseTriggerWrapper,
114
+ PopoverBody,
115
+ PopoverHeader,
116
+ PopoverFooter,
117
+ PopoverTitle,
118
+ PopoverDescription,
119
+ } from './popover';
120
+
121
+ export { Progress } from './progress';
122
+
123
+ export {
124
+ ProgressCircleRoot,
125
+ ProgressCircleRing,
126
+ ProgressCircleValueText,
127
+ } from './progress-circle';
128
+
129
+ export { Radio, RadioGroup } from './radio';
130
+
131
+ export { Rating } from './rating';
132
+
133
+ export {
134
+ SelectRoot,
135
+ SelectControl,
136
+ SelectContent,
137
+ SelectItem,
138
+ SelectValueText,
139
+ SelectItemGroup,
140
+ SelectLabel,
141
+ SelectItemText,
142
+ Select,
143
+ SelectAsync,
144
+ SelectClearTrigger,
145
+ createListCollection,
146
+ } from './select';
147
+ export type { SelectOption, ListCollection, SelectRootProps, SelectProps, SelectAsyncProps } from './select';
148
+
149
+ export { Separator } from './separator';
150
+ export type { SeparatorProps } from './separator';
151
+
152
+ export { Skeleton, SkeletonCircle, SkeletonText } from './skeleton';
153
+ export type { SkeletonProps, SkeletonCircleProps, SkeletonTextProps } from './skeleton';
154
+
155
+ export { Slider } from './slider';
156
+
157
+ export { Switch } from './switch';
158
+
159
+ export {
160
+ TableRoot,
161
+ TableHeader,
162
+ TableBody,
163
+ TableRow,
164
+ TableCell,
165
+ TableColumnHeader,
166
+ TableColumnHeaderSortable,
167
+ TableCaption,
168
+ TableFooter,
169
+ TableScrollWrapper,
170
+ TableHeaderSticky,
171
+ } from './table';
172
+
173
+ export {
174
+ TabsRoot,
175
+ TabsList,
176
+ TabsTrigger,
177
+ TabsContent,
178
+ TabsCounter,
179
+ } from './tabs';
180
+
181
+ export { Tag } from './tag';
182
+ export type { TagProps } from './tag';
183
+
184
+ export { Textarea } from './textarea';
185
+ export type { TextareaProps } from './textarea';
186
+
187
+ export { Toaster, toaster } from './toaster';
188
+
189
+ export { Tooltip } from './tooltip';
190
+ export type { TooltipProps } from './tooltip';
191
+
192
+ export { Provider } from './provider';
193
+
194
+ export {
195
+ OptionChain,
196
+ } from './option-chain';
197
+ export type {
198
+ OptionChainProps,
199
+ OptionQuote,
200
+ OptionContract,
201
+ Strike,
202
+ } from './option-chain';
203
+
204
+ export {
205
+ GreeksDisplay,
206
+ } from './greeks-display';
207
+ export type {
208
+ GreeksDisplayProps,
209
+ } from './greeks-display';
210
+
211
+ export {
212
+ StrategyBuilder,
213
+ } from './strategy-builder';
214
+ export type {
215
+ StrategyBuilderProps,
216
+ StrategyLeg,
217
+ StrategyType,
218
+ StrategySubmission,
219
+ } from './strategy-builder';
220
+
221
+ export {
222
+ PnlDiagram,
223
+ } from './pnl-diagram';
224
+ export type {
225
+ PnlDiagramProps,
226
+ } from './pnl-diagram';
227
+
228
+ export {
229
+ OptionPositionCard,
230
+ } from './option-position';
231
+ export type {
232
+ OptionPositionCardProps,
233
+ OptionPosition,
234
+ } from './option-position';
235
+
236
+ export {
237
+ ExpirationSelector,
238
+ } from './expiration-selector';
239
+ export type {
240
+ ExpirationSelectorProps,
241
+ ExpirationOption,
242
+ } from './expiration-selector';
243
+
244
+ export {
245
+ bankColors,
246
+ BankCard,
247
+ BankInput,
248
+ BankButton,
249
+ BankButtonText,
250
+ BankHeading,
251
+ BankText,
252
+ BankField,
253
+ BankAlert,
254
+ BankAlertText,
255
+ BankPinBox,
256
+ BankDivider,
257
+ BankPage,
258
+ } from './bank';
259
+ export type {
260
+ BankCardProps,
261
+ BankInputProps,
262
+ BankButtonProps,
263
+ BankHeadingProps,
264
+ BankTextProps,
265
+ BankAlertProps,
266
+ BankPinBoxProps,
267
+ BankPageProps,
268
+ } from './bank';
@@ -0,0 +1,159 @@
1
+ import { debounce } from 'es-toolkit';
2
+ import * as React from 'react';
3
+
4
+ import { cn } from './utils';
5
+
6
+ import type { InputProps } from './input';
7
+
8
+ function getComponentDisplayName(type: string | React.JSXElementConstructor<unknown>): string | undefined {
9
+ if (typeof type === 'string') return undefined;
10
+ if ('displayName' in type) return type.displayName as string;
11
+ return undefined;
12
+ }
13
+
14
+ export interface InputElementProps extends React.HTMLAttributes<HTMLDivElement> {
15
+ readonly placement?: 'start' | 'end';
16
+ }
17
+
18
+ export interface InputGroupProps extends React.HTMLAttributes<HTMLDivElement> {
19
+ readonly startElementProps?: InputElementProps;
20
+ readonly endElementProps?: InputElementProps;
21
+ readonly startElement?: React.ReactNode;
22
+ readonly endElement?: React.ReactNode;
23
+ readonly children: React.ReactElement<InputElementProps>;
24
+ readonly startOffset?: string | number;
25
+ readonly endOffset?: string | number;
26
+ }
27
+
28
+ export const InputGroup = React.forwardRef<HTMLDivElement, InputGroupProps>(
29
+ function InputGroup(props, ref) {
30
+ const {
31
+ startElement,
32
+ startElementProps,
33
+ endElement,
34
+ endElementProps,
35
+ children,
36
+ startOffset,
37
+ endOffset,
38
+ className,
39
+ ...rest
40
+ } = props;
41
+
42
+ const startElementRef = React.useRef<HTMLDivElement>(null);
43
+ const endElementRef = React.useRef<HTMLDivElement>(null);
44
+ const groupRef = React.useRef<HTMLDivElement>(null);
45
+
46
+ const [ inlinePaddings, setInlinePaddings ] = React.useState<{ start?: number; end?: number }>();
47
+
48
+ const calculateInlinePaddings = React.useCallback(() => {
49
+ const startWidth = startElementRef.current?.getBoundingClientRect().width ?? 0;
50
+ const endWidth = endElementRef.current?.getBoundingClientRect().width ?? 0;
51
+
52
+ setInlinePaddings({
53
+ start: startWidth,
54
+ end: endWidth,
55
+ });
56
+ }, []);
57
+
58
+ React.useEffect(() => {
59
+ if (!groupRef.current) return;
60
+
61
+ let timeoutId: ReturnType<typeof setTimeout>;
62
+
63
+ const intersectionObserver = new IntersectionObserver(
64
+ (entries) => {
65
+ const entry = entries[0];
66
+ if (entry && entry.isIntersecting) {
67
+ // Small delay to ensure rendering is complete
68
+ timeoutId = setTimeout(calculateInlinePaddings, 50);
69
+ }
70
+ },
71
+ { threshold: 0.01 },
72
+ );
73
+
74
+ intersectionObserver.observe(groupRef.current);
75
+
76
+ return () => {
77
+ intersectionObserver.disconnect();
78
+ if (timeoutId) {
79
+ clearTimeout(timeoutId);
80
+ }
81
+ };
82
+ }, [ calculateInlinePaddings ]);
83
+
84
+ React.useEffect(() => {
85
+ calculateInlinePaddings();
86
+
87
+ const resizeHandler = debounce(calculateInlinePaddings, 300);
88
+ const resizeObserver = new ResizeObserver(resizeHandler);
89
+
90
+ if (groupRef.current) {
91
+ resizeObserver.observe(groupRef.current);
92
+ }
93
+
94
+ return function cleanup() {
95
+ resizeObserver.disconnect();
96
+ };
97
+ }, [ calculateInlinePaddings ]);
98
+
99
+ // Combine refs for the wrapper div
100
+ const combinedRef = React.useCallback((node: HTMLDivElement) => {
101
+ groupRef.current = node;
102
+ if (typeof ref === 'function') {
103
+ ref(node);
104
+ } else if (ref) {
105
+ ref.current = node;
106
+ }
107
+ }, [ ref ]);
108
+
109
+ const { className: startClassName, ...startRest } = startElementProps ?? {};
110
+ const { className: endClassName, ...endRest } = endElementProps ?? {};
111
+
112
+ return (
113
+ <div
114
+ ref={ combinedRef }
115
+ className={ cn('relative flex w-full items-center', className) }
116
+ { ...rest }
117
+ >
118
+ { startElement && (
119
+ <div
120
+ ref={ startElementRef }
121
+ className={ cn(
122
+ 'pointer-events-none absolute inset-y-0 left-0 z-[1] flex items-center text-[var(--chakra-colors-input-element)]',
123
+ startClassName,
124
+ ) }
125
+ { ...startRest }
126
+ >
127
+ { startElement }
128
+ </div>
129
+ ) }
130
+ { React.Children.map(children, (child: React.ReactElement<InputProps>) => {
131
+ if (getComponentDisplayName(child.type) !== 'FieldInput') {
132
+ return child;
133
+ }
134
+ return React.cloneElement(child, {
135
+ ...(startElement && { ps: startOffset ?? (inlinePaddings?.start ? `${ inlinePaddings.start }px` : undefined) }),
136
+ ...(endElement && { pe: endOffset ?? (inlinePaddings?.end ? `${ inlinePaddings.end }px` : undefined) }),
137
+ // hide input value and placeholder for the first render
138
+ value: inlinePaddings ? child.props.value : undefined,
139
+ placeholder: inlinePaddings ? child.props.placeholder : undefined,
140
+ });
141
+ }) }
142
+ { endElement && (
143
+ <div
144
+ ref={ endElementRef }
145
+ className={ cn(
146
+ 'pointer-events-none absolute inset-y-0 right-0 z-[1] flex items-center text-[var(--chakra-colors-input-element)]',
147
+ endClassName,
148
+ ) }
149
+ { ...endRest }
150
+ >
151
+ { endElement }
152
+ </div>
153
+ ) }
154
+ </div>
155
+ );
156
+ },
157
+ );
158
+
159
+ InputGroup.displayName = 'InputGroup';
package/src/input.tsx ADDED
@@ -0,0 +1,60 @@
1
+ import { cva } from 'class-variance-authority';
2
+ import React from 'react';
3
+
4
+ import { cn } from './utils';
5
+
6
+ const inputVariants = cva(
7
+ [
8
+ 'w-full appearance-none outline-none transition-colors',
9
+ 'bg-[var(--color-input-bg)] text-[var(--color-input-fg)] border-[var(--color-input-border)]',
10
+ 'placeholder:text-[var(--color-input-placeholder,theme(colors.gray.400))]',
11
+ 'hover:border-[var(--color-input-border-hover,theme(colors.gray.400))]',
12
+ 'focus:border-[var(--color-input-border-focus,theme(colors.blue.500))]',
13
+ 'focus:placeholder:text-[var(--color-input-placeholder-focus,theme(colors.gray.300))]',
14
+ 'disabled:opacity-40 disabled:cursor-not-allowed',
15
+ 'read-only:opacity-70',
16
+ 'data-[invalid]:border-[var(--color-input-border-invalid,theme(colors.red.500))]',
17
+ ].join(' '),
18
+ {
19
+ variants: {
20
+ size: {
21
+ xs: 'h-6 px-2 text-xs rounded',
22
+ sm: 'h-8 px-3 text-sm rounded-md',
23
+ md: 'h-10 px-4 text-base rounded-md',
24
+ lg: 'h-12 px-4 text-lg rounded-lg',
25
+ '2xl': 'h-14 px-4 text-xl rounded-lg',
26
+ },
27
+ variant: {
28
+ outline: 'border border-solid',
29
+ filled: 'border-0 bg-[var(--color-input-filled-bg,theme(colors.gray.100))]',
30
+ unstyled: 'border-0 bg-transparent p-0 h-auto',
31
+ },
32
+ },
33
+ defaultVariants: {
34
+ size: 'md',
35
+ variant: 'outline',
36
+ },
37
+ },
38
+ );
39
+
40
+ type InputSize = 'xs' | 'sm' | 'md' | 'lg' | '2xl';
41
+ type InputVariant = 'outline' | 'filled' | 'unstyled';
42
+
43
+ export interface InputProps extends Omit<React.ComponentPropsWithRef<'input'>, 'size'> {
44
+ readonly size?: InputSize;
45
+ readonly variant?: InputVariant;
46
+ }
47
+
48
+ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
49
+ ({ size, variant, className, ...rest }, ref) => {
50
+ return (
51
+ <input
52
+ ref={ ref }
53
+ className={ cn(inputVariants({ size, variant }), className) }
54
+ { ...rest }
55
+ />
56
+ );
57
+ },
58
+ );
59
+
60
+ Input.displayName = 'Input';