LinkButton.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import Link from "next/link"
  2. import classnames from "classnames"
  3. type LinkButtonProps = {
  4. /** Renders without border, typically on a dark, illustrated background */
  5. borderless?: boolean
  6. /** Button's label */
  7. children: React.ReactNode
  8. /** Block button, fills parent's width */
  9. fullWidth?: boolean
  10. /** URL, either internal or external */
  11. href: string
  12. /** Light background */
  13. light?: boolean
  14. /** Buttons size, using `b3` typically, or `b1` on `large` */
  15. size: "small" | "medium" | "large"
  16. }
  17. /**
  18. * Default CTA component, renders links in a button style.
  19. */
  20. const LinkButton = ({
  21. borderless,
  22. children,
  23. fullWidth,
  24. href,
  25. light,
  26. size,
  27. }: LinkButtonProps) => {
  28. let linkAttrs: {
  29. target?: string
  30. rel?: string
  31. } = {}
  32. // check if absolute url
  33. if (href.indexOf("http://") === 0 || href.indexOf("https://") === 0) {
  34. linkAttrs.target = "_blank"
  35. linkAttrs.rel = "noopener noreferrer"
  36. }
  37. return (
  38. <Link
  39. href={href}
  40. className={classnames(
  41. "flex items-center justify-center rounded-md border-2 p-4 text-center !font-semibold transition-colors focus:outline-none hocus:border-blurple-600 hocus:bg-blurple-600 hocus:text-white",
  42. borderless ? "border-white" : "border-blurple-500",
  43. fullWidth ? "w-full" : "w-max",
  44. light ? "bg-white text-blurple-500" : "bg-blurple-500 text-white",
  45. size === "small" && "b3 h-10",
  46. size === "medium" && "b3 h-12",
  47. size === "large" && "b3 md:b1 h-12 md:h-16 md:px-6"
  48. )}
  49. {...linkAttrs}
  50. >
  51. {children}
  52. </Link>
  53. )
  54. }
  55. export default LinkButton