@luxfi/ui 6.1.3 → 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 (241) 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 +283 -90
  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 +267 -138
  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/LICENSE +0 -122
  241. package/README.md +0 -109
@@ -0,0 +1,285 @@
1
+ import * as AccordionPrimitive from '@radix-ui/react-accordion';
2
+ import * as React from 'react';
3
+
4
+ import { cn } from './utils';
5
+
6
+ // Inline chevron icon (east-mini arrow)
7
+ const IndicatorIcon = ({ className }: { readonly className?: string }) => (
8
+ <svg className={ className } viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
9
+ <path d="M7.5 15L12.5 10L7.5 5" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
10
+ </svg>
11
+ );
12
+
13
+ // ---------------------------------------------------------------------------
14
+ // AccordionRoot
15
+ // ---------------------------------------------------------------------------
16
+
17
+ interface AccordionRootProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'defaultValue' | 'dir'> {
18
+
19
+ /** Open multiple items simultaneously. Defaults to true. */
20
+ readonly multiple?: boolean;
21
+
22
+ /** Controlled open items (array of `value` strings). */
23
+ readonly value?: Array<string>;
24
+
25
+ /** Uncontrolled initial open items. */
26
+ readonly defaultValue?: Array<string>;
27
+
28
+ /**
29
+ * Called when open items change.
30
+ * Wraps the value in `{ value }` to stay compatible with the Chakra callback shape
31
+ * that consumers already rely on.
32
+ */
33
+ readonly onValueChange?: (details: { value: Array<string> }) => void;
34
+ readonly variant?: 'outline' | 'faq';
35
+ readonly size?: 'sm' | 'md';
36
+
37
+ /** Accepted for compatibility; not applied visually. */
38
+ readonly noAnimation?: boolean;
39
+
40
+ /** Accepted for compatibility; Radix defers rendering internally. */
41
+ readonly lazyMount?: boolean;
42
+ readonly children?: React.ReactNode;
43
+ // Legacy Chakra style-prop shims
44
+ readonly position?: string;
45
+ readonly w?: string;
46
+ readonly bgColor?: string | Record<string, string>;
47
+ readonly borderRadius?: string;
48
+ }
49
+
50
+ export const AccordionRoot = React.forwardRef<HTMLDivElement, AccordionRootProps>(
51
+ function AccordionRoot(props, ref) {
52
+ const {
53
+ multiple: _multiple,
54
+ value,
55
+ defaultValue,
56
+ onValueChange,
57
+ variant,
58
+ size,
59
+ noAnimation: _noAnimation,
60
+ lazyMount: _lazyMount,
61
+ className,
62
+ children,
63
+ position: _position,
64
+ w: _w,
65
+ bgColor: _bgColor,
66
+ borderRadius: _borderRadius,
67
+ ...rest
68
+ } = props;
69
+
70
+ // Radix requires `type` discriminant. We default to "multiple" to match
71
+ // the original Chakra wrapper behavior.
72
+ const handleValueChange = React.useCallback(
73
+ (next: Array<string>) => {
74
+ onValueChange?.({ value: next });
75
+ },
76
+ [ onValueChange ],
77
+ );
78
+
79
+ return (
80
+ <AccordionPrimitive.Root
81
+ ref={ ref }
82
+ type="multiple"
83
+ value={ value }
84
+ defaultValue={ defaultValue }
85
+ onValueChange={ handleValueChange }
86
+ className={ cn(
87
+ 'w-full',
88
+ variant === 'faq' && 'accordion-faq',
89
+ size === 'sm' && 'accordion-sm',
90
+ className,
91
+ ) }
92
+ data-variant={ variant }
93
+ data-size={ size }
94
+ { ...rest }
95
+ >
96
+ { children }
97
+ </AccordionPrimitive.Root>
98
+ );
99
+ },
100
+ );
101
+
102
+ // ---------------------------------------------------------------------------
103
+ // AccordionItem
104
+ // ---------------------------------------------------------------------------
105
+
106
+ interface AccordionItemProps extends React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item> {
107
+ // Legacy Chakra style-prop shims
108
+ as?: string;
109
+ _first?: Record<string, unknown>;
110
+ _last?: Record<string, unknown>;
111
+ display?: string;
112
+ }
113
+
114
+ export const AccordionItem = React.forwardRef<HTMLDivElement, AccordionItemProps>(
115
+ function AccordionItem(props, ref) {
116
+ const { className, as: _as, _first, _last, display: _display, ...rest } = props;
117
+ return (
118
+ <AccordionPrimitive.Item
119
+ ref={ ref }
120
+ className={ cn(
121
+ 'border-b border-[var(--color-border-divider)]',
122
+ className,
123
+ ) }
124
+ { ...rest }
125
+ />
126
+ );
127
+ },
128
+ );
129
+
130
+ // ---------------------------------------------------------------------------
131
+ // AccordionItemTrigger
132
+ // ---------------------------------------------------------------------------
133
+
134
+ interface AccordionItemTriggerProps extends Omit<React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>, 'dir'> {
135
+ readonly indicatorPlacement?: 'start' | 'end';
136
+ readonly noIndicator?: boolean;
137
+ readonly variant?: 'outline' | 'faq';
138
+ // Legacy Chakra style-prop shims
139
+ px?: number | string;
140
+ py?: number | string;
141
+ _hover?: Record<string, string>;
142
+ wordBreak?: string;
143
+ textAlign?: string;
144
+ cursor?: string;
145
+ display?: string;
146
+ alignItems?: string;
147
+ columnGap?: number | string;
148
+ }
149
+
150
+ export const AccordionItemTrigger = React.forwardRef<
151
+ HTMLButtonElement,
152
+ AccordionItemTriggerProps
153
+ >(function AccordionItemTrigger(props, ref) {
154
+ const {
155
+ children, indicatorPlacement: indicatorPlacementProp, variant, noIndicator, className,
156
+ // Strip Chakra style props
157
+ px: _px, py: _py, _hover, wordBreak: _wordBreak, textAlign: _textAlign,
158
+ cursor: _cursor, display: _display, alignItems: _alignItems, columnGap: _columnGap,
159
+ ...rest
160
+ } = props;
161
+
162
+ const indicatorPlacement = variant === 'faq' ? 'start' : (indicatorPlacementProp ?? 'end');
163
+
164
+ const indicator = variant === 'faq' ? (
165
+ <span
166
+ className={ cn(
167
+ 'relative inline-block h-3 w-3 shrink-0',
168
+ // horizontal bar (always visible)
169
+ 'before:absolute before:left-0 before:top-1/2 before:block before:h-[2px] before:w-full before:-translate-y-1/2 before:rounded-[2px] before:bg-current',
170
+ // vertical bar (rotates to 0 when open)
171
+ 'after:absolute after:left-1/2 after:top-0 after:block after:h-full after:w-[2px]',
172
+ 'after:-translate-x-1/2 after:rounded-[2px] after:bg-current',
173
+ 'after:transition-transform after:duration-200 after:ease-in-out',
174
+ // When parent trigger has data-state="open", rotate vertical bar
175
+ 'group-data-[state=open]/trigger:after:rotate-90',
176
+ ) }
177
+ />
178
+ ) : (
179
+ <span
180
+ className={ cn(
181
+ 'inline-flex shrink-0 transition-transform duration-200',
182
+ 'rotate-180',
183
+ 'group-data-[state=open]/trigger:rotate-[270deg]',
184
+ ) }
185
+ >
186
+ <IndicatorIcon className="h-5 w-5"/>
187
+ </span>
188
+ );
189
+
190
+ return (
191
+ <AccordionPrimitive.Header asChild>
192
+ <div>
193
+ <AccordionPrimitive.Trigger
194
+ ref={ ref }
195
+ className={ cn(
196
+ 'group/trigger flex w-full cursor-pointer items-center gap-2 py-3 text-left text-[var(--color-text-primary)]',
197
+ 'hover:text-[var(--color-hover)]',
198
+ 'focus-visible:outline-none',
199
+ className,
200
+ ) }
201
+ { ...rest }
202
+ >
203
+ { indicatorPlacement === 'start' && !noIndicator && indicator }
204
+ { children }
205
+ { indicatorPlacement === 'end' && !noIndicator && indicator }
206
+ </AccordionPrimitive.Trigger>
207
+ </div>
208
+ </AccordionPrimitive.Header>
209
+ );
210
+ });
211
+
212
+ // ---------------------------------------------------------------------------
213
+ // AccordionItemContent
214
+ // ---------------------------------------------------------------------------
215
+
216
+ export interface AccordionItemContentProps extends React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content> {
217
+ // Legacy Chakra style-prop shims
218
+ pb?: number | string;
219
+ pr?: number | string;
220
+ pl?: string;
221
+ w?: string;
222
+ display?: string;
223
+ flexDir?: string;
224
+ rowGap?: number | string;
225
+ }
226
+
227
+ export const AccordionItemContent = React.forwardRef<
228
+ HTMLDivElement,
229
+ AccordionItemContentProps
230
+ >(function AccordionItemContent(props, ref) {
231
+ const { className, children, pb: _pb, pr: _pr, pl: _pl, w: _w, display: _display, flexDir: _flexDir, rowGap: _rowGap, ...rest } = props;
232
+ return (
233
+ <AccordionPrimitive.Content
234
+ ref={ ref }
235
+ className={ cn(
236
+ 'overflow-hidden text-[var(--color-text-primary)]',
237
+ 'data-[state=open]:animate-accordion-down',
238
+ 'data-[state=closed]:animate-accordion-up',
239
+ className,
240
+ ) }
241
+ { ...rest }
242
+ >
243
+ <div className="pb-3">
244
+ { children }
245
+ </div>
246
+ </AccordionPrimitive.Content>
247
+ );
248
+ });
249
+
250
+ // ---------------------------------------------------------------------------
251
+ // useAccordion
252
+ // ---------------------------------------------------------------------------
253
+
254
+ export function useAccordion(items: Array<{ id: string }>) {
255
+ const [ value, setValue ] = React.useState<Array<string>>([]);
256
+
257
+ const onValueChange = React.useCallback(({ value }: { value: Array<string> }) => {
258
+ setValue(value);
259
+ }, []);
260
+
261
+ const scrollToItemFromUrl = React.useCallback(() => {
262
+ const hash = window.location.hash.replace('#', '');
263
+
264
+ if (!hash) {
265
+ return;
266
+ }
267
+
268
+ const itemToScroll = items.find((item) => item.id === hash);
269
+ if (itemToScroll) {
270
+ const el = document.getElementById(itemToScroll.id);
271
+ if (el) {
272
+ el.scrollIntoView({ behavior: 'smooth', block: 'start' });
273
+ }
274
+ setValue([ itemToScroll.id ]);
275
+ }
276
+ }, [ items ]);
277
+
278
+ return React.useMemo(() => {
279
+ return {
280
+ value,
281
+ onValueChange,
282
+ scrollToItemFromUrl,
283
+ };
284
+ }, [ value, onValueChange, scrollToItemFromUrl ]);
285
+ }
package/src/alert.tsx ADDED
@@ -0,0 +1,221 @@
1
+ import { cva } from 'class-variance-authority';
2
+ import * as React from 'react';
3
+
4
+ import { cn } from './utils';
5
+
6
+ // Inline info icon (filled circle with i)
7
+ const IndicatorIcon = ({ className }: { readonly className?: string }) => (
8
+ <svg className={ className } viewBox="0 0 20 20" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
9
+ <path fillRule="evenodd" clipRule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm.75-11.25a.75.75 0 11-1.5 0 .75.75 0 011.5 0zM9.25 10a.75.75 0 011.5 0v3a.75.75 0 01-1.5 0v-3z"/>
10
+ </svg>
11
+ );
12
+
13
+ import { CloseButton } from './close-button';
14
+ import { Skeleton } from './skeleton';
15
+
16
+ /* ------------------------------------------------------------------ */
17
+ /* Status type */
18
+ /* ------------------------------------------------------------------ */
19
+
20
+ type AlertStatus = 'info' | 'warning' | 'warning_table' | 'success' | 'error';
21
+
22
+ /* ------------------------------------------------------------------ */
23
+ /* CVA variants */
24
+ /* ------------------------------------------------------------------ */
25
+
26
+ const alertRoot = cva(
27
+ // base
28
+ 'w-full flex items-start relative rounded text-[var(--color-alert-fg)]',
29
+ {
30
+ variants: {
31
+ status: {
32
+ info: 'bg-[var(--color-alert-bg-info)]',
33
+ warning: 'bg-[var(--color-alert-bg-warning)]',
34
+ warning_table: 'bg-[var(--color-alert-bg-warning-table)]',
35
+ success: 'bg-[var(--color-alert-bg-success)]',
36
+ error: 'bg-[var(--color-alert-bg-error)]',
37
+ },
38
+ size: {
39
+ sm: 'gap-2 px-2 py-2 text-xs',
40
+ md: 'gap-2 px-3 py-2 text-base',
41
+ },
42
+ },
43
+ defaultVariants: {
44
+ status: 'info',
45
+ size: 'md',
46
+ },
47
+ },
48
+ );
49
+
50
+ const alertContent = cva('flex flex-1', {
51
+ variants: {
52
+ inline: {
53
+ 'true': 'inline-flex flex-row items-center',
54
+ 'false': 'flex flex-col',
55
+ },
56
+ },
57
+ defaultVariants: {
58
+ inline: true,
59
+ },
60
+ });
61
+
62
+ const INDICATOR_BASE = 'inline-flex items-center justify-center shrink-0 w-5 h-5 text-[var(--color-alert-fg)] [&>svg]:w-full [&>svg]:h-full';
63
+
64
+ const indicatorVariants = cva(INDICATOR_BASE, {
65
+ variants: {
66
+ size: {
67
+ sm: 'w-5 h-5 my-0',
68
+ md: 'w-5 h-5 my-[2px]',
69
+ },
70
+ },
71
+ defaultVariants: {
72
+ size: 'md',
73
+ },
74
+ });
75
+
76
+ /* ------------------------------------------------------------------ */
77
+ /* Props */
78
+ /* ------------------------------------------------------------------ */
79
+
80
+ export interface AlertProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'title'> {
81
+ readonly status?: AlertStatus;
82
+ readonly size?: 'sm' | 'md';
83
+ readonly inline?: boolean;
84
+ readonly startElement?: React.ReactNode;
85
+ readonly endElement?: React.ReactNode;
86
+ readonly descriptionProps?: Omit<React.ComponentPropsWithoutRef<'div'>, 'ref'> & {
87
+ whiteSpace?: string;
88
+ alignItems?: string;
89
+ flexDir?: string;
90
+ flexWrap?: string;
91
+ rowGap?: number | string;
92
+ columnGap?: number | string;
93
+ };
94
+ readonly title?: React.ReactNode;
95
+ readonly icon?: React.ReactElement;
96
+ readonly closable?: boolean;
97
+ readonly onClose?: () => void;
98
+ readonly loading?: boolean;
99
+ readonly showIcon?: boolean;
100
+ // Legacy Chakra style-prop shims
101
+ readonly whiteSpace?: string;
102
+ readonly mb?: number | string;
103
+ readonly mt?: number | string;
104
+ }
105
+
106
+ /* ------------------------------------------------------------------ */
107
+ /* Component */
108
+ /* ------------------------------------------------------------------ */
109
+
110
+ export const Alert = React.forwardRef<HTMLDivElement, AlertProps>(
111
+ function Alert(props, ref) {
112
+ const {
113
+ title,
114
+ children,
115
+ icon,
116
+ closable,
117
+ onClose,
118
+ startElement,
119
+ endElement,
120
+ loading,
121
+ size,
122
+ inline = true,
123
+ showIcon = false,
124
+ descriptionProps,
125
+ status = 'info',
126
+ className,
127
+ ...rest
128
+ } = props;
129
+
130
+ // Strip style prop shims
131
+ const { whiteSpace: _whiteSpace, mb: _mb, mt: _mt, style: styleProp, ...alertRest } = rest;
132
+ const shimStyle: React.CSSProperties = { ...styleProp };
133
+ if (_whiteSpace) shimStyle.whiteSpace = _whiteSpace as React.CSSProperties['whiteSpace'];
134
+ if (_mb !== undefined) shimStyle.marginBottom = typeof _mb === 'number' ? `${ _mb * 4 }px` : _mb;
135
+ if (_mt !== undefined) shimStyle.marginTop = typeof _mt === 'number' ? `${ _mt * 4 }px` : _mt;
136
+ const alertStyle = Object.keys(shimStyle).length > 0 ? shimStyle : undefined;
137
+
138
+ const [ isOpen, setIsOpen ] = React.useState(true);
139
+
140
+ const resolvedSize = size ?? 'md';
141
+
142
+ const defaultIcon = (
143
+ <IndicatorIcon className="w-5 h-5"/>
144
+ );
145
+
146
+ const iconElement = (() => {
147
+ if (startElement !== undefined) {
148
+ return startElement;
149
+ }
150
+
151
+ if (!showIcon && icon === undefined) {
152
+ return null;
153
+ }
154
+
155
+ return (
156
+ <span className={ indicatorVariants({ size: resolvedSize }) }>
157
+ { icon || defaultIcon }
158
+ </span>
159
+ );
160
+ })();
161
+
162
+ const handleClose = React.useCallback(() => {
163
+ setIsOpen(false);
164
+ onClose?.();
165
+ }, [ onClose ]);
166
+
167
+ if (closable && !isOpen) {
168
+ return null;
169
+ }
170
+
171
+ const {
172
+ className: descClassName, whiteSpace: descWhiteSpace,
173
+ alignItems: descAlignItems, flexDir: descFlexDir,
174
+ flexWrap: descFlexWrap, rowGap: descRowGap, columnGap: descColumnGap,
175
+ style: descStyleProp, ...descRest
176
+ } = descriptionProps ?? {};
177
+ const descStyle: React.CSSProperties = {
178
+ ...descStyleProp,
179
+ ...(descWhiteSpace ? { whiteSpace: descWhiteSpace as React.CSSProperties['whiteSpace'] } : {}),
180
+ ...(descAlignItems ? { alignItems: descAlignItems } : {}),
181
+ ...(descFlexDir ? { flexDirection: descFlexDir as React.CSSProperties['flexDirection'] } : {}),
182
+ ...(descFlexWrap ? { flexWrap: descFlexWrap as React.CSSProperties['flexWrap'] } : {}),
183
+ ...(descRowGap !== undefined ? { rowGap: typeof descRowGap === 'number' ? `${ descRowGap * 4 }px` : descRowGap } : {}),
184
+ ...(descColumnGap !== undefined ? { columnGap: typeof descColumnGap === 'number' ? `${ descColumnGap * 4 }px` : descColumnGap } : {}),
185
+ };
186
+
187
+ return (
188
+ <Skeleton loading={ loading }>
189
+ <div
190
+ ref={ ref }
191
+ className={ cn(alertRoot({ status, size: resolvedSize }), className) }
192
+ style={ alertStyle }
193
+ { ...alertRest }
194
+ >
195
+ { iconElement }
196
+ { children ? (
197
+ <div className={ alertContent({ inline }) }>
198
+ { title && <div className="font-semibold">{ title }</div> }
199
+ <div
200
+ className={ cn('inline-flex flex-wrap', descClassName) }
201
+ style={ Object.keys(descStyle).length > 0 ? descStyle : undefined }
202
+ { ...descRest }
203
+ >
204
+ { children }
205
+ </div>
206
+ </div>
207
+ ) : (
208
+ <div className="font-semibold flex-1">{ title }</div>
209
+ ) }
210
+ { endElement }
211
+ { closable && (
212
+ <CloseButton
213
+ className="relative self-start"
214
+ onClick={ handleClose }
215
+ />
216
+ ) }
217
+ </div>
218
+ </Skeleton>
219
+ );
220
+ },
221
+ );
package/src/avatar.tsx ADDED
@@ -0,0 +1,174 @@
1
+ 'use client';
2
+
3
+ import * as RadixAvatar from '@radix-ui/react-avatar';
4
+ import * as React from 'react';
5
+
6
+ import { cn } from './utils';
7
+
8
+ type ImageProps = React.ImgHTMLAttributes<HTMLImageElement>;
9
+
10
+ // -- Size & variant mappings ------------------------------------------------
11
+
12
+ type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
13
+ type AvatarVariant = 'solid' | 'subtle' | 'outline';
14
+
15
+ const SIZE_CLASSES: Record<AvatarSize, string> = {
16
+ xs: 'h-6 w-6 text-[10px]',
17
+ sm: 'h-8 w-8 text-xs',
18
+ md: 'h-10 w-10 text-sm',
19
+ lg: 'h-12 w-12 text-base',
20
+ xl: 'h-16 w-16 text-lg',
21
+ '2xl': 'h-20 w-20 text-xl',
22
+ };
23
+
24
+ const VARIANT_CLASSES: Record<AvatarVariant, string> = {
25
+ solid: 'bg-gray-500 text-white',
26
+ subtle: 'bg-gray-200 text-gray-700 dark:bg-gray-700 dark:text-gray-200',
27
+ outline: 'border-2 border-gray-300 bg-transparent text-gray-700 dark:border-gray-600 dark:text-gray-200',
28
+ };
29
+
30
+ const DEFAULT_SIZE: AvatarSize = 'md';
31
+ const DEFAULT_VARIANT: AvatarVariant = 'subtle';
32
+
33
+ // -- Context for AvatarGroup ------------------------------------------------
34
+
35
+ interface AvatarGroupContextValue {
36
+ readonly size?: AvatarSize;
37
+ readonly variant?: AvatarVariant;
38
+ readonly borderless?: boolean;
39
+ }
40
+
41
+ const AvatarGroupContext = React.createContext<AvatarGroupContextValue>({});
42
+
43
+ function useAvatarGroupContext(): AvatarGroupContextValue {
44
+ return React.useContext(AvatarGroupContext);
45
+ }
46
+
47
+ // -- Avatar -----------------------------------------------------------------
48
+
49
+ export interface AvatarProps extends React.ComponentPropsWithoutRef<'span'> {
50
+ name?: string;
51
+ src?: string;
52
+ srcSet?: string;
53
+ loading?: ImageProps['loading'];
54
+ icon?: React.ReactElement;
55
+ fallback?: React.ReactNode;
56
+ size?: AvatarSize;
57
+ variant?: AvatarVariant;
58
+ borderless?: boolean;
59
+ }
60
+
61
+ export const Avatar = React.forwardRef<HTMLSpanElement, AvatarProps>(
62
+ function Avatar(props, ref) {
63
+ const group = useAvatarGroupContext();
64
+ const {
65
+ name,
66
+ src,
67
+ srcSet,
68
+ loading,
69
+ icon,
70
+ fallback,
71
+ children,
72
+ className,
73
+ size: sizeProp,
74
+ variant: variantProp,
75
+ borderless,
76
+ ...rest
77
+ } = props;
78
+
79
+ const size = sizeProp ?? group.size ?? DEFAULT_SIZE;
80
+ const variant = variantProp ?? group.variant ?? DEFAULT_VARIANT;
81
+ const isBorderless = borderless ?? group.borderless ?? false;
82
+
83
+ return (
84
+ <RadixAvatar.Root
85
+ ref={ ref }
86
+ className={ cn(
87
+ 'relative inline-flex shrink-0 items-center justify-center overflow-hidden rounded-full align-middle',
88
+ SIZE_CLASSES[size],
89
+ VARIANT_CLASSES[variant],
90
+ !isBorderless && 'ring-2 ring-white dark:ring-gray-900',
91
+ className,
92
+ ) }
93
+ { ...rest }
94
+ >
95
+ <AvatarFallback name={ name } icon={ icon }>
96
+ { fallback }
97
+ </AvatarFallback>
98
+ <RadixAvatar.Image
99
+ className="h-full w-full rounded-[inherit] object-cover"
100
+ src={ src }
101
+ srcSet={ srcSet }
102
+ loading={ loading }
103
+ alt={ name ?? '' }
104
+ />
105
+ { children }
106
+ </RadixAvatar.Root>
107
+ );
108
+ },
109
+ );
110
+
111
+ // -- AvatarFallback (internal) ----------------------------------------------
112
+
113
+ interface AvatarFallbackInternalProps extends React.ComponentPropsWithoutRef<'span'> {
114
+ name?: string;
115
+ icon?: React.ReactElement;
116
+ }
117
+
118
+ const AvatarFallback = React.forwardRef<HTMLSpanElement, AvatarFallbackInternalProps>(
119
+ function AvatarFallback(props, ref) {
120
+ const { name, icon, children, className, ...rest } = props;
121
+ return (
122
+ <RadixAvatar.Fallback
123
+ ref={ ref }
124
+ className={ cn(
125
+ 'flex h-full w-full items-center justify-center font-medium',
126
+ className,
127
+ ) }
128
+ { ...rest }
129
+ >
130
+ { children }
131
+ { name != null && children == null && <>{ getInitials(name) }</> }
132
+ { name == null && children == null && icon }
133
+ </RadixAvatar.Fallback>
134
+ );
135
+ },
136
+ );
137
+
138
+ // -- getInitials ------------------------------------------------------------
139
+
140
+ function getInitials(name: string): string {
141
+ const names = name.trim().split(' ');
142
+ const firstName = names[0] != null ? names[0] : '';
143
+ const lastName = names.length > 1 ? names[names.length - 1] : '';
144
+ return firstName && lastName ?
145
+ `${ firstName.charAt(0) }${ lastName.charAt(0) }` :
146
+ firstName.charAt(0);
147
+ }
148
+
149
+ // -- AvatarGroup ------------------------------------------------------------
150
+
151
+ interface AvatarGroupProps extends React.ComponentPropsWithoutRef<'div'> {
152
+ size?: AvatarSize;
153
+ variant?: AvatarVariant;
154
+ borderless?: boolean;
155
+ }
156
+
157
+ export const AvatarGroup = React.forwardRef<HTMLDivElement, AvatarGroupProps>(
158
+ function AvatarGroup(props, ref) {
159
+ const { size, variant, borderless, className, ...rest } = props;
160
+ const contextValue = React.useMemo(
161
+ () => ({ size, variant, borderless }),
162
+ [ size, variant, borderless ],
163
+ );
164
+ return (
165
+ <AvatarGroupContext.Provider value={ contextValue }>
166
+ <div
167
+ ref={ ref }
168
+ className={ cn('flex -space-x-3', className) }
169
+ { ...rest }
170
+ />
171
+ </AvatarGroupContext.Provider>
172
+ );
173
+ },
174
+ );