@mhome/ui 0.1.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 (53) hide show
  1. package/README.md +188 -0
  2. package/dist/index.cjs.js +9 -0
  3. package/dist/index.cjs.js.map +1 -0
  4. package/dist/index.css +2 -0
  5. package/dist/index.esm.js +9 -0
  6. package/dist/index.esm.js.map +1 -0
  7. package/package.json +54 -0
  8. package/src/common/adaptive-theme-provider.js +19 -0
  9. package/src/components/accordion.jsx +306 -0
  10. package/src/components/alert.jsx +137 -0
  11. package/src/components/app-bar.jsx +105 -0
  12. package/src/components/autocomplete.jsx +347 -0
  13. package/src/components/avatar.jsx +160 -0
  14. package/src/components/box.jsx +165 -0
  15. package/src/components/button.jsx +104 -0
  16. package/src/components/card.jsx +156 -0
  17. package/src/components/checkbox.jsx +63 -0
  18. package/src/components/chip.jsx +137 -0
  19. package/src/components/collapse.jsx +188 -0
  20. package/src/components/container.jsx +67 -0
  21. package/src/components/date-picker.jsx +528 -0
  22. package/src/components/dialog-content-text.jsx +27 -0
  23. package/src/components/dialog.jsx +584 -0
  24. package/src/components/divider.jsx +192 -0
  25. package/src/components/drawer.jsx +255 -0
  26. package/src/components/form-control-label.jsx +89 -0
  27. package/src/components/form-group.jsx +32 -0
  28. package/src/components/form-label.jsx +54 -0
  29. package/src/components/grid.jsx +135 -0
  30. package/src/components/icon-button.jsx +101 -0
  31. package/src/components/index.js +78 -0
  32. package/src/components/input-adornment.jsx +43 -0
  33. package/src/components/input-label.jsx +55 -0
  34. package/src/components/list.jsx +239 -0
  35. package/src/components/menu.jsx +370 -0
  36. package/src/components/paper.jsx +173 -0
  37. package/src/components/radio-group.jsx +76 -0
  38. package/src/components/radio.jsx +108 -0
  39. package/src/components/select.jsx +308 -0
  40. package/src/components/slider.jsx +382 -0
  41. package/src/components/stack.jsx +110 -0
  42. package/src/components/table.jsx +243 -0
  43. package/src/components/tabs.jsx +363 -0
  44. package/src/components/text-field.jsx +289 -0
  45. package/src/components/toggle-button.jsx +209 -0
  46. package/src/components/toolbar.jsx +48 -0
  47. package/src/components/tooltip.jsx +127 -0
  48. package/src/components/typography.jsx +77 -0
  49. package/src/global-state.js +29 -0
  50. package/src/index.css +110 -0
  51. package/src/index.js +6 -0
  52. package/src/lib/useMediaQuery.js +37 -0
  53. package/src/lib/utils.js +113 -0
