Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
feat: add cta option to <Link/>
Browse files Browse the repository at this point in the history
  • Loading branch information
CanRau committed Dec 12, 2019
1 parent 0d2b8f1 commit eef8fb4
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/components/Link.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global window */
import React from 'react'
/** @jsx jsx */
import { jsx } from 'theme-ui'
import PropTypes from 'prop-types'
import * as QS from '@gaiama/query-string'
import { Link as GatsbyLink } from 'gatsby'
Expand All @@ -13,6 +14,29 @@ if (typeof window !== `undefined`) {
window.__navigatingToLink = false
}

const Cta = props => (
<div
{...props}
sx={{
display: `inline-block`,
backgroundColor: `cta`,
fontWeight: `400`,
borderRadius: `3px`,
color: `#042f37`,
fontSize: `1.2rem`,
padding: `0.2rem 0.7rem`,
margin: `0 1rem`,
textAlign: `center`,
a: {
border: `none`,
':hover': {
background: `none`,
},
},
}}
/>
)

const Link = ({
children,
to,
Expand All @@ -21,6 +45,7 @@ const Link = ({
ext,
blank,
persistQuery,
cta,
...props
}) => {
if (persistQuery) {
Expand Down Expand Up @@ -56,7 +81,9 @@ const Link = ({
</GatsbyLink>
)

return isExt ? externalLink : internalLink
const link = isExt ? externalLink : internalLink

return !cta ? link : <Cta>{link}</Cta>
}

Link.propTypes = {
Expand All @@ -66,6 +93,7 @@ Link.propTypes = {
ext: PropTypes.bool,
blank: PropTypes.bool,
persistQuery: PropTypes.bool,
cta: PropTypes.bool,
}

Link.defaultProps = {
Expand Down

0 comments on commit eef8fb4

Please sign in to comment.