114 lines
2.8 KiB
JavaScript
114 lines
2.8 KiB
JavaScript
|
|
import { Con, Row, Col } from 'bee-layout';
|
|
import { Panel } from 'bee-panel';
|
|
import Button from 'bee-button';
|
|
import React, { Component } from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import FormControl from 'bee-form-control';
|
|
import Tree from '../src';
|
|
|
|
const x = 3;
|
|
const y = 2;
|
|
const z = 1;
|
|
const gData = [];
|
|
|
|
const generateData = (_level, _preKey, _tns) => {
|
|
const preKey = _preKey || '0';
|
|
const tns = _tns || gData;
|
|
|
|
const children = [];
|
|
for (let i = 0; i < x; i++) {
|
|
const key = `${preKey}-${i}`;
|
|
tns.push({ title: key, key });
|
|
if (i < y) {
|
|
children.push(key);
|
|
}
|
|
}
|
|
if (_level < 0) {
|
|
return tns;
|
|
}
|
|
const level = _level - 1;
|
|
children.forEach((key, index) => {
|
|
tns[index].children = [];
|
|
return generateData(level, key, tns[index].children);
|
|
});
|
|
};
|
|
generateData(z);
|
|
|
|
const TreeNode = Tree.TreeNode;
|
|
|
|
const CARET = <i className="uf uf-arrow-down"></i>;
|
|
|
|
const CARETUP = <i className="uf uf-arrow-up"></i>;
|
|
|
|
|
|
{demolist}
|
|
|
|
class Demo extends Component {
|
|
constructor(props){
|
|
super(props);
|
|
this.state = {
|
|
open: false
|
|
}
|
|
this.handleClick = this.handleClick.bind(this);
|
|
}
|
|
handleClick() {
|
|
this.setState({ open: !this.state.open })
|
|
}
|
|
|
|
render () {
|
|
const { title, example, code, desc } = this.props;
|
|
let caret = this.state.open ? CARETUP : CARET;
|
|
let text = this.state.open ? "隐藏代码" : "查看代码";
|
|
|
|
const footer = (
|
|
<Button shape="block" onClick={ this.handleClick }>
|
|
{ caret }
|
|
{ text }
|
|
</Button>
|
|
);
|
|
const header = (
|
|
<Row>
|
|
<Col md={11}>
|
|
{ example }
|
|
</Col>
|
|
<Col md={1}>
|
|
<Button shape="icon" onClick={ this.handleClick }>
|
|
{ caret }
|
|
</Button>
|
|
</Col>
|
|
</Row>
|
|
);
|
|
return (
|
|
<Col md={12} >
|
|
<h3>{ title }</h3>
|
|
<p>{ desc }</p>
|
|
<Panel collapsible headerContent expanded={ this.state.open } colors='bordered' header={ header } footer={footer} footerStyle = {{padding: 0}}>
|
|
<pre><code className="hljs javascript">{ code }</code></pre>
|
|
</Panel>
|
|
</Col>
|
|
)
|
|
}
|
|
}
|
|
|
|
class DemoGroup extends Component {
|
|
constructor(props){
|
|
super(props)
|
|
}
|
|
render () {
|
|
return (
|
|
<Row>
|
|
{DemoArray.map((child,index) => {
|
|
|
|
return (
|
|
<Demo example= {child.example} title= {child.title} code= {child.code} desc= {child.desc} key= {index}/>
|
|
)
|
|
|
|
})}
|
|
</Row>
|
|
)
|
|
}
|
|
}
|
|
|
|
ReactDOM.render(<DemoGroup/>, document.getElementById('tinperBeeDemo'));
|