1 |
|
2 | import { Con, Row, Col } from 'bee-layout';
|
3 | import { Panel } from 'bee-panel';
|
4 | import Button from 'bee-button';
|
5 | import React, { Component } from 'react';
|
6 | import ReactDOM from 'react-dom';
|
7 | import ButtonGroup from '../src';
|
8 |
|
9 |
|
10 | const CARET = <i className="uf uf-chevronarrowdown"></i>;
|
11 |
|
12 | const CARETUP = <i className="uf uf-chevronarrowup"></i>;
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | class Demo1 extends Component {
|
23 | render () {
|
24 | return (
|
25 | <ButtonGroup>
|
26 | <Button colors="primary">按钮一</Button>
|
27 | <Button colors="primary">按钮二</Button>
|
28 | <Button colors="primary">按钮三</Button>
|
29 | </ButtonGroup>
|
30 | )
|
31 | }
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | class Demo2 extends Component {
|
41 | render () {
|
42 | return (
|
43 | <ButtonGroup vertical>
|
44 | <Button colors="primary">上</Button>
|
45 | <Button colors="warning">中</Button>
|
46 | <Button colors="info">下</Button>
|
47 | </ButtonGroup>
|
48 | )
|
49 | }
|
50 | }
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | class Demo3 extends Component {
|
59 |
|
60 | render () {
|
61 | return (
|
62 | <Row>
|
63 | <Col xs={4} xsOffset={4}>
|
64 | <ButtonGroup vertical block>
|
65 | <Button colors="primary">上</Button>
|
66 | <Button colors="primary">中</Button>
|
67 | <Button colors="primary">下</Button>
|
68 | </ButtonGroup>
|
69 | </Col>
|
70 | </Row>
|
71 |
|
72 | )
|
73 | }
|
74 | }
|
75 | var DemoArray = [{"example":<Demo1 />,"title":" 默认按钮组","code":"/**\r\n *\r\n * @title 默认按钮组\r\n * @description 基础按钮组\r\n *\r\n */\r\n\r\nclass Demo1 extends Component {\r\n render () {\r\n return (\r\n <ButtonGroup>\r\n <Button colors=\"primary\">按钮一</Button>\r\n <Button colors=\"primary\">按钮二</Button>\r\n <Button colors=\"primary\">按钮三</Button>\r\n </ButtonGroup>\r\n )\r\n }\r\n}\r\n","desc":" 基础按钮组"},{"example":<Demo2 />,"title":" 垂直排列的按钮组","code":"/**\r\n *\r\n * @title 垂直排列的按钮组\r\n * @description 通过`vertical`属性设置按钮组垂直排列\r\n *\r\n */\r\n\r\nclass Demo2 extends Component {\r\n render () {\r\n return (\r\n <ButtonGroup vertical>\r\n <Button colors=\"primary\">上</Button>\r\n <Button colors=\"warning\">中</Button>\r\n <Button colors=\"info\">下</Button>\r\n </ButtonGroup>\r\n )\r\n }\r\n}\r\n","desc":" 通过`vertical`属性设置按钮组垂直排列"},{"example":<Demo3 />,"title":" 块状按钮组","code":"/**\r\n *\r\n * @title 块状按钮组\r\n * @description 块状按钮组会充满父元素\r\n *\r\n */\r\n\r\nclass Demo3 extends Component {\r\n\r\n render () {\r\n return (\r\n <Row>\r\n <Col xs={4} xsOffset={4}>\r\n <ButtonGroup vertical block>\r\n <Button colors=\"primary\">上</Button>\r\n <Button colors=\"primary\">中</Button>\r\n <Button colors=\"primary\">下</Button>\r\n </ButtonGroup>\r\n </Col>\r\n </Row>\r\n\r\n )\r\n }\r\n}\r\n","desc":" 块状按钮组会充满父元素"}]
|
76 |
|
77 |
|
78 | class Demo extends Component {
|
79 | constructor(props){
|
80 | super(props);
|
81 | this.state = {
|
82 | open: false
|
83 | }
|
84 | this.handleClick = this.handleClick.bind(this);
|
85 | }
|
86 | handleClick() {
|
87 | this.setState({ open: !this.state.open })
|
88 | }
|
89 |
|
90 | render () {
|
91 | const { title, example, code, desc } = this.props;
|
92 | let caret = this.state.open ? CARETUP : CARET;
|
93 | let text = this.state.open ? "隐藏代码" : "查看代码";
|
94 |
|
95 | const footer = (
|
96 | <Button shape="block" onClick={ this.handleClick }>
|
97 | { caret }
|
98 | { text }
|
99 | </Button>
|
100 | );
|
101 |
|
102 |
|
103 | return (
|
104 | <Col md={12}>
|
105 | <h3>{ title }</h3>
|
106 | <p>{ desc }</p>
|
107 | <Panel collapsible headerContent expanded={ this.state.open } colors='bordered' header={ example } footer={footer} footerStyle = {{padding: 0, borderColor: "transparent"}}>
|
108 | <pre><code className="hljs javascript">{ code }</code></pre>
|
109 | </Panel>
|
110 | </Col>
|
111 | )
|
112 | }
|
113 | }
|
114 |
|
115 | class DemoGroup extends Component {
|
116 | constructor(props){
|
117 | super(props)
|
118 | }
|
119 | render () {
|
120 | return (
|
121 | <Row>
|
122 | {DemoArray.map((child,index) => {
|
123 |
|
124 | return (
|
125 | <Demo example= {child.example} title= {child.title} code= {child.code} desc= {child.desc} key= {index}/>
|
126 | )
|
127 |
|
128 | })}
|
129 | </Row>
|
130 | )
|
131 | }
|
132 | }
|
133 |
|
134 | ReactDOM.render(<DemoGroup/>, document.getElementById('tinperBeeDemo'));
|