@coreui/vue-pro 4.2.0 → 4.3.0

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 (77) hide show
  1. package/README.md +1 -1
  2. package/dist/components/calendar/CCalendar.d.ts +198 -0
  3. package/dist/components/calendar/index.d.ts +6 -0
  4. package/dist/components/carousel/CCarousel.d.ts +1 -1
  5. package/dist/components/date-picker/CDatePicker.d.ts +414 -0
  6. package/dist/components/date-picker/index.d.ts +6 -0
  7. package/dist/components/date-range-picker/CDateRangePicker.d.ts +563 -0
  8. package/dist/components/date-range-picker/index.d.ts +6 -0
  9. package/dist/components/form/CFormCheck.d.ts +88 -39
  10. package/dist/components/form/CFormControlValidation.d.ts +98 -0
  11. package/dist/components/form/CFormControlWrapper.d.ts +6 -0
  12. package/dist/components/form/CFormFeedback.d.ts +2 -2
  13. package/dist/components/form/CFormInput.d.ts +125 -25
  14. package/dist/components/form/CFormRange.d.ts +18 -16
  15. package/dist/components/form/CFormSelect.d.ts +125 -16
  16. package/dist/components/form/CFormSwitch.d.ts +0 -23
  17. package/dist/components/form/CFormTextarea.d.ts +125 -24
  18. package/dist/components/index.d.ts +5 -0
  19. package/dist/components/modal/CModal.d.ts +1 -1
  20. package/dist/components/multi-select/CMultiSelect.d.ts +2 -2
  21. package/dist/components/offcanvas/COffcanvas.d.ts +1 -1
  22. package/dist/components/picker/CPicker.d.ts +11 -0
  23. package/dist/components/picker/index.d.ts +6 -0
  24. package/dist/components/popover/CPopover.d.ts +1 -1
  25. package/dist/components/sidebar/CSidebar.d.ts +1 -1
  26. package/dist/components/smart-table/CSmartTable.d.ts +35 -99
  27. package/dist/components/smart-table/CSmartTableInterface.d.ts +3 -3
  28. package/dist/components/time-picker/CTimePicker.d.ts +10 -0
  29. package/dist/components/time-picker/CTimePickerRollCol.d.ts +27 -0
  30. package/dist/components/time-picker/index.d.ts +6 -0
  31. package/dist/components/toast/CToast.d.ts +8 -2
  32. package/dist/index.es.js +6249 -1276
  33. package/dist/index.es.js.map +1 -1
  34. package/dist/index.js +6256 -1273
  35. package/dist/index.js.map +1 -1
  36. package/dist/utils/calendar.d.ts +23 -0
  37. package/dist/utils/time.d.ts +21 -0
  38. package/dist/utils/transition.d.ts +3 -0
  39. package/package.json +11 -10
  40. package/src/components/backdrop/CBackdrop.ts +8 -6
  41. package/src/components/button/CButton.ts +2 -2
  42. package/src/components/calendar/CCalendar.ts +616 -0
  43. package/src/components/calendar/index.ts +10 -0
  44. package/src/components/collapse/CCollapse.ts +5 -6
  45. package/src/components/date-picker/CDatePicker.ts +240 -0
  46. package/src/components/date-picker/index.ts +10 -0
  47. package/src/components/date-range-picker/CDateRangePicker.ts +733 -0
  48. package/src/components/date-range-picker/index.ts +10 -0
  49. package/src/components/dropdown/CDropdownMenu.ts +4 -2
  50. package/src/components/dropdown/CDropdownToggle.ts +24 -9
  51. package/src/components/form/CFormCheck.ts +119 -94
  52. package/src/components/form/CFormControlValidation.ts +97 -0
  53. package/src/components/form/CFormControlWrapper.ts +106 -0
  54. package/src/components/form/CFormInput.ts +113 -29
  55. package/src/components/form/CFormRange.ts +25 -11
  56. package/src/components/form/CFormSelect.ts +126 -41
  57. package/src/components/form/CFormSwitch.ts +2 -21
  58. package/src/components/form/CFormTextarea.ts +105 -25
  59. package/src/components/index.ts +5 -0
  60. package/src/components/modal/CModal.ts +14 -6
  61. package/src/components/nav/CNavGroup.ts +4 -6
  62. package/src/components/offcanvas/COffcanvas.ts +5 -7
  63. package/src/components/pagination/CSmartPagination.ts +4 -4
  64. package/src/components/picker/CPicker.ts +221 -0
  65. package/src/components/picker/index.ts +10 -0
  66. package/src/components/popover/CPopover.ts +5 -5
  67. package/src/components/smart-table/CSmartTable.ts +17 -49
  68. package/src/components/smart-table/CSmartTableInterface.ts +5 -3
  69. package/src/components/tabs/CTabPane.ts +4 -6
  70. package/src/components/time-picker/CTimePicker.ts +405 -0
  71. package/src/components/time-picker/CTimePickerRollCol.ts +58 -0
  72. package/src/components/time-picker/index.ts +10 -0
  73. package/src/components/toast/CToast.ts +17 -12
  74. package/src/components/tooltip/CTooltip.ts +5 -5
  75. package/src/utils/calendar.ts +270 -0
  76. package/src/utils/time.ts +84 -0
  77. package/src/utils/transition.ts +65 -0
