Created
August 1, 2018 20:17
-
-
Save grantglidewell/829489093e0abf71f5b3a77d96332158 to your computer and use it in GitHub Desktop.
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
export class CollapsibleCard extends Component { | |
static defaultProps = { | |
isCollapsed: false, | |
header: 'Header Required', | |
body: 'body required', | |
footer: '' | |
} | |
state = { | |
isCollapsed: false | |
} | |
componentDidMount() { | |
if (this.props.collapsed) { | |
this.setState({ isCollapsed: this.props.collapsed }) | |
} | |
} | |
render() { | |
const { isCollapsed } = this.state | |
const { header, footer } = this.props | |
return ( | |
<Card className={styles.Card}> | |
<CardHeader className={styles.CardHeader}> | |
<i | |
className={isCollapsed ? 'fa fa-caret-left' : 'fa fa-caret-down'} | |
onClick={this.onCollapse} | |
/> | |
<h2>{header}</h2> | |
</CardHeader> | |
{/* render or dont render, later I want to do animation with css on close */} | |
{isCollapsed ? null : ( | |
<React.Fragment> | |
<CardContent>{this.props.children}</CardContent> | |
<CardFooter>{footer}</CardFooter> | |
</React.Fragment> | |
)} | |
</Card> | |
) | |
} | |
onCollapse = () => { | |
this.setState({ | |
isCollapsed: !this.state.isCollapsed | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment