Skip to content

Commit

Permalink
fix: 增加default props
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczj committed Jul 19, 2018
1 parent 05497ed commit 667b9c3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
52 changes: 35 additions & 17 deletions src/components/input/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import Taro from '@tarojs/taro'
import { View, Input, Label } from '@tarojs/components'
import './index.scss'
import PropTypes from 'prop-types'
import AtIcon from '../../components/icon/index'

import './index.scss'
/**
* @author:chenzeji
* @description 单行输入框
* @prop value {String|Number} 输入框值
* @prop placeholder {String} 提示字符
* @prop maxlength {Number} 最大长度
* @prop type {String} 图标类型 eg:'collection_fill' 图标列表详细请看文档:https://weapp.iviewui.com/components/icon
* @prop size {Number|String} 图标大小 default: 30
* @prop color {String} 图标颜色 default:#6190e8
* @prop title {String} 输入框左侧标题,若传入为空,则不显示标题
* @prop maxlength {Number} 最大长度 default:200
* @prop type {String} 输入框类型,可选为 text,number,password
* @prop onChange {Function} 输入框值改变时触发的事件
* @prop onFocus {Function} 输入框被选中时触发的事件
* @prop onBlur {Function} 输入框失去焦点时触发的事件
*/
class AtInput extends Taro.Component {
handleInput(e) {
Expand All @@ -20,32 +22,48 @@ class AtInput extends Taro.Component {
handleFocus(e) {
this.props.onFocus(e)
}
handleBlur(e) {
this.props.onBlur(e)
}
render() {
return <View className={this.props.error ? 'at-input at-input--error' : 'at-input'}>
<View className='at-input_border'>
<Label className='at-input__label'>{this.props.label}</Label>
<View className='at-input__border'>
<Label className='at-input__title'>{this.props.title}</Label>
<Input className='at-input__input'
type={this.props.type ? this.props.type : 'text'}
type={this.props.type}
placeholder={this.props.placeholder}
maxlength={this.props.maxlength || 140}
maxlength={this.props.maxlength}
onInput={this.handleInput.bind(this)}
onChange={this.handleInput.bind(this)}
onFocus={this.handleFocus.bind(this)}
value={this.props.value || ''} />
onBlur={this.handleBlur.bind(this)}
value={this.props.value} />
<View className='at-input__icon'><AtIcon type='warning_fill' color='#e93b3d' size='20' /></View>
</View>
</View>
}
}
AtInput.defaultProps = {
color: '#6190e8',
size: '30',
onClick: () => { }
value: '',
placeholder: '',
title: '',
maxlength: 200,
type: 'text',
onChange: () => {},
onFocus: () => {},
onBlur: () => {},
}
AtInput.propTypes = {
color: PropTypes.string,

value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]),
placeholder: PropTypes.string,
title: PropTypes.string,
maxlength: PropTypes.number,
type: PropTypes.string,
onChange: PropTypes.func,
onFocus: PropTypes.func
onFocus: PropTypes.func,
onBlur: PropTypes.func
}
export default AtInput
6 changes: 3 additions & 3 deletions src/components/input/index.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.at-input {
background-color: #fff;
+ .at-input .at-input_border {
+ .at-input .at-input__border {
border-top: #e9eaec solid 1px;
}
.at-input_border {
.at-input__border {
padding: 22px 0;
margin-left:22px;
display: flex;
align-items: center;
}
.at-input__label {
.at-input__title {
flex:2;
margin-right:20px;
font-size: 28px;
Expand Down
1 change: 0 additions & 1 deletion src/pages/input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export default class Index extends Taro.Component {
<View className='index-page'><AtInputNumber min={0} max={1} step={0.01} value={this.state.number} onChange={this.handleNumberChange.bind(this)} /></View>
<View className='index-page'><AtRadio options={this.state.radioOptions} value={this.state.radioValue} onClick={this.handleRadioChange.bind(this)} /></View>
<View className='index-page'>
<View>sdf: <AtCheckbox onChange={1} /></View>
<AtCheckbox options={this.state.checkboxOption} selectedList={this.state.checkedList} onChange={this.handleCheckboxChange.bind(this)} />
</View>
<View className='index-page'>
Expand Down

0 comments on commit 667b9c3

Please sign in to comment.