bee-tree/demo/index-demo-base.js

78 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-01-21 21:47:49 +08:00
import {Col, Row} from 'bee-layout';
import {Panel} from 'bee-panel';
2016-12-30 15:43:08 +08:00
import Button from 'bee-button';
2018-01-21 21:47:49 +08:00
import React, {Component} from 'react';
2016-12-30 15:43:08 +08:00
import ReactDOM from 'react-dom';
const CARET = <i className="uf uf-arrow-down"></i>;
const CARETUP = <i className="uf uf-arrow-up"></i>;
{demolist}
class Demo extends Component {
2018-01-21 21:47:49 +08:00
constructor(props) {
2016-12-30 15:43:08 +08:00
super(props);
this.state = {
open: false
}
this.handleClick = this.handleClick.bind(this);
}
2018-01-21 21:47:49 +08:00
2016-12-30 15:43:08 +08:00
handleClick() {
2018-01-21 21:47:49 +08:00
this.setState({open: !this.state.open})
2016-12-30 15:43:08 +08:00
}
2018-01-21 21:47:49 +08:00
render() {
const {title, example, code, desc, scss_code} = this.props;
2016-12-30 15:43:08 +08:00
let caret = this.state.open ? CARETUP : CARET;
let text = this.state.open ? "隐藏代码" : "查看代码";
const header = (
2018-01-21 21:47:49 +08:00
<div>
{example}
<Button style={{"marginTop": "10px"}} shape="block" onClick={this.handleClick}>
{caret}
{text}
2016-12-30 15:43:08 +08:00
</Button>
2018-01-21 21:47:49 +08:00
</div>
2016-12-30 15:43:08 +08:00
);
return (
2018-01-21 21:47:49 +08:00
<Col md={12}>
<h3>{title}</h3>
<p>{desc}</p>
<Panel collapsible headerContent expanded={this.state.open} colors='bordered' header={header}
footerStyle={{padding: 0}}>
<pre><code className="hljs javascript">{code}</code></pre>
{!!scss_code ? <pre><code className="hljs css">{scss_code}</code></pre> : null}
2016-12-30 15:43:08 +08:00
</Panel>
</Col>
)
}
}
class DemoGroup extends Component {
2018-01-21 21:47:49 +08:00
constructor(props) {
2016-12-30 15:43:08 +08:00
super(props)
}
2018-01-21 21:47:49 +08:00
render() {
2016-12-30 15:43:08 +08:00
return (
2018-01-21 21:47:49 +08:00
<Row>
{DemoArray.map((child, index) => {
2016-12-30 15:43:08 +08:00
2018-01-21 21:47:49 +08:00
return (
<Demo example={child.example} title={child.title} code={child.code} scss_code={child.scss_code}
desc={child.desc} key={index}/>
)
2016-12-30 15:43:08 +08:00
2018-01-21 21:47:49 +08:00
})}
</Row>
2016-12-30 15:43:08 +08:00
)
}
}
ReactDOM.render(<DemoGroup/>, document.getElementById('tinperBeeDemo'));