Skip to content

Commit 6b477a7

Browse files
authored
Merge pull request #170 from scientist-softserv/165-link-proptypes
165 link proptypes
2 parents bbb4b4f + 00ba8aa commit 6b477a7

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

src/components/FilesTable/FilesTable.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const FilesTable = ({ addClass, files }) => {
3434
<td className='text-center'>
3535
<Link
3636
icon='fa-download'
37+
label=''
3738
href={href}
3839
aria-label='download'
3940
/>

src/components/Link/Link.jsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,39 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
33
import PropTypes from 'prop-types'
44
import './link.css'
55

6-
const Link = ({ addClass, href, icon, label, style, ...props }) => (
7-
<a
8-
href={href}
9-
className={`link ${addClass}`}
10-
style={style}
11-
{...props}
12-
>
13-
{icon && (
14-
<FontAwesomeIcon icon={icon} className={`small ${label.length > 0 && 'me-2'}`} />
15-
)}
16-
{label}
17-
</a>
18-
)
6+
const Link = ({ addClass, href, icon, label, style, ...props }) => {
7+
return (
8+
<a
9+
href={href}
10+
className={`link ${addClass}`}
11+
style={style}
12+
{...props}
13+
>
14+
{icon && (
15+
<FontAwesomeIcon icon={icon} className={`small ${label.length && 'me-2'}`} />
16+
)}
17+
{label && label}
18+
</a>
19+
)
20+
}
1921

22+
/**
23+
* there isn't an easy way to require either the icon OR the label. there are additional packages we could install that have the
24+
* capability, but that would bloat the package unnecessarily. instead, we're requiring that the label be passed. the overwhelming
25+
* majority of instances where a link is used, will want a label anyway. however, in the event a label isn't desired, passing the
26+
* value as an empty string will satisfy prop types, while still only showing an icon.
27+
*/
2028
Link.propTypes = {
2129
addClass: PropTypes.string,
2230
href: PropTypes.string.isRequired,
2331
icon: PropTypes.string,
24-
label: PropTypes.string,
32+
label: PropTypes.string.isRequired,
2533
style: PropTypes.shape({}),
2634
}
2735

2836
Link.defaultProps = {
2937
addClass: '',
3038
icon: '',
31-
label: '',
3239
style: {},
3340
}
3441

src/components/Link/Link.stories.jsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@ const Template = (args) => <Link {...args} />
1313

1414
export const Default = Template.bind({})
1515
Default.args = {
16-
href: '',
16+
href: '/',
1717
label: 'I am a link',
1818
style: {},
1919
}
2020

2121
export const Alternate = Template.bind({})
2222
Alternate.args = {
23-
href: '',
23+
href: '/',
24+
icon: 'fa-envelope',
2425
label: 'No underline!',
2526
style: {
2627
textDecoration: 'none',
2728
color: '#AB1289',
2829
},
29-
icon: 'fa-envelope',
30+
}
31+
32+
export const NoLabel = Template.bind({})
33+
NoLabel.args = {
34+
href: '/',
35+
icon: 'fa-download',
36+
label: '',
37+
style: {},
3038
}

0 commit comments

Comments
 (0)