Skip to content

Instantly share code, notes, and snippets.

@grantglidewell
Created August 1, 2018 20:17
Show Gist options
  • Save grantglidewell/829489093e0abf71f5b3a77d96332158 to your computer and use it in GitHub Desktop.
Save grantglidewell/829489093e0abf71f5b3a77d96332158 to your computer and use it in GitHub Desktop.
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