The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
import { cn } from "@/lib/utils"
import Spinner from "@/icons/spinner"
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: "filled" | "tonal" | "text" | "destructive"
size?: "small" | "large"
loading?: boolean
"data-testid"?: string
}
export function Button({
children,
variant = "filled",
size = "small",
loading = false,
disabled = false,
className,
"data-testid": dataTestId,
...props
}: ButtonProps) {
const baseClasses =
"text-md button-text rounded-sm disabled:bg-disabled disabled:text-disabled dark:bg-action-tertiary dark:hover:bg-action-tertiary-hover dark:active:bg-action-tertiary-pressed dark:disabled:bg-disabled"
const variantClasses = {
filled: `bg-action text-action-on-primary hover:bg-action-hover active:bg-action-pressed ${
loading && "button-text-filled"
}`,
tonal:
"bg-action-secondary hover:bg-action-secondary-hover active:bg-action-secondary-pressed text-action-on-secondary",
text: "bg-primary dark:bg-primary hover:bg-action-secondary-hover active:bg-action-secondary-pressed text-primary",
destructive: `text-negative-on-primary bg-negative hover:bg-negative-hover active:bg-negative-pressed ${
loading && "button-text-filled"
}`,
}
const sizeClasses = {
small: "px-[16px] py-[8px]",
large: "px-[24px] py-[8px]",
}
return (
<button
disabled={disabled}
className={cn(
variantClasses[variant],
sizeClasses[size],
baseClasses,
className
)}
data-testid={dataTestId ?? `button-${variant}-${size}`}
{...props}
>
{loading ? <Spinner /> : children}
</button>
)
}