@@ -0,0 +1,58 @@
1
+ import { defineComponent, h, onUpdated, PropType, ref } from 'vue'
2
+
3
+ export interface Element {
4
+ value: number | string
5
+ label: number | string
6
+ }
7
+
8
+ const CTimePickerRollCol = defineComponent({
9
+ name: 'CTimePickerRollCol',
10
+ props: {
11
+ elements: {
12
+ type: Array as PropType<Element[]>,
13
+ required: true,
14
+ },
15
+ selected: {
16
+ type: [Number, String],
17
+ },
18
+ },
19
+ emits: ['click'],
20
+ setup(props, { emit }) {
21
+ const init = ref(true)
22
+ const colRef = ref<HTMLDivElement>()
23
+
24
+ onUpdated(() => {
25
+ const nodeEl = colRef.value?.querySelector('.selected')
26
+ if (nodeEl && nodeEl instanceof HTMLElement) {
27
+ colRef.value?.scrollTo({
28
+ top: nodeEl.offsetTop,
29
+ behavior: init.value ? 'auto' : 'smooth',
30
+ })
31
+ }
32
+ init.value = false
33
+ })
34
+
35
+ return () =>
36
+ h(
37
+ 'div',
38
+ { class: 'time-picker-roll-col', ref: colRef },
39
+ props.elements.map((element) => {
40
+ return h(
41
+ 'div',
42
+ {
43
+ class: [
44
+ 'time-picker-roll-cell',
45
+ {
46
+ selected: element.value === props.selected,
47
+ },
48
+ ],
49
+ onClick: () => emit('click', element.value),
50
+ role: 'button',
51
+ },
52
+ element.label,
53
+ )
54
+ }),
55
+ )
56
+ },
57
+ })
58
+ export { CTimePickerRollCol }
@@ -0,0 +1,10 @@
1
+ import { App } from 'vue'
2
+ import { CTimePicker } from './CTimePicker'
3
+
4
+ const CTimePickerPlugin = {
5
+ install: (app: App): void => {
6
+ app.component(CTimePicker.name, CTimePicker)
7
+ },
8
+ }
9
+
10
+ export { CTimePicker, CTimePickerPlugin }
@@ -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
  },
