1 | import {Col, Row} from 'bee-layout';
|
2 | import {Panel} from 'bee-panel';
|
3 | import Button from 'bee-button';
|
4 | import React, {Component} from 'react';
|
5 | import ReactDOM from 'react-dom';
|
6 |
|
7 |
|
8 | const CARET = <i className="uf uf-arrow-down"></i>;
|
9 |
|
10 | const CARETUP = <i className="uf uf-arrow-up"></i>;
|
11 |
|
12 |
|
13 | {demolist}
|
14 |
|
15 | class Demo extends Component {
|
16 | constructor(props) {
|
17 | super(props);
|
18 | this.state = {
|
19 | open: false
|
20 | }
|
21 | this.handleClick = this.handleClick.bind(this);
|
22 | }
|
23 |
|
24 | handleClick() {
|
25 | this.setState({open: !this.state.open})
|
26 | }
|
27 |
|
28 | render() {
|
29 | const {title, example, code, desc, scss_code} = this.props;
|
30 | let caret = this.state.open ? CARETUP : CARET;
|
31 | let text = this.state.open ? "隐藏代码" : "查看代码";
|
32 |
|
33 | const header = (
|
34 | <div>
|
35 | {example}
|
36 | <Button style={{"marginTop": "10px"}} shape="block" onClick={this.handleClick}>
|
37 | {caret}
|
38 | {text}
|
39 | </Button>
|
40 | </div>
|
41 | );
|
42 | return (
|
43 | <Col md={12}>
|
44 | <h3>{title}</h3>
|
45 | <p>{desc}</p>
|
46 | <Panel collapsible headerContent expanded={this.state.open} colors='bordered' header={header}
|
47 | footerStyle={{padding: 0}}>
|
48 | <pre><code className="hljs javascript">{code}</code></pre>
|
49 | {!!scss_code ? <pre><code className="hljs css">{scss_code}</code></pre> : null}
|
50 | </Panel>
|
51 | </Col>
|
52 | )
|
53 | }
|
54 | }
|
55 |
|
56 | class DemoGroup extends Component {
|
57 | constructor(props) {
|
58 | super(props)
|
59 | }
|
60 |
|
61 | render() {
|
62 | return (
|
63 | <Row>
|
64 | {DemoArray.map((child, index) => {
|
65 |
|
66 | return (
|
67 | <Demo example={child.example} title={child.title} code={child.code} scss_code={child.scss_code}
|
68 | desc={child.desc} key={index}/>
|
69 | )
|
70 |
|
71 | })}
|
72 | </Row>
|
73 | )
|
74 | }
|
75 | }
|
76 |
|
77 | ReactDOM.render(<DemoGroup/>, document.getElementById('tinperBeeDemo'));
|