[improvement] Switch: support form-field (#478)

This commit is contained in:
neverland 2018-08-29 16:35:17 +08:00 committed by GitHub
parent b2fbf5a7de
commit 309cf21075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 23 deletions

View File

@ -1 +1 @@
.van-field__body{display:-webkit-box;display:-webkit-flex;display:flex;-webkit-box-align:center;-webkit-align-items:center;align-items:center}.van-field__body--textarea{min-height:24px}.van-field__control{border:0;margin:0;padding:0;width:100%;resize:none;display:block;text-align:left;box-sizing:border-box;line-height:inherit;background-color:transparent}.van-field__control--disabled{opacity:1;color:#666;background-color:transparent}.van-field__control--center{text-align:center}.van-field__control--right{text-align:right}.van-field__button,.van-field__clear,.van-field__icon-container{-webkit-flex-shrink:0;flex-shrink:0}.van-field__clear,.van-field__icon-container{padding:0 10px;color:#999;line-height:inherit;margin-right:-10px;vertical-align:middle}.van-field__icon{display:block;font-size:16px;line-height:inherit}.van-field__button{padding-left:10px}.van-field__error-message{color:#f44;font-size:12px;text-align:left}.van-field--error{color:#f44}.van-field--label-center .van-cell__title{text-align:center}.van-field--label-right .van-cell__title{text-align:right} .van-field__body{display:-webkit-box;display:-webkit-flex;display:flex;-webkit-box-align:center;-webkit-align-items:center;align-items:center}.van-field__body--textarea{min-height:24px}.van-field__control{border:0;margin:0;padding:0;width:100%;resize:none;display:block;text-align:left;box-sizing:border-box;line-height:inherit;background-color:transparent}.van-field__control--disabled{opacity:1;color:#666;background-color:transparent}.van-field__control--center{text-align:center}.van-field__control--right{text-align:right}.van-field__button,.van-field__clear,.van-field__icon-container{-webkit-flex-shrink:0;flex-shrink:0}.van-field__clear,.van-field__icon-container{padding:0 10px;line-height:inherit;margin-right:-10px;vertical-align:middle}.van-field__clear{color:#c9c9c9}.van-field__icon-container{color:#999}.van-field__icon{display:block;font-size:16px;line-height:inherit}.van-field__button{padding-left:10px}.van-field__error-message{color:#f44;font-size:12px;text-align:left}.van-field--error{color:#f44}.van-field--label-center .van-cell__title{text-align:center}.van-field--label-right .van-cell__title{text-align:right}

5
dist/icon/index.js vendored
View File

@ -10,7 +10,10 @@ Component({
name: String, name: String,
size: String, size: String,
color: String, color: String,
classPrefix: String classPrefix: {
type: String,
value: 'van-icon'
}
}, },
methods: { methods: {

25
dist/stepper/index.js vendored
View File

@ -3,6 +3,8 @@
const MAX = 2147483647; const MAX = 2147483647;
Component({ Component({
behaviors: ['wx://form-field'],
options: { options: {
addGlobalClass: true addGlobalClass: true
}, },
@ -15,14 +17,6 @@ Component({
], ],
properties: { properties: {
value: {
type: null,
observer(val) {
if (val !== this.currentValue) {
this.setData({ currentValue: this.range(val) });
}
}
},
integer: Boolean, integer: Boolean,
disabled: Boolean, disabled: Boolean,
disableInput: Boolean, disableInput: Boolean,
@ -42,7 +36,7 @@ Component({
attached() { attached() {
this.setData({ this.setData({
currentValue: this.range(this.data.value) value: this.range(this.data.value)
}); });
}, },
@ -64,14 +58,14 @@ Component({
} }
const diff = type === 'minus' ? -this.data.step : +this.data.step; const diff = type === 'minus' ? -this.data.step : +this.data.step;
const value = Math.round((this.data.currentValue + diff) * 100) / 100; const value = Math.round((this.data.value + diff) * 100) / 100;
this.triggerInput(this.range(value)); this.triggerInput(this.range(value));
this.triggerEvent(type); this.triggerEvent(type);
}, },
onBlur(event) { onBlur(event) {
const currentValue = this.range(this.data.currentValue); const value = this.range(this.data.value);
this.triggerInput(currentValue); this.triggerInput(value);
this.triggerEvent('blur', event); this.triggerEvent('blur', event);
}, },
@ -83,10 +77,9 @@ Component({
this.onChange('plus'); this.onChange('plus');
}, },
triggerInput(currentValue) { triggerInput(value) {
this.setData({ currentValue }); this.setData({ value });
this.triggerEvent('input', currentValue); this.triggerEvent('change', value);
this.triggerEvent('change', currentValue);
} }
} }
}); });

View File

@ -1,18 +1,18 @@
<view class="van-stepper custom-class"> <view class="van-stepper custom-class">
<view <view
class="minus-class van-stepper__minus {{ disabled || currentValue <= min ? 'van-stepper__minus--disabled' : '' }}" class="minus-class van-stepper__minus {{ disabled || value <= min ? 'van-stepper__minus--disabled' : '' }}"
bind:tap="onMinus" bind:tap="onMinus"
/> />
<input <input
type="{{ integer ? 'number' : 'digit' }}" type="{{ integer ? 'number' : 'digit' }}"
class="input-class van-stepper__input {{ disabled || disableInput ? 'van-stepper__input--disabled' : '' }}" class="input-class van-stepper__input {{ disabled || disableInput ? 'van-stepper__input--disabled' : '' }}"
value="{{ currentValue }}" value="{{ value }}"
disabled="{{ disabled || disableInput }}" disabled="{{ disabled || disableInput }}"
bindinput="onInput" bindinput="onInput"
bind:blur="onBlur" bind:blur="onBlur"
/> />
<view <view
class="plus-class van-stepper__plus {{ disabled || currentValue >= max ? 'van-stepper__plus--disabled' : '' }}" class="plus-class van-stepper__plus {{ disabled || value >= max ? 'van-stepper__plus--disabled' : '' }}"
bind:tap="onPlus" bind:tap="onPlus"
/> />
</view> </view>

13
dist/switch/index.js vendored
View File

@ -1,4 +1,6 @@
Component({ Component({
behaviors: ['wx://form-field'],
options: { options: {
addGlobalClass: true addGlobalClass: true
}, },
@ -6,15 +8,24 @@ Component({
externalClasses: ['custom-class', 'node-class'], externalClasses: ['custom-class', 'node-class'],
properties: { properties: {
checked: Boolean,
loading: Boolean, loading: Boolean,
disabled: Boolean, disabled: Boolean,
checked: {
type: Boolean,
observer(value) {
this.setData({ value });
}
},
size: { size: {
type: String, type: String,
value: '30px' value: '30px'
} }
}, },
attached() {
this.setData({ value: this.data.checked });
},
methods: { methods: {
onClick() { onClick() {
if (!this.data.disabled && !this.data.loading) { if (!this.data.disabled && !this.data.loading) {

View File

@ -71,6 +71,7 @@ Page({
| 参数 | 说明 | 类型 | 默认值 | | 参数 | 说明 | 类型 | 默认值 |
|-----------|-----------|-----------|-------------| |-----------|-----------|-----------|-------------|
| name | 在表单内提交时的标识符 | `String` | - |
| checked | 开关选中状态 | `Boolean` | `false` | | checked | 开关选中状态 | `Boolean` | `false` |
| loading | 是否为加载状态 | `Boolean` | `false` | | loading | 是否为加载状态 | `Boolean` | `false` |
| disabled | 是否为禁用状态 | `Boolean` | `false` | | disabled | 是否为禁用状态 | `Boolean` | `false` |

View File

@ -1,4 +1,6 @@
Component({ Component({
behaviors: ['wx://form-field'],
options: { options: {
addGlobalClass: true addGlobalClass: true
}, },
@ -6,15 +8,24 @@ Component({
externalClasses: ['custom-class', 'node-class'], externalClasses: ['custom-class', 'node-class'],
properties: { properties: {
checked: Boolean,
loading: Boolean, loading: Boolean,
disabled: Boolean, disabled: Boolean,
checked: {
type: Boolean,
observer(value) {
this.setData({ value });
}
},
size: { size: {
type: String, type: String,
value: '30px' value: '30px'
} }
}, },
attached() {
this.setData({ value: this.data.checked });
},
methods: { methods: {
onClick() { onClick() {
if (!this.data.disabled && !this.data.loading) { if (!this.data.disabled && !this.data.loading) {