@coreui/vue-pro 4.9.0-beta.2 → 4.9.0-rc.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/dropdown/CDropdown.d.ts +62 -4
- package/dist/components/dropdown/CDropdownToggle.d.ts +1 -1
- package/dist/components/form/CFormCheck.d.ts +1 -1
- package/dist/components/form/CFormControl.d.ts +1 -1
- package/dist/components/form/CFormInput.d.ts +2 -2
- package/dist/components/form/CFormTextarea.d.ts +2 -2
- package/dist/components/multi-select/CMultiSelect.d.ts +1 -1
- package/dist/components/multi-select/CMultiSelectNativeSelect.d.ts +1 -1
- package/dist/components/multi-select/CMultiSelectSelection.d.ts +1 -1
- package/dist/components/picker/CPicker.d.ts +3 -3
- package/dist/components/popover/CPopover.d.ts +75 -6
- package/dist/components/toast/CToast.d.ts +1 -1
- package/dist/components/tooltip/CTooltip.d.ts +77 -8
- package/dist/composables/index.d.ts +2 -2
- package/dist/composables/useColorModes.d.ts +1 -1
- package/dist/composables/usePopper.d.ts +6 -0
- package/dist/index.es.js +3748 -3667
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +3747 -3666
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/getRTLPlacement.d.ts +3 -0
- package/dist/utils/index.d.ts +2 -1
- package/package.json +2 -2
- package/src/components/date-range-picker/CDateRangePicker.ts +85 -65
- package/src/components/dropdown/CDropdown.ts +116 -61
- package/src/components/dropdown/CDropdownMenu.ts +2 -47
- package/src/components/dropdown/CDropdownToggle.ts +5 -5
- package/src/components/multi-select/CMultiSelect.ts +55 -64
- package/src/components/multi-select/CMultiSelectSelection.ts +10 -11
- package/src/components/picker/CPicker.ts +22 -7
- package/src/components/popover/CPopover.ts +96 -50
- package/src/components/time-picker/CTimePicker.ts +29 -11
- package/src/components/tooltip/CTooltip.ts +97 -51
- package/src/composables/index.ts +2 -2
- package/src/composables/usePopper.ts +25 -0
- package/src/types.ts +1 -1
- package/src/utils/getRTLPlacement.ts +18 -0
- package/src/utils/index.ts +2 -1
- package/src/composables/useColorModes.ts +0 -62
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type Breakpoints = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
|
|
2
2
|
export type Colors = 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'dark' | 'light' | 'primary-gradient' | 'secondary-gradient' | 'success-gradient' | 'danger-gradient' | 'warning-gradient' | 'info-gradient' | 'dark-gradient' | 'light-gradient' | string;
|
|
3
|
-
export type Placements = 'auto' | 'auto-start' | 'auto-end' | 'top-end' | 'top' | 'top-start' | 'bottom-end' | 'bottom' | 'bottom-start' | 'right-start' | 'right' | 'right-end' | 'left-start' | 'left' | 'left-end' |
|
|
3
|
+
export type Placements = 'auto' | 'auto-start' | 'auto-end' | 'top-end' | 'top' | 'top-start' | 'bottom-end' | 'bottom' | 'bottom-start' | 'right-start' | 'right' | 'right-end' | 'left-start' | 'left' | 'left-end' | string;
|
|
4
4
|
export type Shapes = 'rounded' | 'rounded-top' | 'rounded-end' | 'rounded-bottom' | 'rounded-start' | 'rounded-circle' | 'rounded-pill' | 'rounded-0' | 'rounded-1' | 'rounded-2' | 'rounded-3' | string;
|
|
5
5
|
export type Triggers = 'hover' | 'focus' | 'click';
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import getRTLPlacement from './getRTLPlacement';
|
|
1
2
|
import getUID from './getUID';
|
|
2
3
|
import isInViewport from './isInViewport';
|
|
3
4
|
import isObjectInArray from './isObjectInArray';
|
|
4
5
|
import isRTL from './isRTL';
|
|
5
|
-
export { getUID, isInViewport, isObjectInArray, isRTL };
|
|
6
|
+
export { getRTLPlacement, getUID, isInViewport, isObjectInArray, isRTL };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreui/vue-pro",
|
|
3
|
-
"version": "4.9.0-
|
|
3
|
+
"version": "4.9.0-rc.0",
|
|
4
4
|
"description": "UI Components Library for Vue.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"vue-types": "^5.0.3"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@coreui/coreui-pro": "^4.
|
|
58
|
+
"@coreui/coreui-pro": "^4.5.0",
|
|
59
59
|
"vue": "^3.2.21"
|
|
60
60
|
},
|
|
61
61
|
"standard": {
|
|
@@ -4,6 +4,7 @@ import { format as dateFormat } from 'date-fns'
|
|
|
4
4
|
|
|
5
5
|
import { CButton } from '../button'
|
|
6
6
|
import { CCalendar } from '../calendar'
|
|
7
|
+
import { CInputGroup } from '../form'
|
|
7
8
|
import { CFormControlWrapper } from './../form/CFormControlWrapper'
|
|
8
9
|
import { CPicker } from '../picker'
|
|
9
10
|
import { CTimePicker } from '../time-picker'
|
|
@@ -495,8 +496,9 @@ const CDateRangePicker = defineComponent({
|
|
|
495
496
|
() => props.startDate,
|
|
496
497
|
() => {
|
|
497
498
|
if (props.startDate) {
|
|
498
|
-
|
|
499
|
-
|
|
499
|
+
const date = new Date(props.startDate)
|
|
500
|
+
calendarDate.value = date
|
|
501
|
+
startDate.value = date
|
|
500
502
|
}
|
|
501
503
|
},
|
|
502
504
|
)
|
|
@@ -505,8 +507,9 @@ const CDateRangePicker = defineComponent({
|
|
|
505
507
|
() => props.endDate,
|
|
506
508
|
() => {
|
|
507
509
|
if (props.endDate) {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
+
const date = new Date(props.endDate)
|
|
511
|
+
calendarDate.value = date
|
|
512
|
+
endDate.value = date
|
|
510
513
|
}
|
|
511
514
|
},
|
|
512
515
|
)
|
|
@@ -642,24 +645,61 @@ const CDateRangePicker = defineComponent({
|
|
|
642
645
|
}
|
|
643
646
|
|
|
644
647
|
const InputGroup = () =>
|
|
645
|
-
h(
|
|
646
|
-
'
|
|
647
|
-
|
|
648
|
-
class:
|
|
649
|
-
|
|
650
|
-
|
|
648
|
+
h(CInputGroup, { class: 'picker-input-group', size: props.size }, () => [
|
|
649
|
+
h('input', {
|
|
650
|
+
autocomplete: 'off',
|
|
651
|
+
class: [
|
|
652
|
+
'form-control date-picker-input',
|
|
653
|
+
{
|
|
654
|
+
hover: inputStartHoverValue.value,
|
|
655
|
+
},
|
|
656
|
+
],
|
|
657
|
+
disabled: props.disabled,
|
|
658
|
+
...(props.id && { name: props.range ? `${props.id}-start-date` : `${props.id}-date` }),
|
|
659
|
+
onClick: () => {
|
|
660
|
+
selectEndDate.value = false
|
|
661
|
+
},
|
|
662
|
+
onInput: (event: Event) => {
|
|
663
|
+
const date = getLocalDateFromString(
|
|
664
|
+
(event.target as HTMLInputElement).value,
|
|
665
|
+
props.locale,
|
|
666
|
+
props.timepicker,
|
|
667
|
+
)
|
|
668
|
+
if (date instanceof Date && date.getTime()) {
|
|
669
|
+
calendarDate.value = date
|
|
670
|
+
startDate.value = date
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
placeholder: Array.isArray(props.placeholder) ? props.placeholder[0] : props.placeholder,
|
|
674
|
+
readonly: props.inputReadOnly || typeof props.format === 'string',
|
|
675
|
+
required: props.required,
|
|
676
|
+
ref: inputStartRef,
|
|
677
|
+
value: inputStartHoverValue.value
|
|
678
|
+
? setInputValue(inputStartHoverValue.value)
|
|
679
|
+
: setInputValue(startDate.value),
|
|
680
|
+
}),
|
|
681
|
+
props.range &&
|
|
682
|
+
props.separator !== false &&
|
|
683
|
+
h(
|
|
684
|
+
'span',
|
|
685
|
+
{ class: 'input-group-text' },
|
|
686
|
+
slots.separator
|
|
687
|
+
? slots.separator()
|
|
688
|
+
: h('span', { class: 'picker-input-group-icon date-picker-arrow-icon' }),
|
|
689
|
+
),
|
|
690
|
+
props.range &&
|
|
651
691
|
h('input', {
|
|
652
692
|
autocomplete: 'off',
|
|
653
693
|
class: [
|
|
654
|
-
'date-picker-input',
|
|
694
|
+
'form-control date-picker-input',
|
|
655
695
|
{
|
|
656
|
-
hover:
|
|
696
|
+
hover: inputEndHoverValue.value,
|
|
657
697
|
},
|
|
658
698
|
],
|
|
659
699
|
disabled: props.disabled,
|
|
660
|
-
...(props.id && { name:
|
|
700
|
+
...(props.id && { name: `${props.id}-end-date` }),
|
|
661
701
|
onClick: () => {
|
|
662
|
-
selectEndDate.value =
|
|
702
|
+
selectEndDate.value = true
|
|
663
703
|
},
|
|
664
704
|
onInput: (event: Event) => {
|
|
665
705
|
const date = getLocalDateFromString(
|
|
@@ -669,62 +709,43 @@ const CDateRangePicker = defineComponent({
|
|
|
669
709
|
)
|
|
670
710
|
if (date instanceof Date && date.getTime()) {
|
|
671
711
|
calendarDate.value = date
|
|
672
|
-
|
|
712
|
+
endDate.value = date
|
|
673
713
|
}
|
|
674
714
|
},
|
|
675
|
-
placeholder:
|
|
676
|
-
? props.placeholder[0]
|
|
677
|
-
: props.placeholder,
|
|
715
|
+
placeholder: props.placeholder[1],
|
|
678
716
|
readonly: props.inputReadOnly || typeof props.format === 'string',
|
|
679
717
|
required: props.required,
|
|
680
|
-
ref:
|
|
681
|
-
value:
|
|
682
|
-
? setInputValue(
|
|
683
|
-
: setInputValue(
|
|
718
|
+
ref: inputEndRef,
|
|
719
|
+
value: inputEndHoverValue.value
|
|
720
|
+
? setInputValue(inputEndHoverValue.value)
|
|
721
|
+
: setInputValue(endDate.value),
|
|
684
722
|
}),
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
'date-picker-input',
|
|
723
|
+
(props.indicator || props.cleaner) &&
|
|
724
|
+
h('span', { class: 'input-group-text' }, [
|
|
725
|
+
props.indicator &&
|
|
726
|
+
h(
|
|
727
|
+
'span',
|
|
691
728
|
{
|
|
692
|
-
|
|
729
|
+
class: 'picker-input-group-indicator',
|
|
693
730
|
},
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
readonly: props.inputReadOnly || typeof props.format === 'string',
|
|
713
|
-
required: props.required,
|
|
714
|
-
ref: inputEndRef,
|
|
715
|
-
value: inputEndHoverValue.value
|
|
716
|
-
? setInputValue(inputEndHoverValue.value)
|
|
717
|
-
: setInputValue(endDate.value),
|
|
718
|
-
}),
|
|
719
|
-
props.indicator && h('div', { class: 'date-picker-indicator' }),
|
|
720
|
-
props.cleaner &&
|
|
721
|
-
(startDate.value || endDate.value) &&
|
|
722
|
-
h('div', {
|
|
723
|
-
class: 'date-picker-cleaner',
|
|
724
|
-
onClick: (event: Event) => handleClear(event),
|
|
725
|
-
}),
|
|
726
|
-
],
|
|
727
|
-
)
|
|
731
|
+
slots.indicator
|
|
732
|
+
? slots.indicator()
|
|
733
|
+
: h('span', { class: 'picker-input-group-icon date-picker-input-icon' }),
|
|
734
|
+
),
|
|
735
|
+
props.cleaner &&
|
|
736
|
+
h(
|
|
737
|
+
'span',
|
|
738
|
+
{
|
|
739
|
+
class: 'picker-input-group-cleaner',
|
|
740
|
+
onClick: (event: Event) => handleClear(event),
|
|
741
|
+
role: 'button',
|
|
742
|
+
},
|
|
743
|
+
slots.cleaner
|
|
744
|
+
? slots.cleaner()
|
|
745
|
+
: h('span', { class: 'picker-input-group-icon date-picker-cleaner-icon' }),
|
|
746
|
+
),
|
|
747
|
+
]),
|
|
748
|
+
])
|
|
728
749
|
|
|
729
750
|
return () =>
|
|
730
751
|
h(
|
|
@@ -749,7 +770,6 @@ const CDateRangePicker = defineComponent({
|
|
|
749
770
|
class: [
|
|
750
771
|
'date-picker',
|
|
751
772
|
{
|
|
752
|
-
[`date-picker-${props.size}`]: props.size,
|
|
753
773
|
disabled: props.disabled,
|
|
754
774
|
'is-invalid': isValid.value === false ? true : false,
|
|
755
775
|
'is-valid': isValid.value,
|
|
@@ -780,7 +800,7 @@ const CDateRangePicker = defineComponent({
|
|
|
780
800
|
{
|
|
781
801
|
toggler: () => InputGroup(),
|
|
782
802
|
footer: () =>
|
|
783
|
-
h('div', { class: '
|
|
803
|
+
h('div', { class: 'picker-footer' }, [
|
|
784
804
|
props.todayButton &&
|
|
785
805
|
h(
|
|
786
806
|
CButton,
|
|
@@ -1,9 +1,53 @@
|
|
|
1
|
-
import { defineComponent, h, ref, provide, watch, PropType
|
|
2
|
-
import {
|
|
1
|
+
import { defineComponent, h, ref, provide, watch, PropType } from 'vue'
|
|
2
|
+
import type { Placement } from '@popperjs/core'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { usePopper } from '../../composables'
|
|
5
|
+
import type { Placements, Triggers } from '../../types'
|
|
5
6
|
import { isRTL } from '../../utils'
|
|
6
7
|
|
|
8
|
+
export type Directions = 'start' | 'end'
|
|
9
|
+
|
|
10
|
+
export type Breakpoints =
|
|
11
|
+
| { xs: Directions }
|
|
12
|
+
| { sm: Directions }
|
|
13
|
+
| { md: Directions }
|
|
14
|
+
| { lg: Directions }
|
|
15
|
+
| { xl: Directions }
|
|
16
|
+
| { xxl: Directions }
|
|
17
|
+
|
|
18
|
+
export type Alignments = Directions | Breakpoints
|
|
19
|
+
|
|
20
|
+
const getPlacement = (
|
|
21
|
+
placement: Placement,
|
|
22
|
+
direction: string | undefined,
|
|
23
|
+
alignment: Alignments | string | undefined,
|
|
24
|
+
isRTL: boolean,
|
|
25
|
+
): Placements => {
|
|
26
|
+
let _placement = placement
|
|
27
|
+
|
|
28
|
+
if (direction === 'dropup') {
|
|
29
|
+
_placement = isRTL ? 'top-end' : 'top-start'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (direction === 'dropup-center') {
|
|
33
|
+
_placement = 'top'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (direction === 'dropend') {
|
|
37
|
+
_placement = isRTL ? 'left-start' : 'right-start'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (direction === 'dropstart') {
|
|
41
|
+
_placement = isRTL ? 'right-start' : 'left-start'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (alignment === 'end') {
|
|
45
|
+
_placement = isRTL ? 'bottom-start' : 'bottom-end'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return _placement
|
|
49
|
+
}
|
|
50
|
+
|
|
7
51
|
const CDropdown = defineComponent({
|
|
8
52
|
name: 'CDropdown',
|
|
9
53
|
props: {
|
|
@@ -13,7 +57,7 @@ const CDropdown = defineComponent({
|
|
|
13
57
|
* @values { 'start' | 'end' | { xs: 'start' | 'end' } | { sm: 'start' | 'end' } | { md: 'start' | 'end' } | { lg: 'start' | 'end' } | { xl: 'start' | 'end'} | { xxl: 'start' | 'end'} }
|
|
14
58
|
*/
|
|
15
59
|
alignment: {
|
|
16
|
-
type: [String, Object]
|
|
60
|
+
type: [String, Object] as PropType<string | Alignments>,
|
|
17
61
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
62
|
validator: (value: string | any) => {
|
|
19
63
|
if (value === 'start' || value === 'end') {
|
|
@@ -74,6 +118,15 @@ const CDropdown = defineComponent({
|
|
|
74
118
|
* Toggle the disabled state for the component.
|
|
75
119
|
*/
|
|
76
120
|
disabled: Boolean,
|
|
121
|
+
/**
|
|
122
|
+
* Offset of the dropdown menu relative to its target.
|
|
123
|
+
*
|
|
124
|
+
* @since 4.9.0-rc.0
|
|
125
|
+
*/
|
|
126
|
+
offset: {
|
|
127
|
+
type: Array,
|
|
128
|
+
default: () => [0, 2],
|
|
129
|
+
},
|
|
77
130
|
/**
|
|
78
131
|
* Describes the placement of your component after Popper.js has applied all the modifiers that may have flipped or altered the originally provided placement property.
|
|
79
132
|
*
|
|
@@ -127,10 +180,28 @@ const CDropdown = defineComponent({
|
|
|
127
180
|
setup(props, { slots, emit }) {
|
|
128
181
|
const dropdownToggleRef = ref()
|
|
129
182
|
const dropdownMenuRef = ref()
|
|
130
|
-
const
|
|
131
|
-
const popper = ref()
|
|
183
|
+
const popper = ref(typeof props.alignment === 'object' ? false : props.popper)
|
|
132
184
|
const visible = ref(props.visible)
|
|
133
185
|
|
|
186
|
+
const { initPopper, destroyPopper } = usePopper()
|
|
187
|
+
|
|
188
|
+
const popperConfig = {
|
|
189
|
+
modifiers: [
|
|
190
|
+
{
|
|
191
|
+
name: 'offset',
|
|
192
|
+
options: {
|
|
193
|
+
offset: props.offset,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
placement: getPlacement(
|
|
198
|
+
props.placement,
|
|
199
|
+
props.direction,
|
|
200
|
+
props.alignment,
|
|
201
|
+
isRTL(dropdownMenuRef.value),
|
|
202
|
+
) as Placement,
|
|
203
|
+
}
|
|
204
|
+
|
|
134
205
|
watch(
|
|
135
206
|
() => props.visible,
|
|
136
207
|
() => {
|
|
@@ -138,8 +209,22 @@ const CDropdown = defineComponent({
|
|
|
138
209
|
},
|
|
139
210
|
)
|
|
140
211
|
|
|
212
|
+
watch(visible, () => {
|
|
213
|
+
if (visible.value && dropdownToggleRef.value && dropdownMenuRef.value) {
|
|
214
|
+
popper.value && initPopper(dropdownToggleRef.value, dropdownMenuRef.value, popperConfig)
|
|
215
|
+
window.addEventListener('mouseup', handleMouseUp)
|
|
216
|
+
window.addEventListener('keyup', handleKeyup)
|
|
217
|
+
emit('show')
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
popper.value && destroyPopper()
|
|
222
|
+
window.removeEventListener('mouseup', handleMouseUp)
|
|
223
|
+
window.removeEventListener('keyup', handleKeyup)
|
|
224
|
+
emit('hide')
|
|
225
|
+
})
|
|
226
|
+
|
|
141
227
|
provide('config', {
|
|
142
|
-
autoClose: props.autoClose,
|
|
143
228
|
alignment: props.alignment,
|
|
144
229
|
dark: props.dark,
|
|
145
230
|
popper: props.popper,
|
|
@@ -150,27 +235,38 @@ const CDropdown = defineComponent({
|
|
|
150
235
|
provide('dropdownToggleRef', dropdownToggleRef)
|
|
151
236
|
provide('dropdownMenuRef', dropdownMenuRef)
|
|
152
237
|
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
if (typeof props.alignment === 'object') {
|
|
238
|
+
const handleKeyup = (event: KeyboardEvent) => {
|
|
239
|
+
if (props.autoClose === false) {
|
|
156
240
|
return
|
|
157
241
|
}
|
|
158
242
|
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
placement: placement.value,
|
|
162
|
-
})
|
|
243
|
+
if (event.key === 'Escape') {
|
|
244
|
+
setVisible(false)
|
|
163
245
|
}
|
|
164
246
|
}
|
|
165
247
|
|
|
166
|
-
const
|
|
167
|
-
if (
|
|
168
|
-
|
|
248
|
+
const handleMouseUp = (event: Event) => {
|
|
249
|
+
if (!dropdownToggleRef.value || !dropdownMenuRef.value) {
|
|
250
|
+
return
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (dropdownToggleRef.value.contains(event.target as HTMLElement)) {
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (
|
|
258
|
+
props.autoClose === true ||
|
|
259
|
+
(props.autoClose === 'inside' &&
|
|
260
|
+
dropdownMenuRef.value.contains(event.target as HTMLElement)) ||
|
|
261
|
+
(props.autoClose === 'outside' &&
|
|
262
|
+
!dropdownMenuRef.value.contains(event.target as HTMLElement))
|
|
263
|
+
) {
|
|
264
|
+
setVisible(false)
|
|
265
|
+
return
|
|
169
266
|
}
|
|
170
|
-
popper.value = undefined
|
|
171
267
|
}
|
|
172
268
|
|
|
173
|
-
const
|
|
269
|
+
const setVisible = (_visible?: boolean) => {
|
|
174
270
|
if (props.disabled) {
|
|
175
271
|
return
|
|
176
272
|
}
|
|
@@ -188,48 +284,7 @@ const CDropdown = defineComponent({
|
|
|
188
284
|
visible.value = true
|
|
189
285
|
}
|
|
190
286
|
|
|
191
|
-
provide('
|
|
192
|
-
|
|
193
|
-
const hideMenu = () => {
|
|
194
|
-
if (props.disabled) {
|
|
195
|
-
return
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
visible.value = false
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
provide('hideMenu', hideMenu)
|
|
202
|
-
|
|
203
|
-
watch(visible, () => {
|
|
204
|
-
props.popper && (visible.value ? initPopper() : destroyPopper())
|
|
205
|
-
visible.value ? emit('show') : emit('hide')
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
onMounted(() => {
|
|
209
|
-
if (props.direction === 'center') {
|
|
210
|
-
placement.value = 'bottom'
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (props.direction === 'dropup') {
|
|
214
|
-
placement.value = isRTL(dropdownMenuRef.value) ? 'top-end' : 'top-start'
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (props.direction === 'dropup-center') {
|
|
218
|
-
placement.value = 'top'
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (props.direction === 'dropend') {
|
|
222
|
-
placement.value = isRTL(dropdownMenuRef.value) ? 'left-start' : 'right-start'
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (props.direction === 'dropstart') {
|
|
226
|
-
placement.value = isRTL(dropdownMenuRef.value) ? 'right-start' : 'left-start'
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (props.alignment === 'end') {
|
|
230
|
-
placement.value = isRTL(dropdownMenuRef.value) ? 'bottom-start' : 'bottom-end'
|
|
231
|
-
}
|
|
232
|
-
})
|
|
287
|
+
provide('setVisible', setVisible)
|
|
233
288
|
|
|
234
289
|
return () =>
|
|
235
290
|
props.variant === 'input-group'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, h, inject,
|
|
1
|
+
import { defineComponent, h, inject, Ref } from 'vue'
|
|
2
2
|
|
|
3
3
|
const CDropdownMenu = defineComponent({
|
|
4
4
|
name: 'CDropdownMenu',
|
|
@@ -14,13 +14,11 @@ const CDropdownMenu = defineComponent({
|
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
setup(props, { slots }) {
|
|
17
|
-
const dropdownToggleRef = inject('dropdownToggleRef') as Ref<HTMLElement>
|
|
18
17
|
const dropdownMenuRef = inject('dropdownMenuRef') as Ref<HTMLElement>
|
|
19
18
|
const config = inject('config') as any // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
20
|
-
const hideMenu = inject('hideMenu') as () => void
|
|
21
19
|
const visible = inject('visible') as Ref<boolean>
|
|
22
20
|
|
|
23
|
-
const {
|
|
21
|
+
const { alignment, dark, popper } = config
|
|
24
22
|
|
|
25
23
|
// eslint-disable-next-line @typescript-eslint/ban-types, unicorn/consistent-function-scoping
|
|
26
24
|
const alignmentClassNames = (alignment: object | string) => {
|
|
@@ -36,49 +34,6 @@ const CDropdownMenu = defineComponent({
|
|
|
36
34
|
return classNames
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
const handleKeyup = (event: KeyboardEvent) => {
|
|
40
|
-
if (autoClose === false) {
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (event.key === 'Escape') {
|
|
45
|
-
hideMenu()
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const handleMouseUp = (event: Event) => {
|
|
50
|
-
if (dropdownToggleRef.value?.contains(event.target as HTMLElement)) {
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (autoClose === true) {
|
|
55
|
-
hideMenu()
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (autoClose === 'inside' && dropdownMenuRef.value?.contains(event.target as HTMLElement)) {
|
|
60
|
-
hideMenu()
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
autoClose === 'outside' &&
|
|
66
|
-
!dropdownMenuRef.value?.contains(event.target as HTMLElement)
|
|
67
|
-
) {
|
|
68
|
-
hideMenu()
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
onUpdated(() => {
|
|
73
|
-
visible.value && window.addEventListener('mouseup', handleMouseUp)
|
|
74
|
-
visible.value && window.addEventListener('keyup', handleKeyup)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
onUnmounted(() => {
|
|
78
|
-
window.removeEventListener('mouseup', handleMouseUp)
|
|
79
|
-
window.removeEventListener('keyup', handleKeyup)
|
|
80
|
-
})
|
|
81
|
-
|
|
82
37
|
return () =>
|
|
83
38
|
h(
|
|
84
39
|
props.component,
|
|
@@ -3,7 +3,7 @@ import { cloneVNode, defineComponent, h, inject, onMounted, PropType, Ref, ref }
|
|
|
3
3
|
import { CButton } from '../button'
|
|
4
4
|
|
|
5
5
|
import { Color, Shape } from '../../props'
|
|
6
|
-
import { Triggers } from '../../types'
|
|
6
|
+
import type { Triggers } from '../../types'
|
|
7
7
|
|
|
8
8
|
const CDropdownToggle = defineComponent({
|
|
9
9
|
name: 'CDropdownToggle',
|
|
@@ -85,7 +85,7 @@ const CDropdownToggle = defineComponent({
|
|
|
85
85
|
const dropdownToggleRef = inject('dropdownToggleRef') as Ref<HTMLElement>
|
|
86
86
|
const dropdownVariant = inject('variant') as string
|
|
87
87
|
const visible = inject('visible') as Ref<boolean>
|
|
88
|
-
const
|
|
88
|
+
const setVisible = inject('setVisible') as (_visible?: boolean) => void
|
|
89
89
|
|
|
90
90
|
const className = [
|
|
91
91
|
{
|
|
@@ -103,7 +103,7 @@ const CDropdownToggle = defineComponent({
|
|
|
103
103
|
return
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
setVisible()
|
|
107
107
|
},
|
|
108
108
|
}),
|
|
109
109
|
...((props.trigger === 'focus' || props.trigger.includes('focus')) && {
|
|
@@ -112,13 +112,13 @@ const CDropdownToggle = defineComponent({
|
|
|
112
112
|
return
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
setVisible(true)
|
|
116
116
|
},
|
|
117
117
|
onblur: () => {
|
|
118
118
|
if (props.disabled) {
|
|
119
119
|
return
|
|
120
120
|
}
|
|
121
|
-
|
|
121
|
+
setVisible(false)
|
|
122
122
|
},
|
|
123
123
|
}),
|
|
124
124
|
}
|