Skip to content

Commit 4eefaf4

Browse files
authored
Merge pull request #144 from fs-webdev/reducingDuplication
moving duplicated code to a ButtonLink component
2 parents e077bd2 + 820a6ad commit 4eefaf4

File tree

5 files changed

+32
-37
lines changed

5 files changed

+32
-37
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import { Button } from '@fs/zion-ui'
4+
5+
export default function ButtonLink({ href, ...props }) {
6+
return <Button variant="text" size="small" color="primary" href={href} {...props} />
7+
}
8+
9+
ButtonLink.propTypes = {
10+
href: PropTypes.string.isRequired,
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react'
2+
import { storiesOf } from '@storybook/react'
3+
import ButtonLink from './ButtonLink'
4+
5+
storiesOf('ButtonLink', module)
6+
.add('Link to google', () => <ButtonLink href="https://www.google.com">Google</ButtonLink>)
7+
.add('Link to github', () => <ButtonLink href="https://www.github.com">Github</ButtonLink>)

packages/react-scripts/template/src/components/example/FrontierDocsCard.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
3-
import { Button, Card, CardActions, CardContent, CardActionArea } from '@fs/zion-ui'
3+
import { Card, CardActions, CardContent, CardActionArea } from '@fs/zion-ui'
44
import { useTranslation } from 'react-i18next'
5+
import ButtonLink from '../ButtonLink'
56
import Logo from './Logo'
67

78
const FrontierDocsCard = ({ logoColor, animationDuration, handleLogoClick }) => {
@@ -31,14 +32,9 @@ const FrontierDocsCard = ({ logoColor, animationDuration, handleLogoClick }) =>
3132
</CardContent>
3233

3334
<CardActions>
34-
<Button
35-
variant="text"
36-
size="small"
37-
color="primary"
38-
href="https://www.familysearch.org/frontier/docs"
39-
>
35+
<ButtonLink href="https://www.familysearch.org/frontier/docs">
4036
{t('getting.started.docs.link', 'Frontier Docs')}
41-
</Button>
37+
</ButtonLink>
4238
</CardActions>
4339
</Card>
4440
)

packages/react-scripts/template/src/components/example/LearnReactCard.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
2-
import { Button, Card, CardMedia, CardActions, CardContent } from '@fs/zion-ui'
2+
import { Card, CardMedia, CardActions, CardContent } from '@fs/zion-ui'
3+
import ButtonLink from '../ButtonLink'
34
import ReactImage from './reactjs.jpg'
45

56
const LearnReactCard = () => (
@@ -9,22 +10,10 @@ const LearnReactCard = () => (
910
<h2>Learn React</h2>
1011
</CardContent>
1112
<CardActions>
12-
<Button
13-
variant="text"
14-
size="small"
15-
color="primary"
16-
href="https://reactjs.org/docs/getting-started.html"
17-
>
18-
React Docs
19-
</Button>
20-
<Button
21-
href="https://github.com/fs-webdev/skill-building-program/tree/master/badges-active/react"
22-
variant="text"
23-
size="small"
24-
color="primary"
25-
>
26-
Earn your Badge
27-
</Button>
13+
<ButtonLink href="https://reactjs.org/docs/getting-started.html">React Docs</ButtonLink>
14+
<ButtonLink href="https://github.com/fs-webdev/skill-building-program/tree/master/badges-active/react">
15+
Earn your badge
16+
</ButtonLink>
2817
</CardActions>
2918
</Card>
3019
)

packages/react-scripts/template/src/components/example/ZionCard.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
2-
import { Button, Card, CardMedia, CardActions, CardContent } from '@fs/zion-ui'
2+
import { Card, CardMedia, CardActions, CardContent } from '@fs/zion-ui'
3+
import ButtonLink from '../ButtonLink'
34
import ZionImage from './zion.jpg'
45

56
const ZionCard = () => (
@@ -14,17 +15,8 @@ const ZionCard = () => (
1415
<p>Zion is the place to go to find reusable components for your FamilySearch application.</p>
1516
</CardContent>
1617
<CardActions>
17-
<Button
18-
variant="text"
19-
size="small"
20-
color="primary"
21-
href="https://beta.familysearch.org/frontier/zion"
22-
>
23-
Components
24-
</Button>
25-
<Button variant="text" size="small" color="primary" href="https://github.com/fs-webdev/zion">
26-
Github
27-
</Button>
18+
<ButtonLink href="https://beta.familysearch.org/frontier/zion">Components</ButtonLink>
19+
<ButtonLink href="https://github.com/fs-webdev/zion">Github</ButtonLink>
2820
</CardActions>
2921
</Card>
3022
)

0 commit comments

Comments
 (0)