vuetify
Version:
Vue.js 2 Semantic Component Framework
230 lines (191 loc) • 6.58 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _loadable = require('./loadable');
var _loadable2 = _interopRequireDefault(_loadable);
var _themeable = require('./themeable');
var _themeable2 = _interopRequireDefault(_themeable);
var _validatable = require('./validatable');
var _validatable2 = _interopRequireDefault(_validatable);
var _VIcon = require('../components/VIcon');
var _VIcon2 = _interopRequireDefault(_VIcon);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
exports.default = {
name: 'input',
components: {
VIcon: _VIcon2.default
},
mixins: [_loadable2.default, _themeable2.default, _validatable2.default],
data: function data() {
return {
isFocused: false,
tabFocused: false,
internalTabIndex: null,
lazyValue: this.value
};
},
props: {
appendIcon: String,
appendIconCb: Function,
disabled: Boolean,
hint: String,
hideDetails: Boolean,
label: String,
persistentHint: Boolean,
placeholder: String,
prependIcon: String,
prependIconCb: Function,
readonly: Boolean,
required: Boolean,
tabindex: {
default: 0
},
toggleKeys: {
type: Array,
default: function _default() {
return [13, 32];
}
},
value: {
required: false
}
},
computed: {
inputGroupClasses: function inputGroupClasses() {
return Object.assign({
'input-group': true,
'input-group--async-loading': this.loading !== false,
'input-group--focused': this.isFocused,
'input-group--dirty': this.isDirty,
'input-group--tab-focused': this.tabFocused,
'input-group--disabled': this.disabled,
'input-group--error': this.hasError,
'input-group--append-icon': this.appendIcon,
'input-group--prepend-icon': this.prependIcon,
'input-group--required': this.required,
'input-group--hide-details': this.hideDetails,
'input-group--placeholder': !!this.placeholder,
'theme--dark': this.dark,
'theme--light': this.light
}, this.classes);
},
isDirty: function isDirty() {
return !!this.inputValue;
}
},
methods: {
groupFocus: function groupFocus(e) {},
groupBlur: function groupBlur(e) {
this.tabFocused = false;
},
genLabel: function genLabel() {
return this.$createElement('label', {
attrs: {
for: this.$attrs.id
}
}, this.$slots.label || this.label);
},
genMessages: function genMessages() {
var messages = null;
if (this.hint && (this.isFocused || this.persistentHint) && !this.validations.length) {
messages = [this.genHint()];
} else if (this.validations.length) {
messages = [this.genError(this.validations[0])];
}
return this.$createElement('transition', {
props: {
name: 'slide-y-transition'
}
}, messages);
},
genHint: function genHint() {
return this.$createElement('div', {
'class': 'input-group__messages input-group__hint',
domProps: { innerHTML: this.hint }
});
},
genError: function genError(error) {
return this.$createElement('div', {
'class': 'input-group__messages input-group__error'
}, error);
},
genIcon: function genIcon(type) {
var _class;
var defaultCallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var shouldClear = type === 'append' && this.clearable && this.isDirty;
var icon = shouldClear ? 'clear' : this[type + 'Icon'];
var callback = shouldClear ? this.clearableCallback : this[type + 'IconCb'] || defaultCallback;
return this.$createElement('v-icon', {
'class': (_class = {}, _defineProperty(_class, 'input-group__' + type + '-icon', true), _defineProperty(_class, 'input-group__icon-cb', !!callback), _defineProperty(_class, 'input-group__icon-clearable', shouldClear), _class),
props: {
disabled: this.disabled
},
on: {
click: function click(e) {
if (!callback) return;
e.stopPropagation();
callback();
}
}
}, icon);
},
genInputGroup: function genInputGroup(input) {
var _this = this;
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var defaultAppendCallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var children = [];
var wrapperChildren = [];
var detailsChildren = [];
data = Object.assign({}, {
'class': this.inputGroupClasses,
attrs: {
tabindex: this.disabled ? -1 : this.internalTabIndex || this.tabindex
},
on: {
focus: this.groupFocus,
blur: this.groupBlur,
click: function click() {
return _this.tabFocused = false;
},
keyup: function keyup(e) {
if ([9, 16].includes(e.keyCode)) {
_this.tabFocused = true;
}
},
keydown: function keydown(e) {
if (!_this.toggle) return;
if (_this.toggleKeys.includes(e.keyCode)) {
e.preventDefault();
_this.toggle();
}
}
}
}, data);
if (this.$slots.label || this.label) {
children.push(this.genLabel());
}
wrapperChildren.push(input);
if (this.prependIcon) {
wrapperChildren.unshift(this.genIcon('prepend'));
}
if (this.appendIcon || this.clearable) {
wrapperChildren.push(this.genIcon('append', defaultAppendCallback));
}
var progress = this.genProgress();
progress && detailsChildren.push(progress);
children.push(this.$createElement('div', {
'class': 'input-group__input'
}, wrapperChildren));
!this.hideDetails && detailsChildren.push(this.genMessages());
if (this.counter) {
detailsChildren.push(this.genCounter());
}
children.push(this.$createElement('div', {
'class': 'input-group__details'
}, detailsChildren));
return this.$createElement('div', data, children);
}
}
};