Skip to content

Commit

Permalink
Feat input reverse (didi#180)
Browse files Browse the repository at this point in the history
* [add]{input.vue} reverse prop for input

* [update]{input.vue} pwdVisible and eyeClass logic

* [update] {input.vue} eye logic

* [update] {input.vue} input example

* [update] input.vue
  • Loading branch information
tank0317 authored and dolymood committed Apr 28, 2018
1 parent e1f2e00 commit 49bc55d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
11 changes: 9 additions & 2 deletions example/pages/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
@update:value="updatePwd"></switch-option>
<switch-option class="item" name="show eye" :value="showEye"
@update:value="updateShowEye" v-if="isPwd"></switch-option>
<switch-option class="item" name="reverse" :value="reverse"
@update:value="updateReverse" v-if="isPwd && showEye"></switch-option>
<switch-option class="item" name="password visible" :value="pwdVisible"
@update:value="updatePwdVisible" v-if="isPwd && showEye"></switch-option>
</div>
Expand All @@ -57,14 +59,16 @@
readonly: false,
isPwd: true,
showEye: true,
pwdVisible: true
pwdVisible: true,
reverse: false
}
},
computed: {
eye() {
if (this.isPwd && this.showEye) {
return {
open: this.pwdVisible
open: this.pwdVisible,
reverse: this.reverse
}
} else {
return false
Expand All @@ -90,6 +94,9 @@
},
updatePwdVisible(val) {
this.pwdVisible = val
},
updateReverse(val) {
this.reverse = val
}
},
components: {
Expand Down
32 changes: 20 additions & 12 deletions src/components/input/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@
return {
inputValue: this.value,
isFocus: false,
pwdVisible: false
formatedEye: {
open: false,
reverse: false
}
}
},
computed: {
_type() {
const type = this.type
if (type === 'password' && this.pwdVisible) {
if (type === 'password' && this.formatedEye.open) {
return 'text'
}
return type
Expand All @@ -102,7 +105,12 @@
return this.type === 'password' && this.eye && !this.disabled
},
eyeClass() {
return this.pwdVisible ? 'cubeic-eye-invisible' : 'cubeic-eye-visible'
const eye = this.formatedEye
let shouleBeVisible = !eye.open
if (eye.reverse) {
shouleBeVisible = !shouleBeVisible
}
return shouleBeVisible ? 'cubeic-eye-visible' : 'cubeic-eye-invisible'
}
},
watch: {
Expand All @@ -112,22 +120,22 @@
inputValue(newValue) {
this.$emit(EVENT_INPUT, newValue)
},
eye() {
this._computedPwdVisible()
eye: {
handler() {
this.formateEye()
},
immediate: true
}
},
created() {
this._computedPwdVisible()
},
methods: {
changeHander(e) {
this.$emit(EVENT_CHANGE, e)
},
_computedPwdVisible() {
formateEye() {
if (typeof this.eye === 'boolean') {
this.pwdVisible = this.eye
this.formatedEye.open = this.eye
} else {
this.pwdVisible = this.eye.open
Object.assign(this.formatedEye, this.eye)
}
},
handleFocus(e) {
Expand All @@ -143,7 +151,7 @@
this.$refs.input.focus()
},
handlePwdEye() {
this.pwdVisible = !this.pwdVisible
this.formatedEye.open = !this.formatedEye.open
}
}
}
Expand Down

0 comments on commit 49bc55d

Please sign in to comment.