Skip to content

Commit a3df823

Browse files
author
vikasrohit
committed
AS#103506492417792, Support hyperlinks in StandardListItem component
-- Added support for rendering StandardListItem as hyperlink
1 parent 141a16d commit a3df823

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed
Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {PropTypes, Component } from 'react'
1+
import {PropTypes } from 'react'
22
import React from 'react'
33

44
require('./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

3235
StandardListItem.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

4045
StandardListItem.defaultProps = {
41-
showIcon: true,
42-
showLabel: true,
43-
placeIcon: 'top'
46+
showIcon : true,
47+
showLabel : true,
48+
linkTarget : '_self',
49+
placeIcon : 'top'
4450
}
4551

4652
export default StandardListItem

components/StandardListItem/StandardListItemExamples.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,26 @@ const StandardListItemExamples = () => (
1616

1717
<h1>Icon on the Right</h1>
1818

19-
<StandardListItem imgSrc="../components/Avatar/place-holder.svg" labelText="This is a test" placeIcon="right" />
19+
<StandardListItem imgSrc="../components/Avatar/place-holder.svg" labelText="This is a test" placeIcon="right" />
2020

2121
<h1>Icon Hidden</h1>
2222
<StandardListItem labelText="This is a test" showIcon={false} />
2323

2424
<h1>Label Hidden</h1>
2525
<StandardListItem imgSrc="../components/Avatar/place-holder.svg" showLabel={false} />
2626

27+
<h1>With Link In Self</h1>
28+
<StandardListItem imgSrc="../components/Avatar/place-holder.svg" labelText="Click Me" linkUrl="http://google.com" />
29+
30+
<h1>With Link In New Tab</h1>
31+
<StandardListItem imgSrc="../components/Avatar/place-holder.svg" labelText="Click Me" linkUrl="http://google.com" linkTarget="_blank" />
32+
33+
<h1>Link: Icon on the Right</h1>
34+
<StandardListItem imgSrc="../components/Avatar/place-holder.svg" labelText="This is a test" placeIcon="right" linkUrl="http://google.com" />
35+
36+
<h1>Link: Icon on the Left</h1>
37+
<StandardListItem imgSrc="../components/Avatar/place-holder.svg" labelText="This is a test" placeIcon="left" linkUrl="http://google.com" />
38+
2739
</div>
2840
)
2941

0 commit comments

Comments
 (0)