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
|
|
|
|
2016-08-02 04:20:35 +00:00
|
|
|
<span class="md-count" v-if="enableCounter">{{ inputLength }} / {{ counterLength }}</span>
|
|
|
|
|
|
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>
|
|
|
|
|
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() {
|
2016-08-10 04:36:20 +00:00
|
|
|
return {
|
|
|
|
|
'md-input-inline': this.mdInline,
|
|
|
|
|
'md-has-password': this.mdHasPassword,
|
|
|
|
|
'md-has-select': this.mdHasSelect
|
|
|
|
|
};
|
2016-07-27 04:55:32 +00:00
|
|
|
}
|
|
|
|
|
},
|
2016-07-26 22:55:29 +00:00
|
|
|
data() {
|
|
|
|
|
return {
|
2016-07-27 22:17:22 +00:00
|
|
|
input: false,
|
|
|
|
|
inputType: false,
|
2016-08-02 04:20:35 +00:00
|
|
|
showPassword: false,
|
|
|
|
|
enableCounter: false,
|
2016-08-10 04:36:20 +00:00
|
|
|
mdHasSelect: false,
|
2016-08-02 04:20:35 +00:00
|
|
|
counterLength: 0,
|
|
|
|
|
inputLength: 0
|
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-08-31 22:20:23 +00:00
|
|
|
mounted() {
|
2016-08-10 04:36:20 +00:00
|
|
|
this.input = this.$el.querySelector('input') || this.$el.querySelector('textarea') || this.$el.querySelector('select');
|
2016-08-02 04:20:35 +00:00
|
|
|
|
|
|
|
|
if (!this.input) {
|
|
|
|
|
this.$destroy();
|
|
|
|
|
|
2016-08-10 04:36:20 +00:00
|
|
|
throw new Error('Missing input/select/textarea inside md-input-container');
|
2016-08-02 04:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-27 22:17:22 +00:00
|
|
|
this.inputType = this.input.type;
|
2016-08-10 04:36:20 +00:00
|
|
|
|
|
|
|
|
if (this.$el.querySelector('select')) {
|
|
|
|
|
this.mdHasSelect = true;
|
|
|
|
|
}
|
2016-07-26 22:55:29 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|