forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQInputFrame.vue
More file actions
148 lines (140 loc) · 3.35 KB
/
QInputFrame.vue
File metadata and controls
148 lines (140 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<template>
<div
class="q-if row no-wrap items-center relative-position"
:class="classes"
:tabindex="focusable && !disable ? 0 : null"
@click="__onClick"
>
<template v-if="before">
<q-icon
v-for="item in before"
:key="item.icon"
class="q-if-control q-if-control-before"
:class="{hidden: __additionalHidden(item, hasError, length)}"
:name="item.icon"
@click="__baHandler($event, item)"
></q-icon>
</template>
<div class="q-if-inner col row no-wrap items-center relative-position">
<div
v-if="label"
class="q-if-label ellipsis full-width absolute self-start"
:class="{'q-if-label-above': labelIsAbove}"
v-html="label"
></div>
<span
v-if="prefix"
class="q-if-addon q-if-addon-left"
:class="addonClass"
v-html="prefix"
></span>
<slot></slot>
<span
v-if="suffix"
class="q-if-addon q-if-addon-right"
:class="addonClass"
v-html="suffix"
></span>
</div>
<slot name="after"></slot>
<template v-if="after">
<q-icon
v-for="item in after"
:key="item.icon"
class="q-if-control"
:class="{hidden: __additionalHidden(item, hasError, length)}"
:name="item.icon"
@click="__baHandler($event, item)"
></q-icon>
</template>
</div>
</template>
<script>
import Mixin from './input-frame-mixin'
export default {
name: 'q-input-frame',
mixins: [Mixin],
props: {
topAddons: Boolean,
focused: Boolean,
length: Number,
focusable: Boolean,
additionalLength: Boolean
},
data () {
return {
field: {}
}
},
inject: {
__field: { default: null }
},
computed: {
label () {
return this.stackLabel || this.floatLabel
},
addonClass () {
return {
'q-if-addon-visible': this.labelIsAbove,
'self-start': this.topAddons
}
},
classes () {
const cls = [{
'q-if-has-label': this.label,
'q-if-focused': this.focused,
'q-if-error': this.hasError,
'q-if-disabled': this.disable,
'q-if-focusable': this.focusable && !this.disable,
'q-if-inverted': this.inverted,
'q-if-dark': this.dark || this.inverted
}]
const color = this.hasError ? 'negative' : this.color
if (this.inverted) {
cls.push(`bg-${color}`)
cls.push(`text-white`)
}
else {
cls.push(`text-${color}`)
}
return cls
},
hasError () {
return !!(this.field.error || this.error)
}
},
methods: {
__onClick (e) {
this.$emit('click', e)
},
__additionalHidden (item, hasError, length) {
if (item.condition !== void 0) {
return item.condition === false
}
return (
(item.content !== void 0 && !item.content === (length > 0)) ||
(item.error !== void 0 && !item.error === hasError)
)
},
__baHandler (evt, item) {
if (!item.allowPropagation) {
evt.stopPropagation()
}
if (item.handler) {
item.handler(evt)
}
}
},
created () {
if (this.__field) {
this.field = this.__field
this.field.__registerInput(this)
}
},
beforeDestroy () {
if (this.__field) {
this.field.__unregisterInput()
}
}
}
</script>