@@ -3,32 +3,39 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
3
3
import PropTypes from 'prop-types'
4
4
import './link.css'
5
5
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
+ }
19
21
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
+ */
20
28
Link . propTypes = {
21
29
addClass : PropTypes . string ,
22
30
href : PropTypes . string . isRequired ,
23
31
icon : PropTypes . string ,
24
- label : PropTypes . string ,
32
+ label : PropTypes . string . isRequired ,
25
33
style : PropTypes . shape ( { } ) ,
26
34
}
27
35
28
36
Link . defaultProps = {
29
37
addClass : '' ,
30
38
icon : '' ,
31
- label : '' ,
32
39
style : { } ,
33
40
}
34
41
0 commit comments