forked from op7418/CodePilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIconAction.tsx
More file actions
40 lines (36 loc) · 1.06 KB
/
IconAction.tsx
File metadata and controls
40 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { type ReactElement, forwardRef, type ComponentPropsWithoutRef } from "react";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
interface IconActionProps extends Omit<ComponentPropsWithoutRef<typeof Button>, "variant" | "size" | "children"> {
icon: ReactElement;
tooltip?: string;
size?: "sm" | "md";
}
export const IconAction = forwardRef<HTMLButtonElement, IconActionProps>(
function IconAction({ icon, tooltip, size = "md", className, ...props }, ref) {
const button = (
<Button
ref={ref}
variant="ghost"
size="icon"
className={cn(
size === "sm" ? "h-7 w-7" : "h-8 w-8",
className
)}
{...props}
>
{icon}
</Button>
);
if (tooltip) {
return (
<Tooltip>
<TooltipTrigger asChild>{button}</TooltipTrigger>
<TooltipContent>{tooltip}</TooltipContent>
</Tooltip>
);
}
return button;
}
);