82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
// * Packages
|
|
import { Link } from "@inertiajs/react";
|
|
import { CSSProperties, ReactNode } from "react";
|
|
import { VariantProps } from "class-variance-authority";
|
|
// * Components shadcn
|
|
import { Button, buttonVariants } from "@/components/ui/button";
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from "@/components/ui/tooltip";
|
|
// * Other
|
|
import { cn } from "@/lib/utils";
|
|
|
|
type ButtonVariant = VariantProps<typeof buttonVariants>["variant"];
|
|
type ButtonSize = VariantProps<typeof buttonVariants>["size"];
|
|
type ButtonType = React.ButtonHTMLAttributes<HTMLButtonElement>["type"];
|
|
|
|
type BtnOptionnalLinkWithTooltipProps = {
|
|
link?: string | null;
|
|
content: ReactNode;
|
|
tooltipContent: ReactNode;
|
|
className?: string;
|
|
type?: ButtonType;
|
|
size?: ButtonSize;
|
|
variant?: ButtonVariant;
|
|
externalLink?: boolean;
|
|
disabled?: boolean;
|
|
style?: CSSProperties;
|
|
onClick?: () => void;
|
|
};
|
|
|
|
export default function BtnOptionnalLinkWithTooltip({
|
|
link = null,
|
|
content,
|
|
tooltipContent,
|
|
className = "",
|
|
type = "button",
|
|
size = "icon",
|
|
variant = "default",
|
|
externalLink = false,
|
|
disabled = false,
|
|
style,
|
|
onClick,
|
|
...props
|
|
}: BtnOptionnalLinkWithTooltipProps) {
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant={variant}
|
|
size={size}
|
|
className={className}
|
|
type={type}
|
|
asChild={link !== null}
|
|
disabled={disabled}
|
|
onClick={onClick}
|
|
style={style}
|
|
{...props}
|
|
>
|
|
{link !== null ? (
|
|
externalLink ? (
|
|
<a
|
|
href={!disabled ? link : undefined}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className={cn({ "pointer-events-none opacity-50": disabled })}
|
|
>
|
|
{content}
|
|
</a>
|
|
) : (
|
|
<Link href={link}>{content}</Link>
|
|
)
|
|
) : (
|
|
content
|
|
)}
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{tooltipContent}</TooltipContent>
|
|
</Tooltip>
|
|
);
|
|
}
|