@coreui/vue-pro 4.1.4 → 4.3.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/button/CButton.d.ts +29 -2
- package/dist/components/calendar/CCalendar.d.ts +185 -0
- package/dist/components/calendar/index.d.ts +6 -0
- package/dist/components/date-picker/CDatePicker.d.ts +406 -0
- package/dist/components/date-picker/index.d.ts +6 -0
- package/dist/components/date-range-picker/CDateRangePicker.d.ts +480 -0
- package/dist/components/date-range-picker/index.d.ts +6 -0
- package/dist/components/dropdown/CDropdown.d.ts +25 -0
- package/dist/components/dropdown/CDropdownToggle.d.ts +35 -1
- package/dist/components/index.d.ts +5 -0
- package/dist/components/multi-select/CMultiSelect.d.ts +2 -2
- package/dist/components/picker/CPicker.d.ts +11 -0
- package/dist/components/picker/index.d.ts +6 -0
- package/dist/components/popover/CPopover.d.ts +1 -1
- package/dist/components/sidebar/CSidebar.d.ts +1 -1
- package/dist/components/smart-table/CSmartTable.d.ts +35 -99
- package/dist/components/smart-table/CSmartTableInterface.d.ts +3 -3
- package/dist/components/time-picker/CTimePicker.d.ts +10 -0
- package/dist/components/time-picker/CTimePickerRollCol.d.ts +27 -0
- package/dist/components/time-picker/index.d.ts +6 -0
- package/dist/components/toast/CToast.d.ts +1 -1
- package/dist/index.es.js +3726 -1646
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +3734 -1644
- package/dist/index.js.map +1 -1
- package/dist/utils/calendar.d.ts +21 -0
- package/dist/utils/time.d.ts +17 -0
- package/package.json +9 -9
- package/src/components/accordion/CAccordionButton.ts +1 -0
- package/src/components/accordion/__tests__/__snapshots__/CAccordionButton.spec.ts.snap +1 -1
- package/src/components/accordion/__tests__/__snapshots__/CAccordionHeader.spec.ts.snap +1 -1
- package/src/components/button/CButton.ts +30 -1
- package/src/components/button/__tests__/__snapshots__/CButton.spec.ts.snap +1 -1
- package/src/components/calendar/CCalendar.ts +546 -0
- package/src/components/calendar/index.ts +10 -0
- package/src/components/close-button/CCloseButton.ts +4 -1
- package/src/components/date-picker/CDatePicker.ts +243 -0
- package/src/components/date-picker/index.ts +10 -0
- package/src/components/date-range-picker/CDateRangePicker.ts +635 -0
- package/src/components/date-range-picker/index.ts +10 -0
- package/src/components/dropdown/CDropdown.ts +48 -49
- package/src/components/dropdown/CDropdownMenu.ts +52 -7
- package/src/components/dropdown/CDropdownToggle.ts +93 -29
- package/src/components/dropdown/__tests__/CDropdownMenu.spec.ts +7 -7
- package/src/components/dropdown/__tests__/CDropdownToggle.spec.ts +4 -5
- package/src/components/dropdown/__tests__/__snapshots__/CDropdownToggle.spec.ts.snap +2 -2
- package/src/components/form/CFormCheck.ts +2 -1
- package/src/components/form/CFormSwitch.ts +1 -7
- package/src/components/form/__tests__/__snapshots__/CFormCheck.spec.ts.snap +2 -8
- package/src/components/index.ts +5 -0
- package/src/components/modal/__tests__/__snapshots__/CModal.spec.ts.snap +2 -1
- package/src/components/pagination/CSmartPagination.ts +4 -4
- package/src/components/picker/CPicker.ts +220 -0
- package/src/components/picker/index.ts +10 -0
- package/src/components/sidebar/__tests__/__snapshots__/CSidebar.spec.ts.snap +8 -2
- package/src/components/smart-table/CSmartTable.ts +17 -49
- package/src/components/smart-table/CSmartTableInterface.ts +5 -3
- package/src/components/time-picker/CTimePicker.ts +410 -0
- package/src/components/time-picker/CTimePickerRollCol.ts +58 -0
- package/src/components/time-picker/index.ts +10 -0
- package/src/components/toast/__tests__/__snapshots__/CToastClose.spec.ts.snap +1 -1
- package/src/utils/calendar.ts +193 -0
- package/src/utils/time.ts +58 -0
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
import { defineComponent, h, onMounted, PropType, ref, watch } from 'vue'
|
|
2
|
+
|
|
3
|
+
import { CButton } from '../button'
|
|
4
|
+
import { CCalendar } from '../calendar'
|
|
5
|
+
import { CFormInput, CInputGroup, CInputGroupText } from '../form'
|
|
6
|
+
import { CPicker } from '../picker'
|
|
7
|
+
import { CTimePicker } from '../time-picker'
|
|
8
|
+
|
|
9
|
+
import { isValidDate } from '../../utils/calendar'
|
|
10
|
+
|
|
11
|
+
import { Color } from '../props'
|
|
12
|
+
|
|
13
|
+
const CDateRangePicker = defineComponent({
|
|
14
|
+
name: 'CDateRangePicker',
|
|
15
|
+
props: {
|
|
16
|
+
/**
|
|
17
|
+
* The number of calendars that render on desktop devices.
|
|
18
|
+
*/
|
|
19
|
+
calendars: {
|
|
20
|
+
type: Number,
|
|
21
|
+
default: 2,
|
|
22
|
+
},
|
|
23
|
+
/**
|
|
24
|
+
* Default date of the component
|
|
25
|
+
*/
|
|
26
|
+
calendarDate: {
|
|
27
|
+
type: [Date, String],
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* Toggle visibility or set the content of cancel button.
|
|
31
|
+
*/
|
|
32
|
+
cancelButton: {
|
|
33
|
+
type: [Boolean, String],
|
|
34
|
+
default: 'Cancel',
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Sets the color context of the cancel button to one of CoreUI’s themed colors.
|
|
38
|
+
*
|
|
39
|
+
* @values 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light'
|
|
40
|
+
*/
|
|
41
|
+
cancelButtonColor: {
|
|
42
|
+
...Color,
|
|
43
|
+
default: 'primary',
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Size the cancel button small or large.
|
|
47
|
+
*
|
|
48
|
+
* @values 'sm', 'lg'
|
|
49
|
+
*/
|
|
50
|
+
cancelButtonSize: {
|
|
51
|
+
type: String,
|
|
52
|
+
default: 'sm',
|
|
53
|
+
validator: (value: string) => {
|
|
54
|
+
return ['sm', 'lg'].includes(value)
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* Set the cancel button variant to an outlined button or a ghost button.
|
|
59
|
+
*
|
|
60
|
+
* @values 'ghost', 'outline'
|
|
61
|
+
*/
|
|
62
|
+
cancelButtonVariant: {
|
|
63
|
+
type: String,
|
|
64
|
+
default: 'ghost',
|
|
65
|
+
validator: (value: string) => {
|
|
66
|
+
return ['ghost', 'outline'].includes(value)
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
/**
|
|
70
|
+
* Toggle visibility of the cleaner button.
|
|
71
|
+
*/
|
|
72
|
+
cleaner: {
|
|
73
|
+
type: Boolean,
|
|
74
|
+
default: true,
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Toggle visibility or set the content of confirm button.
|
|
78
|
+
*/
|
|
79
|
+
confirmButton: {
|
|
80
|
+
type: [Boolean, String],
|
|
81
|
+
default: 'OK',
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* Sets the color context of the confirm button to one of CoreUI’s themed colors.
|
|
85
|
+
*
|
|
86
|
+
* @values 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light'
|
|
87
|
+
*/
|
|
88
|
+
confirmButtonColor: {
|
|
89
|
+
...Color,
|
|
90
|
+
default: 'primary',
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Size the confirm button small or large.
|
|
94
|
+
*
|
|
95
|
+
* @values 'sm', 'lg'
|
|
96
|
+
*/
|
|
97
|
+
confirmButtonSize: {
|
|
98
|
+
type: String,
|
|
99
|
+
default: 'sm',
|
|
100
|
+
validator: (value: string) => {
|
|
101
|
+
return ['sm', 'lg'].includes(value)
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
* Set the confirm button variant to an outlined button or a ghost button.
|
|
106
|
+
*
|
|
107
|
+
* @values 'ghost', 'outline'
|
|
108
|
+
*/
|
|
109
|
+
confirmButtonVariant: {
|
|
110
|
+
type: String,
|
|
111
|
+
validator: (value: string) => {
|
|
112
|
+
return ['ghost', 'outline'].includes(value)
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
/**
|
|
116
|
+
* Toggle the disabled state for the component.
|
|
117
|
+
*/
|
|
118
|
+
disabled: Boolean,
|
|
119
|
+
/**
|
|
120
|
+
* Specify the list of dates that cannot be selected.
|
|
121
|
+
*/
|
|
122
|
+
disabledDates: {
|
|
123
|
+
type: Array as PropType<Date[] | Date[][]>,
|
|
124
|
+
},
|
|
125
|
+
/**
|
|
126
|
+
* Initial selected to date (range).
|
|
127
|
+
*/
|
|
128
|
+
endDate: {
|
|
129
|
+
type: [Date, String],
|
|
130
|
+
required: false,
|
|
131
|
+
},
|
|
132
|
+
/**
|
|
133
|
+
* Sets the day of start week.
|
|
134
|
+
* - 0 - Sunday,
|
|
135
|
+
* - 1 - Monday,
|
|
136
|
+
* - 2 - Tuesday,
|
|
137
|
+
* - 3 - Wednesday,
|
|
138
|
+
* - 4 - Thursday,
|
|
139
|
+
* - 5 - Friday,
|
|
140
|
+
* - 6 - Saturday,
|
|
141
|
+
* - 7 - Sunday
|
|
142
|
+
*/
|
|
143
|
+
firstDayOfWeek: {
|
|
144
|
+
type: Number,
|
|
145
|
+
default: 1,
|
|
146
|
+
},
|
|
147
|
+
/**
|
|
148
|
+
* Toggle visibility of footer element or set the content of footer.
|
|
149
|
+
*/
|
|
150
|
+
footer: Boolean,
|
|
151
|
+
/**
|
|
152
|
+
* Toggle visibility or set the content of the input indicator.
|
|
153
|
+
*/
|
|
154
|
+
indicator: {
|
|
155
|
+
type: Boolean,
|
|
156
|
+
default: true,
|
|
157
|
+
},
|
|
158
|
+
/**
|
|
159
|
+
* Toggle the readonly state for the component.
|
|
160
|
+
*/
|
|
161
|
+
inputReadOnly: Boolean,
|
|
162
|
+
/**
|
|
163
|
+
* Sets the default locale for components. If not set, it is inherited from the navigator.language.
|
|
164
|
+
*/
|
|
165
|
+
locale: {
|
|
166
|
+
type: String,
|
|
167
|
+
default: 'default',
|
|
168
|
+
},
|
|
169
|
+
/**
|
|
170
|
+
* Max selectable date.
|
|
171
|
+
*/
|
|
172
|
+
maxDate: {
|
|
173
|
+
type: [Date, String],
|
|
174
|
+
},
|
|
175
|
+
/**
|
|
176
|
+
* Min selectable date.
|
|
177
|
+
*/
|
|
178
|
+
minDate: {
|
|
179
|
+
type: [Date, String],
|
|
180
|
+
},
|
|
181
|
+
/**
|
|
182
|
+
* Show arrows navigation.
|
|
183
|
+
*/
|
|
184
|
+
navigation: {
|
|
185
|
+
type: Boolean,
|
|
186
|
+
default: true,
|
|
187
|
+
},
|
|
188
|
+
/**
|
|
189
|
+
* Specifies a short hint that is visible in the input.
|
|
190
|
+
*/
|
|
191
|
+
placeholder: {
|
|
192
|
+
type: [String, Array] as PropType<String | String[]>,
|
|
193
|
+
default: () => ['Start date', 'End date'],
|
|
194
|
+
},
|
|
195
|
+
/**
|
|
196
|
+
* @ignore
|
|
197
|
+
*/
|
|
198
|
+
range: {
|
|
199
|
+
type: Boolean,
|
|
200
|
+
default: true,
|
|
201
|
+
},
|
|
202
|
+
/**
|
|
203
|
+
* Predefined date ranges the user can select from.
|
|
204
|
+
*/
|
|
205
|
+
ranges: Object,
|
|
206
|
+
/**
|
|
207
|
+
* Toggle select mode between start and end date.
|
|
208
|
+
*/
|
|
209
|
+
selectEndDate: Boolean,
|
|
210
|
+
/**
|
|
211
|
+
* Default icon or character character that separates two dates.
|
|
212
|
+
*/
|
|
213
|
+
separator: {
|
|
214
|
+
type: Boolean,
|
|
215
|
+
default: true,
|
|
216
|
+
},
|
|
217
|
+
/**
|
|
218
|
+
* Size the component small or large.
|
|
219
|
+
*
|
|
220
|
+
* @values 'sm', 'lg'
|
|
221
|
+
*/
|
|
222
|
+
size: {
|
|
223
|
+
type: String,
|
|
224
|
+
required: false,
|
|
225
|
+
validator: (value: string) => {
|
|
226
|
+
return ['sm', 'lg'].includes(value)
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
/**
|
|
230
|
+
* Initial selected date.
|
|
231
|
+
*/
|
|
232
|
+
startDate: {
|
|
233
|
+
type: [Date, String],
|
|
234
|
+
},
|
|
235
|
+
/**
|
|
236
|
+
* Provide an additional time selection by adding select boxes to choose times.
|
|
237
|
+
*/
|
|
238
|
+
timepicker: Boolean,
|
|
239
|
+
/**
|
|
240
|
+
* Set length or format of day name.
|
|
241
|
+
*
|
|
242
|
+
* @type number | 'long' | 'narrow' | 'short'
|
|
243
|
+
*/
|
|
244
|
+
weekdayFormat: {
|
|
245
|
+
type: [Number, String],
|
|
246
|
+
default: 2,
|
|
247
|
+
validator: (value: string | number) => {
|
|
248
|
+
if (typeof value === 'string') {
|
|
249
|
+
return ['long', 'narrow', 'short'].includes(value)
|
|
250
|
+
}
|
|
251
|
+
if (typeof value === 'number') {
|
|
252
|
+
return true
|
|
253
|
+
}
|
|
254
|
+
return false
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
},
|
|
258
|
+
emit: [
|
|
259
|
+
/**
|
|
260
|
+
* Callback fired when the end date changed.
|
|
261
|
+
*/
|
|
262
|
+
'end-date-change',
|
|
263
|
+
/**
|
|
264
|
+
* Callback fired when the component requests to be hidden.
|
|
265
|
+
*/
|
|
266
|
+
'hide',
|
|
267
|
+
/**
|
|
268
|
+
* Callback fired when the component requests to be shown.
|
|
269
|
+
*/
|
|
270
|
+
'show',
|
|
271
|
+
/**
|
|
272
|
+
* Callback fired when the start date changed.
|
|
273
|
+
*/
|
|
274
|
+
'start-date-change',
|
|
275
|
+
],
|
|
276
|
+
setup(props, { slots, emit }) {
|
|
277
|
+
const calendarDate = ref<Date>(
|
|
278
|
+
props.calendarDate
|
|
279
|
+
? new Date(props.calendarDate)
|
|
280
|
+
: props.startDate
|
|
281
|
+
? new Date(props.startDate)
|
|
282
|
+
: props.endDate
|
|
283
|
+
? new Date(props.endDate)
|
|
284
|
+
: new Date(),
|
|
285
|
+
)
|
|
286
|
+
const inputStartHoverValue = ref<Date | null>(null)
|
|
287
|
+
const inputEndHoverValue = ref<Date | null>(null)
|
|
288
|
+
const startDate = ref<Date | null>(props.startDate ? new Date(props.startDate) : null)
|
|
289
|
+
const endDate = ref<Date | null>(props.endDate ? new Date(props.endDate) : null)
|
|
290
|
+
const initialStartDate = ref<Date | null>(startDate.value ? new Date(startDate.value) : null)
|
|
291
|
+
const initialEndDate = ref<Date | null>(endDate.value ? new Date(endDate.value) : null)
|
|
292
|
+
const selectEndDate = ref(false)
|
|
293
|
+
|
|
294
|
+
const isMobile = ref(false)
|
|
295
|
+
|
|
296
|
+
onMounted(() => {
|
|
297
|
+
isMobile.value = window.innerWidth < 768
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
watch(
|
|
301
|
+
() => props.startDate,
|
|
302
|
+
() => {
|
|
303
|
+
if (props.startDate) {
|
|
304
|
+
calendarDate.value = new Date(props.startDate)
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
watch(
|
|
310
|
+
() => props.endDate,
|
|
311
|
+
() => {
|
|
312
|
+
if (props.endDate) {
|
|
313
|
+
calendarDate.value = new Date(props.endDate)
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
const setInputValue = (date: Date | null, timepicker?: boolean) => {
|
|
319
|
+
if (date) {
|
|
320
|
+
return timepicker
|
|
321
|
+
? date.toLocaleString(props.locale)
|
|
322
|
+
: date.toLocaleDateString(props.locale)
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return ''
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const handleCalendarCellHover = (date: Date | null) => {
|
|
329
|
+
if (selectEndDate.value) {
|
|
330
|
+
inputEndHoverValue.value = date === null ? null : date
|
|
331
|
+
return
|
|
332
|
+
}
|
|
333
|
+
inputStartHoverValue.value = date === null ? null : date
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const handleCalendarDateChange = (date: Date, difference?: number) => {
|
|
337
|
+
if (difference) {
|
|
338
|
+
calendarDate.value = new Date(date.getFullYear(), date.getMonth() - difference, 1)
|
|
339
|
+
return
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
calendarDate.value = date
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const handleStartDateChange = (date: Date) => {
|
|
346
|
+
startDate.value = date
|
|
347
|
+
inputStartHoverValue.value = null
|
|
348
|
+
if (props.range) {
|
|
349
|
+
selectEndDate.value = true
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
emit('start-date-change', date)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const handleEndDateChange = (date: Date) => {
|
|
356
|
+
endDate.value = date
|
|
357
|
+
inputEndHoverValue.value = null
|
|
358
|
+
if (props.range) {
|
|
359
|
+
selectEndDate.value = false
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
emit('end-date-change', date)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const handleClear = (event: Event) => {
|
|
366
|
+
event.stopPropagation()
|
|
367
|
+
startDate.value = null
|
|
368
|
+
endDate.value = null
|
|
369
|
+
inputStartHoverValue.value = null
|
|
370
|
+
inputEndHoverValue.value = null
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const InputGroup = () =>
|
|
374
|
+
h(
|
|
375
|
+
CInputGroup,
|
|
376
|
+
{
|
|
377
|
+
class: 'picker-input-group',
|
|
378
|
+
size: props.size,
|
|
379
|
+
},
|
|
380
|
+
() => [
|
|
381
|
+
h(CFormInput, {
|
|
382
|
+
class: {
|
|
383
|
+
hover: inputStartHoverValue.value,
|
|
384
|
+
},
|
|
385
|
+
disabled: props.disabled,
|
|
386
|
+
onClick: () => {
|
|
387
|
+
selectEndDate.value = false
|
|
388
|
+
},
|
|
389
|
+
onInput: (event) => {
|
|
390
|
+
if (isValidDate(event.target.value)) {
|
|
391
|
+
calendarDate.value = new Date(event.target.value)
|
|
392
|
+
startDate.value = new Date(event.target.value)
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
placeholder: Array.isArray(props.placeholder)
|
|
396
|
+
? props.placeholder[0]
|
|
397
|
+
: props.placeholder,
|
|
398
|
+
readonly: props.inputReadOnly,
|
|
399
|
+
value: inputStartHoverValue.value
|
|
400
|
+
? setInputValue(inputStartHoverValue.value, props.timepicker)
|
|
401
|
+
: setInputValue(startDate.value, props.timepicker),
|
|
402
|
+
}),
|
|
403
|
+
props.range &&
|
|
404
|
+
props.separator !== false &&
|
|
405
|
+
h(CInputGroupText, {}, () =>
|
|
406
|
+
slots.separator
|
|
407
|
+
? slots.separator()
|
|
408
|
+
: h('span', { class: 'picker-input-group-icon date-picker-arrow-icon' }),
|
|
409
|
+
),
|
|
410
|
+
props.range &&
|
|
411
|
+
h(CFormInput, {
|
|
412
|
+
class: {
|
|
413
|
+
hover: inputEndHoverValue.value,
|
|
414
|
+
},
|
|
415
|
+
disabled: props.disabled,
|
|
416
|
+
onClick: () => {
|
|
417
|
+
selectEndDate.value = true
|
|
418
|
+
},
|
|
419
|
+
onInput: (event) => {
|
|
420
|
+
if (isValidDate(event.target.value)) {
|
|
421
|
+
calendarDate.value = new Date(event.target.value)
|
|
422
|
+
endDate.value = new Date(event.target.value)
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
placeholder: props.placeholder[1],
|
|
426
|
+
readonly: props.inputReadOnly,
|
|
427
|
+
value: inputEndHoverValue.value
|
|
428
|
+
? setInputValue(inputEndHoverValue.value, props.timepicker)
|
|
429
|
+
: setInputValue(endDate.value, props.timepicker),
|
|
430
|
+
}),
|
|
431
|
+
(props.indicator || props.cleaner) &&
|
|
432
|
+
h(CInputGroupText, {}, () => [
|
|
433
|
+
props.indicator &&
|
|
434
|
+
h(
|
|
435
|
+
'span',
|
|
436
|
+
{
|
|
437
|
+
class: 'picker-input-group-indicator',
|
|
438
|
+
},
|
|
439
|
+
slots.indicator
|
|
440
|
+
? slots.indicator()
|
|
441
|
+
: h('span', { class: 'picker-input-group-icon date-picker-input-icon' }),
|
|
442
|
+
),
|
|
443
|
+
props.cleaner &&
|
|
444
|
+
h(
|
|
445
|
+
'span',
|
|
446
|
+
{
|
|
447
|
+
class: 'picker-input-group-cleaner',
|
|
448
|
+
onClick: (event: Event) => handleClear(event),
|
|
449
|
+
role: 'button',
|
|
450
|
+
},
|
|
451
|
+
slots.cleaner
|
|
452
|
+
? slots.cleaner()
|
|
453
|
+
: h('span', { class: 'picker-input-group-icon date-picker-cleaner-icon' }),
|
|
454
|
+
),
|
|
455
|
+
]),
|
|
456
|
+
],
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
return () =>
|
|
460
|
+
h(
|
|
461
|
+
CPicker,
|
|
462
|
+
{
|
|
463
|
+
cancelButton: props.cancelButton,
|
|
464
|
+
cancelButtonColor: props.cancelButtonColor,
|
|
465
|
+
cancelButtonSize: props.cancelButtonSize,
|
|
466
|
+
cancelButtonVariant: props.cancelButtonVariant,
|
|
467
|
+
class: 'date-picker',
|
|
468
|
+
confirmButton: props.confirmButton,
|
|
469
|
+
confirmButtonColor: props.confirmButtonColor,
|
|
470
|
+
confirmButtonSize: props.confirmButtonSize,
|
|
471
|
+
confirmButtonVariant: props.confirmButtonVariant,
|
|
472
|
+
disabled: props.disabled,
|
|
473
|
+
footer: props.footer || props.timepicker,
|
|
474
|
+
onCancel: () => {
|
|
475
|
+
startDate.value = initialStartDate.value
|
|
476
|
+
endDate.value = initialEndDate.value
|
|
477
|
+
},
|
|
478
|
+
onHide: () => {
|
|
479
|
+
emit('hide')
|
|
480
|
+
},
|
|
481
|
+
onShow: () => {
|
|
482
|
+
if (startDate.value) {
|
|
483
|
+
initialStartDate.value = new Date(startDate.value)
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (endDate.value) {
|
|
487
|
+
initialEndDate.value = new Date(endDate.value)
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
emit('show')
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
...(slots.cancelButton && {
|
|
495
|
+
cancelButton: () => slots.cancelButton && slots.cancelButton(),
|
|
496
|
+
}),
|
|
497
|
+
...(slots.confirmButton && {
|
|
498
|
+
confirmButton: () => slots.confirmButton && slots.confirmButton(),
|
|
499
|
+
}),
|
|
500
|
+
toggler: () => InputGroup(),
|
|
501
|
+
default: () =>
|
|
502
|
+
h(
|
|
503
|
+
'div',
|
|
504
|
+
{
|
|
505
|
+
class: 'date-picker-body',
|
|
506
|
+
},
|
|
507
|
+
[
|
|
508
|
+
props.ranges &&
|
|
509
|
+
h(
|
|
510
|
+
'div',
|
|
511
|
+
{ class: 'date-picker-ranges' },
|
|
512
|
+
Object.keys(props.ranges).map((key: string) =>
|
|
513
|
+
h(
|
|
514
|
+
CButton,
|
|
515
|
+
{
|
|
516
|
+
color: 'secondary',
|
|
517
|
+
onClick: () => {
|
|
518
|
+
if (props.ranges) {
|
|
519
|
+
startDate.value = props.ranges[key][0]
|
|
520
|
+
endDate.value = props.ranges[key][1]
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
variant: 'ghost',
|
|
524
|
+
},
|
|
525
|
+
() => key,
|
|
526
|
+
),
|
|
527
|
+
),
|
|
528
|
+
),
|
|
529
|
+
h(
|
|
530
|
+
'div',
|
|
531
|
+
{ class: 'date-picker-calendars' },
|
|
532
|
+
[...Array(isMobile.value ? 1 : props.calendars)].map((_, index) =>
|
|
533
|
+
h('div', { class: 'date-picker-calendar' }, [
|
|
534
|
+
h(
|
|
535
|
+
CCalendar,
|
|
536
|
+
{
|
|
537
|
+
calendarDate: new Date(
|
|
538
|
+
calendarDate.value.getFullYear(),
|
|
539
|
+
calendarDate.value.getMonth() + index,
|
|
540
|
+
1,
|
|
541
|
+
),
|
|
542
|
+
disabledDates: props.disabledDates,
|
|
543
|
+
...(endDate.value && { endDate: endDate.value }),
|
|
544
|
+
firstDayOfWeek: props.firstDayOfWeek,
|
|
545
|
+
locale: props.locale,
|
|
546
|
+
maxDate: props.maxDate,
|
|
547
|
+
minDate: props.minDate,
|
|
548
|
+
navigation: props.navigation,
|
|
549
|
+
range: true,
|
|
550
|
+
selectEndDate: selectEndDate.value,
|
|
551
|
+
...(startDate.value && { startDate: startDate.value }),
|
|
552
|
+
onCalendarCellHover: (date: Date | null) => handleCalendarCellHover(date),
|
|
553
|
+
onCalendarDateChange: (date: Date) =>
|
|
554
|
+
handleCalendarDateChange(date, index),
|
|
555
|
+
onStartDateChange: (date: Date) => handleStartDateChange(date),
|
|
556
|
+
onEndDateChange: (date: Date) => handleEndDateChange(date),
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
/**
|
|
560
|
+
* @slot Location for next icon.
|
|
561
|
+
*/
|
|
562
|
+
...(slots.navNextIcon && {
|
|
563
|
+
navNextIcon: () => slots.navNextIcon && slots.navNextIcon(),
|
|
564
|
+
}),
|
|
565
|
+
/**
|
|
566
|
+
* @slot Location for next double icon.
|
|
567
|
+
*/
|
|
568
|
+
...(slots.navNextDoubleIcon && {
|
|
569
|
+
navNextDoubleIcon: () =>
|
|
570
|
+
slots.navNextDoubleIcon && slots.navNextDoubleIcon(),
|
|
571
|
+
}),
|
|
572
|
+
/**
|
|
573
|
+
* @slot Location for previous icon.
|
|
574
|
+
*/
|
|
575
|
+
...(slots.navPrevIcon && {
|
|
576
|
+
navPrevIcon: () => slots.navPrevIcon && slots.navPrevIcon(),
|
|
577
|
+
}),
|
|
578
|
+
/**
|
|
579
|
+
* @slot Location for double previous icon.
|
|
580
|
+
*/
|
|
581
|
+
...(slots.navPrevDoubleIcon && {
|
|
582
|
+
navPrevDoubleIcon: () =>
|
|
583
|
+
slots.navPrevDoubleIcon && slots.navPrevDoubleIcon(),
|
|
584
|
+
}),
|
|
585
|
+
},
|
|
586
|
+
),
|
|
587
|
+
!isMobile.value &&
|
|
588
|
+
props.timepicker &&
|
|
589
|
+
(index === 0 || props.calendars - index === 1) &&
|
|
590
|
+
h(CTimePicker, {
|
|
591
|
+
container: 'inline',
|
|
592
|
+
disabled:
|
|
593
|
+
index === 0
|
|
594
|
+
? startDate.value === null
|
|
595
|
+
? true
|
|
596
|
+
: false
|
|
597
|
+
: endDate.value === null
|
|
598
|
+
? true
|
|
599
|
+
: false,
|
|
600
|
+
locale: props.locale,
|
|
601
|
+
onChange: (_: any, __: any, date: Date) =>
|
|
602
|
+
index === 0 ? handleStartDateChange(date) : handleEndDateChange(date),
|
|
603
|
+
time: index === 0 ? startDate.value : endDate.value,
|
|
604
|
+
variant: 'select',
|
|
605
|
+
}),
|
|
606
|
+
isMobile.value &&
|
|
607
|
+
props.timepicker && [
|
|
608
|
+
h(CTimePicker, {
|
|
609
|
+
container: 'inline',
|
|
610
|
+
disabled: startDate.value === null ? true : false,
|
|
611
|
+
locale: props.locale,
|
|
612
|
+
onChange: (_: any, __: any, date: Date) => handleStartDateChange(date),
|
|
613
|
+
time: startDate.value,
|
|
614
|
+
variant: 'select',
|
|
615
|
+
}),
|
|
616
|
+
h(CTimePicker, {
|
|
617
|
+
container: 'inline',
|
|
618
|
+
disabled: endDate.value === null ? true : false,
|
|
619
|
+
locale: props.locale,
|
|
620
|
+
onChange: (_: any, __: any, date: Date) => handleEndDateChange(date),
|
|
621
|
+
time: endDate.value,
|
|
622
|
+
variant: 'select',
|
|
623
|
+
}),
|
|
624
|
+
],
|
|
625
|
+
]),
|
|
626
|
+
),
|
|
627
|
+
),
|
|
628
|
+
],
|
|
629
|
+
),
|
|
630
|
+
},
|
|
631
|
+
)
|
|
632
|
+
},
|
|
633
|
+
})
|
|
634
|
+
|
|
635
|
+
export { CDateRangePicker }
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { App } from 'vue'
|
|
2
|
+
import { CDateRangePicker } from './CDateRangePicker'
|
|
3
|
+
|
|
4
|
+
const CDateRangePickerPlugin = {
|
|
5
|
+
install: (app: App): void => {
|
|
6
|
+
app.component(CDateRangePicker.name, CDateRangePicker)
|
|
7
|
+
},
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { CDateRangePickerPlugin, CDateRangePicker }
|