LinkButton.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 href={href}>
  39. <a
  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. </a>
  53. </Link>
  54. )
  55. }
  56. export default LinkButton