@coreui/vue-pro 4.3.0-beta.0 → 4.3.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.
Files changed (78) hide show
  1. package/README.md +113 -5
  2. package/dist/components/accordion/index.d.ts +1 -2
  3. package/dist/components/calendar/CCalendar.d.ts +15 -2
  4. package/dist/components/carousel/CCarousel.d.ts +1 -1
  5. package/dist/components/date-picker/CDatePicker.d.ts +24 -2
  6. package/dist/components/date-range-picker/CDateRangePicker.d.ts +102 -3
  7. package/dist/components/form/CFormCheck.d.ts +88 -39
  8. package/dist/components/form/CFormControlValidation.d.ts +98 -0
  9. package/dist/components/form/CFormControlWrapper.d.ts +6 -0
  10. package/dist/components/form/CFormFeedback.d.ts +2 -2
  11. package/dist/components/form/CFormInput.d.ts +133 -27
  12. package/dist/components/form/CFormRange.d.ts +18 -16
  13. package/dist/components/form/CFormSelect.d.ts +125 -16
  14. package/dist/components/form/CFormSwitch.d.ts +0 -23
  15. package/dist/components/form/CFormTextarea.d.ts +125 -24
  16. package/dist/components/modal/CModal.d.ts +1 -1
  17. package/dist/components/offcanvas/COffcanvas.d.ts +1 -1
  18. package/dist/components/smart-table/CSmartTable.d.ts +34 -98
  19. package/dist/components/smart-table/CSmartTableInterface.d.ts +3 -3
  20. package/dist/components/time-picker/CTimePicker.d.ts +1 -1
  21. package/dist/components/toast/CToast.d.ts +7 -1
  22. package/dist/components/widgets/CWidgetStatsB.d.ts +3 -8
  23. package/dist/components/widgets/CWidgetStatsC.d.ts +3 -8
  24. package/dist/directives/v-c-popover.d.ts +1 -1
  25. package/dist/directives/v-c-tooltip.d.ts +1 -1
  26. package/dist/index.es.js +5523 -644
  27. package/dist/index.es.js.map +1 -1
  28. package/dist/index.js +5522 -644
  29. package/dist/index.js.map +1 -1
  30. package/dist/utils/calendar.d.ts +4 -2
  31. package/dist/utils/time.d.ts +6 -2
  32. package/dist/utils/transition.d.ts +3 -0
  33. package/package.json +12 -11
  34. package/src/components/accordion/index.ts +0 -3
  35. package/src/components/backdrop/CBackdrop.ts +8 -6
  36. package/src/components/button/CButton.ts +2 -2
  37. package/src/components/calendar/CCalendar.ts +132 -62
  38. package/src/components/close-button/CCloseButton.ts +1 -0
  39. package/src/components/close-button/__tests__/__snapshots__/CCloseButton.spec.ts.snap +2 -2
  40. package/src/components/collapse/CCollapse.ts +5 -6
  41. package/src/components/date-picker/CDatePicker.ts +14 -10
  42. package/src/components/date-range-picker/CDateRangePicker.ts +209 -100
  43. package/src/components/form/CFormCheck.ts +118 -95
  44. package/src/components/form/CFormControlValidation.ts +97 -0
  45. package/src/components/form/CFormControlWrapper.ts +106 -0
  46. package/src/components/form/CFormInput.ts +115 -30
  47. package/src/components/form/CFormRange.ts +25 -11
  48. package/src/components/form/CFormSelect.ts +127 -41
  49. package/src/components/form/CFormSwitch.ts +2 -21
  50. package/src/components/form/CFormTextarea.ts +113 -25
  51. package/src/components/form/__tests__/CFormInput.spec.ts +11 -11
  52. package/src/components/form/__tests__/CFormRange.spec.ts +9 -9
  53. package/src/components/form/__tests__/CFormSelect.spec.ts +4 -4
  54. package/src/components/form/__tests__/CFormTextarea.spec.ts +4 -4
  55. package/src/components/form/__tests__/__snapshots__/CFormCheck.spec.ts.snap +8 -2
  56. package/src/components/form/__tests__/__snapshots__/CFormRange.spec.ts.snap +1 -1
  57. package/src/components/modal/CModal.ts +14 -6
  58. package/src/components/modal/__tests__/__snapshots__/CModal.spec.ts.snap +1 -2
  59. package/src/components/modal/__tests__/__snapshots__/CModalHeader.spec.ts.snap +2 -2
  60. package/src/components/nav/CNavGroup.ts +4 -6
  61. package/src/components/offcanvas/COffcanvas.ts +5 -7
  62. package/src/components/pagination/CSmartPagination.ts +4 -4
  63. package/src/components/picker/CPicker.ts +1 -0
  64. package/src/components/popover/CPopover.ts +5 -5
  65. package/src/components/sidebar/__tests__/__snapshots__/CSidebar.spec.ts.snap +2 -8
  66. package/src/components/smart-table/CSmartTable.ts +17 -49
  67. package/src/components/smart-table/CSmartTableInterface.ts +5 -3
  68. package/src/components/tabs/CTabPane.ts +4 -6
  69. package/src/components/time-picker/CTimePicker.ts +12 -17
  70. package/src/components/toast/CToast.ts +17 -12
  71. package/src/components/toast/__tests__/__snapshots__/CToastClose.spec.ts.snap +1 -1
  72. package/src/components/toast/__tests__/__snapshots__/CToastHeader.spec.ts.snap +1 -1
  73. package/src/components/tooltip/CTooltip.ts +5 -5
  74. package/src/directives/v-c-popover.ts +1 -1
  75. package/src/directives/v-c-tooltip.ts +1 -1
  76. package/src/utils/calendar.ts +86 -9
  77. package/src/utils/time.ts +29 -3
  78. package/src/utils/transition.ts +65 -0
