Created
May 24, 2017 01:36
-
-
Save d-levin/9e13a75be115f76ea7cf934f7924f37a to your computer and use it in GitHub Desktop.
Generic input component for Vuejs that supports dynamic input type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generic input component of type [text] or [number] | |
*/ | |
export default { | |
render (createElement) { | |
return createElement( | |
'input', | |
{ | |
'class': { | |
'has-error': this.hasErrorClass && !this.hasValidClass, | |
'valid-input': this.hasValidClass | |
}, | |
staticClass: [ 'full-width' ], | |
attrs: { | |
'data-automate-id': this.dataAutomateId, | |
type: this.type | |
}, | |
domProps: { | |
required: true, | |
value: this.value, | |
readOnly: this.readOnly, | |
disabled: this.disabled | |
}, | |
on: { | |
blur: evt => this.$emit('blur', evt), | |
change: evt => this.$emit('change', evt), | |
click: evt => this.$emit('click', evt), | |
input: evt => this.$emit('input', evt.target.value) | |
} | |
} | |
) | |
}, | |
props: { | |
dataAutomateId: String, | |
disabled: Boolean, | |
hasErrorClass: Boolean, | |
hasValidClass: Boolean, | |
readOnly: Boolean, | |
type: { | |
type: String, | |
validator (type) { | |
return type === 'number' || type === 'text' | |
}, | |
default () { | |
return 'text' | |
} | |
}, | |
value: { | |
required: true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment