Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mastodon
GitHub Repository: mastodon/joinmastodon
Path: blob/main/components/LinkButton.tsx
1006 views
1
import Link, { LinkProps } from "next/link"
2
import classnames from "classnames"
3
4
type LinkButtonProps = {
5
/** Renders without border, typically on a dark, illustrated background */
6
borderless?: boolean
7
/** Button's label */
8
children: React.ReactNode
9
/** Block button, fills parent's width */
10
fullWidth?: boolean
11
/** URL, either internal or external */
12
href: string
13
/** Light background */
14
light?: boolean
15
/** Buttons size, using `b3` typically, or `b1` on `large` */
16
size: "small" | "medium" | "large"
17
/** Whether to allow a referrer to be passed */
18
allowReferrer?: boolean
19
}
20
21
/**
22
* Default CTA component, renders links in a button style.
23
*/
24
const LinkButton = ({
25
borderless,
26
children,
27
fullWidth,
28
href,
29
light,
30
size,
31
allowReferrer = false,
32
}: LinkButtonProps) => {
33
let linkAttrs: React.JSX.IntrinsicElements["a"] = {}
34
35
// check if absolute url
36
if (href.indexOf("http://") === 0 || href.indexOf("https://") === 0) {
37
linkAttrs.target = "_blank"
38
linkAttrs.rel = allowReferrer ? "noopener" : "noopener noreferrer"
39
}
40
41
return (
42
<Link
43
href={href}
44
className={classnames(
45
"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",
46
borderless ? "border-white" : "border-blurple-500",
47
fullWidth ? "w-full" : "w-max",
48
light ? "bg-white text-blurple-500" : "bg-blurple-500 text-white",
49
size === "small" && "b3 h-10",
50
size === "medium" && "b3 h-12",
51
size === "large" && "b3 md:b1 h-12 md:h-16 md:px-6"
52
)}
53
{...linkAttrs}
54
>
55
{children}
56
</Link>
57
)
58
}
59
60
export default LinkButton
61
62