Skip to content

Commit 81f0859

Browse files
author
BearJ
committed
add switch
1 parent 0f2dcef commit 81f0859

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

example/pages/cell/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { ButtonArea,
1919
Icon,
2020
Input,
2121
Label,
22-
TextArea
22+
TextArea,
23+
Switch
2324
} from '../../../src/index';
2425
import Page from '../../component/page';
2526
import iconSrc from './images/icon.png';
@@ -114,6 +115,16 @@ export default class CellDemo extends React.Component {
114115
</Cell>
115116
</Cells>
116117

118+
<CellsTitle>开关</CellsTitle>
119+
<Form>
120+
<FormCell switch>
121+
<CellBody>标题文字</CellBody>
122+
<CellFooter>
123+
<Switch/>
124+
</CellFooter>
125+
</FormCell>
126+
</Form>
127+
117128
<Form>
118129
<FormCell>
119130
<CellHeader>

src/components/form/form_cell.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ export default class FormCell extends React.Component {
1919
};
2020

2121
render() {
22-
const { className, children, vcode, warn, ...others } = this.props;
22+
const { className, children, ...others } = this.props;
2323
const cls = classNames({
2424
weui_cell: true,
25-
weui_vcode: vcode,
26-
weui_cell_warn: warn,
25+
weui_vcode: this.props.vcode,
26+
weui_cell_warn: this.props.warn,
27+
weui_cell_switch: this.props.switch,
2728
[className]: className
2829
});
2930

src/components/form/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import Form from './form';
99
import FormCell from './form_cell';
1010
import TextArea from './textarea';
1111
import Input from './input';
12+
import Switch from './switch';
1213

1314
export default {
1415
Form,
1516
FormCell,
1617
TextArea,
17-
Input
18+
Input,
19+
Switch
1820
};

src/components/form/switch.js

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

src/index.js

Lines changed: 2 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} from './components/form/index';
8+
import {Form, FormCell, TextArea, Input, Switch} 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';
@@ -31,6 +31,7 @@ export default {
3131
FormCell,
3232
Input,
3333
TextArea,
34+
Switch,
3435
Label,
3536
Toast,
3637
Progress,

0 commit comments

Comments
 (0)