1 |
|
2 | import { Con, Row, Col } from 'bee-layout';
|
3 | import { Panel } from 'bee-panel';
|
4 | import React, { Component } from 'react';
|
5 | import ReactDOM from 'react-dom';
|
6 | import Button from 'bee-button';
|
7 | import Switch from '../src';
|
8 |
|
9 |
|
10 | const CARET = <i className="uf uf-arrow-down"></i>;
|
11 |
|
12 | const CARETUP = <i className="uf uf-arrow-up"></i>;
|
13 |
|
14 |
|
15 | var Demo1 = require("./demolist/Demo1");var Demo2 = require("./demolist/Demo2");var Demo3 = require("./demolist/Demo3");var Demo4 = require("./demolist/Demo4");var DemoArray = [{"example":<Demo1 />,"title":" 默认开关","code":"/**\n *\n * @title 默认开关\n * @description\n *\n */\nimport React, { Component } from \"react\";\nimport { Row, Col } from \"bee-layout\";\nimport Switch from \"../../src\";\n\nclass Demo1 extends Component {\n constructor(props) {\n super(props);\n this.state = {\n checked: true\n };\n }\n onChange = () => {\n this.setState({\n checked: !this.state.checked\n });\n };\n render() {\n return (\n <Row>\n <Col sm={2}>\n <Switch />\n </Col>\n <Col sm={2}>\n <Switch\n checked={this.state.checked}\n onChange={this.onChange}\n />\n </Col>\n </Row>\n );\n }\n}\n\n\n","desc":""},{"example":<Demo2 />,"title":" 不同大小的开关","code":"/**\n *\n * @title 不同大小的开关\n * @description 通过`size`属性控制开关的大小\n *\n */\n\nimport React, { Component } from \"react\";\nimport { Row, Col } from \"bee-layout\";\nimport Switch from \"../../src\";\n\nclass Demo2 extends Component {\n render() {\n return (\n <Row>\n <Col sm={2}>\n <Switch size=\"sm\" />\n </Col>\n <Col sm={2}>\n <Switch />\n </Col>\n <Col sm={2}>\n <Switch size=\"lg\" />\n </Col>\n </Row>\n );\n }\n}\n\n\n","desc":" 通过`size`属性控制开关的大小"},{"example":<Demo3 />,"title":" 事件开关","code":"/**\n *\n * @title 事件开关\n * @description 点击开关触发事件\n *\n */\n\nimport React, { Component } from \"react\";\nimport { Row, Col } from \"bee-layout\";\nimport Switch from \"../../src\";\n\nclass Demo3 extends Component {\n constructor(props) {\n super(props);\n this.state = {\n switch: \"\",\n checked: false\n };\n }\n onChange = e => {\n this.setState({\n switch: `${e}`,\n checked: !this.state.checked\n });\n };\n\n render() {\n return (\n <Row>\n <Col sm={2}>\n <Switch\n checked={this.state.checked}\n onChange={this.onChange}\n checkedChildren={\"on\"}\n unCheckedChildren={\"off\"}\n />\n </Col>\n <Col sm={2}>\n <span>{this.state.switch}</span>\n </Col>\n </Row>\n );\n }\n}\n\n\n","desc":" 点击开关触发事件"},{"example":<Demo4 />,"title":" 被禁用开关","code":"/**\n *\n * @title 被禁用开关\n * @description\n *\n */\nimport React, { Component } from \"react\";\nimport { Row, Col } from \"bee-layout\";\nimport Switch from \"../../src\";\n\nclass Demo4 extends Component {\n constructor(props) {\n super(props);\n this.state = {\n defaultDisabled: true\n };\n }\n onChange = () => {\n this.setState({\n defaultDisabled: !this.state.defaultDisabled\n });\n };\n onConsoleLog=(x)=>{\n console.log(x) \n }\n render() {\n return (\n <Row>\n <Col sm={2}>\n <Switch disabled={this.state.defaultDisabled}/>\n </Col>\n <Col sm={2}>\n <button onClick={this.onChange}>toggle disabled</button>\n </Col>\n </Row>\n );\n }\n}\n\n\n","desc":""}]
|
16 |
|
17 |
|
18 | class Demo extends Component {
|
19 | constructor(props){
|
20 | super(props);
|
21 | this.state = {
|
22 | open: false
|
23 | }
|
24 | this.handleClick = this.handleClick.bind(this);
|
25 | }
|
26 | handleClick() {
|
27 | this.setState({ open: !this.state.open })
|
28 | }
|
29 |
|
30 | render () {
|
31 | const { title, example, code, desc } = this.props;
|
32 | let caret = this.state.open ? CARETUP : CARET;
|
33 | let text = this.state.open ? "隐藏代码" : "查看代码";
|
34 |
|
35 | const footer = (
|
36 | <Button shape="block" onClick={ this.handleClick }>
|
37 | { caret }
|
38 | { text }
|
39 | </Button>
|
40 | );
|
41 |
|
42 |
|
43 | return (
|
44 | <Col md={12} >
|
45 | <h3>{ title }</h3>
|
46 | <p>{ desc }</p>
|
47 | <Panel collapsible expanded={ this.state.open } colors='bordered' header={ example } footer={footer} footerStyle = {{padding: 0}}>
|
48 | <pre><code className="hljs javascript">{ code }</code></pre>
|
49 | </Panel>
|
50 | </Col>
|
51 | )
|
52 | }
|
53 | }
|
54 |
|
55 | class DemoGroup extends Component {
|
56 | constructor(props){
|
57 | super(props)
|
58 | }
|
59 | render () {
|
60 | return (
|
61 | <Row>
|
62 | {DemoArray.map((child,index) => {
|
63 |
|
64 | return (
|
65 | <Demo example= {child.example} title= {child.title} code= {child.code} desc= {child.desc} key= {index}/>
|
66 | )
|
67 |
|
68 | })}
|
69 | </Row>
|
70 | )
|
71 | }
|
72 | }
|
73 |
|
74 | ReactDOM.render(<DemoGroup/>, document.getElementById('tinperBeeDemo'));
|