1- import { PropTypes , Component } from 'react'
1+ import { PropTypes } from 'react'
22import React from 'react'
33
44require ( './StandardListItemStyles.scss' )
@@ -8,39 +8,45 @@ require('./StandardListItemStyles.scss')
88 // labelText: The text for the label
99 // placeIcon: defines the position of the icon. Either: top | left | right. Default to top
1010
11- class StandardListItem extends Component {
12- constructor ( props ) {
13- super ( props )
14- }
15- render ( ) {
16- const classes = 'StandardListItem transition ' + this . props . placeIcon
17- let label
18- let icon
11+ const StandardListItem = ( { showIcon, showLabel, imgSrc, labelText, linkUrl, linkTarget= '_self' , placeIcon= 'top' } ) => {
12+ const classes = 'StandardListItem transition ' + placeIcon
13+ let label
14+ let icon
15+ let item
1916
20- if ( this . props . showLabel ) {
21- label = < p className = "label" > { this . props . labelText } </ p >
22- }
17+ if ( showLabel ) {
18+ label = < p className = "label" > { labelText } </ p >
19+ }
2320
24- if ( this . props . showIcon ) {
25- icon = < img className = "icon" src = { this . props . imgSrc } />
26- }
21+ if ( showIcon ) {
22+ icon = < img className = "icon" src = { imgSrc } />
23+ }
2724
28- return ( < div className = { classes } > { label } { icon } </ div > )
25+ if ( linkUrl ) {
26+ item =
27+ < a className = { classes } href = { linkUrl } target = { linkTarget } > { label } { icon } </ a >
28+ } else {
29+ item = < div className = { classes } > { label } { icon } </ div >
2930 }
31+
32+ return item
3033}
3134
3235StandardListItem . propTypes = {
33- showIcon : PropTypes . bool ,
34- showLabel : PropTypes . bool ,
35- imgSrc : PropTypes . string ,
36- labelText : PropTypes . node ,
37- placeIcon : PropTypes . string
36+ showIcon : PropTypes . bool ,
37+ showLabel : PropTypes . bool ,
38+ imgSrc : PropTypes . string ,
39+ labelText : PropTypes . node ,
40+ linkUrl : PropTypes . string ,
41+ linkTarget : PropTypes . string ,
42+ placeIcon : PropTypes . string
3843}
3944
4045StandardListItem . defaultProps = {
41- showIcon : true ,
42- showLabel : true ,
43- placeIcon : 'top'
46+ showIcon : true ,
47+ showLabel : true ,
48+ linkTarget : '_self' ,
49+ placeIcon : 'top'
4450}
4551
4652export default StandardListItem
0 commit comments