Skip to content

Commit cee2961

Browse files
committed
QColor updates
1 parent 177e45d commit cee2961

File tree

15 files changed

+145
-327
lines changed

15 files changed

+145
-327
lines changed

dev/components/form/color-picker.vue

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,31 @@
3030
</div>
3131
</div>
3232

33+
<h4>Lazy</h4>
34+
<div class="row md-gutter" style="width: 550px">
35+
<div class="col-6">
36+
<q-color-picker :value="modelHex" @change="model => { modelHex = model }" />
37+
<div class="inline-block text-white" style="text-shadow: black 0px 0px 7px; padding: 10px" :style="{ backgroundColor: this.modelHex }">
38+
<pre>Hex: {{modelHex}}</pre>
39+
</div>
40+
</div>
41+
<div class="col-6">
42+
<q-color-picker :value="modelHexa" @change="model => { modelHexa = model }" />
43+
<div class="inline-block text-white" style="text-shadow: black 0px 0px 7px; padding: 10px" :style="{ backgroundColor: this.modelHexa }">
44+
<pre>Hexa: {{modelHexa}}</pre>
45+
</div>
46+
</div>
47+
</div>
48+
3349
<h4>Input</h4>
34-
<q-color v-model="inputModelHex" />
50+
<q-color v-model="inputModelHex" clearable default-selection="#ffffff" />
3551
<q-color v-model="inputModelHex" inverted />
36-
<q-color v-model="inputModelRgb" />
37-
<q-color v-model="inputModelRgb" inverted />
52+
<q-color v-model="inputModelRgb" readonly float-label="Readonly" />
53+
<q-color v-model="inputModelRgb" inverted disable float-label="Disable" />
54+
55+
<h4>Lazy Input</h4>
56+
<q-color :value="inputModelHex" @change="val => inputModelHex = val" clearable />
57+
<q-color :value="inputModelRgb" @change="val => inputModelRgb = val" clearable />
3858

3959
<h4>Readonly</h4>
4060
<div class="row md-gutter" style="width: 550px">

dev/components/form/datetime-range.vue

Lines changed: 0 additions & 132 deletions
This file was deleted.

src/components/color/QColor.js

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import QColorPicker from './QColorPicker'
66
import { QBtn } from '../btn'
77
import { QModal } from '../modal'
88
import clone from '../../utils/clone'
9+
import { stopAndPrevent } from '../../utils/event'
910

1011
let contentCss = __THEME__ === 'ios'
1112
? {
@@ -36,10 +37,11 @@ export default {
3637
},
3738
displayValue: String,
3839
placeholder: String,
39-
noClear: Boolean,
40-
clearLabel: String,
40+
clearable: Boolean,
4141
okLabel: String,
42-
cancelLabel: String
42+
cancelLabel: String,
43+
disable: Boolean,
44+
readonly: Boolean
4345
},
4446
data () {
4547
let data = this.isPopover() ? {} : {
@@ -58,6 +60,9 @@ export default {
5860
usingPopover () {
5961
return this.isPopover()
6062
},
63+
editable () {
64+
return !this.disable && !this.readonly
65+
},
6166
actualValue () {
6267
if (this.displayValue) {
6368
return this.displayValue
@@ -90,15 +95,14 @@ export default {
9095
this.focused = false
9196
return this.$refs.popup.hide()
9297
},
93-
clear () {
94-
if (this.value) {
95-
this.$emit('input', null)
96-
this.$emit('change', null)
97-
}
98-
this.$refs.popup.hide()
98+
clear (evt) {
99+
stopAndPrevent(evt)
100+
this.$emit('input', null)
101+
this.$emit('change', null)
99102
},
100103

101104
__onFocus () {
105+
this.__setModel(this.value)
102106
this.focused = true
103107
this.$emit('focus')
104108
},
@@ -114,15 +118,20 @@ export default {
114118
__onHide () {
115119
this.focused = false
116120
this.$emit('blur')
121+
if (this.usingPopover) {
122+
this.__update(true)
123+
}
117124
},
118-
__setModel () {
119-
this.model = this.value
120-
? clone(this.value)
125+
__setModel (val = this.value) {
126+
this.model = val
127+
? clone(val)
121128
: this.defaultSelection
122129
},
123-
__update () {
130+
__update (change) {
124131
this.$emit('input', this.model)
125-
this.$emit('change', this.model)
132+
if (change) {
133+
this.$emit('change', this.model)
134+
}
126135
},
127136

128137
__getPicker (h, modal) {
@@ -131,14 +140,19 @@ export default {
131140
staticClass: `no-border${modal ? ' full-width' : ''}`,
132141
props: extend({
133142
color: this.color,
134-
value: this.model
143+
value: this.model,
144+
disable: this.disable,
145+
readonly: this.readonly
135146
}, this.$attrs),
136147
on: {
137148
input: v => {
138149
this.model = v
139150
if (this.usingPopover) {
140151
this.__update()
141152
}
153+
},
154+
change: v => {
155+
this.model = v
142156
}
143157
}
144158
})
@@ -148,18 +162,6 @@ export default {
148162
child[__THEME__ === 'mat' ? 'push' : 'unshift'](h('div', {
149163
staticClass: 'modal-buttons modal-buttons-top row full-width'
150164
}, [
151-
!this.noClear && this.model
152-
? h(QBtn, {
153-
props: {
154-
color: this.color,
155-
flat: true,
156-
label: this.clearLabel || this.$q.i18n.label.clear,
157-
waitForRipple: true,
158-
compact: true
159-
},
160-
on: { click: this.clear }
161-
})
162-
: null,
163165
h('div', { staticClass: 'col' }),
164166
h(QBtn, {
165167
props: {
@@ -171,21 +173,23 @@ export default {
171173
},
172174
on: { click: this.hide }
173175
}),
174-
h(QBtn, {
175-
props: {
176-
color: this.color,
177-
flat: true,
178-
label: this.okLabel || this.$q.i18n.label.set,
179-
waitForRipple: true,
180-
compact: true
181-
},
182-
on: {
183-
click: () => {
184-
this.hide()
185-
this.__update()
176+
this.editable
177+
? h(QBtn, {
178+
props: {
179+
color: this.color,
180+
flat: true,
181+
label: this.okLabel || this.$q.i18n.label.set,
182+
waitForRipple: true,
183+
compact: true
184+
},
185+
on: {
186+
click: () => {
187+
this.hide()
188+
this.__update(true)
189+
}
186190
}
187-
}
188-
})
191+
})
192+
: null
189193
]))
190194
}
191195

@@ -256,6 +260,15 @@ export default {
256260
}
257261
}, this.__getPicker(h, true)),
258262

263+
this.editable && this.clearable && this.actualValue.length
264+
? h('q-icon', {
265+
slot: 'after',
266+
props: { name: this.$q.icon.input.clear },
267+
on: { click: this.clear },
268+
staticClass: 'q-if-control'
269+
})
270+
: null,
271+
259272
h('q-icon', {
260273
slot: 'after',
261274
props: { name: this.$q.icon.input.dropdown },

0 commit comments

Comments
 (0)