- Updated translation utility to improve consistency and reduce redundancy. - Removed deprecated useTrans hook and related code. - Introduced a new Zustand store for managing translations and locale settings. - Cleaned up unused hooks and files related to localization.
85 lines
2 KiB
TypeScript
85 lines
2 KiB
TypeScript
import { Link } from "@inertiajs/react";
|
|
import { type VariantProps } from "class-variance-authority";
|
|
import {
|
|
type ButtonHTMLAttributes,
|
|
type CSSProperties,
|
|
type MouseEventHandler,
|
|
type ReactNode,
|
|
} from "react";
|
|
|
|
import { Button, type buttonVariants } from "@/components/ui/button";
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from "@/components/ui/tooltip";
|
|
|
|
type ButtonVariant = VariantProps<typeof buttonVariants>["variant"];
|
|
type ButtonSize = VariantProps<typeof buttonVariants>["size"];
|
|
type ButtonType = ButtonHTMLAttributes<HTMLButtonElement>["type"];
|
|
|
|
interface BtnOptionnalLinkWithTooltipProps {
|
|
link?: string | null;
|
|
content: ReactNode;
|
|
tooltipContent: ReactNode;
|
|
className?: string;
|
|
type?: ButtonType;
|
|
size?: ButtonSize;
|
|
variant?: ButtonVariant;
|
|
externalLink?: boolean;
|
|
disabled?: boolean;
|
|
style?: CSSProperties;
|
|
onClick?: MouseEventHandler<HTMLButtonElement>;
|
|
}
|
|
|
|
export default function BtnOptionnalLinkWithTooltip({
|
|
link = null,
|
|
content,
|
|
tooltipContent,
|
|
className = "",
|
|
type = "button",
|
|
size = "icon",
|
|
variant = "default",
|
|
externalLink = false,
|
|
disabled = false,
|
|
style,
|
|
onClick,
|
|
...props
|
|
}: Readonly<BtnOptionnalLinkWithTooltipProps>) {
|
|
let innerContent: ReactNode = content;
|
|
|
|
if (link !== null) {
|
|
if (externalLink) {
|
|
innerContent = disabled ? (
|
|
<Button disabled>{content}</Button>
|
|
) : (
|
|
<a href={link} target="_blank" rel="noreferrer">
|
|
{content}
|
|
</a>
|
|
);
|
|
} else {
|
|
innerContent = <Link href={link}>{content}</Link>;
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button
|
|
variant={variant}
|
|
size={size}
|
|
className={className}
|
|
type={type}
|
|
asChild={link !== null}
|
|
disabled={disabled}
|
|
onClick={onClick}
|
|
style={style}
|
|
{...props}
|
|
>
|
|
{innerContent}
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>{tooltipContent}</TooltipContent>
|
|
</Tooltip>
|
|
);
|
|
}
|