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 FormControl from 'bee-form-control';
|
8 | import FormGroup from '../src';
|
9 |
|
10 |
|
11 | const CARET = <i className="uf uf-chevronarrowdown"></i>;
|
12 |
|
13 | const CARETUP = <i className="uf uf-chevronarrowup"></i>;
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | class Demo1 extends Component {
|
21 | render () {
|
22 | return (
|
23 | <div className="demo-form-group">
|
24 | <FormGroup validationState="error">
|
25 | <FormControl type="text" />
|
26 | </FormGroup>
|
27 | <FormGroup validationState="warning">
|
28 | <FormControl type="text" />
|
29 | </FormGroup>
|
30 | <FormGroup validationState="success">
|
31 | <FormControl type="text" />
|
32 | </FormGroup>
|
33 | </div>
|
34 | )
|
35 | }
|
36 | } |
37 |
|
38 |
|
39 |
|
40 | class Demo2 extends Component {
|
41 | constructor (props) {
|
42 | super(props);
|
43 | this.state = {
|
44 | value: ''
|
45 | }
|
46 | }
|
47 | validateState () {
|
48 |
|
49 | if ( this.state.value == "" ) {
|
50 | return "warning";
|
51 | }
|
52 | if ( /^[0-9]*$/.test(this.state.value) ) {
|
53 | return "success";
|
54 | } else {
|
55 | return "error"
|
56 | }
|
57 | }
|
58 |
|
59 | handerChange (e) {
|
60 | this.setState({value:e.target.value});
|
61 | }
|
62 | render (){
|
63 | return(
|
64 | <div className="demo-form-control">
|
65 | <FormGroup ref='demo3FormGroup' validationState={this.validateState()}>
|
66 | <FormControl ref="demo3FormControl" placeholder="只能输入数字" value={this.state.value} onChange={this.handerChange.bind(this)}/>
|
67 | </FormGroup>
|
68 | </div>
|
69 | )
|
70 | }
|
71 |
|
72 | }var DemoArray = [{"example":<Demo1 />,"title":" FromGroup 三种校验状态实例","code":"/**\n * @title FromGroup 三种校验状态实例\n * @description `validationState`参数控制状态颜色\n */\nclass Demo1 extends Component {\n\trender () {\n\t\treturn (\n\t\t\t<div className=\"demo-form-group\">\n\t \t<FormGroup validationState=\"error\"> \n\t\t\t\t\t<FormControl type=\"text\" />\n\t\t\t\t</FormGroup>\t\n\t\t\t\t<FormGroup validationState=\"warning\"> \n\t\t\t\t\t<FormControl type=\"text\" />\n\t\t\t\t</FormGroup>\t\n\t\t\t\t<FormGroup validationState=\"success\"> \n\t\t\t\t\t<FormControl type=\"text\" />\n\t\t\t\t</FormGroup>\t\t\t\n\t </div>\n\t\t)\n\t}\n}","desc":" `validationState`参数控制状态颜色"},{"example":<Demo2 />,"title":" FormGroup 动态校验实例","code":"/**\n * @title FormGroup 动态校验实例\n * @description 限制只能输入数字\n */\nclass Demo2 extends Component {\n constructor (props) {\n super(props);\n this.state = {\n value: ''\n }\n }\n validateState () {\n\n if ( this.state.value == \"\" ) {\n return \"warning\";\n }\n if ( /^[0-9]*$/.test(this.state.value) ) {\n return \"success\";\n } else {\n return \"error\"\n }\n }\n\n handerChange (e) {\n this.setState({value:e.target.value});\n }\n render (){\n return( \n <div className=\"demo-form-control\">\n <FormGroup ref='demo3FormGroup' validationState={this.validateState()}>\n <FormControl ref=\"demo3FormControl\" placeholder=\"只能输入数字\" value={this.state.value} onChange={this.handerChange.bind(this)}/> \n </FormGroup>\n </div>\n )\n }\n\n}","desc":" 限制只能输入数字"}]
|
73 |
|
74 |
|
75 | class Demo extends Component {
|
76 | constructor(props){
|
77 | super(props);
|
78 | this.state = {
|
79 | open: false
|
80 | }
|
81 | this.handleClick = this.handleClick.bind(this);
|
82 | }
|
83 | handleClick() {
|
84 | this.setState({ open: !this.state.open })
|
85 | }
|
86 |
|
87 | render () {
|
88 | const { title, example, code, desc } = this.props;
|
89 | let caret = this.state.open ? CARETUP : CARET;
|
90 | let text = this.state.open ? "隐藏代码" : "查看代码";
|
91 |
|
92 | const footer = (
|
93 | <Button shape="block" onClick={ this.handleClick }>
|
94 | { caret }
|
95 | { text }
|
96 | </Button>
|
97 | );
|
98 | return (
|
99 | <Col md={12}>
|
100 | <h3>{ title }</h3>
|
101 | <p>{ desc }</p>
|
102 | <Panel collapsible expanded={ this.state.open } colors='bordered' header={ example } footer={footer} footerStyle = {{padding: 0,borderColor: "transparent"}} >
|
103 | <pre><code className="hljs javascript">{ code }</code></pre>
|
104 | </Panel>
|
105 | </Col>
|
106 | )
|
107 | }
|
108 | }
|
109 |
|
110 | class DemoGroup extends Component {
|
111 | constructor(props){
|
112 | super(props)
|
113 | }
|
114 | render () {
|
115 | return (
|
116 | <Row>
|
117 | {DemoArray.map((child,index) => {
|
118 |
|
119 | return (
|
120 | <Demo example= {child.example} title= {child.title} code= {child.code} desc= {child.desc} key= {index}/>
|
121 | )
|
122 |
|
123 | })}
|
124 | </Row>
|
125 | )
|
126 | }
|
127 | }
|
128 |
|
129 | ReactDOM.render(<DemoGroup/>, document.getElementById('tinperBeeDemo'));
|