Skip to content

Commit ab0ec55

Browse files
committed
feat: QDatetime coloring
1 parent e982f82 commit ab0ec55

File tree

11 files changed

+124
-116
lines changed

11 files changed

+124
-116
lines changed

dev/components/form/datetime.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
<q-inline-datetime v-model="model" type="time" format24h />
156156

157157
<p class="caption">Date & Time</p>
158-
<q-inline-datetime v-model="model" type="datetime" />
158+
<q-inline-datetime color="secondary" v-model="model" type="datetime" />
159159

160160
<p class="caption">Date - Monday as First</p>
161161
<q-inline-datetime v-model="model" monday-first type="date" />

src/components/datetime/InlineDatetimeIOS.vue

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,27 @@
9191
</div>
9292
</div>
9393
</template>
94-
9594
</div>
9695

97-
<div class="q-datetime-highlight"></div>
9896
<div class="q-datetime-mask"></div>
97+
<div class="q-datetime-highlight"></div>
9998
</div>
10099
</div>
101100
</template>
102101

103102
<script>
104-
import { between } from '../../utils/format'
103+
import { between, capitalize } from '../../utils/format'
105104
import { position } from '../../utils/event'
106105
import { css } from '../../utils/dom'
107106
import { isSameDate } from '../../utils/date'
108-
import mixin from './datetime-mixin'
107+
import DateMixin from './datetime-mixin'
109108
110109
export default {
111110
name: 'q-inline-datetime',
112-
mixins: [mixin],
111+
mixins: [DateMixin],
113112
props: {
114113
defaultSelection: [String, Number, Date],
114+
disable: Boolean,
115115
readonly: Boolean
116116
},
117117
data () {
@@ -267,28 +267,26 @@ export default {
267267
return
268268
}
269269
270-
this.__dragCleanup()
271-
;['month', 'date', 'year', 'hour', 'minute'].forEach(type => {
272-
this[type + 'DragOffset'] = 0
273-
})
274270
ev.stopPropagation()
275271
ev.preventDefault()
276272
277-
if (!this.value) {
278-
this.__updateModel()
279-
}
280-
273+
this[type + 'DragOffset'] = 0
281274
this.dragging = type
275+
this.__actualType = type === 'date' ? 'day' : type
276+
this.__typeOffset = type === 'month' ? -1 : 0
282277
this.__dragPosition = position(ev).top
283278
},
284279
__dragMove (ev, type) {
285280
if (this.dragging !== type || !this.editable) {
286281
return
287282
}
283+
288284
ev.stopPropagation()
289285
ev.preventDefault()
290-
this[type + 'DragOffset'] = (this.__dragPosition - position(ev).top) / 36
291-
this.__updatePositions(type, this.date[type]() + this[type + 'DragOffset'])
286+
287+
const offset = (this.__dragPosition - position(ev).top) / 36
288+
this[type + 'DragOffset'] = offset
289+
this.__updatePositions(type, this[this.__actualType] + offset + this.__typeOffset)
292290
},
293291
__dragStop (ev, type) {
294292
if (this.dragging !== type || !this.editable) {
@@ -300,30 +298,21 @@ export default {
300298
301299
let
302300
offset = Math.round(this[type + 'DragOffset']),
303-
newValue = this.__parseTypeValue(type, this[type === 'date' ? 'day' : type] + offset),
304-
actualType = type === 'date' ? 'day' : type
301+
newValue = this.__parseTypeValue(type, this[this.__actualType] + offset)
305302
306-
if (newValue !== this[actualType]) {
307-
this['set' + actualType.charAt(0).toUpperCase() + actualType.slice(1)](newValue)
308-
this[type + 'DragOffset'] = 0
303+
if (newValue !== this[this.__actualType]) {
304+
this[`set${capitalize(this.__actualType)}`](newValue)
309305
}
310306
else {
311-
this.__updatePositions(type, this.date[type]())
312-
this.timeout = setTimeout(() => {
313-
this[type + 'DragOffset'] = 0
314-
}, 150)
307+
this.__updatePositions(type, this[this.__actualType] + this.__typeOffset)
315308
}
316-
},
317-
__dragCleanup () {
318-
clearTimeout(this.timeout)
319-
this.timeout = null
309+
this.$nextTick(() => {
310+
this[type + 'DragOffset'] = 0
311+
})
320312
}
321313
},
322314
mounted () {
323315
this.$nextTick(this.__updateAllPositions)
324-
},
325-
beforeDestroy () {
326-
this.__dragCleanup()
327316
}
328317
}
329318
</script>

src/components/datetime/InlineDatetimeMat.vue

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="q-datetime inline row" :class="{disabled: disable, readonly: readonly}">
2+
<div class="q-datetime inline row" :class="classes">
33
<div class="q-datetime-header column col-xs-12 col-md-4 justify-center">
44
<div v-if="typeHasDate">
55
<div class="q-datetime-weekdaystring col-12">{{ weekDayString }}</div>
@@ -72,7 +72,6 @@
7272
v-for="n in yearInterval"
7373
:key="n"
7474
flat
75-
color="black"
7675
class="q-datetime-btn full-width"
7776
:class="{active: n + yearMin === year}"
7877
@click="setYear(n + yearMin)"
@@ -89,7 +88,6 @@
8988
v-for="index in monthInterval"
9089
:key="index"
9190
flat
92-
color="black"
9391
class="q-datetime-btn full-width"
9492
:class="{active: month === index + monthMin}"
9593
@click="setMonth(index + monthMin, true)"
@@ -100,26 +98,26 @@
10098

10199
<div
102100
v-if="view === 'day'"
103-
class="q-datetime-view-day q-datetime-animate"
101+
class="q-datetime-view-day"
104102
>
105103
<div class="row items-center content-center">
106104
<q-btn
107105
round
108106
small
109107
flat
110-
color="primary"
108+
:color="color"
111109
@click="setMonth(month - 1, true)"
112110
>
113111
<q-icon name="keyboard_arrow_left"></q-icon>
114112
</q-btn>
115-
<div class="col">
113+
<div class="col q-datetime-dark">
116114
{{ monthStamp }}
117115
</div>
118116
<q-btn
119117
round
120118
small
121119
flat
122-
color="primary"
120+
:color="color"
123121
@click="setMonth(month + 1, true)"
124122
>
125123
<q-icon name="keyboard_arrow_right"></q-icon>
@@ -139,7 +137,7 @@
139137
:class="{active: monthDay === day}"
140138
@click="setDay(monthDay)"
141139
>
142-
{{ monthDay }}
140+
<span>{{ monthDay }}</span>
143141
</div>
144142
<div v-if="max" v-for="fillerDay in aferMaxDays" class="row items-center content-center justify-center disabled">
145143
{{ fillerDay + maxDay }}
@@ -173,7 +171,7 @@
173171
class="q-datetime-clock-position fmt24"
174172
:class="[`q-datetime-clock-pos-${n-1}`, (n - 1) === hour ? 'active' : '']"
175173
>
176-
{{ n - 1 }}
174+
<span>{{ n - 1 }}</span>
177175
</div>
178176
</div>
179177
<div v-else>
@@ -182,7 +180,7 @@
182180
class="q-datetime-clock-position"
183181
:class="['q-datetime-clock-pos-' + n, n === hour ? 'active' : '']"
184182
>
185-
{{ n }}
183+
<span>{{ n }}</span>
186184
</div>
187185
</div>
188186
</div>
@@ -208,7 +206,7 @@
208206
class="q-datetime-clock-position"
209207
:class="['q-datetime-clock-pos-' + (n - 1), (n - 1) * 5 === minute ? 'active' : '']"
210208
>
211-
{{ (n - 1) * 5 }}
209+
<span>{{ (n - 1) * 5 }}</span>
212210
</div>
213211
</div>
214212
</div>
@@ -226,7 +224,7 @@ import { position } from '../../utils/event'
226224
import { QIcon } from '../icon'
227225
import { QBtn } from '../btn'
228226
import { formatDate, isSameDate } from '../../utils/date'
229-
import mixin from './datetime-mixin'
227+
import DateMixin from './datetime-mixin'
230228
import Ripple from '../../directives/ripple'
231229
232230
function convertToAmPm (hour) {
@@ -235,7 +233,7 @@ function convertToAmPm (hour) {
235233
236234
export default {
237235
name: 'q-inline-datetime',
238-
mixins: [mixin],
236+
mixins: [DateMixin],
239237
props: {
240238
defaultSelection: [String, Number, Date],
241239
disable: Boolean,
@@ -288,6 +286,19 @@ export default {
288286
}
289287
},
290288
computed: {
289+
classes () {
290+
const cls = []
291+
if (this.disable) {
292+
cls.push('disabled')
293+
}
294+
if (this.readonly) {
295+
cls.push('readonly')
296+
}
297+
if (this.color) {
298+
cls.push(`text-${this.color}`)
299+
}
300+
return cls
301+
},
291302
firstDayOfWeek () {
292303
return this.mondayFirst ? 1 : 0
293304
},

src/components/datetime/QDatetime.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@
4242
:max="max"
4343
:format24h="format24h"
4444
:monday-first="mondayFirst"
45+
:color="color"
4546
class="no-border"
4647
>
47-
<div class="modal-buttons row">
48-
<q-btn v-if="!noClear && model" @click="clear()" flat>
48+
<div class="row q-datetime-controls modal-buttons-top">
49+
<q-btn :color="color" v-if="!noClear && model" @click="clear()" flat>
4950
<span v-html="clearLabel"></span>
5051
</q-btn>
5152
<div class="col"></div>
52-
<q-btn @click="close()" flat><span v-html="cancelLabel"></span></q-btn>
53-
<q-btn @click="close(__update)" flat><span v-html="okLabel"></span></q-btn>
53+
<q-btn :color="color" @click="close()" flat><span v-html="cancelLabel"></span></q-btn>
54+
<q-btn :color="color" @click="close(__update)" flat><span v-html="okLabel"></span></q-btn>
5455
</div>
5556
</q-inline-datetime>
5657
</q-popover>
@@ -75,15 +76,17 @@
7576
:max="max"
7677
:format24h="format24h"
7778
:monday-first="mondayFirst"
79+
:color="color"
7880
class="no-border"
81+
:class="{'full-width': $q.theme === 'ios'}"
7982
>
80-
<div class="modal-buttons row full-width">
81-
<q-btn v-if="!noClear && model" @click="clear()" flat>
83+
<div class="modal-buttons modal-buttons-top row full-width">
84+
<q-btn :color="color" v-if="!noClear && model" @click="clear()" flat>
8285
<span v-html="clearLabel"></span>
8386
</q-btn>
8487
<div class="col"></div>
85-
<q-btn @click="close()" flat><span v-html="cancelLabel"></span></q-btn>
86-
<q-btn @click="close(__update)" flat><span v-html="okLabel"></span></q-btn>
88+
<q-btn :color="color" @click="close()" flat><span v-html="cancelLabel"></span></q-btn>
89+
<q-btn :color="color" @click="close(__update)" flat><span v-html="okLabel"></span></q-btn>
8790
</div>
8891
</q-inline-datetime>
8992
</q-modal>

src/components/datetime/QDatetimeRange.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export default {
8282
className: [String, Object],
8383
css: [String, Object],
8484
defaultFrom: [String, Number, Date],
85-
defaultTo: [String, Number, Date]
85+
defaultTo: [String, Number, Date],
86+
color: String,
87+
disable: Boolean
8688
}
8789
),
8890
computed: {

src/components/datetime/datetime-props.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export const inline = {
2424
return ['date', 'time', 'datetime'].includes(value)
2525
}
2626
},
27+
color: {
28+
type: String,
29+
default: 'primary'
30+
},
2731
min: {
2832
validator: modelValidator,
2933
default: null

src/components/datetime/datetime.ios.styl

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ $datetime-input-min-width ?= 70px
2828
text-align right
2929
position relative
3030
padding 0
31-
background rgba(0, 0, 0, .1)
32-
33-
.q-datetime-mask
34-
position absolute
35-
top 0
36-
right 0
37-
bottom 0
38-
left 0
39-
height 100%
40-
width 100%
41-
background linear-gradient(to top, white, transparent 50%, white)
42-
pointer-events none
4331

4432
.q-datetime-col
4533
display block
@@ -86,6 +74,17 @@ body.desktop .q-datetime-col-wrapper
8674
backface-visibility hidden
8775
transform-origin center center -110px
8876

77+
.q-datetime-mask
78+
position absolute
79+
top 0
80+
right 0
81+
bottom 0
82+
left 0
83+
height 100%
84+
width 100%
85+
background linear-gradient(to top, white, transparent 50%, white)
86+
pointer-events none
87+
8988
.q-datetime-highlight
9089
height 36px
9190
position absolute
@@ -95,22 +94,14 @@ body.desktop .q-datetime-col-wrapper
9594
top 50%
9695
margin-top -18px
9796
pointer-events none
98-
border-top 1px solid rgba(0, 0, 0, .2)
99-
border-bottom 1px solid rgba(0, 0, 0, .2)
100-
101-
&.q-datetime-no-selection
102-
letter-spacing 3px
103-
background white
104-
color $grey-6
105-
> div
106-
padding 0 6px
107-
text-align center
97+
border-top 1px solid $grey-5
98+
border-bottom 1px solid $grey-5
10899

109100
.q-datetime-range
110-
display flex
111-
> div
112-
flex 0 1 auto
113-
&.full-width > div
114-
flex-grow 1
115-
> div + div
116-
margin-left $datetime-range-space
101+
display flex
102+
> div
103+
flex 0 1 auto
104+
&.full-width > div
105+
flex-grow 1
106+
> div + div
107+
margin-left $datetime-range-space

0 commit comments

Comments
 (0)