-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* clean up * add collapse component * apply collapsable across board
- Loading branch information
Showing
7 changed files
with
163 additions
and
128 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from "prop-types"; | ||
|
||
import Col from 'antd/lib/col'; | ||
import Divider from 'antd/lib/divider'; | ||
import Layout from 'antd/lib/layout'; | ||
|
||
import 'antd/lib/col/style'; | ||
import 'antd/lib/divider/style'; | ||
import 'antd/lib/layout/style'; | ||
|
||
class Collapsable extends Component { | ||
|
||
constructor (props) { | ||
super(props); | ||
|
||
this.state = { | ||
collapsed: props.opened ? false : true | ||
} | ||
this.toggleCollapse = this.toggleCollapse.bind(this); | ||
} | ||
|
||
toggleCollapse () { | ||
console.log(this.state) | ||
this.setState({ | ||
collapsed: !this.state.collapsed | ||
}); | ||
} | ||
|
||
render () { | ||
const { title, children, opened, ...others } = this.props; | ||
return ( | ||
<Layout {...others}> | ||
<Col span={24} style={{ cursor: 'pointer', margin: '0 0 12px' }}> | ||
<div onClick={this.toggleCollapse} > | ||
{typeof title === 'string' && | ||
<h3> | ||
{title} | ||
</h3> | ||
} | ||
{typeof title === 'object' && | ||
title | ||
} | ||
<Divider style={{ height: '1px', margin: '0' }} /> | ||
</div> | ||
</Col> | ||
<Col span={24} > | ||
{ !this.state.collapsed && children } | ||
</Col> | ||
</Layout> | ||
); | ||
} | ||
} | ||
|
||
Collapsable.propTypes = { | ||
opened: PropTypes.bool, | ||
title: PropTypes.any.isRequired, | ||
children: PropTypes.object.isRequired | ||
} | ||
|
||
export default Collapsable; |
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
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
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
Oops, something went wrong.