import React from "react"; import Link, { LinkProps } from "next/link"; type CommonProps = { className?: string; children?: React.ReactNode; isPrimary?: boolean; isSecondary?: boolean; }; type ButtonAsButton = { as?: "button"; } & React.ButtonHTMLAttributes; type ButtonAsAnchor = { as: "a"; } & React.AnchorHTMLAttributes; type ButtonAsLink = { as: "link"; } & LinkProps; type ButtonProps = CommonProps & (ButtonAsButton | ButtonAsAnchor | ButtonAsLink); const Button: React.FC = ({ className, children, isPrimary, isSecondary, as = "button", ...props }) => { const isLink = as === "link"; const Component: React.ElementType = isLink ? Link : as; return ( {children} ); }; export default Button;