@@ -0,0 +1,370 @@
1
+ import * as React from "react";
2
+ import { cn } from "../lib/utils";
3
+
4
+ const Menu = React.forwardRef(
5
+ (
6
+ {
7
+ className,
8
+ anchorEl,
9
+ open = false,
10
+ onClose,
11
+ PaperProps,
12
+ anchorOrigin = { vertical: "bottom", horizontal: "left" },
13
+ transformOrigin = { vertical: "top", horizontal: "left" },
14
+ children,
15
+ ...props
16
+ },
17
+ ref
18
+ ) => {
19
+ const menuRef = React.useRef(null);
20
+ const [position, setPosition] = React.useState({ top: 0, left: 0 });
21
+
22
+ React.useImperativeHandle(ref, () => menuRef.current);
23
+
24
+ // Calculate position using useLayoutEffect to ensure DOM is ready
25
+ React.useLayoutEffect(() => {
26
+ if (!open || !anchorEl) {
27
+ setPosition({ top: 0, left: 0 });
28
+ return;
29
+ }
30
+
31
+ let isMounted = true;
32
+ let rafId = null;
33
+
34
+ // Use requestAnimationFrame to ensure DOM is fully updated
35
+ rafId = requestAnimationFrame(() => {
36
+ // Check if component is still mounted before updating state
37
+ if (!isMounted) return;
38
+
39
+ try {
40
+ // Check if anchorEl is still valid and connected to DOM
41
+ if (!anchorEl || !anchorEl.getBoundingClientRect || !anchorEl.isConnected) {
42
+ if (isMounted) {
43
+ setPosition({ top: 50, left: 0 });
44
+ }
45
+ return;
46
+ }
47
+
48
+ const anchorRect = anchorEl.getBoundingClientRect();
49
+
50
+ // Validate that getBoundingClientRect returned valid values
51
+ if (!anchorRect || isNaN(anchorRect.bottom) || isNaN(anchorRect.left)) {
52
+ if (isMounted) {
53
+ setPosition({ top: 50, left: 0 });
54
+ }
55
+ return;
56
+ }
57
+
58
+ // Find the nearest positioned ancestor (position: relative, absolute, or fixed)
59
+ let container = anchorEl.parentElement;
60
+ while (container && container !== document.body && container.isConnected) {
61
+ try {
62
+ const style = window.getComputedStyle(container);
63
+ if (style.position === 'relative' || style.position === 'absolute' || style.position === 'fixed') {
64
+ break;
65
+ }
66
+ container = container.parentElement;
67
+ } catch (e) {
68
+ // If getComputedStyle fails, break the loop
69
+ break;
70
+ }
71
+ }
72
+
73
+ let containerRect = { top: 0, left: 0 };
74
+ if (container && container !== document.body && container.isConnected && container.getBoundingClientRect) {
75
+ try {
76
+ containerRect = container.getBoundingClientRect();
77
+ // Validate containerRect
78
+ if (!containerRect || isNaN(containerRect.top) || isNaN(containerRect.left)) {
79
+ containerRect = { top: 0, left: 0 };
80
+ }
81
+ } catch (e) {
82
+ containerRect = { top: 0, left: 0 };
83
+ }
84
+ }
85
+
86
+ // Calculate relative position - menu appears below the button
87
+ const relativeTop = anchorRect.bottom - containerRect.top + 8;
88
+ const relativeLeft = anchorRect.left - containerRect.left;
89
+
90
+ // Validate calculated values
91
+ if (isNaN(relativeTop) || isNaN(relativeLeft)) {
92
+ if (isMounted) {
93
+ setPosition({ top: 50, left: 0 });
94
+ }
95
+ return;
96
+ }
97
+
98
+ // Only update state if component is still mounted
99
+ if (isMounted) {
100
+ setPosition({ top: relativeTop, left: relativeLeft });
101
+ }
102
+ } catch (e) {
103
+ // Fallback position - only update if mounted
104
+ if (isMounted) {
105
+ setPosition({ top: 50, left: 0 });
106
+ }
107
+ }
108
+ });
109
+
110
+ return () => {
111
+ isMounted = false;
112
+ if (rafId !== null) {
113
+ cancelAnimationFrame(rafId);
114
+ }
115
+ };
116
+ }, [open, anchorEl]);
117
+
118
+ // Handle backdrop click
119
+ React.useEffect(() => {
120
+ if (!open) return;
121
+
122
+ const handleClickOutside = (e) => {
123
+ if (
124
+ menuRef.current &&
125
+ !menuRef.current.contains(e.target) &&
126
+ anchorEl &&
127
+ !anchorEl.contains(e.target)
128
+ ) {
129
+ if (onClose) {
130
+ onClose(e, "backdropClick");
131
+ }
132
+ }
133
+ };
134
+
135
+ const handleEscape = (e) => {
136
+ if (e.key === "Escape" && onClose) {
137
+ onClose(e, "escapeKeyDown");
138
+ }
139
+ };
140
+
141
+ // Use capture phase to catch events before they reach other elements
142
+ document.addEventListener("mousedown", handleClickOutside, true);
143
+ document.addEventListener("keydown", handleEscape, true);
144
+
145
+ return () => {
146
+ document.removeEventListener("mousedown", handleClickOutside, true);
147
+ document.removeEventListener("keydown", handleEscape, true);
148
+ };
149
+ }, [open, onClose, anchorEl]);
150
+
151
+ if (!open || !anchorEl) return null;
152
+
153
+ // Get theme mode for shadow
154
+ const isDark = document.documentElement.classList.contains('dark') ||
155
+ window.matchMedia('(prefers-color-scheme: dark)').matches;
156
+
157
+ return (
158
+ <div
159
+ ref={menuRef}
160
+ className={cn("rounded-lg shadow-lg", className)}
161
+ style={{
162
+ position: "absolute",
163
+ top: `${position.top}px`,
164
+ left: `${position.left}px`,
165
+ zIndex: 1300,
166
+ pointerEvents: "auto",
167
+ visibility: "visible",
168
+ display: "block",
169
+ opacity: 1,
170
+ backgroundColor: "hsl(var(--card))",
171
+ boxShadow: isDark
172
+ ? "0px 4px 12px rgba(0, 0, 0, 0.4), 0px 0px 0px 1px rgba(255, 255, 255, 0.1)"
173
+ : "0px 4px 12px rgba(0, 0, 0, 0.15)",
174
+ border: isDark
175
+ ? "1px solid rgba(255, 255, 255, 0.1)"
176
+ : "1px solid hsl(var(--border))",
177
+ borderRadius: PaperProps?.style?.borderRadius || "8px",
178
+ minWidth: PaperProps?.style?.minWidth || 180,
179
+ maxWidth: "calc(100vw - 32px)",
180
+ padding: "4px 0",
181
+ height: "auto",
182
+ overflow: "visible", // Ensure content is visible
183
+ ...PaperProps?.style,
184
+ ...props.style,
185
+ }}
186
+ {...Object.fromEntries(
187
+ Object.entries(props || {}).filter(([key]) => key !== "style")
188
+ )}
189
+ >
190
+ {children}
191
+ </div>
192
+ );
193
+ }
194
+ );
195
+
196
+ Menu.displayName = "Menu";
197
+
198
+ const MenuItem = React.forwardRef(
199
+ (
200
+ { className, onClick, disabled = false, sx, style, children, ...props },
201
+ ref
202
+ ) => {
203
+ const [hovered, setHovered] = React.useState(false);
204
+
205
+ // Convert sx prop to style if provided
206
+ const sxStyles = React.useMemo(() => {
207
+ if (!sx) return {};
208
+ const sxObj = typeof sx === "function" ? sx({}) : sx;
209
+ return sxObj;
210
+ }, [sx]);
211
+
212
+ // Use design tokens for consistent spacing and typography
213
+ const menuItemPadding = { x: 16, y: 12 }; // px-4 py-3 (increased from py-2)
214
+ const menuItemFontSize = "0.875rem"; // text-sm
215
+
216
+ const mergedStyle = {
217
+ display: "flex",
218
+ alignItems: "center",
219
+ minHeight: "36px", // Ensure minimum height for menu items
220
+ height: "auto", // Ensure height is auto
221
+ paddingLeft: `${menuItemPadding.x}px`,
222
+ paddingRight: `${menuItemPadding.x}px`,
223
+ paddingTop: `${menuItemPadding.y}px`,
224
+ paddingBottom: `${menuItemPadding.y}px`,
225
+ cursor: disabled ? "not-allowed" : "pointer",
226
+ fontSize: menuItemFontSize,
227
+ color: disabled
228
+ ? "#666666"
229
+ : "#000000", // Use fixed color for testing
230
+ backgroundColor:
231
+ hovered && !disabled ? "hsl(var(--accent))" : "transparent",
232
+ opacity: disabled
233
+ ? 0.5
234
+ : sxStyles.opacity !== undefined
235
+ ? sxStyles.opacity
236
+ : 1,
237
+ transition: "background-color 200ms cubic-bezier(0.4, 0, 0.2, 1)",
238
+ whiteSpace: "nowrap", // Prevent text wrapping
239
+ visibility: "visible",
240
+ textAlign: "left",
241
+ fontWeight: "normal",
242
+ width: "100%",
243
+ boxSizing: "border-box",
244
+ ...sxStyles,
245
+ ...style,
246
+ };
247
+
248
+ const handleClick = (e) => {
249
+ if (disabled) return;
250
+ if (onClick) {
251
+ onClick(e);
252
+ }
253
+ };
254
+
255
+ const handleMouseDown = (e) => {
256
+ if (disabled) return;
257
+ e.preventDefault(); // Prevent default behavior
258
+ e.stopPropagation(); // Prevent event bubbling to parent elements
259
+ };
260
+
261
+ const handleKeyDown = (e) => {
262
+ if (disabled) return;
263
+ // Support Enter and Space keys for keyboard navigation
264
+ if (e.key === "Enter" || e.key === " ") {
265
+ e.preventDefault();
266
+ e.stopPropagation();
267
+ if (onClick) {
268
+ onClick(e);
269
+ }
270
+ }
271
+ };
272
+
273
+ return (
274
+ <div
275
+ ref={ref}
276
+ role="menuitem"
277
+ tabIndex={disabled ? -1 : 0}
278
+ aria-disabled={disabled}
279
+ className={cn(
280
+ "focus:outline-none focus:bg-accent focus:text-accent-foreground",
281
+ className
282
+ )}
283
+ style={mergedStyle}
284
+ onClick={handleClick}
285
+ onMouseDown={handleMouseDown}
286
+ onKeyDown={handleKeyDown}
287
+ onMouseEnter={() => setHovered(true)}
288
+ onMouseLeave={() => setHovered(false)}
289
+ {...props}
290
+ >
291
+ {children}
292
+ </div>
293
+ );
294
+ }
295
+ );
296
+
297
+ MenuItem.displayName = "MenuItem";
298
+
299
+ const MenuItemIcon = React.forwardRef(
300
+ ({ className, style, children, ...props }, ref) => {
301
+ return (
302
+ <div
303
+ ref={ref}
304
+ className={cn("flex items-center justify-center", className)}
305
+ style={{
306
+ minWidth: "40px",
307
+ marginRight: "8px",
308
+ color: "inherit",
309
+ fontSize: "1.25rem",
310
+ ...style,
311
+ }}
312
+ {...props}
313
+ >
314
+ {children}
315
+ </div>
316
+ );
317
+ }
318
+ );
319
+ MenuItemIcon.displayName = "MenuItemIcon";
320
+
321
+ const MenuItemText = React.forwardRef(
322
+ ({ className, style, children, primary, secondary, ...props }, ref) => {
323
+ // Determine what content to display
324
+ const content = primary !== undefined ? primary : children;
325
+ const hasSecondary = secondary !== undefined && secondary !== null;
326
+
327
+ return (
328
+ <div
329
+ ref={ref}
330
+ className={cn("flex-1", className)}
331
+ style={{
332
+ fontSize: "0.875rem",
333
+ lineHeight: "1.5",
334
+ display: "flex",
335
+ alignItems: "center",
336
+ width: "100%",
337
+ textAlign: "left",
338
+ color: "#000000", // Use fixed color for testing
339
+ minHeight: "1.5em", // Ensure minimum height
340
+ boxSizing: "border-box",
341
+ ...style,
342
+ }}
343
+ {...props}
344
+ >
345
+ {hasSecondary ? (
346
+ <>
347
+ <div style={{ fontSize: "0.875rem", lineHeight: "1.5", color: "#000000", textAlign: "left", display: "block" }}>
348
+ {content}
349
+ </div>
350
+ <div
351
+ style={{
352
+ fontSize: "0.75rem",
353
+ color: "#666666",
354
+ marginTop: "2px",
355
+ display: "block",
356
+ }}
357
+ >
358
+ {secondary}
359
+ </div>
360
+ </>
361
+ ) : (
362
+ <span style={{ color: "#000000", display: "inline-block", width: "100%" }}>{content || ""}</span>
363
+ )}
364
+ </div>
365
+ );
366
+ }
367
+ );
368
+ MenuItemText.displayName = "MenuItemText";
369
+
370
+ export { Menu, MenuItem, MenuItemIcon, MenuItemText };
@@ -0,0 +1,173 @@
1
+ import * as React from "react";
2
+ import { cn, spacingToPx } from "../lib/utils";
3
+
4
+ const Paper = React.forwardRef(
5
+ (
6
+ {
7
+ className,
8
+ elevation = 0,
9
+ square = false,
10
+ variant = "elevation",
11
+ sx,
12
+ style,
13
+ children,
14
+ ...props
15
+ },
16
+ ref
17
+ ) => {
18
+ // Convert sx prop to style if provided, handling MUI spacing
19
+ const sxStyles = React.useMemo(() => {
20
+ if (!sx) return {};
21
+ const sxObj = typeof sx === "function" ? sx({}) : sx;
22
+
23
+ // Convert MUI spacing properties to CSS
24
+ const converted = { ...sxObj };
25
+
26
+ // Padding shortcuts
27
+ if (converted.p !== undefined) {
28
+ converted.padding = spacingToPx(converted.p);
29
+ delete converted.p;
30
+ }
31
+ if (converted.px !== undefined) {
32
+ converted.paddingLeft = spacingToPx(converted.px);
33
+ converted.paddingRight = spacingToPx(converted.px);
34
+ delete converted.px;
35
+ }
36
+ if (converted.py !== undefined) {
37
+ converted.paddingTop = spacingToPx(converted.py);
38
+ converted.paddingBottom = spacingToPx(converted.py);
39
+ delete converted.py;
40
+ }
41
+ if (converted.pt !== undefined) {
42
+ converted.paddingTop = spacingToPx(converted.pt);
43
+ delete converted.pt;
44
+ }
45
+ if (converted.pb !== undefined) {
46
+ converted.paddingBottom = spacingToPx(converted.pb);
47
+ delete converted.pb;
48
+ }
49
+ if (converted.pl !== undefined) {
50
+ converted.paddingLeft = spacingToPx(converted.pl);
51
+ delete converted.pl;
52
+ }
53
+ if (converted.pr !== undefined) {
54
+ converted.paddingRight = spacingToPx(converted.pr);
55
+ delete converted.pr;
56
+ }
57
+
58
+ // Margin shortcuts
59
+ if (converted.m !== undefined) {
60
+ converted.margin = spacingToPx(converted.m);
61
+ delete converted.m;
62
+ }
63
+ if (converted.mx !== undefined) {
64
+ converted.marginLeft = spacingToPx(converted.mx);
65
+ converted.marginRight = spacingToPx(converted.mx);
66
+ delete converted.mx;
67
+ }
68
+ if (converted.my !== undefined) {
69
+ converted.marginTop = spacingToPx(converted.my);
70
+ converted.marginBottom = spacingToPx(converted.my);
71
+ delete converted.my;
72
+ }
73
+ if (converted.mt !== undefined) {
74
+ converted.marginTop = spacingToPx(converted.mt);
75
+ delete converted.mt;
76
+ }
77
+ if (converted.mb !== undefined) {
78
+ converted.marginBottom = spacingToPx(converted.mb);
79
+ delete converted.mb;
80
+ }
81
+ if (converted.ml !== undefined) {
82
+ converted.marginLeft = spacingToPx(converted.ml);
83
+ delete converted.ml;
84
+ }
85
+ if (converted.mr !== undefined) {
86
+ converted.marginRight = spacingToPx(converted.mr);
87
+ delete converted.mr;
88
+ }
89
+
90
+ // Gap
91
+ if (converted.gap !== undefined) {
92
+ converted.gap = spacingToPx(converted.gap);
93
+ }
94
+
95
+ return converted;
96
+ }, [sx]);
97
+
98
+ // Get elevation shadow
99
+ const getElevationShadow = () => {
100
+ if (variant === "outlined") {
101
+ return {
102
+ boxShadow: "none",
103
+ border: "1px solid hsl(var(--border))",
104
+ };
105
+ }
106
+ // elevation variant (default) - Material Design elevation shadows
107
+ const shadows = {
108
+ 0: "none",
109
+ 1: "0px 2px 1px -1px rgba(0,0,0,0.2), 0px 1px 1px 0px rgba(0,0,0,0.14), 0px 1px 3px 0px rgba(0,0,0,0.12)",
110
+ 2: "0px 3px 1px -2px rgba(0,0,0,0.2), 0px 2px 2px 0px rgba(0,0,0,0.14), 0px 1px 5px 0px rgba(0,0,0,0.12)",
111
+ 3: "0px 3px 3px -2px rgba(0,0,0,0.2), 0px 3px 4px 0px rgba(0,0,0,0.14), 0px 1px 8px 0px rgba(0,0,0,0.12)",
112
+ 4: "0px 2px 4px -1px rgba(0,0,0,0.2), 0px 4px 5px 0px rgba(0,0,0,0.14), 0px 1px 10px 0px rgba(0,0,0,0.12)",
113
+ 5: "0px 3px 5px -1px rgba(0,0,0,0.2), 0px 5px 8px 0px rgba(0,0,0,0.14), 0px 1px 14px 0px rgba(0,0,0,0.12)",
114
+ 6: "0px 3px 5px -1px rgba(0,0,0,0.2), 0px 6px 10px 0px rgba(0,0,0,0.14), 0px 1px 18px 0px rgba(0,0,0,0.12)",
115
+ 7: "0px 4px 5px -2px rgba(0,0,0,0.2), 0px 7px 10px 1px rgba(0,0,0,0.14), 0px 2px 16px 1px rgba(0,0,0,0.12)",
116
+ 8: "0px 5px 5px -3px rgba(0,0,0,0.2), 0px 8px 10px 1px rgba(0,0,0,0.14), 0px 3px 14px 2px rgba(0,0,0,0.12)",
117
+ 9: "0px 5px 6px -3px rgba(0,0,0,0.2), 0px 9px 12px 1px rgba(0,0,0,0.14), 0px 3px 16px 2px rgba(0,0,0,0.12)",
118
+ 10: "0px 6px 6px -3px rgba(0,0,0,0.2), 0px 10px 14px 1px rgba(0,0,0,0.14), 0px 4px 18px 3px rgba(0,0,0,0.12)",
119
+ 11: "0px 6px 7px -4px rgba(0,0,0,0.2), 0px 11px 15px 1px rgba(0,0,0,0.14), 0px 4px 20px 3px rgba(0,0,0,0.12)",
120
+ 12: "0px 7px 8px -4px rgba(0,0,0,0.2), 0px 12px 17px 2px rgba(0,0,0,0.14), 0px 5px 22px 4px rgba(0,0,0,0.12)",
121
+ 13: "0px 7px 8px -4px rgba(0,0,0,0.2), 0px 13px 19px 2px rgba(0,0,0,0.14), 0px 5px 24px 4px rgba(0,0,0,0.12)",
122
+ 14: "0px 7px 9px -4px rgba(0,0,0,0.2), 0px 14px 21px 2px rgba(0,0,0,0.14), 0px 5px 26px 4px rgba(0,0,0,0.12)",
123
+ 15: "0px 8px 9px -5px rgba(0,0,0,0.2), 0px 15px 22px 2px rgba(0,0,0,0.14), 0px 6px 28px 5px rgba(0,0,0,0.12)",
124
+ 16: "0px 8px 10px -5px rgba(0,0,0,0.2), 0px 16px 24px 2px rgba(0,0,0,0.14), 0px 6px 30px 5px rgba(0,0,0,0.12)",
125
+ 17: "0px 8px 11px -5px rgba(0,0,0,0.2), 0px 17px 26px 2px rgba(0,0,0,0.14), 0px 6px 32px 5px rgba(0,0,0,0.12)",
126
+ 18: "0px 9px 11px -5px rgba(0,0,0,0.2), 0px 18px 28px 2px rgba(0,0,0,0.14), 0px 7px 34px 6px rgba(0,0,0,0.12)",
127
+ 19: "0px 9px 12px -6px rgba(0,0,0,0.2), 0px 19px 29px 2px rgba(0,0,0,0.14), 0px 7px 36px 6px rgba(0,0,0,0.12)",
128
+ 20: "0px 10px 13px -6px rgba(0,0,0,0.2), 0px 20px 31px 3px rgba(0,0,0,0.14), 0px 8px 38px 7px rgba(0,0,0,0.12)",
129
+ 21: "0px 10px 13px -6px rgba(0,0,0,0.2), 0px 21px 33px 3px rgba(0,0,0,0.14), 0px 8px 40px 7px rgba(0,0,0,0.12)",
130
+ 22: "0px 10px 14px -6px rgba(0,0,0,0.2), 0px 22px 35px 3px rgba(0,0,0,0.14), 0px 8px 42px 7px rgba(0,0,0,0.12)",
131
+ 23: "0px 11px 14px -7px rgba(0,0,0,0.2), 0px 23px 36px 3px rgba(0,0,0,0.14), 0px 9px 44px 8px rgba(0,0,0,0.12)",
132
+ 24: "0px 11px 15px -7px rgba(0,0,0,0.2), 0px 24px 38px 3px rgba(0,0,0,0.14), 0px 9px 46px 8px rgba(0,0,0,0.12)",
133
+ };
134
+ // Clamp elevation to valid range (0-24)
135
+ const clampedElevation = Math.max(0, Math.min(24, elevation));
136
+ return { boxShadow: shadows[clampedElevation] || shadows[1] };
137
+ };
138
+
139
+ // Get border color based on elevation (use shadow color as border)
140
+ const getBorderColor = () => {
141
+ // Use a subtle border color similar to shadow effect
142
+ // elevation 1 shadow: rgba(0,0,0,0.2), rgba(0,0,0,0.14), rgba(0,0,0,0.12)
143
+ // Convert to a subtle border color
144
+ return "rgba(0, 0, 0, 0.12)"; // Light gray border, similar to shadow color
145
+ };
146
+
147
+ const elevationShadow = getElevationShadow();
148
+
149
+ return (
150
+ <div
151
+ ref={ref}
152
+ className={cn(
153
+ "bg-card",
154
+ !square && "rounded-lg",
155
+ variant === "outlined" && "border border-border",
156
+ className
157
+ )}
158
+ style={{
159
+ ...elevationShadow,
160
+ ...sxStyles,
161
+ ...style,
162
+ }}
163
+ {...props}
164
+ >
165
+ {children}
166
+ </div>
167
+ );
168
+ }
169
+ );
170
+
171
+ Paper.displayName = "Paper";
172
+
173
+ export { Paper };
@@ -0,0 +1,76 @@
1
+ import * as React from "react";
2
+ import { cn } from "../lib/utils";
3
+
4
+ const RadioGroupContext = React.createContext({
5
+ value: null,
6
+ onChange: null,
7
+ name: null,
8
+ disabled: false,
9
+ });
10
+
11
+ const RadioGroup = React.forwardRef(
12
+ (
13
+ {
14
+ children,
15
+ value,
16
+ onChange,
17
+ name,
18
+ className,
19
+ sx,
20
+ style,
21
+ disabled = false,
22
+ row = false,
23
+ ...props
24
+ },
25
+ ref
26
+ ) => {
27
+ const mergedSx = React.useMemo(() => {
28
+ if (!sx) return {};
29
+ return typeof sx === "function" ? sx({}) : sx;
30
+ }, [sx]);
31
+
32
+ const handleChange = React.useCallback(
33
+ (event) => {
34
+ if (onChange && !disabled) {
35
+ onChange(event);
36
+ }
37
+ },
38
+ [onChange, disabled]
39
+ );
40
+
41
+ const contextValue = React.useMemo(
42
+ () => ({
43
+ value,
44
+ onChange: handleChange,
45
+ name: name || `radio-group-${Math.random().toString(36).substr(2, 9)}`,
46
+ disabled,
47
+ }),
48
+ [value, handleChange, name, disabled]
49
+ );
50
+
51
+ return (
52
+ <RadioGroupContext.Provider value={contextValue}>
53
+ <div
54
+ ref={ref}
55
+ className={cn(
56
+ "flex",
57
+ row ? "flex-row gap-4" : "flex-col gap-2",
58
+ disabled && "opacity-50",
59
+ className
60
+ )}
61
+ style={{
62
+ ...mergedSx,
63
+ ...style,
64
+ }}
65
+ role="radiogroup"
66
+ {...props}
67
+ >
68
+ {children}
69
+ </div>
70
+ </RadioGroupContext.Provider>
71
+ );
72
+ }
73
+ );
74
+ RadioGroup.displayName = "RadioGroup";
75
+
76
+ export { RadioGroup, RadioGroupContext };