-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
/
VTimePickerControls.tsx
171 lines (153 loc) Β· 6.03 KB
/
VTimePickerControls.tsx
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Styles
import './VTimePickerControls.sass'
// Components
import { VBtn } from '@/components/VBtn'
import { pad } from '@/components/VDatePicker/util'
// Composables
import { useLocale } from '@/composables/locale'
// Utilities
import { genericComponent, propsFactory, useRender } from '@/util'
// Types
import { SelectingTimes } from './SelectingTimes'
type Period = 'am' | 'pm'
export const makeVTimePickerControlsProps = propsFactory({
ampm: Boolean,
ampmReadonly: Boolean,
color: String,
disabled: Boolean,
hour: Number,
minute: Number,
second: Number,
period: String,
readonly: Boolean,
useSeconds: Boolean,
selecting: Number,
value: Number,
}, 'VTimePickerControls')
export const VTimePickerControls = genericComponent()({
name: 'VTimePickerControls',
props: makeVTimePickerControlsProps(),
emits: {
'update:period': (data: Period) => data,
'update:selecting': (data: 1 | 2 | 3) => data,
},
setup (props, { emit, slots }) {
const { t } = useLocale()
useRender(() => {
let hour = props.hour
if (props.ampm) {
hour = hour ? ((hour - 1) % 12 + 1) : 12
}
return (
<div class="v-time-picker-controls">
<div
class={{
'v-time-picker-controls__time': true,
'v-time-picker-hide-controls': props.hideHeader,
'v-time-picker-controls__time--with-seconds': props.useSeconds,
}}
>
{
!props.hideHeader && (
<div key="timePickerTimeBtns">
<VBtn
active={ props.selecting === 1 }
color={ props.selecting === 1 ? props.color : undefined }
variant="tonal"
class={{
'v-time-picker-controls__time__btn': true,
'v-time-picker-controls__time--with-ampm__btn': props.ampm,
'v-time-picker-controls__time--with-seconds__btn': props.useSeconds,
}}
text={ props.hour == null ? '--' : pad(`${hour}`) }
onClick={ () => emit('update:selecting', SelectingTimes.Hour) }
/>
<span
class={[
'v-time-picker-controls__time__separator',
{ 'v-time-picker-controls--with-seconds__time__separator': props.useSeconds },
]}
>:</span>
<VBtn
active={ props.selecting === 2 }
color={ props.selecting === 2 ? props.color : undefined }
class={{
'v-time-picker-controls__time__btn': true,
'v-time-picker-controls__time__btn__active': props.selecting === 2,
'v-time-picker-controls__time--with-ampm__btn': props.ampm,
'v-time-picker-controls__time--with-seconds__btn': props.useSeconds,
}}
variant="tonal"
text={ props.minute == null ? '--' : pad(props.minute) }
onClick={ () => emit('update:selecting', SelectingTimes.Minute) }
/>
{
props.useSeconds && (
<span
class={[
'v-time-picker-controls__time__separator',
{ 'v-time-picker-controls--with-seconds__time__separator': props.useSeconds },
]}
key="secondsDivider"
>:</span>
)
}
{
props.useSeconds && (
<VBtn
key="secondsVal"
variant="tonal"
onClick={ () => emit('update:selecting', SelectingTimes.Second) }
class={{
'v-time-picker-controls__time__btn': true,
'v-time-picker-controls__time__btn__active': props.selecting === 3,
'v-time-picker-controls__time--with-seconds__btn': props.useSeconds,
}}
text={ props.second == null ? '--' : pad(props.second) }
/>
)
}
</div>
)}
{
props.ampm && (
<div
class={['v-time-picker-controls__ampm', {
'v-time-picker-controls__ampm--readonly': props.ampmReadonly,
}]}
>
<VBtn
active={ props.period === 'am' }
color={ props.period === 'am' ? props.color : undefined }
class={{
'v-time-picker-controls__ampm__am': true,
'v-time-picker-controls__ampm__btn': true,
'v-time-picker-controls__ampm__btn__active': props.period === 'am',
}}
text={ t('$vuetify.timePicker.am') }
variant="tonal"
onClick={ () => props.period !== 'am' ? emit('update:period', 'am') : null }
/>
<VBtn
active={ props.period === 'pm' }
color={ props.period === 'pm' ? props.color : undefined }
class={{
'v-time-picker-controls__ampm__pm': true,
'v-time-picker-controls__ampm__btn': true,
'v-time-picker-controls__ampm__btn__active': props.period === 'pm',
}}
text={ t('$vuetify.timePicker.pm') }
variant="tonal"
onClick={ () => props.period !== 'pm' ? emit('update:period', 'pm') : null }
/>
</div>
)
}
</div>
</div>
)
})
return {}
},
})
export type VTimePickerControls = InstanceType<typeof VTimePickerControls>