@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.
- package/README.md +188 -0
- package/dist/index.cjs.js +9 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.css +2 -0
- package/dist/index.esm.js +9 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +54 -0
- package/src/common/adaptive-theme-provider.js +19 -0
- package/src/components/accordion.jsx +306 -0
- package/src/components/alert.jsx +137 -0
- package/src/components/app-bar.jsx +105 -0
- package/src/components/autocomplete.jsx +347 -0
- package/src/components/avatar.jsx +160 -0
- package/src/components/box.jsx +165 -0
- package/src/components/button.jsx +104 -0
- package/src/components/card.jsx +156 -0
- package/src/components/checkbox.jsx +63 -0
- package/src/components/chip.jsx +137 -0
- package/src/components/collapse.jsx +188 -0
- package/src/components/container.jsx +67 -0
- package/src/components/date-picker.jsx +528 -0
- package/src/components/dialog-content-text.jsx +27 -0
- package/src/components/dialog.jsx +584 -0
- package/src/components/divider.jsx +192 -0
- package/src/components/drawer.jsx +255 -0
- package/src/components/form-control-label.jsx +89 -0
- package/src/components/form-group.jsx +32 -0
- package/src/components/form-label.jsx +54 -0
- package/src/components/grid.jsx +135 -0
- package/src/components/icon-button.jsx +101 -0
- package/src/components/index.js +78 -0
- package/src/components/input-adornment.jsx +43 -0
- package/src/components/input-label.jsx +55 -0
- package/src/components/list.jsx +239 -0
- package/src/components/menu.jsx +370 -0
- package/src/components/paper.jsx +173 -0
- package/src/components/radio-group.jsx +76 -0
- package/src/components/radio.jsx +108 -0
- package/src/components/select.jsx +308 -0
- package/src/components/slider.jsx +382 -0
- package/src/components/stack.jsx +110 -0
- package/src/components/table.jsx +243 -0
- package/src/components/tabs.jsx +363 -0
- package/src/components/text-field.jsx +289 -0
- package/src/components/toggle-button.jsx +209 -0
- package/src/components/toolbar.jsx +48 -0
- package/src/components/tooltip.jsx +127 -0
- package/src/components/typography.jsx +77 -0
- package/src/global-state.js +29 -0
- package/src/index.css +110 -0
- package/src/index.js +6 -0
- package/src/lib/useMediaQuery.js +37 -0
- package/src/lib/utils.js +113 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cva } from "class-variance-authority";
|
|
3
|
+
import { cn } from "../lib/utils";
|
|
4
|
+
|
|
5
|
+
const buttonVariants = cva(
|
|
6
|
+
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
11
|
+
destructive:
|
|
12
|
+
"bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
13
|
+
outline:
|
|
14
|
+
"border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
15
|
+
secondary:
|
|
16
|
+
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
17
|
+
ghost: "hover:bg-accent hover:text-accent-foreground",
|
|
18
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
19
|
+
},
|
|
20
|
+
size: {
|
|
21
|
+
default: "h-10 px-4 py-2",
|
|
22
|
+
sm: "h-9 rounded-md px-3",
|
|
23
|
+
lg: "h-11 rounded-md px-8",
|
|
24
|
+
icon: "h-10 w-10",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
defaultVariants: {
|
|
28
|
+
variant: "default",
|
|
29
|
+
size: "default",
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const Button = React.forwardRef(
|
|
35
|
+
(
|
|
36
|
+
{
|
|
37
|
+
className,
|
|
38
|
+
variant,
|
|
39
|
+
size,
|
|
40
|
+
startIcon,
|
|
41
|
+
endIcon,
|
|
42
|
+
children,
|
|
43
|
+
style,
|
|
44
|
+
color,
|
|
45
|
+
fullWidth = false,
|
|
46
|
+
disabled = false,
|
|
47
|
+
href,
|
|
48
|
+
component,
|
|
49
|
+
...props
|
|
50
|
+
},
|
|
51
|
+
ref
|
|
52
|
+
) => {
|
|
53
|
+
// Map MUI variants to shadcn variants
|
|
54
|
+
const mappedVariant =
|
|
55
|
+
variant === "outlined"
|
|
56
|
+
? "outline"
|
|
57
|
+
: variant === "contained"
|
|
58
|
+
? "default"
|
|
59
|
+
: variant === "text"
|
|
60
|
+
? "ghost"
|
|
61
|
+
: color === "error"
|
|
62
|
+
? "destructive"
|
|
63
|
+
: variant;
|
|
64
|
+
|
|
65
|
+
// Map MUI size to shadcn size
|
|
66
|
+
const mappedSize =
|
|
67
|
+
size === "small"
|
|
68
|
+
? "sm"
|
|
69
|
+
: size === "medium"
|
|
70
|
+
? "default"
|
|
71
|
+
: size === "large"
|
|
72
|
+
? "lg"
|
|
73
|
+
: size || "default";
|
|
74
|
+
|
|
75
|
+
const Component = component || (href ? "a" : "button");
|
|
76
|
+
const buttonProps = href
|
|
77
|
+
? { href, ...props }
|
|
78
|
+
: { type: "button", disabled, ...props };
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<Component
|
|
82
|
+
className={cn(
|
|
83
|
+
buttonVariants({ variant: mappedVariant, size: mappedSize }),
|
|
84
|
+
fullWidth && "w-full",
|
|
85
|
+
className
|
|
86
|
+
)}
|
|
87
|
+
ref={ref}
|
|
88
|
+
style={style}
|
|
89
|
+
{...buttonProps}
|
|
90
|
+
>
|
|
91
|
+
{startIcon && (
|
|
92
|
+
<span className="mr-2 inline-flex items-center">{startIcon}</span>
|
|
93
|
+
)}
|
|
94
|
+
{children}
|
|
95
|
+
{endIcon && (
|
|
96
|
+
<span className="ml-2 inline-flex items-center">{endIcon}</span>
|
|
97
|
+
)}
|
|
98
|
+
</Component>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
Button.displayName = "Button";
|
|
103
|
+
|
|
104
|
+
export { Button, buttonVariants };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "../lib/utils";
|
|
3
|
+
|
|
4
|
+
const Card = React.forwardRef(
|
|
5
|
+
({ className, elevation = 1, variant = "elevation", square = false, style, ...props }, ref) => {
|
|
6
|
+
// Get elevation shadow (Material Design elevation system)
|
|
7
|
+
const getElevationShadow = () => {
|
|
8
|
+
// If variant is "outlined", no shadow
|
|
9
|
+
if (variant === "outlined") {
|
|
10
|
+
return {
|
|
11
|
+
boxShadow: "none",
|
|
12
|
+
border: "1px solid hsl(var(--border))",
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// elevation variant (default)
|
|
17
|
+
const shadows = {
|
|
18
|
+
0: "none",
|
|
19
|
+
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)",
|
|
20
|
+
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)",
|
|
21
|
+
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)",
|
|
22
|
+
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)",
|
|
23
|
+
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)",
|
|
24
|
+
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)",
|
|
25
|
+
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)",
|
|
26
|
+
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)",
|
|
27
|
+
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)",
|
|
28
|
+
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)",
|
|
29
|
+
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)",
|
|
30
|
+
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)",
|
|
31
|
+
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)",
|
|
32
|
+
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)",
|
|
33
|
+
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)",
|
|
34
|
+
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)",
|
|
35
|
+
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)",
|
|
36
|
+
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)",
|
|
37
|
+
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)",
|
|
38
|
+
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)",
|
|
39
|
+
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)",
|
|
40
|
+
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)",
|
|
41
|
+
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)",
|
|
42
|
+
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)",
|
|
43
|
+
};
|
|
44
|
+
// Clamp elevation to valid range and get shadow
|
|
45
|
+
const clampedElevation = Math.max(0, Math.min(24, Math.round(elevation)));
|
|
46
|
+
return { boxShadow: shadows[clampedElevation] || shadows[1] };
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div
|
|
51
|
+
ref={ref}
|
|
52
|
+
className={cn(
|
|
53
|
+
"bg-card text-card-foreground",
|
|
54
|
+
!square && "rounded-lg",
|
|
55
|
+
variant === "outlined" ? "border" : "border",
|
|
56
|
+
elevation === 0 && variant === "elevation" && "shadow-none",
|
|
57
|
+
className
|
|
58
|
+
)}
|
|
59
|
+
style={{
|
|
60
|
+
...getElevationShadow(),
|
|
61
|
+
...style,
|
|
62
|
+
}}
|
|
63
|
+
{...props}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
Card.displayName = "Card";
|
|
69
|
+
|
|
70
|
+
const CardHeader = React.memo(
|
|
71
|
+
React.forwardRef(({ className, ...props }, ref) => (
|
|
72
|
+
<div
|
|
73
|
+
ref={ref}
|
|
74
|
+
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
|
75
|
+
{...props}
|
|
76
|
+
/>
|
|
77
|
+
))
|
|
78
|
+
);
|
|
79
|
+
CardHeader.displayName = "CardHeader";
|
|
80
|
+
|
|
81
|
+
const CardTitle = React.memo(
|
|
82
|
+
React.forwardRef(({ className, ...props }, ref) => (
|
|
83
|
+
<h3
|
|
84
|
+
ref={ref}
|
|
85
|
+
className={cn(
|
|
86
|
+
"text-2xl font-semibold leading-none tracking-tight",
|
|
87
|
+
className
|
|
88
|
+
)}
|
|
89
|
+
{...props}
|
|
90
|
+
/>
|
|
91
|
+
))
|
|
92
|
+
);
|
|
93
|
+
CardTitle.displayName = "CardTitle";
|
|
94
|
+
|
|
95
|
+
const CardDescription = React.memo(
|
|
96
|
+
React.forwardRef(({ className, ...props }, ref) => (
|
|
97
|
+
<p
|
|
98
|
+
ref={ref}
|
|
99
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
100
|
+
{...props}
|
|
101
|
+
/>
|
|
102
|
+
))
|
|
103
|
+
);
|
|
104
|
+
CardDescription.displayName = "CardDescription";
|
|
105
|
+
|
|
106
|
+
const CardContent = React.memo(
|
|
107
|
+
React.forwardRef(({ className, ...props }, ref) => {
|
|
108
|
+
return <div ref={ref} className={cn("p-6", className)} {...props} />;
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
CardContent.displayName = "CardContent";
|
|
112
|
+
|
|
113
|
+
const CardFooter = React.memo(
|
|
114
|
+
React.forwardRef(({ className, ...props }, ref) => (
|
|
115
|
+
<div
|
|
116
|
+
ref={ref}
|
|
117
|
+
className={cn("flex items-center p-6 pt-0", className)}
|
|
118
|
+
{...props}
|
|
119
|
+
/>
|
|
120
|
+
))
|
|
121
|
+
);
|
|
122
|
+
CardFooter.displayName = "CardFooter";
|
|
123
|
+
|
|
124
|
+
const CardActionArea = React.forwardRef(({ className, ...props }, ref) => {
|
|
125
|
+
return (
|
|
126
|
+
<div
|
|
127
|
+
ref={ref}
|
|
128
|
+
role="button"
|
|
129
|
+
tabIndex={0}
|
|
130
|
+
className={cn(
|
|
131
|
+
"cursor-pointer rounded-lg transition-colors hover:bg-accent focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
|
|
132
|
+
className
|
|
133
|
+
)}
|
|
134
|
+
onKeyDown={(e) => {
|
|
135
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
if (props.onClick) {
|
|
138
|
+
props.onClick(e);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}}
|
|
142
|
+
{...props}
|
|
143
|
+
/>
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
CardActionArea.displayName = "CardActionArea";
|
|
147
|
+
|
|
148
|
+
export {
|
|
149
|
+
Card,
|
|
150
|
+
CardHeader,
|
|
151
|
+
CardFooter,
|
|
152
|
+
CardTitle,
|
|
153
|
+
CardDescription,
|
|
154
|
+
CardContent,
|
|
155
|
+
CardActionArea,
|
|
156
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "../lib/utils";
|
|
3
|
+
import { Check } from "lucide-react";
|
|
4
|
+
|
|
5
|
+
const Checkbox = React.forwardRef(
|
|
6
|
+
(
|
|
7
|
+
{
|
|
8
|
+
className,
|
|
9
|
+
checked,
|
|
10
|
+
onChange,
|
|
11
|
+
disabled,
|
|
12
|
+
style,
|
|
13
|
+
"aria-label": ariaLabel,
|
|
14
|
+
"aria-labelledby": ariaLabelledBy,
|
|
15
|
+
...props
|
|
16
|
+
},
|
|
17
|
+
ref
|
|
18
|
+
) => {
|
|
19
|
+
const [hovered, setHovered] = React.useState(false);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<label
|
|
23
|
+
className={cn(
|
|
24
|
+
"relative inline-flex items-center justify-center cursor-pointer",
|
|
25
|
+
disabled && "cursor-not-allowed opacity-50",
|
|
26
|
+
className
|
|
27
|
+
)}
|
|
28
|
+
style={style}
|
|
29
|
+
>
|
|
30
|
+
<input
|
|
31
|
+
ref={ref}
|
|
32
|
+
type="checkbox"
|
|
33
|
+
checked={checked}
|
|
34
|
+
onChange={onChange}
|
|
35
|
+
disabled={disabled}
|
|
36
|
+
className="sr-only"
|
|
37
|
+
aria-label={ariaLabel}
|
|
38
|
+
aria-labelledby={ariaLabelledBy}
|
|
39
|
+
{...props}
|
|
40
|
+
/>
|
|
41
|
+
<div
|
|
42
|
+
className={cn(
|
|
43
|
+
"flex items-center justify-center transition-colors w-5 h-5 border-2 rounded",
|
|
44
|
+
checked
|
|
45
|
+
? "bg-primary border-primary"
|
|
46
|
+
: hovered && !disabled
|
|
47
|
+
? "border-primary"
|
|
48
|
+
: "border-input bg-transparent",
|
|
49
|
+
disabled && "opacity-50 cursor-not-allowed"
|
|
50
|
+
)}
|
|
51
|
+
onMouseEnter={() => !disabled && setHovered(true)}
|
|
52
|
+
onMouseLeave={() => setHovered(false)}
|
|
53
|
+
aria-hidden="true"
|
|
54
|
+
>
|
|
55
|
+
{checked && <Check size={14} className="text-primary-foreground" />}
|
|
56
|
+
</div>
|
|
57
|
+
</label>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
Checkbox.displayName = "Checkbox";
|
|
62
|
+
|
|
63
|
+
export { Checkbox };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cva } from "class-variance-authority";
|
|
3
|
+
import { cn } from "../lib/utils";
|
|
4
|
+
|
|
5
|
+
const chipVariants = cva(
|
|
6
|
+
"inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold transition-colors",
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
variant: {
|
|
10
|
+
default: "text-white",
|
|
11
|
+
secondary: "bg-secondary text-secondary-foreground",
|
|
12
|
+
outline: "border border-input bg-background hover:bg-accent",
|
|
13
|
+
outlined: "border border-input bg-background hover:bg-accent",
|
|
14
|
+
},
|
|
15
|
+
size: {
|
|
16
|
+
small: "h-6 text-xs px-2",
|
|
17
|
+
medium: "h-7 text-sm px-2.5",
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
defaultVariants: {
|
|
21
|
+
variant: "default",
|
|
22
|
+
size: "medium",
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const Chip = React.forwardRef(
|
|
28
|
+
(
|
|
29
|
+
{
|
|
30
|
+
className,
|
|
31
|
+
variant,
|
|
32
|
+
size,
|
|
33
|
+
label,
|
|
34
|
+
onClick,
|
|
35
|
+
onDelete,
|
|
36
|
+
style,
|
|
37
|
+
icon,
|
|
38
|
+
color,
|
|
39
|
+
...props
|
|
40
|
+
},
|
|
41
|
+
ref
|
|
42
|
+
) => {
|
|
43
|
+
const Component = onClick || onDelete ? "button" : "span";
|
|
44
|
+
|
|
45
|
+
// Get color classes based on color prop
|
|
46
|
+
const getColorClasses = () => {
|
|
47
|
+
if (color === "primary")
|
|
48
|
+
return "bg-primary text-primary-foreground hover:bg-primary/90";
|
|
49
|
+
if (color === "secondary")
|
|
50
|
+
return "bg-secondary text-secondary-foreground hover:bg-secondary/80";
|
|
51
|
+
if (color === "error" || color === "destructive")
|
|
52
|
+
return "bg-destructive text-destructive-foreground hover:bg-destructive/90";
|
|
53
|
+
if (color === "success")
|
|
54
|
+
return "bg-success text-success-foreground hover:bg-success/90";
|
|
55
|
+
if (color === "info")
|
|
56
|
+
return "bg-info text-info-foreground hover:bg-info/90";
|
|
57
|
+
if (color === "warning")
|
|
58
|
+
return "bg-warning text-warning-foreground hover:bg-warning/90";
|
|
59
|
+
return "bg-primary text-primary-foreground hover:bg-primary/90"; // Default
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Get border class for outlined variant
|
|
63
|
+
const getBorderClass = () => {
|
|
64
|
+
if (variant === "outlined" || variant === "outline") {
|
|
65
|
+
if (color === "primary") return "border-primary";
|
|
66
|
+
if (color === "secondary") return "border-secondary";
|
|
67
|
+
if (color === "error" || color === "destructive")
|
|
68
|
+
return "border-destructive";
|
|
69
|
+
return "border-border"; // Default border
|
|
70
|
+
}
|
|
71
|
+
return "";
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<Component
|
|
76
|
+
ref={ref}
|
|
77
|
+
className={cn(
|
|
78
|
+
chipVariants({ variant, size }),
|
|
79
|
+
variant !== "outline" && variant !== "outlined" && getColorClasses(),
|
|
80
|
+
getBorderClass(),
|
|
81
|
+
(onClick || onDelete) && "cursor-pointer",
|
|
82
|
+
className
|
|
83
|
+
)}
|
|
84
|
+
style={style}
|
|
85
|
+
onClick={onClick}
|
|
86
|
+
{...props}
|
|
87
|
+
>
|
|
88
|
+
{icon && React.isValidElement(icon) && (
|
|
89
|
+
<span
|
|
90
|
+
className="flex items-center justify-center flex-shrink-0 mr-1"
|
|
91
|
+
style={{
|
|
92
|
+
color: "inherit",
|
|
93
|
+
display: "inline-flex",
|
|
94
|
+
alignItems: "center",
|
|
95
|
+
justifyContent: "center",
|
|
96
|
+
lineHeight: 1,
|
|
97
|
+
}}
|
|
98
|
+
>
|
|
99
|
+
{React.cloneElement(icon, {
|
|
100
|
+
style: {
|
|
101
|
+
...(icon.props?.style || {}),
|
|
102
|
+
width: icon.props?.style?.width || "16px",
|
|
103
|
+
height: icon.props?.style?.height || "16px",
|
|
104
|
+
fontSize: icon.props?.style?.fontSize || "16px",
|
|
105
|
+
color: "inherit",
|
|
106
|
+
display: "inline-flex",
|
|
107
|
+
alignItems: "center",
|
|
108
|
+
justifyContent: "center",
|
|
109
|
+
},
|
|
110
|
+
sx: icon.props?.sx,
|
|
111
|
+
})}
|
|
112
|
+
</span>
|
|
113
|
+
)}
|
|
114
|
+
<span
|
|
115
|
+
className="flex items-center"
|
|
116
|
+
style={{
|
|
117
|
+
overflow: "hidden",
|
|
118
|
+
textOverflow: "ellipsis",
|
|
119
|
+
whiteSpace: "nowrap",
|
|
120
|
+
maxWidth: "100%",
|
|
121
|
+
lineHeight: 1,
|
|
122
|
+
}}
|
|
123
|
+
>
|
|
124
|
+
{label}
|
|
125
|
+
</span>
|
|
126
|
+
{onDelete && (
|
|
127
|
+
<span className="ml-1 cursor-pointer" onClick={onDelete}>
|
|
128
|
+
×
|
|
129
|
+
</span>
|
|
130
|
+
)}
|
|
131
|
+
</Component>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
Chip.displayName = "Chip";
|
|
136
|
+
|
|
137
|
+
export { Chip };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "../lib/utils";
|
|
3
|
+
|
|
4
|
+
const Collapse = React.forwardRef(
|
|
5
|
+
(
|
|
6
|
+
{
|
|
7
|
+
className,
|
|
8
|
+
style,
|
|
9
|
+
in: inProp = false,
|
|
10
|
+
timeout = "auto",
|
|
11
|
+
children,
|
|
12
|
+
unmountOnExit = false,
|
|
13
|
+
orientation = "vertical",
|
|
14
|
+
collapsedSize = "0px",
|
|
15
|
+
...props
|
|
16
|
+
},
|
|
17
|
+
ref
|
|
18
|
+
) => {
|
|
19
|
+
const [mounted, setMounted] = React.useState(inProp || !unmountOnExit);
|
|
20
|
+
const [height, setHeight] = React.useState(() => {
|
|
21
|
+
// Initial height: if expanding, use auto (for vertical) or 0px (for horizontal); if collapsing, use collapsedSize
|
|
22
|
+
// For horizontal, we'll measure the actual width in useEffect, so start with 0px
|
|
23
|
+
return inProp ? (orientation === "vertical" ? "auto" : "0px") : collapsedSize;
|
|
24
|
+
});
|
|
25
|
+
const contentRef = React.useRef(null);
|
|
26
|
+
const isInitialMount = React.useRef(true);
|
|
27
|
+
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
if (unmountOnExit) {
|
|
30
|
+
if (inProp) {
|
|
31
|
+
setMounted(true);
|
|
32
|
+
// Reset isInitialMount when component remounts
|
|
33
|
+
isInitialMount.current = true;
|
|
34
|
+
} else {
|
|
35
|
+
// Delay unmount to allow animation
|
|
36
|
+
const timer = setTimeout(() => {
|
|
37
|
+
setMounted(false);
|
|
38
|
+
}, 300);
|
|
39
|
+
return () => clearTimeout(timer);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, [inProp, unmountOnExit]);
|
|
43
|
+
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
const isVertical = orientation === "vertical";
|
|
46
|
+
|
|
47
|
+
if (!contentRef.current) {
|
|
48
|
+
// Wait for content to mount, then set initial size
|
|
49
|
+
if (inProp) {
|
|
50
|
+
// Use a small delay to ensure content is rendered
|
|
51
|
+
const timer = setTimeout(() => {
|
|
52
|
+
if (contentRef.current) {
|
|
53
|
+
const size = isVertical
|
|
54
|
+
? contentRef.current.scrollHeight
|
|
55
|
+
: contentRef.current.scrollWidth;
|
|
56
|
+
setHeight(size > 0 ? `${size}px` : (isVertical ? "auto" : "0px"));
|
|
57
|
+
}
|
|
58
|
+
}, 0);
|
|
59
|
+
return () => clearTimeout(timer);
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Skip animation on initial mount if already expanded
|
|
65
|
+
if (isInitialMount.current && inProp) {
|
|
66
|
+
isInitialMount.current = false;
|
|
67
|
+
const size = isVertical
|
|
68
|
+
? contentRef.current.scrollHeight
|
|
69
|
+
: contentRef.current.scrollWidth;
|
|
70
|
+
setHeight(size > 0 ? `${size}px` : (isVertical ? "auto" : "0px"));
|
|
71
|
+
// After a brief moment, set to auto for dynamic content (only for vertical)
|
|
72
|
+
if (isVertical) {
|
|
73
|
+
const timer = setTimeout(() => {
|
|
74
|
+
setHeight("auto");
|
|
75
|
+
}, 50);
|
|
76
|
+
return () => clearTimeout(timer);
|
|
77
|
+
}
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
isInitialMount.current = false;
|
|
81
|
+
|
|
82
|
+
const element = contentRef.current;
|
|
83
|
+
|
|
84
|
+
if (inProp) {
|
|
85
|
+
// Expanding: measure current size and animate to full size
|
|
86
|
+
const currentSize = isVertical
|
|
87
|
+
? element.scrollHeight
|
|
88
|
+
: element.scrollWidth;
|
|
89
|
+
if (currentSize > 0) {
|
|
90
|
+
setHeight(`${currentSize}px`);
|
|
91
|
+
|
|
92
|
+
// After transition, set to auto for dynamic content (only for vertical)
|
|
93
|
+
if (isVertical) {
|
|
94
|
+
const timer = setTimeout(() => {
|
|
95
|
+
setHeight("auto");
|
|
96
|
+
}, 300);
|
|
97
|
+
return () => clearTimeout(timer);
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
setHeight(isVertical ? "auto" : "0px");
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
// Collapsing: measure current size and animate to collapsed
|
|
104
|
+
const currentSize = isVertical
|
|
105
|
+
? element.scrollHeight
|
|
106
|
+
: element.scrollWidth;
|
|
107
|
+
if (currentSize > 0) {
|
|
108
|
+
setHeight(`${currentSize}px`);
|
|
109
|
+
|
|
110
|
+
// Force reflow before collapsing
|
|
111
|
+
requestAnimationFrame(() => {
|
|
112
|
+
requestAnimationFrame(() => {
|
|
113
|
+
setHeight(collapsedSize);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
} else {
|
|
117
|
+
setHeight(collapsedSize);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, [inProp, collapsedSize, orientation]);
|
|
121
|
+
|
|
122
|
+
if (unmountOnExit && !mounted) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const isVertical = orientation === "vertical";
|
|
127
|
+
|
|
128
|
+
// Determine the actual size to use for styling
|
|
129
|
+
// When collapsed (!inProp), always use collapsedSize to ensure proper hiding
|
|
130
|
+
// When expanded (inProp), use height to support animation
|
|
131
|
+
// If height is still initial value (0px) and inProp is true, use auto temporarily to show content
|
|
132
|
+
const actualSize = inProp
|
|
133
|
+
? (height === "0px" ? "auto" : height)
|
|
134
|
+
: collapsedSize;
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<div
|
|
138
|
+
ref={ref}
|
|
139
|
+
className={cn(
|
|
140
|
+
"overflow-hidden transition-all",
|
|
141
|
+
!isVertical && "inline-block",
|
|
142
|
+
className
|
|
143
|
+
)}
|
|
144
|
+
style={{
|
|
145
|
+
...(isVertical
|
|
146
|
+
? {
|
|
147
|
+
height: actualSize,
|
|
148
|
+
maxHeight: inProp ? "none" : collapsedSize,
|
|
149
|
+
}
|
|
150
|
+
: {
|
|
151
|
+
width: actualSize,
|
|
152
|
+
maxWidth: inProp ? "none" : collapsedSize,
|
|
153
|
+
minWidth: 0,
|
|
154
|
+
}),
|
|
155
|
+
transitionDuration:
|
|
156
|
+
timeout === "auto"
|
|
157
|
+
? "300ms"
|
|
158
|
+
: typeof timeout === "number"
|
|
159
|
+
? `${timeout}ms`
|
|
160
|
+
: "300ms",
|
|
161
|
+
transitionTimingFunction: "ease-in-out",
|
|
162
|
+
...style,
|
|
163
|
+
}}
|
|
164
|
+
{...props}
|
|
165
|
+
>
|
|
166
|
+
<div
|
|
167
|
+
ref={contentRef}
|
|
168
|
+
style={
|
|
169
|
+
!isVertical
|
|
170
|
+
? {
|
|
171
|
+
whiteSpace: "nowrap",
|
|
172
|
+
display: "inline-block",
|
|
173
|
+
width: "fit-content",
|
|
174
|
+
minWidth: "fit-content",
|
|
175
|
+
}
|
|
176
|
+
: undefined
|
|
177
|
+
}
|
|
178
|
+
>
|
|
179
|
+
{children}
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
Collapse.displayName = "Collapse";
|
|
187
|
+
|
|
188
|
+
export { Collapse };
|