Skip to content

Commit

Permalink
Merge pull request #1806 from hugo-agbonon/feat-cardExpander
Browse files Browse the repository at this point in the history
[Card] Expand on Click
  • Loading branch information
shaurya947 committed Oct 7, 2015
2 parents 6671f90 + a744e49 commit 58685dc
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 11 deletions.
8 changes: 8 additions & 0 deletions docs/src/app/components/pages/components/cards.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ class CardPage extends React.Component {
header: 'optional',
desc: 'Whether this card component is expandable. Can be set on any child of the Card component.',
},
{
name: 'actAsExpander',
type: 'bool',
header: 'optional',
desc: 'Whether a click on this card component expands the card. ' +
'Can be set on any child of the Card component.',
},
{
name: 'showExpandableButton',
type: 'bool',
Expand Down Expand Up @@ -114,6 +121,7 @@ class CardPage extends React.Component {
title="Title"
subtitle="Subtitle"
avatar={<Avatar style={{color:'red'}}>A</Avatar>}
actAsExpander={true}
showExpandableButton={true}>
</CardHeader>
<CardText expandable={true}>
Expand Down
1 change: 1 addition & 0 deletions docs/src/app/components/raw-code/cards-code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
title="Title"
subtitle="Subtitle"
avatar={<Avatar style={{color:'red'}}>A</Avatar>}
actAsExpander={true}
showExpandableButton={true}>
</CardHeader>
<CardText expandable={true}>
Expand Down
1 change: 1 addition & 0 deletions src/card/card-actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const CardActions = React.createClass({

propTypes: {
expandable: React.PropTypes.bool,
actAsExpander: React.PropTypes.bool,
showExpandableButton: React.PropTypes.bool,
},

Expand Down
9 changes: 1 addition & 8 deletions src/card/card-expandable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ const CardExpandable = React.createClass({
this.setState({muiTheme: newMuiTheme});
},

_onExpanding() {
if (this.props.expanded === true)
this.props.onExpanding(false);
else
this.props.onExpanding(true);
},

render() {
let styles = this.getStyles();

Expand All @@ -100,7 +93,7 @@ const CardExpandable = React.createClass({
let expandableBtn = (
<IconButton
style={mergedStyles}
onClick={this._onExpanding}>
onTouchTap={this.props.onExpanding}>
{expandable}
</IconButton>
);
Expand Down
1 change: 1 addition & 0 deletions src/card/card-header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const CardHeader = React.createClass({
subtitleStyle: React.PropTypes.object,
textStyle: React.PropTypes.object,
expandable: React.PropTypes.bool,
actAsExpander: React.PropTypes.bool,
showExpandableButton: React.PropTypes.bool,
},

Expand Down
1 change: 1 addition & 0 deletions src/card/card-media.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const CardMedia = React.createClass({
overlayContentStyle: React.PropTypes.object,
mediaStyle: React.PropTypes.object,
expandable: React.PropTypes.bool,
actAsExpander: React.PropTypes.bool,
},

getStyles() {
Expand Down
1 change: 1 addition & 0 deletions src/card/card-text.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const CardText = React.createClass({
color: React.PropTypes.string,
style: React.PropTypes.object,
expandable: React.PropTypes.bool,
actAsExpander: React.PropTypes.bool,
},

getDefaultProps() {
Expand Down
1 change: 1 addition & 0 deletions src/card/card-title.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const CardTitle = React.createClass({
subtitleColor: React.PropTypes.string,
subtitleStyle: React.PropTypes.object,
expandable: React.PropTypes.bool,
actAsExpander: React.PropTypes.bool,
showExpandableButton: React.PropTypes.bool,
},

Expand Down
11 changes: 8 additions & 3 deletions src/card/card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ const Card = React.createClass({
onExpandChange: React.PropTypes.func,
},

_onExpandable(value) {
this.setState({expanded: value});
_onExpandable() {
let newExpandedState = !(this.state.expanded === true);
this.setState({expanded: newExpandedState});
if (this.props.onExpandChange)
this.props.onExpandChange(value);
this.props.onExpandChange(newExpandedState);
},

render() {
Expand All @@ -31,6 +32,10 @@ const Card = React.createClass({
}
if (this.state.expanded === false && currentChild.props.expandable === true)
return;
if (currentChild.props.actAsExpander === true) {
currentChild.props.onTouchTap = this._onExpandable;
currentChild.props.style = this.mergeStyles({ cursor: 'pointer' }, currentChild.props.style);
}
if (currentChild.props.showExpandableButton === true) {
lastElement = React.cloneElement(currentChild, {},
currentChild.props.children,
Expand Down

0 comments on commit 58685dc

Please sign in to comment.