@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,5 +1,7 @@
1
1
  import { defineComponent, h, onMounted, provide, ref, RendererElement, Transition } from 'vue'
2
2
 
3
+ import { executeAfterTransition } from './../../utils/transition'
4
+
3
5
  import { Color } from '../props'
4
6
 
5
7
  const CToast = defineComponent({
@@ -79,29 +81,31 @@ const CToast = defineComponent({
79
81
  }
80
82
  provide('updateVisible', updateVisible)
81
83
 
84
+ const handleBeforeEnter = (el: RendererElement) => {
85
+ el.classList.add('showing')
86
+ }
87
+
82
88
  const handleEnter = (el: RendererElement, done: () => void) => {
83
- el.addEventListener('transitionend', () => {
84
- done()
85
- })
89
+ executeAfterTransition(() => done(), el as HTMLElement)
90
+ el.classList.add('show')
86
91
  setTimeout(() => {
87
- el.classList.add('show')
92
+ el.classList.remove('showing')
88
93
  }, 1)
94
+
89
95
  if (props.index) {
90
96
  emit('show', props.index)
91
97
  } else {
92
98
  emit('show')
93
99
  }
94
100
  }
95
- const handleBeforeLeave = (el: RendererElement) => {
96
- el.classList.remove('show')
97
- }
101
+
98
102
  const handleLeave = (el: RendererElement, done: () => void) => {
99
- el.addEventListener('transitionend', () => {
100
- done()
101
- })
102
- el.classList.remove('show')
103
+ executeAfterTransition(() => done(), el as HTMLElement)
104
+ el.classList.add('showing')
103
105
  }
106
+
104
107
  const handleAfterLeave = (el: RendererElement) => {
108
+ el.classList.remove('show')
105
109
  el.classList.add('hide')
106
110
  if (props.index) {
107
111
  emit('close', props.index)
@@ -115,6 +119,7 @@ const CToast = defineComponent({
115
119
  clearTimeout(timeout)
116
120
  timeout = window.setTimeout(() => {
117
121
  visible.value = false
122
+ emit('close')
118
123
  }, props.delay)
119
124
  }
120
125
  })
@@ -124,8 +129,8 @@ const CToast = defineComponent({
124
129
  Transition,
125
130
  {
126
131
  appear: true,
132
+ onBeforeEnter: (el) => handleBeforeEnter(el),
127
133
  onEnter: (el, done) => handleEnter(el, done),
128
- onBeforeLeave: (el) => handleBeforeLeave(el),
129
134
  onLeave: (el, done) => handleLeave(el, done),
130
135
  onAfterLeave: (el) => handleAfterLeave(el),
131
136
  },
@@ -2,4 +2,4 @@
2
2
 
3
3
  exports[`Customize CToastClose component renders correctly 1`] = `"<button class=\\"btn btn-undefined\\" type=\\"button\\">Default slot</button>"`;
4
4
 
5
- exports[`Loads and display CToastClose component renders correctly 1`] = `"<button class=\\"btn btn-close\\" aria-label=\\"Close\\"></button>"`;
5
+ exports[`Loads and display CToastClose component renders correctly 1`] = `"<button type=\\"button\\" class=\\"btn btn-close\\" aria-label=\\"Close\\"></button>"`;
@@ -1,6 +1,6 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`Customize CToastHeader component renders correctly 1`] = `"<div class=\\"toast-header\\">Default slot<button class=\\"btn btn-close\\" aria-label=\\"Close\\"></button></div>"`;
3
+ exports[`Customize CToastHeader component renders correctly 1`] = `"<div class=\\"toast-header\\">Default slot<button type=\\"button\\" class=\\"btn btn-close\\" aria-label=\\"Close\\"></button></div>"`;
4
4
 
5
5
  exports[`Loads and display CToastHeader component renders correctly 1`] = `
6
6
  "<div class=\\"toast-header\\">Default slot
@@ -1,6 +1,8 @@
1
1
  import { defineComponent, h, PropType, ref, RendererElement, Teleport, Transition } from 'vue'
2
2
  import { createPopper, Placement } from '@popperjs/core'
3
3
 
4
+ import { executeAfterTransition } from './../../utils/transition'
5
+
4
6
  const CTooltip = defineComponent({
5
7
  name: 'CTooltip',
6
8
  props: {
@@ -75,18 +77,16 @@ const CTooltip = defineComponent({
75
77
  emit('show')
76
78
  initPopper()
77
79
  el.classList.add('show')
78
- el.addEventListener('transitionend', () => {
79
- done()
80
- })
80
+ executeAfterTransition(() => done(), el as HTMLElement)
81
81
  }
82
82
 
83
83
  const handleLeave = (el: RendererElement, done: () => void) => {
84
84
  emit('hide')
85
85
  el.classList.remove('show')
86
- el.addEventListener('transitionend', () => {
86
+ executeAfterTransition(() => {
87
87
  done()
88
88
  destroyPopper()
89
- })
89
+ }, el as HTMLElement)
90
90
  }
91
91
 
92
92
  const handleToggle = (event: Event) => {
@@ -96,7 +96,7 @@ export default {
96
96
  })
97
97
  }
98
98
  },
99
- unmounted(binding: DirectiveBinding): void {
99
+ unmounted(_el: HTMLElement, binding: DirectiveBinding): void {
100
100
  const popover = binding.arg && document.getElementById(binding.arg)
101
101
  popover && popover.remove()
102
102
  },
@@ -92,7 +92,7 @@ export default {
92
92
  })
93
93
  }
94
94
  },
95
- beforeUnmount(binding: DirectiveBinding): void {
95
+ beforeUnmount(_el: HTMLElement, binding: DirectiveBinding): void {
96
96
  const tooltip = binding.arg && document.getElementById(binding.arg)
97
97
  tooltip && tooltip.remove()
98
98
  },
@@ -15,6 +15,52 @@ export const getCurrentYear = () => new Date().getFullYear()
15
15
 
16
16
  export const getCurrentMonth = () => new Date().getMonth()
17
17
 
18
+ export const getLocalDateFromString = (string: string, locale: string, time?: boolean) => {
19
+ const date = new Date(2013, 11, 31, 17, 19, 22)
20
+ let regex = time ? date.toLocaleString(locale) : date.toLocaleDateString(locale)
21
+ regex = regex
22
+ .replace('2013', '(?<year>[0-9]{2,4})')
23
+ .replace('12', '(?<month>[0-9]{1,2})')
24
+ .replace('31', '(?<day>[0-9]{1,2})')
25
+
26
+ if (time) {
27
+ regex = regex
28
+ .replace('5', '(?<hour>[0-9]{1,2})')
29
+ .replace('17', '(?<hour>[0-9]{1,2})')
30
+ .replace('19', '(?<minute>[0-9]{1,2})')
31
+ .replace('22', '(?<second>[0-9]{1,2})')
32
+ .replace('PM', '(?<ampm>[A-Z]{2})')
33
+ }
34
+
35
+ const rgx = RegExp(`${regex}`)
36
+ const partials = string.match(rgx)
37
+
38
+ if (partials === null) return
39
+
40
+ const newDate =
41
+ partials.groups &&
42
+ (time
43
+ ? new Date(
44
+ Number(partials.groups['year']),
45
+ Number(partials.groups['month']) - 1,
46
+ Number(partials.groups['day']),
47
+ partials.groups['ampm']
48
+ ? partials.groups['ampm'] === 'PM'
49
+ ? Number(partials.groups['hour']) + 12
50
+ : Number(partials.groups['hour'])
51
+ : Number(partials.groups['hour']),
52
+ Number(partials.groups['minute']),
53
+ Number(partials.groups['second']),
54
+ )
55
+ : new Date(
56
+ Number(partials.groups['year']),
57
+ Number(partials.groups['month']) - 1,
58
+ Number(partials.groups['day']),
59
+ ))
60
+
61
+ return newDate
62
+ }
63
+
18
64
  export const getMonthName = (month: number, locale: string) => {
19
65
  const d = new Date()
20
66
  d.setDate(1)
@@ -115,6 +161,29 @@ export const getMonthDetails = (year: number, month: number, firstDayOfWeek: num
115
161
  return weeks
116
162
  }
117
163
 
164
+ export const isDisableDateInRange = (
165
+ startDate?: Date | null,
166
+ endDate?: Date | null,
167
+ dates?: Date[] | Date[][],
168
+ ) => {
169
+ if (startDate && endDate) {
170
+ const date = new Date(startDate)
171
+ let disabled = false
172
+
173
+ while (date < endDate) {
174
+ date.setDate(date.getDate() + 1)
175
+ if (isDateDisabled(date, null, null, dates)) {
176
+ disabled = true
177
+ break
178
+ }
179
+ }
180
+
181
+ return disabled
182
+ }
183
+
184
+ return false
185
+ }
186
+
118
187
  export const isDateDisabled = (
119
188
  date: Date,
120
189
  min?: Date | null,
@@ -166,12 +235,20 @@ export const isLastDayOfMonth = (date: Date) => {
166
235
  return test.getMonth() !== month
167
236
  }
168
237
 
169
- export const isSameDateAs = (date: Date, date2: Date) => {
170
- return (
171
- date.getDate() == date2.getDate() &&
172
- date.getMonth() == date2.getMonth() &&
173
- date.getFullYear() == date2.getFullYear()
174
- )
238
+ export const isSameDateAs = (date: Date | null, date2: Date | null) => {
239
+ if (date instanceof Date && date2 instanceof Date) {
240
+ return (
241
+ date.getDate() === date2.getDate() &&
242
+ date.getMonth() === date2.getMonth() &&
243
+ date.getFullYear() === date2.getFullYear()
244
+ )
245
+ }
246
+
247
+ if (date === null && date2 === null) {
248
+ return true
249
+ }
250
+
251
+ return false
175
252
  }
176
253
 
177
254
  export const isStartDate = (date: Date, start: Date | null, end: Date | null) => {
@@ -181,9 +258,9 @@ export const isStartDate = (date: Date, start: Date | null, end: Date | null) =>
181
258
  export const isToday = (date: Date) => {
182
259
  const today = new Date()
183
260
  return (
184
- date.getDate() == today.getDate() &&
185
- date.getMonth() == today.getMonth() &&
186
- date.getFullYear() == today.getFullYear()
261
+ date.getDate() === today.getDate() &&
262
+ date.getMonth() === today.getMonth() &&
263
+ date.getFullYear() === today.getFullYear()
187
264
  )
188
265
  }
189
266
 
package/src/utils/time.ts CHANGED
@@ -34,11 +34,37 @@ export const getListOfHours = (locale: string) =>
34
34
  }
35
35
  })
36
36
 
37
- export const getMinutesOrSeconds = (locale: string) =>
37
+ export const getListOfMinutes = (locale: string, valueAsString = false) =>
38
38
  Array.from({ length: 60 }, (_, i) => {
39
+ const d = new Date()
40
+ d.setMinutes(i)
39
41
  return {
40
- value: i,
41
- label: i.toLocaleString(locale).padStart(2, (0).toLocaleString(locale)),
42
+ value: valueAsString ? i.toString() : i,
43
+ label: d
44
+ .toLocaleTimeString(locale, {
45
+ hour: '2-digit',
46
+ hour12: false,
47
+ minute: '2-digit',
48
+ second: '2-digit',
49
+ })
50
+ .split(':')[1],
51
+ }
52
+ })
53
+
54
+ export const getListOfSeconds = (locale: string, valueAsString = false) =>
55
+ Array.from({ length: 60 }, (_, i) => {
56
+ const d = new Date()
57
+ d.setSeconds(i)
58
+ return {
59
+ value: valueAsString ? i.toString() : i,
60
+ label: d
61
+ .toLocaleTimeString(locale, {
62
+ hour: '2-digit',
63
+ hour12: false,
64
+ minute: '2-digit',
65
+ second: '2-digit',
66
+ })
67
+ .split(':')[2],
42
68
  }
43
69
  })
44
70
 
@@ -0,0 +1,65 @@
1
+ const execute = (callback: () => void) => {
2
+ if (typeof callback === 'function') {
3
+ callback()
4
+ }
5
+ }
6
+
7
+ export const executeAfterTransition = (
8
+ callback: () => void,
9
+ transitionElement: HTMLElement,
10
+ waitForTransition = true,
11
+ ) => {
12
+ if (!waitForTransition) {
13
+ execute(callback)
14
+ return
15
+ }
16
+
17
+ const durationPadding = 5
18
+ const emulatedDuration = getTransitionDurationFromElement(transitionElement) + durationPadding
19
+
20
+ let called = false
21
+
22
+ const handler = ({ target }: { target: any }) => {
23
+ if (target !== transitionElement) {
24
+ return
25
+ }
26
+
27
+ called = true
28
+ transitionElement.removeEventListener('transitionend', handler)
29
+ execute(callback)
30
+ }
31
+
32
+ transitionElement.addEventListener('transitionend', handler)
33
+ setTimeout(() => {
34
+ if (!called) {
35
+ triggerTransitionEnd(transitionElement)
36
+ }
37
+ }, emulatedDuration)
38
+ }
39
+
40
+ export const getTransitionDurationFromElement = (element: HTMLElement) => {
41
+ if (!element) {
42
+ return 0
43
+ }
44
+
45
+ // Get transition-duration of the element
46
+ let { transitionDuration, transitionDelay } = window.getComputedStyle(element)
47
+
48
+ const floatTransitionDuration = Number.parseFloat(transitionDuration)
49
+ const floatTransitionDelay = Number.parseFloat(transitionDelay)
50
+
51
+ // Return 0 if element or transition duration is not found
52
+ if (!floatTransitionDuration && !floatTransitionDelay) {
53
+ return 0
54
+ }
55
+
56
+ // If multiple durations are defined, take the first
57
+ transitionDuration = transitionDuration.split(',')[0]
58
+ transitionDelay = transitionDelay.split(',')[0]
59
+
60
+ return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * 1000
61
+ }
62
+
63
+ export const triggerTransitionEnd = (element: HTMLElement) => {
64
+ element.dispatchEvent(new Event('transitionend'))
65
+ }