@@ -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) => {
@@ -0,0 +1,270 @@
1
+ export const convertToLocalDate = (d: Date, locale: string, options = {}) =>
2
+ d.toLocaleDateString(locale, options)
3
+
4
+ export const convertToLocalTime = (d: Date, locale: string, options = {}) =>
5
+ d.toLocaleTimeString(locale, options)
6
+
7
+ export const createGroupsInArray = (arr: any[], numberOfGroups: number) => {
8
+ const perGroup = Math.ceil(arr.length / numberOfGroups)
9
+ return new Array(numberOfGroups)
10
+ .fill('')
11
+ .map((_, i) => arr.slice(i * perGroup, (i + 1) * perGroup))
12
+ }
13
+
14
+ export const getCurrentYear = () => new Date().getFullYear()
15
+
16
+ export const getCurrentMonth = () => new Date().getMonth()
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
+
64
+ export const getMonthName = (month: number, locale: string) => {
65
+ const d = new Date()
66
+ d.setDate(1)
67
+ d.setMonth(month)
68
+ return d.toLocaleString(locale, { month: 'long' })
69
+ }
70
+
71
+ export const getMonthsNames = (locale: string) => {
72
+ const months = []
73
+ const d = new Date()
74
+ d.setDate(1)
75
+
76
+ for (let i = 0; i < 12; i++) {
77
+ d.setMonth(i)
78
+ months.push(d.toLocaleString(locale, { month: 'short' }))
79
+ }
80
+
81
+ return months
82
+ }
83
+
84
+ export const getYears = (year: number) => {
85
+ const years = []
86
+ for (let _year = year - 6; _year < year + 6; _year++) {
87
+ years.push(_year)
88
+ }
89
+
90
+ return years
91
+ }
92
+
93
+ const getLeadingDays = (year: number, month: number, firstDayOfWeek: number) => {
94
+ // 0: sunday
95
+ // 1: monday
96
+ const dates = []
97
+ const d = new Date(year, month)
98
+ const y = d.getFullYear()
99
+ const m = d.getMonth()
100
+ const firstWeekday = new Date(y, m, 1).getDay()
101
+ let leadingDays = 6 - (6 - firstWeekday) - firstDayOfWeek
102
+
103
+ if (firstDayOfWeek) {
104
+ leadingDays = leadingDays < 0 ? 7 + leadingDays : leadingDays
105
+ }
106
+
107
+ for (let i = leadingDays * -1; i < 0; i++) {
108
+ dates.push({
109
+ date: new Date(y, m, i + 1),
110
+ month: 'previous',
111
+ })
112
+ }
113
+
114
+ return dates
115
+ }
116
+
117
+ const getMonthDays = (year: number, month: number) => {
118
+ const dates = []
119
+ const lastDay = new Date(year, month + 1, 0).getDate()
120
+ for (let i = 1; i <= lastDay; i++) {
121
+ dates.push({
122
+ date: new Date(year, month, i),
123
+ month: 'current',
124
+ })
125
+ }
126
+ return dates
127
+ }
128
+
129
+ const getTrailingDays = (
130
+ year: number,
131
+ month: number,
132
+ leadingDays: { date: Date; month: string }[],
133
+ monthDays: { date: Date; month: string }[],
134
+ ) => {
135
+ const dates = []
136
+ const days = 42 - (leadingDays.length + monthDays.length)
137
+ for (let i = 1; i <= days; i++) {
138
+ dates.push({
139
+ date: new Date(year, month + 1, i),
140
+ month: 'next',
141
+ })
142
+ }
143
+ return dates
144
+ }
145
+
146
+ export const getMonthDetails = (year: number, month: number, firstDayOfWeek: number) => {
147
+ const daysPrevMonth = getLeadingDays(year, month, firstDayOfWeek)
148
+ const daysThisMonth = getMonthDays(year, month)
149
+ const daysNextMonth = getTrailingDays(year, month, daysPrevMonth, daysThisMonth)
150
+ const days = [...daysPrevMonth, ...daysThisMonth, ...daysNextMonth]
151
+
152
+ const weeks: { date: Date; month: string }[][] = []
153
+
154
+ days.forEach((day, index) => {
155
+ if (index % 7 === 0 || weeks.length === 0) {
156
+ weeks.push([])
157
+ }
158
+ weeks[weeks.length - 1].push(day)
159
+ })
160
+
161
+ return weeks
162
+ }
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
+
187
+ export const isDateDisabled = (
188
+ date: Date,
189
+ min?: Date | null,
190
+ max?: Date | null,
191
+ dates?: Date[] | Date[][],
192
+ ) => {
193
+ let disabled
194
+ if (dates) {
195
+ dates.forEach((_date: Date | Date[]) => {
196
+ if (Array.isArray(_date)) {
197
+ if (isDateInRange(date, _date[0], _date[1])) {
198
+ disabled = true
199
+ }
200
+ }
201
+ if (_date instanceof Date) {
202
+ if (isSameDateAs(date, _date)) {
203
+ disabled = true
204
+ }
205
+ }
206
+ })
207
+ }
208
+ if (min && date < min) {
209
+ disabled = true
210
+ }
211
+
212
+ if (max && date > max) {
213
+ disabled = true
214
+ }
215
+ return disabled
216
+ }
217
+
218
+ export const isDateInRange = (date: Date, start: Date | null, end: Date | null) => {
219
+ return start && end && start <= date && date <= end
220
+ }
221
+
222
+ export const isDateSelected = (date: Date, start: Date | null, end: Date | null) => {
223
+ return (start && isSameDateAs(start, date)) || (end && isSameDateAs(end, date))
224
+ }
225
+
226
+ export const isEndDate = (date: Date, start: Date | null, end: Date | null) => {
227
+ return start && end && isSameDateAs(end, date) && start < end
228
+ }
229
+
230
+ export const isLastDayOfMonth = (date: Date) => {
231
+ const test = new Date(date.getTime())
232
+ const month = test.getMonth()
233
+
234
+ test.setDate(test.getDate() + 1)
235
+ return test.getMonth() !== month
236
+ }
237
+
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
252
+ }
253
+
254
+ export const isStartDate = (date: Date, start: Date | null, end: Date | null) => {
255
+ return start && end && isSameDateAs(start, date) && start < end
256
+ }
257
+
258
+ export const isToday = (date: Date) => {
259
+ const today = new Date()
260
+ return (
261
+ date.getDate() === today.getDate() &&
262
+ date.getMonth() === today.getMonth() &&
263
+ date.getFullYear() === today.getFullYear()
264
+ )
265
+ }
266
+
267
+ export const isValidDate = (date: string) => {
268
+ const d = new Date(date)
269
+ return d instanceof Date && d.getTime()
270
+ }
@@ -0,0 +1,84 @@
1
+ export const convert12hTo24h = (abbr: 'am' | 'pm', hour: number) => {
2
+ if (abbr === 'am' && hour === 12) {
3
+ return 0
4
+ }
5
+ if (abbr === 'am') {
6
+ return hour
7
+ }
8
+ if (abbr === 'pm' && hour === 12) {
9
+ return 12
10
+ }
11
+ return hour + 12
12
+ }
13
+
14
+ export const convert24hTo12h = (hour: number) => hour % 12 || 12
15
+
16
+ export const convertTimeToDate = (time: Date | string | null | undefined) =>
17
+ time ? (time instanceof Date ? new Date(time) : new Date(`1970-01-01 ${time}`)) : null
18
+
19
+ export const getAmPm = (date: Date, locale: string) => {
20
+ if (date.toLocaleTimeString(locale).includes('AM')) {
21
+ return 'am'
22
+ }
23
+ if (date.toLocaleTimeString(locale).includes('PM')) {
24
+ return 'pm'
25
+ }
26
+ return date.getHours() >= 12 ? 'pm' : 'am'
27
+ }
28
+
29
+ export const getListOfHours = (locale: string) =>
30
+ Array.from({ length: isAmPm(locale) ? 12 : 24 }, (_, i) => {
31
+ return {
32
+ value: isAmPm(locale) ? i + 1 : i,
33
+ label: (isAmPm(locale) ? i + 1 : i).toLocaleString(locale),
34
+ }
35
+ })
36
+
37
+ export const getListOfMinutes = (locale: string, valueAsString = false) =>
38
+ Array.from({ length: 60 }, (_, i) => {
39
+ const d = new Date()
40
+ d.setMinutes(i)
41
+ return {
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],
68
+ }
69
+ })
70
+
71
+ export const getSelectedHour = (date: Date | null, locale: string) =>
72
+ date ? (isAmPm(locale) ? convert24hTo12h(date.getHours()) : date.getHours()) : ''
73
+
74
+ export const getSelectedMinutes = (date: Date | null) => (date ? date.getMinutes() : '')
75
+
76
+ export const getSelectedSeconds = (date: Date | null) => (date ? date.getSeconds() : '')
77
+
78
+ export const isAmPm = (locale: string) =>
79
+ ['am', 'AM', 'pm', 'PM'].some((el) => new Date().toLocaleString(locale).includes(el))
80
+
81
+ export const isValidTime = (time: string) => {
82
+ const d = new Date(`1970-01-01 ${time}`)
83
+ return d instanceof Date && d.getTime()
84
+ }
@@ -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
+ }