@luxfi/ui 1.0.1

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 (124) hide show
  1. package/dist/accordion.cjs +213 -0
  2. package/dist/accordion.js +186 -0
  3. package/dist/alert.cjs +553 -0
  4. package/dist/alert.js +531 -0
  5. package/dist/avatar.cjs +149 -0
  6. package/dist/avatar.js +125 -0
  7. package/dist/badge.cjs +611 -0
  8. package/dist/badge.js +589 -0
  9. package/dist/button.cjs +689 -0
  10. package/dist/button.js +664 -0
  11. package/dist/checkbox.cjs +265 -0
  12. package/dist/checkbox.js +241 -0
  13. package/dist/close-button.cjs +73 -0
  14. package/dist/close-button.js +51 -0
  15. package/dist/collapsible.cjs +711 -0
  16. package/dist/collapsible.js +685 -0
  17. package/dist/color-mode.cjs +36 -0
  18. package/dist/color-mode.js +32 -0
  19. package/dist/dialog.cjs +279 -0
  20. package/dist/dialog.js +246 -0
  21. package/dist/drawer.cjs +207 -0
  22. package/dist/drawer.js +175 -0
  23. package/dist/empty-state.cjs +93 -0
  24. package/dist/empty-state.js +71 -0
  25. package/dist/field.cjs +183 -0
  26. package/dist/field.js +160 -0
  27. package/dist/heading.cjs +46 -0
  28. package/dist/heading.js +40 -0
  29. package/dist/icon-button.cjs +491 -0
  30. package/dist/icon-button.js +470 -0
  31. package/dist/image.cjs +572 -0
  32. package/dist/image.js +551 -0
  33. package/dist/index.cjs +5749 -0
  34. package/dist/index.js +5586 -0
  35. package/dist/input-group.cjs +155 -0
  36. package/dist/input-group.js +133 -0
  37. package/dist/input.cjs +65 -0
  38. package/dist/input.js +59 -0
  39. package/dist/link.cjs +639 -0
  40. package/dist/link.js +612 -0
  41. package/dist/menu.cjs +305 -0
  42. package/dist/menu.js +269 -0
  43. package/dist/pin-input.cjs +182 -0
  44. package/dist/pin-input.js +160 -0
  45. package/dist/popover.cjs +327 -0
  46. package/dist/popover.js +294 -0
  47. package/dist/progress-circle.cjs +152 -0
  48. package/dist/progress-circle.js +128 -0
  49. package/dist/progress.cjs +117 -0
  50. package/dist/progress.js +94 -0
  51. package/dist/provider.cjs +22 -0
  52. package/dist/provider.js +20 -0
  53. package/dist/radio.cjs +177 -0
  54. package/dist/radio.js +153 -0
  55. package/dist/rating.cjs +80 -0
  56. package/dist/rating.js +58 -0
  57. package/dist/select.cjs +791 -0
  58. package/dist/select.js +757 -0
  59. package/dist/separator.cjs +57 -0
  60. package/dist/separator.js +51 -0
  61. package/dist/skeleton.cjs +370 -0
  62. package/dist/skeleton.js +346 -0
  63. package/dist/slider.cjs +138 -0
  64. package/dist/slider.js +115 -0
  65. package/dist/switch.cjs +163 -0
  66. package/dist/switch.js +140 -0
  67. package/dist/table.cjs +1053 -0
  68. package/dist/table.js +1019 -0
  69. package/dist/tabs.cjs +240 -0
  70. package/dist/tabs.js +213 -0
  71. package/dist/tag.cjs +651 -0
  72. package/dist/tag.js +628 -0
  73. package/dist/textarea.cjs +65 -0
  74. package/dist/textarea.js +59 -0
  75. package/dist/toaster.cjs +99 -0
  76. package/dist/toaster.js +96 -0
  77. package/dist/tooltip.cjs +171 -0
  78. package/dist/tooltip.js +148 -0
  79. package/dist/utils.cjs +11 -0
  80. package/dist/utils.js +9 -0
  81. package/package.json +296 -0
  82. package/src/accordion.tsx +285 -0
  83. package/src/alert.tsx +221 -0
  84. package/src/avatar.tsx +174 -0
  85. package/src/badge.tsx +158 -0
  86. package/src/button.tsx +411 -0
  87. package/src/checkbox.tsx +307 -0
  88. package/src/close-button.tsx +51 -0
  89. package/src/collapsible.tsx +126 -0
  90. package/src/color-mode.tsx +37 -0
  91. package/src/dialog.tsx +356 -0
  92. package/src/drawer.tsx +186 -0
  93. package/src/empty-state.tsx +97 -0
  94. package/src/field.tsx +202 -0
  95. package/src/heading.tsx +55 -0
  96. package/src/icon-button.tsx +192 -0
  97. package/src/image.tsx +280 -0
  98. package/src/index.ts +192 -0
  99. package/src/input-group.tsx +159 -0
  100. package/src/input.tsx +60 -0
  101. package/src/link.tsx +333 -0
  102. package/src/menu.tsx +471 -0
  103. package/src/pin-input.tsx +187 -0
  104. package/src/popover.tsx +400 -0
  105. package/src/progress-circle.tsx +180 -0
  106. package/src/progress.tsx +109 -0
  107. package/src/provider.tsx +12 -0
  108. package/src/radio.tsx +175 -0
  109. package/src/rating.tsx +79 -0
  110. package/src/select.tsx +696 -0
  111. package/src/separator.tsx +59 -0
  112. package/src/skeleton.tsx +302 -0
  113. package/src/slider.tsx +152 -0
  114. package/src/switch.tsx +158 -0
  115. package/src/table.tsx +621 -0
  116. package/src/tabs.tsx +354 -0
  117. package/src/tag.tsx +159 -0
  118. package/src/textarea.tsx +60 -0
  119. package/src/toaster.tsx +117 -0
  120. package/src/tokens.css +438 -0
  121. package/src/tooltip.tsx +184 -0
  122. package/src/utils/cn.ts +7 -0
  123. package/src/utils.ts +6 -0
  124. package/tokens.css +438 -0
