Skip to content

Commit 4a751f9

Browse files
committed
add radio,checkbox,select w/o testand doc
1 parent 03ae5b4 commit 4a751f9

File tree

8 files changed

+230
-12
lines changed

8 files changed

+230
-12
lines changed

example/pages/cell/index.js

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import { ButtonArea,
2020
Input,
2121
Label,
2222
TextArea,
23-
Switch
23+
Switch,
24+
Radio,
25+
Checkbox,
26+
Select
2427
} from '../../../src/index';
2528
import Page from '../../component/page';
2629
import iconSrc from './images/icon.png';
@@ -115,6 +118,38 @@ export default class CellDemo extends React.Component {
115118
</Cell>
116119
</Cells>
117120

121+
<CellsTitle>单选列表项</CellsTitle>
122+
<Form radio>
123+
<FormCell radio>
124+
<CellBody>标题文字</CellBody>
125+
<CellFooter>
126+
<Radio name="radio1" value="1" defaultChecked/>
127+
</CellFooter>
128+
</FormCell>
129+
<FormCell radio>
130+
<CellBody>标题文字</CellBody>
131+
<CellFooter>
132+
<Radio name="radio1" value="2"/>
133+
</CellFooter>
134+
</FormCell>
135+
</Form>
136+
137+
<CellsTitle>复选列表项</CellsTitle>
138+
<Form checkbox>
139+
<FormCell checkbox>
140+
<CellHeader>
141+
<Checkbox name="checkbox1" value="1"/>
142+
</CellHeader>
143+
<CellBody>标题文字</CellBody>
144+
</FormCell>
145+
<FormCell checkbox>
146+
<CellHeader>
147+
<Checkbox name="checkbox2" value="2" defaultChecked/>
148+
</CellHeader>
149+
<CellBody>标题文字</CellBody>
150+
</FormCell>
151+
</Form>
152+
118153
<CellsTitle>开关</CellsTitle>
119154
<Form>
120155
<FormCell switch>
@@ -180,6 +215,55 @@ export default class CellDemo extends React.Component {
180215
</CellBody>
181216
</FormCell>
182217
</Form>
218+
219+
<CellsTitle>选择</CellsTitle>
220+
<Form>
221+
<FormCell select selectPos="before">
222+
<CellHeader>
223+
<Select>
224+
<option value="1">+86</option>
225+
<option value="2">+80</option>
226+
<option value="3">+84</option>
227+
<option value="4">+87</option>
228+
</Select>
229+
</CellHeader>
230+
<CellBody>
231+
<Input type="tel" placeholder="请输入号码"/>
232+
</CellBody>
233+
</FormCell>
234+
</Form>
235+
236+
<CellsTitle>选择</CellsTitle>
237+
<Form>
238+
<FormCell select>
239+
<CellBody>
240+
<Select defaultValue="2">
241+
<option value="1">微信号</option>
242+
<option value="2">QQ号</option>
243+
<option value="3">Email</option>
244+
</Select>
245+
</CellBody>
246+
</FormCell>
247+
<FormCell select selectPos="after">
248+
<CellHeader>国家/地区</CellHeader>
249+
<CellBody>
250+
<Select data={[
251+
{
252+
value: 1,
253+
label: '中国'
254+
},
255+
{
256+
value: 2,
257+
label: '美国'
258+
},
259+
{
260+
value: 3,
261+
label: '英国'
262+
}
263+
]} />
264+
</CellBody>
265+
</FormCell>
266+
</Form>
183267
</Page>
184268
);
185269
}

src/components/form/checkbox.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Created by n7best on 16/2/25.
3+
*/
4+
5+
6+
7+
import React, { Component, PropTypes } from 'react';
8+
import classNames from 'classnames';
9+
10+
export default class Checkbox extends React.Component {
11+
12+
render() {
13+
const { className, ...others } = this.props;
14+
const cls = classNames({
15+
weui_check: true,
16+
[className]: className
17+
});
18+
19+
return (
20+
<div>
21+
<input className={cls} type="checkbox" {...others}/>
22+
<i className="weui_icon_checked"></i>
23+
</div>
24+
);
25+
}
26+
};

src/components/form/form.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,27 @@
44

55

66

7-
import React, { Component } from 'react';
7+
import React, { Component, PropTypes } from 'react';
88
import classNames from 'classnames';
99

