Last active
December 2, 2015 17:57
-
-
Save arackaf/06243a662c6db27ea2af to your computer and use it in GitHub Desktop.
Mobile/Expandable React Example With State
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookViewListMobileItem extends React.Component{ | |
constructor(){ | |
super(); | |
this.state = { expanded: false }; | |
} | |
toggle(){ | |
this.setState({ expanded: !this.state.expanded }); | |
} | |
render(){ | |
return ( | |
<a onClick={() => this.toggle()} className="list-group-item" style={{ cursor: 'pointer' }}> | |
<div className="row"> | |
<div className="col-xs-3 col-sm-1"> | |
{this.state.expanded ? <img src={this.props.smallImage} /> : null} | |
</div> | |
<div className="col-xs-9 col-sm-11"> | |
<h4 className="list-group-item-heading">{this.props.title}</h4> | |
<p className="list-group-item-text">{this.props.author || 'no author'}</p> | |
{ !this.state.expanded ? null : | |
<div> | |
{this.props.publicationDate ? <p className="list-group-item-text">{'Published ' + this.props.publicationDate}</p> : null} | |
{this.props.pages ? <p className="list-group-item-text">{this.props.pages + ' pages'}</p> : null} | |
{this.props.isbn ? <p className="list-group-item-text">{'ISBN ' + this.props.isbn}</p> : null} | |
</div> | |
} | |
</div> | |
</div> | |
</a> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment