From 4a751f9bf9704c3b090dbf19bb8a49f1d0c5db27 Mon Sep 17 00:00:00 2001 From: n7best Date: Thu, 25 Feb 2016 10:57:23 -0500 Subject: [PATCH] add radio,checkbox,select w/o testand doc --- example/pages/cell/index.js | 86 +++++++++++++++++++++++++++++++- src/components/form/checkbox.js | 26 ++++++++++ src/components/form/form.js | 18 +++++-- src/components/form/form_cell.js | 28 +++++++++-- src/components/form/index.js | 9 +++- src/components/form/radio.js | 26 ++++++++++ src/components/form/select.js | 44 ++++++++++++++++ src/index.js | 5 +- 8 files changed, 230 insertions(+), 12 deletions(-) create mode 100644 src/components/form/checkbox.js create mode 100644 src/components/form/radio.js create mode 100644 src/components/form/select.js diff --git a/example/pages/cell/index.js b/example/pages/cell/index.js index 7826eca..3f60a3b 100644 --- a/example/pages/cell/index.js +++ b/example/pages/cell/index.js @@ -20,7 +20,10 @@ import { ButtonArea, Input, Label, TextArea, - Switch + Switch, + Radio, + Checkbox, + Select } from '../../../src/index'; import Page from '../../component/page'; import iconSrc from './images/icon.png'; @@ -115,6 +118,38 @@ export default class CellDemo extends React.Component { + 单选列表项 +
+ + 标题文字 + + + + + + 标题文字 + + + + +
+ + 复选列表项 +
+ + + + + 标题文字 + + + + + + 标题文字 + +
+ 开关
@@ -180,6 +215,55 @@ export default class CellDemo extends React.Component {
+ + 选择 +
+ + + + + + + + +
+ + 选择 +
+ + + + + + + 国家/地区 + + + + + ); + } +}; diff --git a/src/components/form/form.js b/src/components/form/form.js index fbcf10b..2ba924f 100644 --- a/src/components/form/form.js +++ b/src/components/form/form.js @@ -4,15 +4,27 @@ -import React, { Component } from 'react'; +import React, { Component, PropTypes } from 'react'; import classNames from 'classnames'; export default class Form extends Component { + static propTypes = { + radio: PropTypes.bool, + checkbox: PropTypes.bool + }; + + static defaultProps = { + radio: false, + checkbox: false + }; + render() { - const { children, className, ...others } = this.props; + const { children, className, radio, checkbox, ...others } = this.props; const cls = classNames({ weui_cells: true, - weui_cells_form: true, + weui_cells_form: !radio && !checkbox, + weui_cells_radio: radio, + weui_cells_checkbox: checkbox, [className]: className }); diff --git a/src/components/form/form_cell.js b/src/components/form/form_cell.js index ec3a67f..5c89b1d 100644 --- a/src/components/form/form_cell.js +++ b/src/components/form/form_cell.js @@ -10,12 +10,20 @@ import classNames from 'classnames'; export default class FormCell extends React.Component { static propTypes = { vcode: PropTypes.bool, - warn: PropTypes.bool + warn: PropTypes.bool, + radio: PropTypes.bool, + checkbox: PropTypes.bool, + select: PropTypes.bool, + selectPos: PropTypes.string, }; static defaultProps = { vcode: false, - warn: false + warn: false, + radio: false, + checkbox: false, + select: false, + selectPos: undefined }; render() { @@ -25,11 +33,21 @@ export default class FormCell extends React.Component { weui_vcode: this.props.vcode, weui_cell_warn: this.props.warn, weui_cell_switch: this.props.switch, + weui_cell_select: this.props.select, + weui_select_before: this.props.selectPos == 'before', + weui_select_after: this.props.selectPos == 'after', + weui_check_label: this.props.radio || this.props.checkbox, [className]: className }); - return ( -
{children}
- ); + if(this.props.radio || this.props.checkbox) { + return ( + + ) + }else{ + return ( +
{children}
+ ); + } } }; diff --git a/src/components/form/index.js b/src/components/form/index.js index 78cd9cb..0e1aa8e 100644 --- a/src/components/form/index.js +++ b/src/components/form/index.js @@ -1,6 +1,5 @@ /** * Created by yjcxy12 on 16/1/22. - * -textarea n7best 16/2/16 */ @@ -10,11 +9,17 @@ import FormCell from './form_cell'; import TextArea from './textarea'; import Input from './input'; import Switch from './switch'; +import Radio from './radio'; +import Checkbox from './checkbox'; +import Select from './select'; export default { Form, FormCell, TextArea, Input, - Switch + Switch, + Radio, + Checkbox, + Select }; diff --git a/src/components/form/radio.js b/src/components/form/radio.js new file mode 100644 index 0000000..88615ab --- /dev/null +++ b/src/components/form/radio.js @@ -0,0 +1,26 @@ +/** + * Created by n7best on 16/2/25. + */ + + + +import React, { Component, PropTypes } from 'react'; +import classNames from 'classnames'; + +export default class Radio extends React.Component { + + render() { + const { className, ...others } = this.props; + const cls = classNames({ + weui_check: true, + [className]: className + }); + + return ( +
+ + +
+ ); + } +}; diff --git a/src/components/form/select.js b/src/components/form/select.js new file mode 100644 index 0000000..ad5457e --- /dev/null +++ b/src/components/form/select.js @@ -0,0 +1,44 @@ +/** + * Created by n7best on 16/2/25. + */ + + + +import React, { Component, PropTypes } from 'react'; +import classNames from 'classnames'; + +export default class Select extends React.Component { + static propTypes = { + data: React.PropTypes.array + }; + + static defaultProps = { + data: [] + }; + + renderData(data) { + return data.map((item,i) => { + return ; + }); + } + + render() { + const { className, data, children, ...others } = this.props; + const cls = classNames({ + weui_select: true, + [className]: className + }); + + return ( + + ); + } +}; diff --git a/src/index.js b/src/index.js index 349d087..4efccf0 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,7 @@ import {Button, ButtonArea} from './components/button/index'; import {Cells, CellsTitle, CellsTips, Cell, CellHeader, CellBody, CellFooter} from './components/cell/index'; import Mask from './components/mask/index'; -import {Form, FormCell, TextArea, Input, Switch} from './components/form/index'; +import {Form, FormCell, TextArea, Input, Switch, Radio, Checkbox, Select} from './components/form/index'; import Label from './components/label/index'; import Toast from './components/toast/index'; import Progress from './components/progress/index'; @@ -29,9 +29,12 @@ export default { Mask, Form, FormCell, + Radio, + Checkbox, Input, TextArea, Switch, + Select, Label, Toast, Progress,