1010
export default class Form extends Component {
11+
static propTypes = {
12+
radio: PropTypes.bool,
13+
checkbox: PropTypes.bool
14+
};
15+
16+
static defaultProps = {
17+
radio: false,
18+
checkbox: false
19+
};
20+
1121
render() {
12-
const { children, className, ...others } = this.props;
22+
const { children, className, radio, checkbox, ...others } = this.props;
1323
const cls = classNames({
1424
weui_cells: true,
15-
weui_cells_form: true,
25+
weui_cells_form: !radio && !checkbox,
26+
weui_cells_radio: radio,
27+
weui_cells_checkbox: checkbox,
1628
[className]: className
1729
});
1830

src/components/form/form_cell.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ import classNames from 'classnames';
1010
export default class FormCell extends React.Component {
1111
static propTypes = {
1212
vcode: PropTypes.bool,
13-
warn: PropTypes.bool
13+
warn: PropTypes.bool,
14+
radio: PropTypes.bool,
15+
checkbox: PropTypes.bool,
16+
select: PropTypes.bool,
17+
selectPos: PropTypes.string,
1418
};
1519

1620
static defaultProps = {
1721
vcode: false,
18-
warn: false
22+
warn: false,
23+
radio: false,
24+
checkbox: false,
25+
select: false,
26+
selectPos: undefined
1927
};
2028

2129
render() {
@@ -25,11 +33,21 @@ export default class FormCell extends React.Component {
2533
weui_vcode: this.props.vcode,
2634
weui_cell_warn: this.props.warn,
2735
weui_cell_switch: this.props.switch,
36+
weui_cell_select: this.props.select,
37+
weui_select_before: this.props.selectPos == 'before',
38+
weui_select_after: this.props.selectPos == 'after',
39+
weui_check_label: this.props.radio || this.props.checkbox,
2840
[className]: className
2941
});
3042

31-
return (
32-
<div className={cls} {...others}>{children}</div>
33-
);
43+
if(this.props.radio || this.props.checkbox) {
44+
return (
45+
<label className={cls} {...others}>{children}</label>
46+
)
47+
}else{
48+
return (
49+
<div className={cls} {...others}>{children}</div>
50+
);
51+
}
3452
}
3553
};

src/components/form/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* Created by yjcxy12 on 16/1/22.
3-
* -textarea n7best 16/2/16
43
*/
54

65

@@ -10,11 +9,17 @@ import FormCell from './form_cell';
109
import TextArea from './textarea';
1110
import Input from './input';
1211
import Switch from './switch';
12+
import Radio from './radio';
13+
import Checkbox from './checkbox';
14+
import Select from './select';
1315

1416
export default {
1517
Form,
1618
FormCell,
1719
TextArea,
1820
Input,
19-
Switch
21+
Switch,
22+
Radio,
23+
Checkbox,
24+
Select
2025
};

src/components/form/radio.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Created by n7best on 16/2/25.
3+
*/
4+
5+
6+
7+
import React, { Component, PropTypes } from 'react';
8+
import classNames from 'classnames';
9+
10+
export default class Radio extends React.Component {
11+
12+
render() {
13+
const { className, ...others } = this.props;
14+
const cls = classNames({
15+
weui_check: true,
16+
[className]: className
17+
});
18+
19+
return (
20+
<div>
21+
<input className={cls} type="radio" {...others}/>
22+
<span className="weui_icon_checked"></span>
23+
</div>
24+
);
25+
}
26+
};

src/components/form/select.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Created by n7best on 16/2/25.
3+
*/
4+
5+
6+
7+
import React, { Component, PropTypes } from 'react';
8+
import classNames from 'classnames';
9+
10+
export default class Select extends React.Component {
11+
static propTypes = {
12+
data: React.PropTypes.array
13+
};
14+
15+
static defaultProps = {
16+
data: []
17+
};
18+
19+
renderData(data) {
20+
return data.map((item,i) => {
21+
return <option
22+
key={i}
23+
value={item.value}
24+
{...item}
25+
>
26+
{item.label}
27+
</option>;
28+
});
29+
}
30+
31+
render() {
32+
const { className, data, children, ...others } = this.props;
33+
const cls = classNames({
34+
weui_select: true,
35+
[className]: className
36+
});
37+
38+
return (
39+
<select className={cls} {...others}>
40+
{data.length > 0 ? this.renderData(data) : children}
41+
</select>
42+
);
43+
}
44+
};

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import {Button, ButtonArea} from './components/button/index';
66
import {Cells, CellsTitle, CellsTips, Cell, CellHeader, CellBody, CellFooter} from './components/cell/index';
77
import Mask from './components/mask/index';
8-
import {Form, FormCell, TextArea, Input, Switch} from './components/form/index';
8+
import {Form, FormCell, TextArea, Input, Switch, Radio, Checkbox, Select} from './components/form/index';
99
import Label from './components/label/index';
1010
import Toast from './components/toast/index';
1111
import Progress from './components/progress/index';
@@ -29,9 +29,12 @@ export default {
2929
Mask,
3030
Form,
3131
FormCell,
32+
Radio,
33+
Checkbox,
3234
Input,
3335
TextArea,
3436
Switch,
37+
Select,
3538
Label,
3639
Toast,
3740
Progress,

0 commit comments

Comments
 (0)