2016-07-26 22:55:29 +00:00
|
|
|
<template>
|
2016-07-27 04:55:32 +00:00
|
|
|
<div class="md-input-container" :class="classes">
|
2016-07-26 22:55:29 +00:00
|
|
|
<slot></slot>
|
2016-07-27 22:17:22 +00:00
|
|
|
|
|
|
|
|
<md-button class="md-icon-button md-toggle-password" @click="togglePasswordType" v-if="mdHasPassword">
|
|
|
|
|
<md-icon>{{ showPassword ? 'visibility_off' : 'visibility' }}</md-icon>
|
|
|
|
|
</md-button>
|
2016-07-26 22:55:29 +00:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" src="./mdInputContainer.scss"></style>
|
|
|
|
|
|
|
|
|
|
<script>
|
2016-07-27 04:55:32 +00:00
|
|
|
let inlineClass = 'md-input-inline';
|
2016-07-27 22:17:22 +00:00
|
|
|
let hasPasswordClass = 'md-has-password';
|
2016-07-26 22:55:29 +00:00
|
|
|
|
|
|
|
|
export default {
|
2016-07-27 04:55:32 +00:00
|
|
|
props: {
|
|
|
|
|
mdInline: Boolean,
|
2016-07-27 22:17:22 +00:00
|
|
|
mdDisabled: Boolean,
|
|
|
|
|
mdHasPassword: Boolean
|
2016-07-27 04:55:32 +00:00
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
classes() {
|
|
|
|
|
let cssClasses = [];
|
|
|
|
|
|
|
|
|
|
this.mdInline && cssClasses.push(inlineClass);
|
2016-07-27 22:17:22 +00:00
|
|
|
this.mdHasPassword && cssClasses.push(hasPasswordClass);
|
2016-07-27 04:55:32 +00:00
|
|
|
|
|
|
|
|
return cssClasses.join(' ');
|
|
|
|
|
}
|
|
|
|
|
},
|
2016-07-26 22:55:29 +00:00
|
|
|
data() {
|
|
|
|
|
return {
|
2016-07-27 22:17:22 +00:00
|
|
|
input: false,
|
|
|
|
|
inputType: false,
|
|
|
|
|
showPassword: false
|
2016-07-26 22:55:29 +00:00
|
|
|
};
|
|
|
|
|
},
|
2016-07-27 22:17:22 +00:00
|
|
|
methods: {
|
|
|
|
|
togglePasswordType() {
|
|
|
|
|
if (this.input.tagName.toLowerCase() === 'input') {
|
|
|
|
|
let type = this.input.type;
|
|
|
|
|
|
|
|
|
|
if (type === 'password') {
|
|
|
|
|
this.input.type = 'text';
|
|
|
|
|
this.showPassword = true;
|
|
|
|
|
} else {
|
|
|
|
|
this.input.type = 'password';
|
|
|
|
|
this.showPassword = false;
|
|
|
|
|
}
|
2016-08-01 05:45:40 +00:00
|
|
|
|
|
|
|
|
this.input.focus();
|
2016-07-27 22:17:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2016-07-26 22:55:29 +00:00
|
|
|
ready() {
|
2016-08-01 05:45:40 +00:00
|
|
|
this.input = this.$el.querySelector('input') || this.$el.querySelector('textarea');
|
2016-07-27 22:17:22 +00:00
|
|
|
this.inputType = this.input.type;
|
2016-07-26 22:55:29 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|