import { MouseEventHandler, ReactNode } from "react"; import clsx from "clsx"; import {LinkOrAhref} from "./LinkOrAhref"; import React from "react"; interface Props { className?: string; type?: "button" | "submit" | "reset" | undefined; to?: string; target?: undefined | "_blank"; disabled?: boolean; destructive?: boolean; isExternal?: boolean; onClick?: MouseEventHandler; autoFocus?: boolean; children: ReactNode; prefetch?: "intent" | "render" | "none"; } export function ButtonPrimary({ className = "", type = "button", onClick, disabled, destructive, to, target, isExternal = false, autoFocus, prefetch, children, }: Props) { const combinedClassName = clsx( className, "inline-flex items-center space-x-2 px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white focus:outline-none focus:ring-2 focus:ring-accent-300", disabled && "cursor-not-allowed opacity-75", !destructive && "bg-accent-800", destructive && "bg-red-600", !disabled && !destructive && !className && "hover:bg-accent-900 focus:ring-accent-500 hover:text-accent-100", !disabled && destructive && "hover:bg-red-700 focus:ring-red-500" ); return ( {(() => { if (!to || disabled) { return ( ); } else if (to && isExternal) { return ( {children} ); } else { return ( {children} ); } })()} ); }