@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.
- package/dist/accordion.cjs +213 -0
- package/dist/accordion.d.cts +74 -0
- package/dist/accordion.d.ts +74 -0
- package/dist/accordion.js +186 -0
- package/dist/alert.cjs +553 -0
- package/dist/alert.d.cts +30 -0
- package/dist/alert.d.ts +30 -0
- package/dist/alert.js +531 -0
- package/dist/avatar.cjs +149 -0
- package/dist/avatar.d.cts +25 -0
- package/dist/avatar.d.ts +25 -0
- package/dist/avatar.js +125 -0
- package/dist/badge.cjs +611 -0
- package/dist/badge.d.cts +23 -0
- package/dist/badge.d.ts +23 -0
- package/dist/badge.js +589 -0
- package/dist/bank.cjs +272 -0
- package/dist/bank.d.cts +76 -0
- package/dist/bank.d.ts +76 -0
- package/dist/bank.js +258 -0
- package/dist/button.cjs +689 -0
- package/dist/button.d.cts +52 -0
- package/dist/button.d.ts +52 -0
- package/dist/button.js +664 -0
- package/dist/checkbox.cjs +265 -0
- package/dist/checkbox.d.cts +31 -0
- package/dist/checkbox.d.ts +31 -0
- package/dist/checkbox.js +241 -0
- package/dist/close-button.cjs +73 -0
- package/dist/close-button.d.cts +9 -0
- package/dist/close-button.d.ts +9 -0
- package/dist/close-button.js +51 -0
- package/dist/collapsible.cjs +702 -0
- package/dist/collapsible.d.cts +23 -0
- package/dist/collapsible.d.ts +23 -0
- package/dist/collapsible.js +679 -0
- package/dist/color-mode.cjs +96 -0
- package/dist/color-mode.d.cts +25 -0
- package/dist/color-mode.d.ts +25 -0
- package/dist/color-mode.js +72 -0
- package/dist/dialog.cjs +279 -0
- package/dist/dialog.d.cts +66 -0
- package/dist/dialog.d.ts +66 -0
- package/dist/dialog.js +246 -0
- package/dist/drawer.cjs +207 -0
- package/dist/drawer.d.cts +36 -0
- package/dist/drawer.d.ts +36 -0
- package/dist/drawer.js +175 -0
- package/dist/empty-state.cjs +93 -0
- package/dist/empty-state.d.cts +13 -0
- package/dist/empty-state.d.ts +13 -0
- package/dist/empty-state.js +71 -0
- package/dist/expiration-selector.cjs +138 -0
- package/dist/expiration-selector.d.cts +16 -0
- package/dist/expiration-selector.d.ts +16 -0
- package/dist/expiration-selector.js +116 -0
- package/dist/field.cjs +183 -0
- package/dist/field.d.cts +24 -0
- package/dist/field.d.ts +24 -0
- package/dist/field.js +160 -0
- package/dist/greeks-display.cjs +114 -0
- package/dist/greeks-display.d.cts +14 -0
- package/dist/greeks-display.d.ts +14 -0
- package/dist/greeks-display.js +92 -0
- package/dist/heading.cjs +46 -0
- package/dist/heading.d.cts +10 -0
- package/dist/heading.d.ts +10 -0
- package/dist/heading.js +40 -0
- package/dist/icon-button.cjs +491 -0
- package/dist/icon-button.d.cts +33 -0
- package/dist/icon-button.d.ts +33 -0
- package/dist/icon-button.js +470 -0
- package/dist/image.cjs +572 -0
- package/dist/image.d.cts +57 -0
- package/dist/image.d.ts +57 -0
- package/dist/image.js +551 -0
- package/dist/index.cjs +7316 -0
- package/dist/index.d.cts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +7137 -0
- package/dist/input-group.cjs +155 -0
- package/dist/input-group.d.cts +17 -0
- package/dist/input-group.d.ts +17 -0
- package/dist/input-group.js +133 -0
- package/dist/input.cjs +65 -0
- package/dist/input.d.cts +11 -0
- package/dist/input.d.ts +11 -0
- package/dist/input.js +59 -0
- package/dist/link.cjs +630 -0
- package/dist/link.d.cts +37 -0
- package/dist/link.d.ts +37 -0
- package/dist/link.js +606 -0
- package/dist/menu.cjs +305 -0
- package/dist/menu.d.cts +84 -0
- package/dist/menu.d.ts +84 -0
- package/dist/menu.js +269 -0
- package/dist/option-chain.cjs +221 -0
- package/dist/option-chain.d.cts +37 -0
- package/dist/option-chain.d.ts +37 -0
- package/dist/option-chain.js +199 -0
- package/dist/option-position.cjs +164 -0
- package/dist/option-position.d.cts +29 -0
- package/dist/option-position.d.ts +29 -0
- package/dist/option-position.js +142 -0
- package/dist/pin-input.cjs +182 -0
- package/dist/pin-input.d.cts +25 -0
- package/dist/pin-input.d.ts +25 -0
- package/dist/pin-input.js +160 -0
- package/dist/pnl-diagram.cjs +453 -0
- package/dist/pnl-diagram.d.cts +11 -0
- package/dist/pnl-diagram.d.ts +11 -0
- package/dist/pnl-diagram.js +431 -0
- package/dist/popover.cjs +327 -0
- package/dist/popover.d.cts +73 -0
- package/dist/popover.d.ts +73 -0
- package/dist/popover.js +294 -0
- package/dist/progress-circle.cjs +152 -0
- package/dist/progress-circle.d.cts +47 -0
- package/dist/progress-circle.d.ts +47 -0
- package/dist/progress-circle.js +128 -0
- package/dist/progress.cjs +117 -0
- package/dist/progress.d.cts +28 -0
- package/dist/progress.d.ts +28 -0
- package/dist/progress.js +94 -0
- package/dist/provider.cjs +62 -0
- package/dist/provider.d.cts +7 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +40 -0
- package/dist/radio.cjs +177 -0
- package/dist/radio.d.cts +53 -0
- package/dist/radio.d.ts +53 -0
- package/dist/radio.js +153 -0
- package/dist/rating.cjs +80 -0
- package/dist/rating.d.cts +14 -0
- package/dist/rating.d.ts +14 -0
- package/dist/rating.js +58 -0
- package/dist/select.cjs +791 -0
- package/dist/select.d.cts +130 -0
- package/dist/select.d.ts +130 -0
- package/dist/select.js +757 -0
- package/dist/separator.cjs +57 -0
- package/dist/separator.d.cts +13 -0
- package/dist/separator.d.ts +13 -0
- package/dist/separator.js +51 -0
- package/dist/skeleton.cjs +370 -0
- package/dist/skeleton.d.cts +60 -0
- package/dist/skeleton.d.ts +60 -0
- package/dist/skeleton.js +346 -0
- package/dist/slider.cjs +138 -0
- package/dist/slider.d.cts +24 -0
- package/dist/slider.d.ts +24 -0
- package/dist/slider.js +115 -0
- package/dist/strategy-builder.cjs +373 -0
- package/dist/strategy-builder.d.cts +26 -0
- package/dist/strategy-builder.d.ts +26 -0
- package/dist/strategy-builder.js +351 -0
- package/dist/switch.cjs +163 -0
- package/dist/switch.d.cts +27 -0
- package/dist/switch.d.ts +27 -0
- package/dist/switch.js +140 -0
- package/dist/table.cjs +1044 -0
- package/dist/table.d.cts +107 -0
- package/dist/table.d.ts +107 -0
- package/dist/table.js +1013 -0
- package/dist/tabs.cjs +240 -0
- package/dist/tabs.d.cts +78 -0
- package/dist/tabs.d.ts +78 -0
- package/dist/tabs.js +213 -0
- package/dist/tag.cjs +651 -0
- package/dist/tag.d.cts +21 -0
- package/dist/tag.d.ts +21 -0
- package/dist/tag.js +628 -0
- package/dist/textarea.cjs +65 -0
- package/dist/textarea.d.cts +11 -0
- package/dist/textarea.d.ts +11 -0
- package/dist/textarea.js +59 -0
- package/dist/toaster.cjs +99 -0
- package/dist/toaster.d.cts +29 -0
- package/dist/toaster.d.ts +29 -0
- package/dist/toaster.js +96 -0
- package/dist/tooltip.cjs +171 -0
- package/dist/tooltip.d.cts +39 -0
- package/dist/tooltip.d.ts +39 -0
- package/dist/tooltip.js +148 -0
- package/dist/utils.cjs +11 -0
- package/dist/utils.d.cts +5 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +9 -0
- package/package.json +284 -85
- package/src/accordion.tsx +285 -0
- package/src/alert.tsx +221 -0
- package/src/avatar.tsx +174 -0
- package/src/badge.tsx +158 -0
- package/src/bank.tsx +325 -0
- package/src/button.tsx +411 -0
- package/src/checkbox.tsx +307 -0
- package/src/close-button.tsx +51 -0
- package/src/collapsible.tsx +126 -0
- package/src/color-mode.tsx +125 -0
- package/src/dialog.tsx +356 -0
- package/src/drawer.tsx +186 -0
- package/src/empty-state.tsx +97 -0
- package/src/expiration-selector.tsx +163 -0
- package/src/field.tsx +202 -0
- package/src/greeks-display.tsx +138 -0
- package/src/heading.tsx +55 -0
- package/src/icon-button.tsx +192 -0
- package/src/image.tsx +280 -0
- package/src/index.ts +268 -0
- package/src/input-group.tsx +159 -0
- package/src/input.tsx +60 -0
- package/src/link.tsx +326 -0
- package/src/menu.tsx +471 -0
- package/src/option-chain.tsx +261 -0
- package/src/option-position.tsx +200 -0
- package/src/pin-input.tsx +187 -0
- package/src/pnl-diagram.tsx +458 -0
- package/src/popover.tsx +400 -0
- package/src/progress-circle.tsx +180 -0
- package/src/progress.tsx +109 -0
- package/src/provider.tsx +12 -0
- package/src/radio.tsx +175 -0
- package/src/rating.tsx +79 -0
- package/src/select.tsx +696 -0
- package/src/separator.tsx +59 -0
- package/src/skeleton.tsx +302 -0
- package/src/slider.tsx +152 -0
- package/src/strategy-builder.tsx +466 -0
- package/src/switch.tsx +158 -0
- package/src/table.tsx +621 -0
- package/src/tabs.tsx +354 -0
- package/src/tag.tsx +159 -0
- package/src/textarea.tsx +60 -0
- package/src/toaster.tsx +117 -0
- package/src/tokens.css +438 -0
- package/src/tooltip.tsx +184 -0
- package/src/utils/cn.ts +7 -0
- package/src/utils.ts +6 -0
- package/tokens.css +438 -0
- 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';
|