Skip to content

Commit 8c9176a

Browse files
authored
Merge pull request #427 from keep-network/feat/srt-83-link-update
feat(UI)/SRT-83: General Link Review
2 parents 45c9727 + c41906b commit 8c9176a

13 files changed

Lines changed: 53 additions & 126 deletions

File tree

src/components/Button.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import React from "react"
22
import classNames from "classnames"
33
import PropTypes from "prop-types"
4+
import Link from "./Link"
45

56
const Button = ({ className, label, url, onClick }) => {
6-
const isEmail = /^([A-Za-z0-9_\-.+])+@([A-Za-z0-9_\-.])+\.([A-Za-z]{2,})$/.test(
7-
url
8-
)
9-
10-
return (
11-
<a
12-
href={isEmail ? `mailto:${url}` : url}
13-
className={classNames(["btn", className])}
14-
onClick={(e) => onClick(e)}
15-
>
7+
return url ? (
8+
<Link url={url} className={classNames(["btn", className])}>
9+
{label}
10+
</Link>
11+
) : (
12+
<button className={classNames(["btn", className])} onClick={onClick}>
1613
{label}
17-
</a>
14+
</button>
1815
)
1916
}
2017

@@ -25,4 +22,11 @@ Button.propTypes = {
2522
onClick: PropTypes.func,
2623
}
2724

25+
Button.defaultProps = {
26+
className: "",
27+
label: "",
28+
url: "",
29+
onClick: null,
30+
}
31+
2832
export default Button

src/components/FeatureCarousel.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/components/Header.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import {
1111
NavbarToggler,
1212
NavLink,
1313
} from "reactstrap"
14-
import { graphql, Link, StaticQuery } from "gatsby"
14+
import { graphql, StaticQuery } from "gatsby"
1515
import PropTypes from "prop-types"
1616

1717
import Announcement from "./Announcement"
1818
import NavScrollItem from "./NavScrollItem"
19+
import Link from "./Link"
1920
import * as Icons from "./Icons"
2021

2122
const NavItem = ({ label, url, subitems }) => {
@@ -46,7 +47,7 @@ const NavItem = ({ label, url, subitems }) => {
4647
{item.label}
4748
</NavLink>
4849
) : (
49-
<Link to={item.url} activeClassName="active">
50+
<Link url={item.url} activeClassName="active">
5051
{item.label}
5152
</Link>
5253
)}
@@ -70,7 +71,7 @@ const NavItem = ({ label, url, subitems }) => {
7071

7172
return (
7273
<li className="nav-item">
73-
<Link to={url} activeClassName="active">
74+
<Link url={url} activeClassName="active">
7475
{label}
7576
</Link>
7677
</li>
@@ -152,14 +153,14 @@ export const HeaderTemplate = ({ navItems = [] }) => {
152153
</Nav>
153154
<ul className="external_btn">
154155
<li className="nav-item">
155-
<a
156-
href="https://discordapp.com/invite/wYezN7v"
156+
<Link
157+
url="https://discordapp.com/invite/wYezN7v"
157158
target="_blank"
158159
className="discord"
159160
rel="noopener noreferrer"
160161
>
161162
<Icons.Discord />
162-
</a>
163+
</Link>
163164
<div className="hint">
164165
<Icons.Dashboard />
165166
<span>
@@ -168,13 +169,13 @@ export const HeaderTemplate = ({ navItems = [] }) => {
168169
</div>
169170
</li>
170171
<li className="nav-item">
171-
<a
172-
href="https://dashboard.keep.network/"
172+
<Link
173+
url="https://dashboard.keep.network/"
173174
className="btn btn-primary btn-small nav-item"
174175
rel="noopener noreferrer"
175176
>
176177
Launch
177-
</a>
178+
</Link>
178179
</li>
179180
</ul>
180181
</Collapse>

src/components/KeepBlog.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from "prop-types"
33
import { Row, Col } from "reactstrap"
44

55
import Button from "./Button"
6+
import Link from "./Link"
67
import Image from "./Image"
78

89
const BlogCard = ({ title, source, excerpt, date, icon, url }) => {
@@ -49,7 +50,7 @@ const KeepBlog = ({ title, body, cards, isMore = false }) => {
4950
</div>
5051
{isMore && (
5152
<div className="keep-blog-footer">
52-
<a href="https://blog.keep.network/">Read more articles</a>
53+
<Link url="https://blog.keep.network/">Read more articles</Link>
5354
</div>
5455
)}
5556
</Col>

src/components/Link.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ const Link = ({ url, children, ...props }) => {
1414

1515
const currentPageIsHome = location.pathname === withPrefix("/")
1616

17+
// Test if url is an email address
18+
if (/^([A-Za-z0-9_\-.+])+@([A-Za-z0-9_\-.])+\.([A-Za-z]{2,})$/.test(url)) {
19+
return (
20+
<a href={`mailto:${url}`} {...props}>
21+
{children}
22+
</a>
23+
)
24+
}
25+
1726
// Test if url is an external link
1827
if (/^http/.test(url)) {
1928
return (

src/components/MiniLogoWall.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from "react"
22
import PropTypes from "prop-types"
33
import { Row, Col } from "reactstrap"
4-
import { Link } from "../components"
54
import Image from "./Image"
65

76
const MiniLogoWall = ({ logos }) => {
@@ -11,13 +10,9 @@ const MiniLogoWall = ({ logos }) => {
1110
<div className="minilogo-item-text">FEATURED IN</div>
1211
{logos &&
1312
logos.map((logo, i) => (
14-
<Link
15-
url={logo.icon.url}
16-
className="minilogo-item"
17-
key={`logo-${i}`}
18-
>
13+
<div className="minilogo-item" key={`logo-${i}`}>
1914
<Image imageData={logo.icon} />
20-
</Link>
15+
</div>
2116
))}
2217
</Col>
2318
</Row>

src/components/PageSection.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ const PageSection = ({
5555

5656
PageSection.propTypes = {
5757
id: PropTypes.string,
58-
additionalClassNames: PropTypes.array,
58+
additionalClassNames: PropTypes.oneOfType([
59+
PropTypes.array,
60+
PropTypes.string,
61+
]),
5962
children: PropTypes.oneOfType([
6063
PropTypes.arrayOf(PropTypes.node),
6164
PropTypes.node,

src/components/Profile.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react"
22
import PropTypes from "prop-types"
33
import Image from "./Image"
4+
import Link from "./Link"
45
import { GithubSocial, Keybase, LinkedIn, Twitter } from "./Icons"
56

67
const getIcon = (url) => {
@@ -22,9 +23,9 @@ const SocialLink = ({ url }) => {
2223

2324
if (!!icon) {
2425
return (
25-
<a href={url} target="_blank" rel="noopener noreferrer">
26+
<Link href={url} target="_blank" rel="noopener noreferrer">
2627
{icon}
27-
</a>
28+
</Link>
2829
)
2930
}
3031

src/components/SummaryGrid.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@ const Card = ({ index, name, title, icon, url }) => {
1313
<h4>{title}</h4>
1414
</div>
1515
<div className="summary-grid-card-footer">
16-
<Button
17-
onClick={(e) => {}}
18-
url={url}
19-
label={name}
20-
className="btn-default full-width"
21-
/>
16+
<Button url={url} label={name} className="btn-default full-width" />
2217
</div>
2318
</div>
2419
)

src/components/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import PageSection from "./PageSection"
1515
import Profile from "./Profile"
1616
import SubmitButton from "./SubmitButton"
1717
import Ticker from "./Ticker"
18-
import FeatureCarousel from "./FeatureCarousel"
1918
import SummaryGrid from "./SummaryGrid"
2019
import MiniLogoWall from "./MiniLogoWall"
2120
import KeepBlog from "./KeepBlog"
@@ -39,7 +38,6 @@ export {
3938
Profile,
4039
SubmitButton,
4140
Ticker,
42-
FeatureCarousel,
4341
SummaryGrid,
4442
MiniLogoWall,
4543
KeepBlog,

0 commit comments

Comments
 (0)