@coreui/vue-pro 4.3.0-beta.1 → 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.
- package/README.md +1 -1
- package/dist/components/calendar/CCalendar.d.ts +15 -2
- package/dist/components/carousel/CCarousel.d.ts +1 -1
- package/dist/components/date-picker/CDatePicker.d.ts +10 -2
- package/dist/components/date-range-picker/CDateRangePicker.d.ts +86 -3
- package/dist/components/form/CFormCheck.d.ts +88 -39
- package/dist/components/form/CFormControlValidation.d.ts +98 -0
- package/dist/components/form/CFormControlWrapper.d.ts +6 -0
- package/dist/components/form/CFormFeedback.d.ts +2 -2
- package/dist/components/form/CFormInput.d.ts +125 -25
- package/dist/components/form/CFormRange.d.ts +18 -16
- package/dist/components/form/CFormSelect.d.ts +125 -16
- package/dist/components/form/CFormSwitch.d.ts +0 -23
- package/dist/components/form/CFormTextarea.d.ts +125 -24
- package/dist/components/modal/CModal.d.ts +1 -1
- package/dist/components/offcanvas/COffcanvas.d.ts +1 -1
- package/dist/components/time-picker/CTimePicker.d.ts +1 -1
- package/dist/components/toast/CToast.d.ts +7 -1
- package/dist/index.es.js +3583 -577
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +3582 -576
- package/dist/index.js.map +1 -1
- package/dist/utils/calendar.d.ts +3 -1
- package/dist/utils/time.d.ts +6 -2
- package/dist/utils/transition.d.ts +3 -0
- package/package.json +11 -10
- package/src/components/backdrop/CBackdrop.ts +8 -6
- package/src/components/button/CButton.ts +2 -2
- package/src/components/calendar/CCalendar.ts +132 -62
- package/src/components/collapse/CCollapse.ts +5 -6
- package/src/components/date-picker/CDatePicker.ts +7 -10
- package/src/components/date-range-picker/CDateRangePicker.ts +198 -100
- package/src/components/form/CFormCheck.ts +119 -94
- package/src/components/form/CFormControlValidation.ts +97 -0
- package/src/components/form/CFormControlWrapper.ts +106 -0
- package/src/components/form/CFormInput.ts +113 -29
- package/src/components/form/CFormRange.ts +25 -11
- package/src/components/form/CFormSelect.ts +126 -41
- package/src/components/form/CFormSwitch.ts +2 -21
- package/src/components/form/CFormTextarea.ts +105 -25
- package/src/components/modal/CModal.ts +14 -6
- package/src/components/nav/CNavGroup.ts +4 -6
- package/src/components/offcanvas/COffcanvas.ts +5 -7
- package/src/components/picker/CPicker.ts +1 -0
- package/src/components/popover/CPopover.ts +5 -5
- package/src/components/tabs/CTabPane.ts +4 -6
- package/src/components/time-picker/CTimePicker.ts +12 -17
- package/src/components/toast/CToast.ts +17 -12
- package/src/components/tooltip/CTooltip.ts +5 -5
- package/src/utils/calendar.ts +86 -9
- package/src/utils/time.ts +29 -3
- package/src/utils/transition.ts +65 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { defineComponent, h, ref, RendererElement, Transition, watch, withDirectives } from 'vue'
|
|
2
|
+
|
|
2
3
|
import { CBackdrop } from '../backdrop'
|
|
4
|
+
|
|
3
5
|
import { vVisible } from '../../directives/v-c-visible'
|
|
6
|
+
import { executeAfterTransition } from './../../utils/transition'
|
|
4
7
|
|
|
5
8
|
const COffcanvas = defineComponent({
|
|
6
9
|
name: 'COffcanvas',
|
|
@@ -88,9 +91,7 @@ const COffcanvas = defineComponent({
|
|
|
88
91
|
|
|
89
92
|
const handleEnter = (el: RendererElement, done: () => void) => {
|
|
90
93
|
emit('show')
|
|
91
|
-
|
|
92
|
-
done()
|
|
93
|
-
})
|
|
94
|
+
executeAfterTransition(() => done(), el as HTMLElement)
|
|
94
95
|
setTimeout(() => {
|
|
95
96
|
el.style.visibility = 'visible'
|
|
96
97
|
el.classList.add('show')
|
|
@@ -98,13 +99,10 @@ const COffcanvas = defineComponent({
|
|
|
98
99
|
}
|
|
99
100
|
const handleAfterEnter = () => {
|
|
100
101
|
window.addEventListener('mousedown', handleMouseDown)
|
|
101
|
-
// window.addEventListener('click', handleClickOutside)
|
|
102
102
|
window.addEventListener('keyup', handleKeyUp)
|
|
103
103
|
}
|
|
104
104
|
const handleLeave = (el: RendererElement, done: () => void) => {
|
|
105
|
-
|
|
106
|
-
done()
|
|
107
|
-
})
|
|
105
|
+
executeAfterTransition(() => done(), el as HTMLElement)
|
|
108
106
|
window.removeEventListener('mousedown', handleMouseDown)
|
|
109
107
|
window.removeEventListener('keyup', handleKeyUp)
|
|
110
108
|
el.classList.remove('show')
|
|
@@ -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 CPopover = defineComponent({
|
|
5
7
|
name: 'CPopover',
|
|
6
8
|
props: {
|
|
@@ -83,18 +85,16 @@ const CPopover = defineComponent({
|
|
|
83
85
|
emit('show')
|
|
84
86
|
initPopper()
|
|
85
87
|
el.classList.add('show')
|
|
86
|
-
|
|
87
|
-
done()
|
|
88
|
-
})
|
|
88
|
+
executeAfterTransition(() => done(), el as HTMLElement)
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
const handleLeave = (el: RendererElement, done: () => void) => {
|
|
92
92
|
emit('hide')
|
|
93
93
|
el.classList.remove('show')
|
|
94
|
-
|
|
94
|
+
executeAfterTransition(() => {
|
|
95
95
|
done()
|
|
96
96
|
destroyPopper()
|
|
97
|
-
})
|
|
97
|
+
}, el as HTMLElement)
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
const handleToggle = (event: Event) => {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { defineComponent, h, ref, RendererElement, Transition, vShow, withDirectives } from 'vue'
|
|
2
2
|
|
|
3
|
+
import { executeAfterTransition } from './../../utils/transition'
|
|
4
|
+
|
|
3
5
|
const CTabPane = defineComponent({
|
|
4
6
|
name: 'CTabPane',
|
|
5
7
|
props: {
|
|
@@ -30,20 +32,16 @@ const CTabPane = defineComponent({
|
|
|
30
32
|
firstRender.value = false
|
|
31
33
|
emit('show')
|
|
32
34
|
setTimeout(() => {
|
|
35
|
+
executeAfterTransition(() => done(), el as HTMLElement)
|
|
33
36
|
el.classList.add('show')
|
|
34
37
|
}, 1)
|
|
35
|
-
el.addEventListener('transitionend', () => {
|
|
36
|
-
done()
|
|
37
|
-
})
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const handleLeave = (el: RendererElement, done: () => void) => {
|
|
41
41
|
firstRender.value = false
|
|
42
42
|
emit('hide')
|
|
43
43
|
el.classList.remove('show')
|
|
44
|
-
|
|
45
|
-
done()
|
|
46
|
-
})
|
|
44
|
+
executeAfterTransition(() => done(), el as HTMLElement)
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
return () =>
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
convertTimeToDate,
|
|
10
10
|
getAmPm,
|
|
11
11
|
getListOfHours,
|
|
12
|
-
|
|
12
|
+
getListOfMinutes,
|
|
13
|
+
getListOfSeconds,
|
|
13
14
|
getSelectedHour,
|
|
14
15
|
getSelectedMinutes,
|
|
15
16
|
getSelectedSeconds,
|
|
@@ -288,27 +289,21 @@ const CTimePicker = defineComponent({
|
|
|
288
289
|
...(date.value && { value: getSelectedHour(date.value, props.locale) }),
|
|
289
290
|
}),
|
|
290
291
|
':',
|
|
292
|
+
// @ts-expect-error the getListOfMinutes function returns corect type
|
|
291
293
|
h(CFormSelect, {
|
|
292
294
|
disabled: props.disabled,
|
|
293
|
-
options:
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
label: i.toLocaleString(props.locale).padStart(2, (0).toLocaleString(props.locale)),
|
|
297
|
-
}
|
|
298
|
-
}),
|
|
299
|
-
onChange: (event) => handleTimeChange('minutes', event.target.value),
|
|
295
|
+
options: getListOfMinutes(props.locale, true),
|
|
296
|
+
onChange: (event: Event) =>
|
|
297
|
+
handleTimeChange('minutes', (event.target as HTMLSelectElement).value),
|
|
300
298
|
...(date.value && { value: getSelectedMinutes(date.value) }),
|
|
301
299
|
}),
|
|
302
300
|
':',
|
|
301
|
+
// @ts-expect-error the getListOfMinutes function returns corect type
|
|
303
302
|
h(CFormSelect, {
|
|
304
303
|
disabled: props.disabled,
|
|
305
|
-
options:
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
label: i.toLocaleString(props.locale).padStart(2, (0).toLocaleString(props.locale)),
|
|
309
|
-
}
|
|
310
|
-
}),
|
|
311
|
-
onChange: (event) => handleTimeChange('seconds', event.target.value),
|
|
304
|
+
options: getListOfSeconds(props.locale, true),
|
|
305
|
+
onChange: (event: Event) =>
|
|
306
|
+
handleTimeChange('seconds', (event.target as HTMLSelectElement).value),
|
|
312
307
|
...(date.value && { value: getSelectedSeconds(date.value) }),
|
|
313
308
|
}),
|
|
314
309
|
isAmPm(props.locale) &&
|
|
@@ -330,12 +325,12 @@ const CTimePicker = defineComponent({
|
|
|
330
325
|
selected: getSelectedHour(date.value, props.locale),
|
|
331
326
|
}),
|
|
332
327
|
h(CTimePickerRollCol, {
|
|
333
|
-
elements:
|
|
328
|
+
elements: getListOfMinutes(props.locale),
|
|
334
329
|
onClick: (index: number) => handleTimeChange('minutes', index.toString()),
|
|
335
330
|
selected: getSelectedMinutes(date.value),
|
|
336
331
|
}),
|
|
337
332
|
h(CTimePickerRollCol, {
|
|
338
|
-
elements:
|
|
333
|
+
elements: getListOfSeconds(props.locale),
|
|
339
334
|
onClick: (index: number) => handleTimeChange('seconds', index.toString()),
|
|
340
335
|
selected: getSelectedSeconds(date.value),
|
|
341
336
|
}),
|
|
@@ -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
|
-
|
|
84
|
-
|
|
85
|
-
})
|
|
89
|
+
executeAfterTransition(() => done(), el as HTMLElement)
|
|
90
|
+
el.classList.add('show')
|
|
86
91
|
setTimeout(() => {
|
|
87
|
-
el.classList.
|
|
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
|
-
|
|
96
|
-
el.classList.remove('show')
|
|
97
|
-
}
|
|
101
|
+
|
|
98
102
|
const handleLeave = (el: RendererElement, done: () => void) => {
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
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
|
-
|
|
86
|
+
executeAfterTransition(() => {
|
|
87
87
|
done()
|
|
88
88
|
destroyPopper()
|
|
89
|
-
})
|
|
89
|
+
}, el as HTMLElement)
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const handleToggle = (event: Event) => {
|
package/src/utils/calendar.ts
CHANGED
|
@@ -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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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()
|
|
185
|
-
date.getMonth()
|
|
186
|
-
date.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
|
|
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:
|
|
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
|
+
}
|