@@ -1,12 +1,14 @@
1
1
  import { defineComponent, h, onMounted, PropType, ref, watch } from 'vue'
2
2
 
3
+ import { format as dateFormat } from 'date-fns'
4
+
3
5
  import { CButton } from '../button'
4
6
  import { CCalendar } from '../calendar'
5
7
  import { CFormInput, CInputGroup, CInputGroupText } from '../form'
6
8
  import { CPicker } from '../picker'
7
9
  import { CTimePicker } from '../time-picker'
8
10
 
9
- import { isValidDate } from '../../utils/calendar'
11
+ import { getLocalDateFromString } from '../../utils/calendar'
10
12
 
11
13
  import { Color } from '../props'
12
14
 
@@ -138,16 +140,28 @@ const CDateRangePicker = defineComponent({
138
140
  * - 4 - Thursday,
139
141
  * - 5 - Friday,
140
142
  * - 6 - Saturday,
141
- * - 7 - Sunday
142
143
  */
143
144
  firstDayOfWeek: {
144
145
  type: Number,
145
146
  default: 1,
146
147
  },
148
+ /**
149
+ * Set date format.
150
+ * We use date-fns to format dates. Visit https://date-fns.org/v2.28.0/docs/format to check accepted patterns.
151
+ */
152
+ format: String,
147
153
  /**
148
154
  * Toggle visibility of footer element or set the content of footer.
149
155
  */
150
156
  footer: Boolean,
157
+ /**
158
+ * The id global attribute defines an identifier (ID) that must be unique in the whole document.
159
+ *
160
+ * The name attributes for input elements are generated based on the `id` property:
161
+ * - {id}-start-date
162
+ * - {id}-end-date
163
+ */
164
+ id: String,
151
165
  /**
152
166
  * Toggle visibility or set the content of the input indicator.
153
167
  */
@@ -236,6 +250,45 @@ const CDateRangePicker = defineComponent({
236
250
  * Provide an additional time selection by adding select boxes to choose times.
237
251
  */
238
252
  timepicker: Boolean,
253
+ /**
254
+ * Toggle visibility or set the content of today button.
255
+ */
256
+ todayButton: {
257
+ type: [Boolean, String],
258
+ default: 'Today',
259
+ },
260
+ /**
261
+ * Sets the color context of the today button to one of CoreUI’s themed colors.
262
+ *
263
+ * @values 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'dark', 'light'
264
+ */
265
+ todayButtonColor: {
266
+ ...Color,
267
+ default: 'primary',
268
+ },
269
+ /**
270
+ * Size the today button small or large.
271
+ *
272
+ * @values 'sm', 'lg'
273
+ */
274
+ todayButtonSize: {
275
+ type: String,
276
+ default: 'sm',
277
+ validator: (value: string) => {
278
+ return ['sm', 'lg'].includes(value)
279
+ },
280
+ },
281
+ /**
282
+ * Set the today button variant to an outlined button or a ghost button.
283
+ *
284
+ * @values 'ghost', 'outline'
285
+ */
286
+ todayButtonVariant: {
287
+ type: String,
288
+ validator: (value: string) => {
289
+ return ['ghost', 'outline'].includes(value)
290
+ },
291
+ },
239
292
  /**
240
293
  * Set length or format of day name.
241
294
  *
@@ -289,6 +342,8 @@ const CDateRangePicker = defineComponent({
289
342
  const endDate = ref<Date | null>(props.endDate ? new Date(props.endDate) : null)
290
343
  const initialStartDate = ref<Date | null>(startDate.value ? new Date(startDate.value) : null)
291
344
  const initialEndDate = ref<Date | null>(endDate.value ? new Date(endDate.value) : null)
345
+ const maxDate = ref(props.maxDate && new Date(props.maxDate))
346
+ const minDate = ref(props.minDate && new Date(props.minDate))
292
347
  const selectEndDate = ref(false)
293
348
 
294
349
  const isMobile = ref(false)
@@ -315,11 +370,35 @@ const CDateRangePicker = defineComponent({
315
370
  },
316
371
  )
317
372
 
318
- const setInputValue = (date: Date | null, timepicker?: boolean) => {
373
+ watch(
374
+ () => props.maxDate,
375
+ () => {
376
+ if (props.maxDate) {
377
+ maxDate.value = new Date(props.maxDate)
378
+ }
379
+ },
380
+ )
381
+
382
+ watch(
383
+ () => props.minDate,
384
+ () => {
385
+ if (props.minDate) {
386
+ minDate.value = new Date(props.minDate)
387
+ }
388
+ },
389
+ )
390
+
391
+ const formatDate = (date: Date) => {
392
+ return props.format
393
+ ? dateFormat(date, props.format)
394
+ : props.timepicker
395
+ ? date.toLocaleString(props.format)
396
+ : date.toLocaleDateString(props.format)
397
+ }
398
+
399
+ const setInputValue = (date: Date | null) => {
319
400
  if (date) {
320
- return timepicker
321
- ? date.toLocaleString(props.locale)
322
- : date.toLocaleDateString(props.locale)
401
+ return formatDate(date)
323
402
  }
324
403
 
325
404
  return ''
@@ -327,10 +406,10 @@ const CDateRangePicker = defineComponent({
327
406
 
328
407
  const handleCalendarCellHover = (date: Date | null) => {
329
408
  if (selectEndDate.value) {
330
- inputEndHoverValue.value = date === null ? null : date
409
+ inputEndHoverValue.value = date
331
410
  return
332
411
  }
333
- inputStartHoverValue.value = date === null ? null : date
412
+ inputStartHoverValue.value = date
334
413
  }
335
414
 
336
415
  const handleCalendarDateChange = (date: Date, difference?: number) => {
@@ -349,7 +428,7 @@ const CDateRangePicker = defineComponent({
349
428
  selectEndDate.value = true
350
429
  }
351
430
 
352
- emit('start-date-change', date)
431
+ emit('start-date-change', date, date ? formatDate(date) : undefined)
353
432
  }
354
433
 
355
434
  const handleEndDateChange = (date: Date) => {
@@ -359,7 +438,7 @@ const CDateRangePicker = defineComponent({
359
438
  selectEndDate.value = false
360
439
  }
361
440
 
362
- emit('end-date-change', date)
441
+ emit('end-date-change', date, date ? formatDate(date) : undefined)
363
442
  }
364
443
 
365
444
  const handleClear = (event: Event) => {
@@ -383,22 +462,28 @@ const CDateRangePicker = defineComponent({
383
462
  hover: inputStartHoverValue.value,
384
463
  },
385
464
  disabled: props.disabled,
465
+ name: props.range ? `${props.id}-start-date` : `${props.id}-date`,
386
466
  onClick: () => {
387
467
  selectEndDate.value = false
388
468
  },
389
469
  onInput: (event) => {
390
- if (isValidDate(event.target.value)) {
391
- calendarDate.value = new Date(event.target.value)
392
- startDate.value = new Date(event.target.value)
470
+ const date = getLocalDateFromString(
471
+ event.target.value,
472
+ props.locale,
473
+ props.timepicker,
474
+ )
475
+ if (date instanceof Date && date.getTime()) {
476
+ calendarDate.value = date
477
+ startDate.value = date
393
478
  }
394
479
  },
395
480
  placeholder: Array.isArray(props.placeholder)
396
481
  ? props.placeholder[0]
397
482
  : props.placeholder,
398
- readonly: props.inputReadOnly,
483
+ readonly: props.inputReadOnly || typeof props.format === 'string',
399
484
  value: inputStartHoverValue.value
400
- ? setInputValue(inputStartHoverValue.value, props.timepicker)
401
- : setInputValue(startDate.value, props.timepicker),
485
+ ? setInputValue(inputStartHoverValue.value)
486
+ : setInputValue(startDate.value),
402
487
  }),
403
488
  props.range &&
404
489
  props.separator !== false &&
@@ -413,20 +498,26 @@ const CDateRangePicker = defineComponent({
413
498
  hover: inputEndHoverValue.value,
414
499
  },
415
500
  disabled: props.disabled,
501
+ name: `${props.id}-end-date`,
416
502
  onClick: () => {
417
503
  selectEndDate.value = true
418
504
  },
419
505
  onInput: (event) => {
420
- if (isValidDate(event.target.value)) {
421
- calendarDate.value = new Date(event.target.value)
422
- endDate.value = new Date(event.target.value)
506
+ const date = getLocalDateFromString(
507
+ event.target.value,
508
+ props.locale,
509
+ props.timepicker,
510
+ )
511
+ if (date instanceof Date && date.getTime()) {
512
+ calendarDate.value = date
513
+ endDate.value = date
423
514
  }
424
515
  },
425
516
  placeholder: props.placeholder[1],
426
- readonly: props.inputReadOnly,
517
+ readonly: props.inputReadOnly || typeof props.format === 'string',
427
518
  value: inputEndHoverValue.value
428
- ? setInputValue(inputEndHoverValue.value, props.timepicker)
429
- : setInputValue(endDate.value, props.timepicker),
519
+ ? setInputValue(inputEndHoverValue.value)
520
+ : setInputValue(endDate.value),
430
521
  }),
431
522
  (props.indicator || props.cleaner) &&
432
523
  h(CInputGroupText, {}, () => [
@@ -471,6 +562,7 @@ const CDateRangePicker = defineComponent({
471
562
  confirmButtonVariant: props.confirmButtonVariant,
472
563
  disabled: props.disabled,
473
564
  footer: props.footer || props.timepicker,
565
+ id: props.id,
474
566
  onCancel: () => {
475
567
  startDate.value = initialStartDate.value
476
568
  endDate.value = initialEndDate.value
@@ -498,6 +590,23 @@ const CDateRangePicker = defineComponent({
498
590
  confirmButton: () => slots.confirmButton && slots.confirmButton(),
499
591
  }),
500
592
  toggler: () => InputGroup(),
593
+ footer: () =>
594
+ h(
595
+ CButton,
596
+ {
597
+ class: 'me-auto',
598
+ color: props.todayButtonColor,
599
+ size: props.todayButtonSize,
600
+ variant: props.todayButtonVariant,
601
+ onClick: () => {
602
+ const date = new Date()
603
+ startDate.value = date
604
+ endDate.value = date
605
+ calendarDate.value = date
606
+ },
607
+ },
608
+ () => props.todayButton,
609
+ ),
501
610
  default: () =>
502
611
  h(
503
612
  'div',
@@ -529,82 +638,66 @@ const CDateRangePicker = defineComponent({
529
638
  h(
530
639
  'div',
531
640
  { 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
- },
641
+ h(
642
+ CCalendar,
643
+ {
644
+ calendarDate: new Date(
645
+ calendarDate.value.getFullYear(),
646
+ calendarDate.value.getMonth(),
647
+ 1,
586
648
  ),
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 && [
649
+ calendars: props.calendars,
650
+ disabledDates: props.disabledDates,
651
+ ...(endDate.value && { endDate: endDate.value }),
652
+ firstDayOfWeek: props.firstDayOfWeek,
653
+ locale: props.locale,
654
+ maxDate: maxDate.value,
655
+ minDate: minDate.value,
656
+ navigation: props.navigation,
657
+ range: true,
658
+ selectEndDate: selectEndDate.value,
659
+ ...(startDate.value && { startDate: startDate.value }),
660
+ onCalendarCellHover: (date: Date | null) => handleCalendarCellHover(date),
661
+ onCalendarDateChange: (date: Date) => handleCalendarDateChange(date),
662
+ onStartDateChange: (date: Date) => handleStartDateChange(date),
663
+ onEndDateChange: (date: Date) => handleEndDateChange(date),
664
+ },
665
+ {
666
+ /**
667
+ * @slot Location for next icon.
668
+ */
669
+ ...(slots.navNextIcon && {
670
+ navNextIcon: () => slots.navNextIcon && slots.navNextIcon(),
671
+ }),
672
+ /**
673
+ * @slot Location for next double icon.
674
+ */
675
+ ...(slots.navNextDoubleIcon && {
676
+ navNextDoubleIcon: () =>
677
+ slots.navNextDoubleIcon && slots.navNextDoubleIcon(),
678
+ }),
679
+ /**
680
+ * @slot Location for previous icon.
681
+ */
682
+ ...(slots.navPrevIcon && {
683
+ navPrevIcon: () => slots.navPrevIcon && slots.navPrevIcon(),
684
+ }),
685
+ /**
686
+ * @slot Location for double previous icon.
687
+ */
688
+ ...(slots.navPrevDoubleIcon && {
689
+ navPrevDoubleIcon: () =>
690
+ slots.navPrevDoubleIcon && slots.navPrevDoubleIcon(),
691
+ }),
692
+ },
693
+ ),
694
+ ),
695
+ props.timepicker &&
696
+ h(
697
+ 'div',
698
+ { class: 'date-picker-timepickers' },
699
+ isMobile.value || (props.range && props.calendars === 1)
700
+ ? [
608
701
  h(CTimePicker, {
609
702
  container: 'inline',
610
703
  disabled: startDate.value === null ? true : false,
@@ -621,10 +714,26 @@ const CDateRangePicker = defineComponent({
621
714
  time: endDate.value,
622
715
  variant: 'select',
623
716
  }),
624
- ],
625
- ]),
717
+ ]
718
+ : [...Array(props.calendars)].map((_, index) =>
719
+ h(CTimePicker, {
720
+ container: 'inline',
721
+ disabled:
722
+ index === 0
723
+ ? startDate.value === null
724
+ ? true
725
+ : false
726
+ : endDate.value === null
727
+ ? true
728
+ : false,
729
+ locale: props.locale,
730
+ onChange: (_: any, __: any, date: Date) =>
731
+ index === 0 ? handleStartDateChange(date) : handleEndDateChange(date),
732
+ time: index === 0 ? startDate.value : endDate.value,
733
+ variant: 'select',
734
+ }),
735
+ ),
626
736
  ),
627
- ),
628
737
  ],
629
738
  ),
630
739
  },