diff --git a/src/components/form/index.scss b/src/components/form/index.scss index 1c6de9d2c..85de6eb63 100644 --- a/src/components/form/index.scss +++ b/src/components/form/index.scss @@ -1,8 +1,10 @@ +@import '../../style/theme/default.scss'; + .at-form { display: block; - padding-left: 30px; - background-color: #fff; - border-bottom: 1px solid #e5e5e5; - border-top: 1px solid #e5e5e5; + padding-left: $spacing-h-lg; + background-color: $color-bg; + border-bottom: $border; + border-top: $border; overflow: hidden; } diff --git a/src/components/input/index.js b/src/components/input/index.js index e7860a742..7ceb6a851 100644 --- a/src/components/input/index.js +++ b/src/components/input/index.js @@ -6,36 +6,25 @@ import './index.scss' /** * @author:chenzeji * @description 单行输入框 + * @prop name {String} 输入框的唯一标识,传入点击title会聚焦输入框,小程序官方bug,暂时有问题 * @prop value {String|Number} 输入框值 * @prop placeholder {String} 提示字符 * @prop title {String} 输入框左侧标题,若传入为空,则不显示标题 - * @prop maxlength {Number} 最大长度 default:200 - * @prop backgroundColor {String} 背景颜色 default:#fff + * @prop maxlength {Number} 最大长度 default:140 * @prop disabled {Boolean} 是否禁止输入,禁止点击按钮 default: false + * @prop editable {Boolean} 是否可编辑 default: true * @prop error {Boolean} 是否出现错误, default: false * @prop clear {Boolean} 是否显示清除按钮, default: false - * @prop type {String} 输入框类型,可选为 text,number,password,phone default: text + * @prop type {String} 输入框类型,可选为 text,number,password,phone,idcard,digit default: text * @prop autoFocus {Boolean} 是否自动聚焦 default:false * @prop onChange {Function} 输入框值改变时触发的事件 * @prop onFocus {Function} 输入框被选中时触发的事件 * @prop onBlur {Function} 输入框失去焦点时触发的事件 - * @prop onClickErrorIcon {Function} 点击错误按钮触发的事件 + * @prop onErrorClick {Function} 点击错误按钮触发的事件 */ class AtInput extends Taro.Component { handleInput (e) { - const { value } = e.target - const { type } = this.props - let newValue = value - if (type === 'phone') { - newValue = value.replace(/\D/g, '').substring(0, 11) - const valueLen = newValue.length - if (valueLen > 3 && valueLen < 8) { - newValue = `${newValue.substr(0, 3)} ${newValue.substr(3)}` - } else if (valueLen >= 8) { - newValue = `${newValue.substr(0, 3)} ${newValue.substr(3, 4)} ${newValue.substr(7)}` - } - } - this.props.onChange(newValue, ...arguments) + this.props.onChange(e.target.value, ...arguments) } handleFocus (e) { this.props.onFocus(e.target.value, ...arguments) @@ -47,87 +36,96 @@ class AtInput extends Taro.Component { this.props.onChange('', ...arguments) } handleClickErrIcon () { - this.props.onClickErrorIcon(...arguments) - } - transferType (type) { - if (type === 'phone') { - return 'text' - } - return type + this.props.onErrorClick(...arguments) } render () { - const { title, disabled, error, clear, type, placeholder, maxlength, autoFocus, value, backgroundColor } = this.props - const rootStyle = `background-color: ${backgroundColor};` - const rootCls = ['at-input'] + const { name, type, maxlength, disabled, title, editable, error, clear, placeholder, autoFocus, value } = this.props + let newMaxlength = maxlength + let newType = type + let newDisabled = disabled + const containerCls = ['at-input__container'] if (error) { - rootCls.push('at-input--error') + containerCls.push('at-input--error') } if (disabled) { - rootCls.push('at-input--disabled') + containerCls.push('at-input--disabled') + } + if (type === 'phone') { + newMaxlength = 11 + newType = 'number' + } + if (disabled === false && editable === false) { + newDisabled = true } - return - { - title - ? - : null - } - - { - clear && value - ? - - - : null - } - { - error - ? - - - : null - } - {this.props.children} + return + + { + title + ? + : null + } + + { + clear && value + ? + + + : null + } + { + error + ? + + + : null + } + {this.props.children} + } } const defaultFunc = () => {} AtInput.defaultProps = { value: '', + name: '', placeholder: '', title: '', - maxlength: 200, + maxlength: 140, type: 'text', disabled: false, + editable: true, error: false, clear: false, - backgroundColor: '#fff', autoFocus: false, onChange: defaultFunc, onFocus: defaultFunc, onBlur: defaultFunc, - onClickErrorIcon: defaultFunc + onErrorClick: defaultFunc } AtInput.propTypes = { value: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]), + name: '', placeholder: PropTypes.string, title: PropTypes.string, maxlength: PropTypes.number, type: PropTypes.string, disabled: PropTypes.bool, + editable: PropTypes.bool, error: PropTypes.bool, clear: PropTypes.bool, backgroundColor: PropTypes.string, @@ -135,6 +133,6 @@ AtInput.propTypes = { onChange: PropTypes.func, onFocus: PropTypes.func, onBlur: PropTypes.func, - onClickErrorIcon: PropTypes.func, + onErrorClick: PropTypes.func, } export default AtInput diff --git a/src/components/input/index.scss b/src/components/input/index.scss index aff4b9a6f..ed4a88fb2 100644 --- a/src/components/input/index.scss +++ b/src/components/input/index.scss @@ -1,39 +1,47 @@ -@import '../../style/mixins/index.scss'; @import '../../style/theme/default.scss'; .at-input { - background-color: #fff; - padding: 22px 0; - display: flex; - align-items: center; - border-bottom: #e5e5e5 solid 1px; + background-color: $color-bg; + padding: $spacing-v-md 0; + border-bottom: $border; + + &__container { + display: flex; + align-items: center; + } &__input { flex: 1; - font-size: 28px; - padding: 0 12px; + font-size: $font-size-base; + padding-right: $spacing-v-md; display: inline-block; vertical-align: middle; } + input { + height: auto !important; + min-height: auto !important; + } + &__icon { display: inline-block; - padding: 0 6px; + padding: 0 $spacing-v-md; text-align: center; - font-size: 20px; + font-size: $font-size-base; } &__title { width: 150px; - margin-right: 20px; - font-size: 28px; + margin-right: $spacing-h-md; + font-size: $font-size-base; + line-height: $line-height-zh; vertical-align: middle; text-align: left; } &__children { display: inline-flex; - border-left: #e7e7e7 solid 1px; + border-left: $border; > view, div, @@ -41,10 +49,11 @@ text, image, .taro-img { - font-size: 28px; + font-size: $font-size-base; display: inline-block; - padding: 0 20px; - color: #78a4fa; + text-align: center; + padding: 0 $spacing-v-md; + color: $color-brand-dark; } > image, @@ -58,7 +67,7 @@ } &--error { - color: #e93b3d; + color: $color-error; } &--disabled { diff --git a/src/pages/form/input/index.js b/src/pages/form/input/index.js index 587827ab8..358bf3868 100644 --- a/src/pages/form/input/index.js +++ b/src/pages/form/input/index.js @@ -21,6 +21,13 @@ export default class Index extends Taro.Component { value5: '', value6: '', value7: '', + value8: '', + value9: '', + value10: '', + value12: '', + value13: '', + value14: '', + value15: '', disabled: false, second: 60 } @@ -44,7 +51,7 @@ export default class Index extends Taro.Component { // 使用setState 数值更新有延迟 this.state.disabled = false this.setState({ - second: this.props.second, + second: 60, disabled: false }) clearInterval(timer) @@ -75,25 +82,66 @@ export default class Index extends Taro.Component { {/* S Header */} {/* E Header */} - {/* S Body */} - 基础输入框 + 输入框标题 + + + + + + + + + + + + 输入框类型 + + + + + + + + + + + + + + + 状态 + + + + + + + + + + + + + 自定义右边栏 - - - - - - - + - - {this.showTipText()} + + + {this.showTipText()} + diff --git a/src/style/theme/default.scss b/src/style/theme/default.scss index 96b6c897f..c5ff85570 100644 --- a/src/style/theme/default.scss +++ b/src/style/theme/default.scss @@ -113,6 +113,9 @@ $zindex-action-sheet: 1010; $zindex-picker: 1010; $zindex-toast: 1090; +/* border */ +$border: 1px solid #e5e5e5; + /** * CSS cubic-bezier timing functions * http://bourbon.io/docs/#timing-functions