package/src/link.tsx ADDED
@@ -0,0 +1,333 @@
1
+ import NextLink from 'next/link';
2
+ import type { LinkProps as NextLinkProps } from 'next/link';
3
+ import React from 'react';
4
+
5
+ import { cn } from './utils';
6
+
7
+ // Inline external link arrow icon
8
+ const ArrowIcon = ({ className, style }: { readonly className?: string; readonly style?: React.CSSProperties }) => (
9
+ <svg className={ className } style={ style } viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
10
+ <path d="M11 3h6v6M17 3L7 13M14 11v6H3V6h6" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/>
11
+ </svg>
12
+ );
13
+
14
+ // Strip UTM params for privacy (standalone, no config dependency)
15
+ function stripUtmParams(url: string): string {
16
+ try {
17
+ const urlObj = new URL(url);
18
+ for (const param of [ 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content' ]) {
19
+ urlObj.searchParams.delete(param);
20
+ }
21
+ return urlObj.toString();
22
+ } catch {
23
+ return url;
24
+ }
25
+ }
26
+
27
+ import { Skeleton } from './skeleton';
28
+
29
+ type LinkVariant = 'primary' | 'secondary' | 'subtle' | 'underlaid' | 'menu' | 'navigation' | 'plain';
30
+
31
+ export interface LinkProps
32
+ extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>,
33
+ Partial<Pick<NextLinkProps, 'shallow' | 'prefetch' | 'scroll'>> {
34
+ readonly href?: string;
35
+ readonly loading?: boolean;
36
+ readonly external?: boolean;
37
+ readonly iconColor?: string;
38
+ readonly noIcon?: boolean;
39
+ readonly disabled?: boolean;
40
+ readonly variant?: LinkVariant;
41
+ readonly asChild?: boolean;
42
+ // Legacy Chakra style-prop shims
43
+ readonly fontWeight?: string | number;
44
+ readonly whiteSpace?: string;
45
+ readonly wordBreak?: string;
46
+ readonly textStyle?: string;
47
+ readonly ml?: number | string | Record<string, string | number>;
48
+ readonly mr?: number | string;
49
+ readonly display?: string;
50
+ readonly alignItems?: string;
51
+ readonly flexShrink?: number;
52
+ readonly minW?: number | string;
53
+ readonly justifyContent?: string;
54
+ readonly position?: string;
55
+ }
56
+
57
+ const VARIANT_CLASSES: Record<LinkVariant, string> = {
58
+ primary: cn(
59
+ 'text-[var(--color-link-primary)]',
60
+ 'hover:no-underline hover:text-[var(--color-link-primary-hover)]',
61
+ 'data-[hover]:no-underline data-[hover]:text-[var(--color-link-primary-hover)]',
62
+ ),
63
+ secondary: cn(
64
+ 'text-[var(--color-link-secondary)]',
65
+ 'hover:no-underline hover:text-[var(--color-hover)]',
66
+ 'data-[hover]:no-underline data-[hover]:text-[var(--color-hover)]',
67
+ ),
68
+ subtle: cn(
69
+ 'text-[var(--color-link-subtle)]',
70
+ 'hover:text-[var(--color-link-subtle-hover)] hover:underline hover:decoration-[var(--color-link-subtle-hover)]',
71
+ 'data-[hover]:text-[var(--color-link-subtle-hover)] data-[hover]:underline data-[hover]:decoration-[var(--color-link-subtle-hover)]',
72
+ ),
73
+ underlaid: cn(
74
+ 'text-[var(--color-link-primary)] bg-[var(--color-link-underlaid-bg)]',
75
+ 'px-2 py-1.5 rounded-md text-sm',
76
+ 'hover:text-[var(--color-link-primary-hover)] hover:no-underline',
77
+ 'data-[hover]:text-[var(--color-link-primary-hover)] data-[hover]:no-underline',
78
+ ),
79
+ menu: cn(
80
+ 'text-[var(--color-link-menu)]',
81
+ 'hover:text-[var(--color-hover)] hover:no-underline',
82
+ 'data-[hover]:text-[var(--color-hover)] data-[hover]:no-underline',
83
+ ),
84
+ navigation: cn(
85
+ 'text-[var(--color-link-nav-fg)] bg-transparent',
86
+ 'hover:text-[var(--color-link-nav-fg-hover)] hover:no-underline',
87
+ 'data-[hover]:text-[var(--color-link-nav-fg-hover)] data-[hover]:no-underline',
88
+ 'data-[selected]:text-[var(--color-link-nav-fg-selected)] data-[selected]:bg-[var(--color-link-nav-bg-selected)]',
89
+ 'data-[active]:text-[var(--color-link-nav-fg-active)]',
90
+ ),
91
+ plain: cn(
92
+ 'text-inherit',
93
+ 'hover:no-underline',
94
+ 'data-[hover]:no-underline',
95
+ ),
96
+ };
97
+
98
+ const BASE_CLASSES = 'inline-flex items-center gap-0 cursor-pointer data-[disabled]:cursor-not-allowed';
99
+
100
+ export const LinkExternalIcon = ({ color }: { color?: string }) => (
101
+ <ArrowIcon
102
+ className={ cn(
103
+ 'size-3 align-middle shrink-0',
104
+ 'group-hover:text-inherit',
105
+ ) }
106
+ style={ color ? { color } : { color: 'var(--color-icon-secondary)' } }
107
+ aria-hidden="true"
108
+ />
109
+ );
110
+
111
+ const splitProps = (props: LinkProps): {
112
+ own: Omit<LinkProps, 'scroll' | 'shallow' | 'prefetch'>;
113
+ next: Pick<NextLinkProps, 'href' | 'scroll' | 'shallow' | 'prefetch'>;
114
+ } => {
115
+ const { scroll = true, shallow = false, prefetch = false, ...rest } = props;
116
+
117
+ return {
118
+ own: rest,
119
+ next: {
120
+ href: (rest.href ?? '') as NextLinkProps['href'],
121
+ scroll,
122
+ shallow,
123
+ prefetch,
124
+ },
125
+ };
126
+ };
127
+
128
+ const SPACING = 4;
129
+
130
+ function resolveSpacing(v: number | string | Record<string, string | number> | undefined): string | undefined {
131
+ if (v === undefined) return undefined;
132
+ if (typeof v === 'number') return `${ v * SPACING }px`;
133
+ if (typeof v === 'string') return v;
134
+ // Responsive object - use base value
135
+ if (typeof v === 'object' && v !== null) {
136
+ const base = (v as Record<string, string | number>).base;
137
+ if (base !== undefined) return typeof base === 'number' ? `${ base * SPACING }px` : base;
138
+ const lg = (v as Record<string, string | number>).lg;
139
+ if (lg !== undefined) return typeof lg === 'number' ? `${ lg * SPACING }px` : lg;
140
+ }
141
+ return undefined;
142
+ }
143
+
144
+ export const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(
145
+ function Link(props, ref) {
146
+ const { own, next } = splitProps(props);
147
+ const {
148
+ external,
149
+ loading,
150
+ href,
151
+ children,
152
+ disabled,
153
+ noIcon,
154
+ iconColor,
155
+ variant = 'primary',
156
+ className,
157
+ asChild: _asChild,
158
+ // Strip Chakra style props
159
+ fontWeight: _fontWeight,
160
+ whiteSpace: _whiteSpace,
161
+ wordBreak: _wordBreak,
162
+ textStyle: _textStyle,
163
+ ml: _ml,
164
+ mr: _mr,
165
+ display: _display,
166
+ alignItems: _alignItems,
167
+ flexShrink: _flexShrink,
168
+ minW: _minW,
169
+ justifyContent: _justifyContent,
170
+ position: _position,
171
+ ...rest
172
+ } = own;
173
+
174
+ // Build inline style from Chakra style props
175
+ const shimStyle: React.CSSProperties = {};
176
+ if (_fontWeight !== undefined) shimStyle.fontWeight = _fontWeight;
177
+ if (_whiteSpace) shimStyle.whiteSpace = _whiteSpace as React.CSSProperties['whiteSpace'];
178
+ if (_wordBreak) shimStyle.wordBreak = _wordBreak as React.CSSProperties['wordBreak'];
179
+ if (_ml !== undefined) shimStyle.marginLeft = resolveSpacing(_ml);
180
+ if (_mr !== undefined) shimStyle.marginRight = resolveSpacing(_mr);
181
+ if (_display) shimStyle.display = _display;
182
+ if (_alignItems) shimStyle.alignItems = _alignItems;
183
+ if (_flexShrink !== undefined) shimStyle.flexShrink = _flexShrink;
184
+ if (_minW !== undefined) shimStyle.minWidth = typeof _minW === 'number' ? `${ _minW * SPACING }px` : _minW;
185
+ if (_justifyContent) shimStyle.justifyContent = _justifyContent;
186
+ if (_position) shimStyle.position = _position as React.CSSProperties['position'];
187
+
188
+ const linkClasses = cn(BASE_CLASSES, VARIANT_CLASSES[variant], className);
189
+ const linkStyle = Object.keys(shimStyle).length > 0 ? shimStyle : undefined;
190
+
191
+ if (external) {
192
+ const processedHref = typeof href === 'string' ? stripUtmParams(href) : href;
193
+
194
+ return (
195
+ <Skeleton loading={ loading } ref={ ref as React.ForwardedRef<HTMLDivElement> } asChild>
196
+ <a
197
+ href={ processedHref }
198
+ className={ cn('group', linkClasses) }
199
+ style={ linkStyle }
200
+ target="_blank"
201
+ rel="noopener noreferrer"
202
+ { ...(disabled ? { 'data-disabled': true } : {}) }
203
+ { ...rest }
204
+ >
205
+ { children }
206
+ { !noIcon && <LinkExternalIcon color={ iconColor }/> }
207
+ </a>
208
+ </Skeleton>
209
+ );
210
+ }
211
+
212
+ return (
213
+ <Skeleton loading={ loading } ref={ ref as React.ForwardedRef<HTMLDivElement> } asChild>
214
+ { next.href ? (
215
+ <NextLink
216
+ { ...next }
217
+ className={ linkClasses }
218
+ style={ linkStyle }
219
+ { ...(disabled ? { 'data-disabled': true } : {}) }
220
+ { ...rest }
221
+ >
222
+ { children }
223
+ </NextLink>
224
+ ) : (
225
+ <span
226
+ className={ linkClasses }
227
+ { ...(disabled ? { 'data-disabled': true } : {}) }
228
+ { ...rest as React.HTMLAttributes<HTMLSpanElement> }
229
+ >
230
+ { children }
231
+ </span>
232
+ ) }
233
+ </Skeleton>
234
+ );
235
+ },
236
+ );
237
+
238
+ export const LinkBox = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
239
+ function LinkBox(props, ref) {
240
+ const { className, ...rest } = props;
241
+ return (
242
+ <div
243
+ ref={ ref }
244
+ className={ cn('relative', className) }
245
+ { ...rest }
246
+ />
247
+ );
248
+ },
249
+ );
250
+
251
+ export const LinkOverlay = React.forwardRef<HTMLAnchorElement, LinkProps>(
252
+ function LinkOverlay(props, ref) {
253
+ const { own, next } = splitProps(props);
254
+ const {
255
+ children,
256
+ external,
257
+ loading,
258
+ href,
259
+ noIcon,
260
+ iconColor,
261
+ variant = 'primary',
262
+ className,
263
+ disabled,
264
+ asChild: _asChild2,
265
+ fontWeight: _fw2, whiteSpace: _ws2, wordBreak: _wb2, textStyle: _ts2,
266
+ ml: _ml2, mr: _mr2, display: _d2, alignItems: _ai2, flexShrink: _fs2,
267
+ minW: _mw2, justifyContent: _jc2, position: _p2,
268
+ ...rest
269
+ } = own;
270
+
271
+ const overlayClasses = cn(
272
+ BASE_CLASSES,
273
+ VARIANT_CLASSES[variant],
274
+ // Static positioning with a ::before pseudo-element that covers the LinkBox
275
+ 'static',
276
+ 'before:absolute before:inset-0 before:z-0 before:content-[""]',
277
+ className,
278
+ );
279
+
280
+ if (external) {
281
+ const processedHref = typeof href === 'string' ? stripUtmParams(href) : href;
282
+
283
+ return (
284
+ <a
285
+ ref={ ref }
286
+ href={ loading ? undefined : processedHref }
287
+ className={ overlayClasses }
288
+ target="_blank"
289
+ rel="noopener noreferrer"
290
+ { ...rest }
291
+ >
292
+ { (children || (!noIcon && href)) && (
293
+ <Skeleton display="inline-flex" alignItems="center" loading={ loading } maxW="100%" h="100%">
294
+ { children }
295
+ { !noIcon && href && <LinkExternalIcon color={ iconColor }/> }
296
+ </Skeleton>
297
+ ) }
298
+ </a>
299
+ );
300
+ }
301
+
302
+ const content = children ? (
303
+ <Skeleton display="inline-flex" alignItems="center" loading={ loading } maxW="100%" h="100%">
304
+ { children }
305
+ </Skeleton>
306
+ ) : null;
307
+
308
+ if (next.href) {
309
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
310
+ const anchorRest = rest as any;
311
+ return (
312
+ <NextLink
313
+ ref={ ref }
314
+ { ...next }
315
+ className={ overlayClasses }
316
+ { ...anchorRest }
317
+ >
318
+ { content }
319
+ </NextLink>
320
+ );
321
+ }
322
+
323
+ return (
324
+ <span
325
+ ref={ ref as React.ForwardedRef<HTMLDivElement> }
326
+ className={ overlayClasses }
327
+ { ...rest as React.HTMLAttributes<HTMLSpanElement> }
328
+ >
329
+ { content }
330
+ </span>
331
+ );
332
+ },
333
+ );