@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,192 @@
1
+ import { cva } from 'class-variance-authority';
2
+ import React from 'react';
3
+
4
+ import { cn } from './utils';
5
+
6
+ import { Skeleton } from './skeleton';
7
+
8
+ /* -------------------------------------------------------------------------- */
9
+ /* CVA variant definitions */
10
+ /* -------------------------------------------------------------------------- */
11
+
12
+ const iconButtonVariants = cva(
13
+ // base
14
+ [
15
+ 'inline-flex items-center justify-center',
16
+ 'p-0 min-w-auto shrink-0',
17
+ 'cursor-pointer border-0 bg-transparent',
18
+ 'disabled:opacity-[var(--opacity-control-disabled,0.4)] disabled:cursor-not-allowed',
19
+ ],
20
+ {
21
+ variants: {
22
+ variant: {
23
+ plain: 'bg-transparent text-inherit border-none hover:bg-transparent',
24
+ icon_secondary: [
25
+ 'bg-transparent text-icon-secondary border-none',
26
+ 'hover:text-hover',
27
+ 'data-[selected]:bg-selected-control-bg data-[selected]:text-selected-control-text',
28
+ 'data-[selected]:hover:text-hover',
29
+ 'data-[expanded]:text-hover',
30
+ ],
31
+ icon_background: [
32
+ 'bg-[var(--color-button-icon-background-bg)] text-icon-secondary border-none',
33
+ 'hover:text-hover',
34
+ 'data-[selected]:bg-selected-control-bg data-[selected]:text-selected-control-text',
35
+ 'data-[selected]:hover:text-hover',
36
+ 'data-[expanded]:text-hover',
37
+ ],
38
+ link: [
39
+ 'bg-transparent text-link-primary border-none font-normal px-0 h-auto',
40
+ 'hover:bg-transparent hover:text-link-primary-hover',
41
+ 'disabled:text-text-secondary',
42
+ ],
43
+ dropdown: [
44
+ 'border-2 border-solid bg-transparent',
45
+ 'text-[var(--color-button-dropdown-fg)] border-[var(--color-button-dropdown-border)]',
46
+ 'hover:bg-transparent hover:text-hover hover:border-hover',
47
+ 'data-[expanded]:bg-transparent data-[expanded]:text-hover data-[expanded]:border-hover',
48
+ 'data-[selected]:bg-selected-control-bg data-[selected]:text-selected-control-text data-[selected]:border-transparent',
49
+ 'data-[selected]:hover:text-hover',
50
+ ],
51
+ pagination: [
52
+ 'border-2 border-solid bg-transparent',
53
+ 'text-[var(--color-button-pagination-fg)] border-[var(--color-button-pagination-border)]',
54
+ 'hover:bg-transparent hover:text-hover hover:border-hover',
55
+ 'data-[selected]:bg-selected-control-bg data-[selected]:text-selected-control-text data-[selected]:border-transparent',
56
+ ],
57
+ },
58
+ size: {
59
+ '2xs': 'size-5 rounded-sm [&_svg]:size-5',
60
+ '2xs_alt': 'size-5 rounded-sm [&_svg]:size-3',
61
+ md: 'size-8 rounded-[var(--radius-base,8px)] [&_svg]:size-5',
62
+ },
63
+ },
64
+ defaultVariants: {
65
+ variant: 'plain',
66
+ },
67
+ },
68
+ );
69
+
70
+ /* -------------------------------------------------------------------------- */
71
+ /* Types */
72
+ /* -------------------------------------------------------------------------- */
73
+
74
+ type Variant = 'plain' | 'icon_secondary' | 'icon_background' | 'link' | 'dropdown' | 'pagination';
75
+ type Size = '2xs' | '2xs_alt' | 'md';
76
+
77
+ export interface IconButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
78
+
79
+ /** Visual variant */
80
+ variant?: Variant;
81
+
82
+ /** Icon-button size */
83
+ size?: Size;
84
+
85
+ /** Show a loading spinner (disables button) */
86
+ loading?: boolean;
87
+
88
+ /** Render a skeleton placeholder instead of the button */
89
+ loadingSkeleton?: boolean;
90
+
91
+ /** Maps to data-expanded for popover trigger styling */
92
+ expanded?: boolean;
93
+
94
+ /** Maps to data-selected for toggle styling */
95
+ selected?: boolean;
96
+
97
+ /** Maps to data-highlighted */
98
+ highlighted?: boolean;
99
+
100
+ /** Polymorphic element type (e.g. "div") */
101
+ as?: React.ElementType;
102
+
103
+ // Legacy Chakra style-prop shims
104
+ boxSize?: number | string;
105
+ color?: string;
106
+ px?: string | number;
107
+ borderRadius?: string;
108
+ ml?: number | string;
109
+ mr?: number | string;
110
+ _hover?: Record<string, string>;
111
+ _expanded?: Record<string, string>;
112
+ }
113
+
114
+ /* -------------------------------------------------------------------------- */
115
+ /* Component */
116
+ /* -------------------------------------------------------------------------- */
117
+
118
+ export const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(
119
+ function IconButton(props, ref) {
120
+ const {
121
+ size,
122
+ variant = 'plain',
123
+ loading,
124
+ loadingSkeleton = false,
125
+ expanded,
126
+ selected,
127
+ highlighted,
128
+ disabled,
129
+ className,
130
+ children,
131
+ as: Comp = 'button',
132
+ style: styleProp,
133
+ // Strip Chakra style props
134
+ boxSize: _boxSize,
135
+ color: _color,
136
+ px: _px,
137
+ borderRadius: _borderRadius,
138
+ ml: _ml,
139
+ mr: _mr,
140
+ _hover,
141
+ _expanded,
142
+ ...rest
143
+ } = props;
144
+
145
+ const SP = 4;
146
+ const shimStyle: React.CSSProperties = { ...styleProp };
147
+ if (_boxSize !== undefined) {
148
+ const bs = typeof _boxSize === 'number' ? `${ _boxSize * SP }px` : _boxSize;
149
+ shimStyle.width = bs;
150
+ shimStyle.height = bs;
151
+ }
152
+ if (_color) shimStyle.color = _color;
153
+ if (_px !== undefined) {
154
+ const v = typeof _px === 'number' ? `${ _px * SP }px` : _px;
155
+ shimStyle.paddingLeft = v;
156
+ shimStyle.paddingRight = v;
157
+ }
158
+ if (_borderRadius) shimStyle.borderRadius = _borderRadius;
159
+ if (_ml !== undefined) shimStyle.marginLeft = typeof _ml === 'number' ? `${ _ml * SP }px` : _ml;
160
+ if (_mr !== undefined) shimStyle.marginRight = typeof _mr === 'number' ? `${ _mr * SP }px` : _mr;
161
+ const mergedBtnStyle = Object.keys(shimStyle).length > 0 ? shimStyle : undefined;
162
+
163
+ const button = (
164
+ <Comp
165
+ ref={ ref }
166
+ type={ Comp === 'button' ? 'button' : undefined }
167
+ disabled={ !loadingSkeleton && (loading || disabled) }
168
+ className={ cn(iconButtonVariants({ variant, size }), className) }
169
+ style={ mergedBtnStyle }
170
+ { ...(expanded ? { 'data-expanded': true } : {}) }
171
+ { ...(selected ? { 'data-selected': true } : {}) }
172
+ { ...(highlighted ? { 'data-highlighted': true } : {}) }
173
+ { ...(loadingSkeleton ? { 'data-loading-skeleton': true } : {}) }
174
+ { ...rest }
175
+ >
176
+ { loading ? (
177
+ <span className="inline-block size-5 animate-spin rounded-full border-2 border-current border-b-transparent border-l-transparent"/>
178
+ ) : children }
179
+ </Comp>
180
+ );
181
+
182
+ if (loadingSkeleton) {
183
+ return (
184
+ <Skeleton loading={ loadingSkeleton } asChild ref={ ref as React.ForwardedRef<HTMLDivElement> }>
185
+ { button }
186
+ </Skeleton>
187
+ );
188
+ }
189
+
190
+ return button;
191
+ },
192
+ );
package/src/image.tsx ADDED
@@ -0,0 +1,280 @@
1
+ import React from 'react';
2
+
3
+ import { cn } from './utils';
4
+
5
+ import type { SkeletonProps } from './skeleton';
6
+ import { Skeleton } from './skeleton';
7
+
8
+ type CSSValue = string | number | undefined;
9
+ type ResponsiveValue<T> = T | { base?: T; sm?: T; md?: T; lg?: T; xl?: T; _light?: T; _dark?: T };
10
+
11
+ // Style props accepted for backward compatibility with Chakra callers.
12
+ // These are converted to inline styles on the <img> element.
13
+ interface StyleProps {
14
+ boxSize?: CSSValue;
15
+ borderRadius?: CSSValue;
16
+ width?: CSSValue;
17
+ w?: ResponsiveValue<CSSValue>;
18
+ height?: CSSValue;
19
+ h?: ResponsiveValue<CSSValue>;
20
+ maxW?: CSSValue;
21
+ maxH?: CSSValue;
22
+ minW?: CSSValue;
23
+ mr?: CSSValue;
24
+ mb?: CSSValue;
25
+ ml?: CSSValue;
26
+ mt?: CSSValue;
27
+ mx?: CSSValue;
28
+ my?: CSSValue;
29
+ marginRight?: CSSValue;
30
+ display?: CSSValue;
31
+ position?: CSSValue;
32
+ top?: CSSValue;
33
+ left?: ResponsiveValue<CSSValue>;
34
+ right?: CSSValue;
35
+ bottom?: CSSValue;
36
+ zIndex?: CSSValue;
37
+ objectFit?: CSSValue;
38
+ objectPosition?: CSSValue;
39
+ flexShrink?: CSSValue;
40
+ overflow?: CSSValue;
41
+ cursor?: CSSValue;
42
+ }
43
+
44
+ export interface ImageProps extends StyleProps {
45
+ readonly className?: string;
46
+ readonly src?: string;
47
+ readonly alt?: string;
48
+ readonly style?: React.CSSProperties;
49
+ readonly fallback?: React.ReactNode;
50
+ readonly onClick?: React.MouseEventHandler<HTMLImageElement>;
51
+ readonly onLoad?: React.ReactEventHandler<HTMLImageElement>;
52
+ readonly onError?: React.ReactEventHandler<HTMLImageElement>;
53
+ // for the case where the image dimensions are not known before the image is loaded
54
+ readonly skeletonWidth?: CSSValue;
55
+ readonly skeletonHeight?: CSSValue;
56
+ }
57
+
58
+ const CHAKRA_SPACING_SCALE: Record<string, string> = {
59
+ '0': '0px',
60
+ '1': '0.25rem',
61
+ '2': '0.5rem',
62
+ '3': '0.75rem',
63
+ '4': '1rem',
64
+ '5': '1.25rem',
65
+ '6': '1.5rem',
66
+ '7': '1.75rem',
67
+ '8': '2rem',
68
+ '10': '2.5rem',
69
+ '12': '3rem',
70
+ '14': '3.5rem',
71
+ '16': '4rem',
72
+ '20': '5rem',
73
+ };
74
+
75
+ const CHAKRA_RADII: Record<string, string> = {
76
+ none: '0',
77
+ sm: '0.125rem',
78
+ base: '0.25rem',
79
+ md: '0.375rem',
80
+ lg: '0.5rem',
81
+ xl: '0.75rem',
82
+ '2xl': '1rem',
83
+ '3xl': '1.5rem',
84
+ full: '9999px',
85
+ };
86
+
87
+ function resolveSize(value: CSSValue): string | undefined {
88
+ if (value === undefined) return undefined;
89
+ if (typeof value === 'number') return `${ value }px`;
90
+ if (CHAKRA_SPACING_SCALE[value]) return CHAKRA_SPACING_SCALE[value];
91
+ return value;
92
+ }
93
+
94
+ function resolveRadius(value: CSSValue): string | undefined {
95
+ if (value === undefined) return undefined;
96
+ if (typeof value === 'number') return `${ value }px`;
97
+ if (CHAKRA_RADII[value as string]) return CHAKRA_RADII[value as string];
98
+ return String(value);
99
+ }
100
+
101
+ function resolveSimple(value: CSSValue): string | number | undefined {
102
+ if (value === undefined) return undefined;
103
+ return typeof value === 'number' ? value : value;
104
+ }
105
+
106
+ // Extract the "base" value from a responsive value or plain value
107
+ function baseValue<T>(val: ResponsiveValue<T> | undefined): T | undefined {
108
+ if (val === undefined) return undefined;
109
+ if (typeof val === 'object' && val !== null && ('base' in val || 'md' in val || 'lg' in val)) {
110
+ return (val as { base?: T }).base;
111
+ }
112
+ return val as T;
113
+ }
114
+
115
+ function buildStyle(props: StyleProps): React.CSSProperties {
116
+ const s: React.CSSProperties = {};
117
+
118
+ const size = resolveSize(props.boxSize);
119
+ if (size) {
120
+ s.width = size;
121
+ s.height = size;
122
+ }
123
+
124
+ const w = resolveSize(props.width ?? baseValue(props.w) as CSSValue);
125
+ if (w) s.width = w;
126
+
127
+ const hVal = baseValue(props.height ?? props.h);
128
+ const h = resolveSize(hVal);
129
+ if (h) s.height = h;
130
+
131
+ const maxW = resolveSize(props.maxW);
132
+ if (maxW) s.maxWidth = maxW;
133
+
134
+ const maxH = resolveSize(props.maxH);
135
+ if (maxH) s.maxHeight = maxH;
136
+
137
+ const minW = resolveSize(props.minW);
138
+ if (minW) s.minWidth = minW;
139
+
140
+ const br = resolveRadius(props.borderRadius);
141
+ if (br) s.borderRadius = br;
142
+
143
+ const mr = resolveSize(props.marginRight ?? props.mr);
144
+ if (mr) s.marginRight = mr;
145
+
146
+ const ml = resolveSize(props.ml);
147
+ if (ml) s.marginLeft = ml;
148
+
149
+ const mt = resolveSize(props.mt);
150
+ if (mt) s.marginTop = mt;
151
+
152
+ const mb = resolveSize(props.mb);
153
+ if (mb) s.marginBottom = mb;
154
+
155
+ const mx = resolveSize(props.mx);
156
+ if (mx) {
157
+ s.marginLeft = mx; s.marginRight = mx;
158
+ }
159
+
160
+ const my = resolveSize(props.my);
161
+ if (my) {
162
+ s.marginTop = my; s.marginBottom = my;
163
+ }
164
+
165
+ if (props.display !== undefined) s.display = String(props.display) as React.CSSProperties['display'];
166
+ if (props.position !== undefined) s.position = String(props.position) as React.CSSProperties['position'];
167
+
168
+ const top = resolveSimple(props.top);
169
+ if (top !== undefined) s.top = typeof top === 'number' ? `${ top }px` : top;
170
+
171
+ const leftVal = baseValue(props.left);
172
+ const left = resolveSimple(leftVal);
173
+ if (left !== undefined) s.left = typeof left === 'number' ? `${ left }px` : left;
174
+
175
+ const right = resolveSimple(props.right);
176
+ if (right !== undefined) s.right = typeof right === 'number' ? `${ right }px` : right;
177
+
178
+ const bottom = resolveSimple(props.bottom);
179
+ if (bottom !== undefined) s.bottom = typeof bottom === 'number' ? `${ bottom }px` : bottom;
180
+
181
+ if (props.zIndex !== undefined) s.zIndex = typeof props.zIndex === 'number' ? props.zIndex : Number(props.zIndex) || undefined;
182
+ if (props.objectFit !== undefined) s.objectFit = String(props.objectFit) as React.CSSProperties['objectFit'];
183
+ if (props.objectPosition !== undefined) s.objectPosition = String(props.objectPosition);
184
+ if (props.flexShrink !== undefined) s.flexShrink = typeof props.flexShrink === 'number' ? props.flexShrink : Number(props.flexShrink);
185
+ if (props.overflow !== undefined) s.overflow = String(props.overflow) as React.CSSProperties['overflow'];
186
+
187
+ return s;
188
+ }
189
+
190
+ // Keys that are style props and should NOT be forwarded to the <img> element
191
+ const STYLE_PROP_KEYS = new Set<string>([
192
+ 'boxSize', 'borderRadius', 'width', 'w', 'height', 'h',
193
+ 'maxW', 'maxH', 'minW',
194
+ 'mr', 'mb', 'ml', 'mt', 'mx', 'my', 'marginRight',
195
+ 'display', 'position', 'top', 'left', 'right', 'bottom',
196
+ 'zIndex', 'objectFit', 'objectPosition', 'flexShrink', 'overflow',
197
+ ]);
198
+
199
+ function extractStyleProps(props: Record<string, unknown>): { styleProps: StyleProps; rest: Record<string, unknown> } {
200
+ const styleProps: Record<string, unknown> = {};
201
+ const rest: Record<string, unknown> = {};
202
+
203
+ for (const key in props) {
204
+ if (STYLE_PROP_KEYS.has(key)) {
205
+ styleProps[key] = props[key];
206
+ } else {
207
+ rest[key] = props[key];
208
+ }
209
+ }
210
+
211
+ return { styleProps: styleProps as StyleProps, rest };
212
+ }
213
+
214
+ export const Image = React.forwardRef<HTMLImageElement, ImageProps>(
215
+ function Image(props, ref) {
216
+ const { fallback, src, onLoad, onError, skeletonWidth, skeletonHeight, alt, className, style: styleProp, ...allRest } = props;
217
+
218
+ const { styleProps, rest: extraProps } = extractStyleProps(allRest as Record<string, unknown>);
219
+
220
+ const [ loading, setLoading ] = React.useState(true);
221
+ const [ error, setError ] = React.useState(false);
222
+
223
+ const handleLoadError = React.useCallback((event: React.SyntheticEvent<HTMLImageElement>) => {
224
+ setError(true);
225
+ setLoading(false);
226
+ onError?.(event);
227
+ }, [ onError ]);
228
+
229
+ const handleLoadSuccess = React.useCallback((event: React.SyntheticEvent<HTMLImageElement>) => {
230
+ setLoading(false);
231
+ onLoad?.(event);
232
+ }, [ onLoad ]);
233
+
234
+ // For fallback rendering, pass through all original style props so Chakra-based fallbacks still work
235
+ const passthroughProps = allRest;
236
+
237
+ if (!src && fallback) {
238
+ if (React.isValidElement(fallback)) {
239
+ return React.cloneElement(fallback, passthroughProps);
240
+ }
241
+ return fallback;
242
+ }
243
+
244
+ if (error) {
245
+ if (React.isValidElement(fallback)) {
246
+ return React.cloneElement(fallback, passthroughProps);
247
+ }
248
+ return fallback;
249
+ }
250
+
251
+ const skeletonProps = {
252
+ ...passthroughProps,
253
+ ...(skeletonWidth !== undefined && { width: skeletonWidth }),
254
+ ...(skeletonHeight !== undefined && { height: skeletonHeight }),
255
+ };
256
+
257
+ const computedStyle = buildStyle(styleProps);
258
+ const mergedStyle: React.CSSProperties = {
259
+ ...computedStyle,
260
+ ...styleProp,
261
+ display: loading ? 'none' : (computedStyle.display || styleProp?.display || 'block'),
262
+ };
263
+
264
+ return (
265
+ <>
266
+ { loading && <Skeleton loading { ...skeletonProps as Partial<SkeletonProps> }/> }
267
+ <img
268
+ ref={ ref }
269
+ src={ src }
270
+ alt={ alt || '' }
271
+ onError={ handleLoadError }
272
+ onLoad={ handleLoadSuccess }
273
+ className={ cn(className) }
274
+ style={ mergedStyle }
275
+ { ...extraProps }
276
+ />
277
+ </>
278
+ );
279
+ },
280
+ );