@coreui/vue-pro 4.1.4 → 4.2.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/button/CButton.d.ts +29 -2
- package/dist/components/dropdown/CDropdown.d.ts +25 -0
- package/dist/components/dropdown/CDropdownToggle.d.ts +35 -1
- package/dist/index.es.js +198 -85
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +197 -84
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/components/accordion/CAccordionButton.ts +1 -0
- package/src/components/accordion/__tests__/__snapshots__/CAccordionButton.spec.ts.snap +1 -1
- package/src/components/accordion/__tests__/__snapshots__/CAccordionHeader.spec.ts.snap +1 -1
- package/src/components/button/CButton.ts +30 -1
- package/src/components/button/__tests__/__snapshots__/CButton.spec.ts.snap +1 -1
- package/src/components/close-button/CCloseButton.ts +4 -1
- package/src/components/dropdown/CDropdown.ts +48 -49
- package/src/components/dropdown/CDropdownMenu.ts +50 -7
- package/src/components/dropdown/CDropdownToggle.ts +78 -29
- package/src/components/dropdown/__tests__/CDropdownMenu.spec.ts +7 -7
- package/src/components/dropdown/__tests__/CDropdownToggle.spec.ts +4 -5
- package/src/components/dropdown/__tests__/__snapshots__/CDropdownToggle.spec.ts.snap +2 -2
- package/src/components/form/CFormCheck.ts +2 -1
- package/src/components/form/CFormSwitch.ts +1 -7
- package/src/components/form/__tests__/__snapshots__/CFormCheck.spec.ts.snap +2 -8
- package/src/components/modal/__tests__/__snapshots__/CModal.spec.ts.snap +2 -1
- package/src/components/sidebar/__tests__/__snapshots__/CSidebar.spec.ts.snap +8 -2
- package/src/components/toast/__tests__/__snapshots__/CToastClose.spec.ts.snap +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coreui/vue-pro",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "UI Components Library for Vue.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -35,18 +35,18 @@
|
|
|
35
35
|
"watch": "rollup -c -w"
|
|
36
36
|
},
|
|
37
37
|
"config": {
|
|
38
|
-
"version_short": "4.
|
|
38
|
+
"version_short": "4.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@popperjs/core": "^2.11.
|
|
42
|
-
"@rollup/plugin-commonjs": "^21.0.
|
|
41
|
+
"@popperjs/core": "^2.11.4",
|
|
42
|
+
"@rollup/plugin-commonjs": "^21.0.2",
|
|
43
43
|
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
44
|
-
"@rollup/plugin-typescript": "^8.3.
|
|
45
|
-
"@vue/test-utils": "^2.0.0-
|
|
46
|
-
"rollup": "^2.
|
|
44
|
+
"@rollup/plugin-typescript": "^8.3.1",
|
|
45
|
+
"@vue/test-utils": "^2.0.0-rc.17",
|
|
46
|
+
"rollup": "^2.70.1",
|
|
47
47
|
"rollup-plugin-vue": "^6.0.0",
|
|
48
|
-
"typescript": "^4.
|
|
49
|
-
"vue": "^3.2.
|
|
48
|
+
"typescript": "^4.6.2",
|
|
49
|
+
"vue": "^3.2.31",
|
|
50
50
|
"vue-types": "^4.1.1"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`Loads and display CAccordionButton component renders correctly 1`] = `"<button aria-expanded=\\"true\\" class=\\"accordion-button collapsed\\">Default slot</button>"`;
|
|
3
|
+
exports[`Loads and display CAccordionButton component renders correctly 1`] = `"<button type=\\"button\\" aria-expanded=\\"true\\" class=\\"accordion-button collapsed\\">Default slot</button>"`;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`Loads and display CAccordionHeader component renders correctly 1`] = `"<div class=\\"accordion-header\\"><button aria-expanded=\\"true\\" class=\\"accordion-button collapsed\\">Default slot</button></div>"`;
|
|
3
|
+
exports[`Loads and display CAccordionHeader component renders correctly 1`] = `"<div class=\\"accordion-header\\"><button type=\\"button\\" aria-expanded=\\"true\\" class=\\"accordion-button collapsed\\">Default slot</button></div>"`;
|
|
@@ -60,6 +60,20 @@ export const CButton = defineComponent({
|
|
|
60
60
|
return ['sm', 'lg'].includes(value)
|
|
61
61
|
},
|
|
62
62
|
},
|
|
63
|
+
/**
|
|
64
|
+
* Specifies the type of button. Always specify the type attribute for the `<button>` element.
|
|
65
|
+
* Different browsers may use different default types for the `<button>` element.
|
|
66
|
+
*
|
|
67
|
+
* @values 'button', 'submit', 'reset'
|
|
68
|
+
*/
|
|
69
|
+
type: {
|
|
70
|
+
type: String,
|
|
71
|
+
default: 'button',
|
|
72
|
+
required: false,
|
|
73
|
+
validator: (value: string) => {
|
|
74
|
+
return ['button', 'submit', 'reset'].includes(value)
|
|
75
|
+
},
|
|
76
|
+
},
|
|
63
77
|
/**
|
|
64
78
|
* Set the button variant to an outlined button or a ghost button.
|
|
65
79
|
*
|
|
@@ -74,7 +88,20 @@ export const CButton = defineComponent({
|
|
|
74
88
|
},
|
|
75
89
|
},
|
|
76
90
|
},
|
|
77
|
-
|
|
91
|
+
emits: [
|
|
92
|
+
/**
|
|
93
|
+
* Event called when the user clicks on the button.
|
|
94
|
+
*/
|
|
95
|
+
'click',
|
|
96
|
+
],
|
|
97
|
+
setup(props, { emit, slots }) {
|
|
98
|
+
const handleClick = () => {
|
|
99
|
+
if (props.disabled) {
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
emit('click')
|
|
104
|
+
}
|
|
78
105
|
return () =>
|
|
79
106
|
h(
|
|
80
107
|
props.component,
|
|
@@ -92,6 +119,8 @@ export const CButton = defineComponent({
|
|
|
92
119
|
disabled: props.disabled && props.component !== 'a',
|
|
93
120
|
...(props.component === 'a' && props.disabled && { 'aria-disabled': true, tabIndex: -1 }),
|
|
94
121
|
...(props.component === 'a' && props.href && { href: props.href }),
|
|
122
|
+
...(props.component === 'button' && { type: props.type }),
|
|
123
|
+
onClick: handleClick,
|
|
95
124
|
},
|
|
96
125
|
slots.default && slots.default(),
|
|
97
126
|
)
|
|
@@ -4,4 +4,4 @@ exports[`Customize (number two) CButton component renders correctly 1`] = `"<a c
|
|
|
4
4
|
|
|
5
5
|
exports[`Customize CButton component renders correctly 1`] = `"<div class=\\"btn btn-outline-warning btn-lg active disabled rounded-pill\\" disabled=\\"true\\">Default slot</div>"`;
|
|
6
6
|
|
|
7
|
-
exports[`Loads and display CButton component renders correctly 1`] = `"<button class=\\"btn btn-undefined\\">Default slot</button>"`;
|
|
7
|
+
exports[`Loads and display CButton component renders correctly 1`] = `"<button class=\\"btn btn-undefined\\" type=\\"button\\">Default slot</button>"`;
|
|
@@ -18,7 +18,6 @@ export const CCloseButton = defineComponent({
|
|
|
18
18
|
required: false,
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
|
-
|
|
22
21
|
emits: [
|
|
23
22
|
/**
|
|
24
23
|
* Event called when the user clicks on the component.
|
|
@@ -27,6 +26,10 @@ export const CCloseButton = defineComponent({
|
|
|
27
26
|
],
|
|
28
27
|
setup(props, { emit }) {
|
|
29
28
|
const handleClick = () => {
|
|
29
|
+
if (props.disabled) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
30
33
|
emit('click')
|
|
31
34
|
}
|
|
32
35
|
return () =>
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineComponent,
|
|
3
|
-
h,
|
|
4
|
-
ref,
|
|
5
|
-
onUnmounted,
|
|
6
|
-
onMounted,
|
|
7
|
-
provide,
|
|
8
|
-
reactive,
|
|
9
|
-
toRefs,
|
|
10
|
-
watch,
|
|
11
|
-
PropType,
|
|
12
|
-
} from 'vue'
|
|
1
|
+
import { defineComponent, h, ref, provide, watch, PropType } from 'vue'
|
|
13
2
|
import { createPopper, Placement } from '@popperjs/core'
|
|
14
3
|
|
|
15
4
|
const CDropdown = defineComponent({
|
|
@@ -51,6 +40,20 @@ const CDropdown = defineComponent({
|
|
|
51
40
|
}
|
|
52
41
|
},
|
|
53
42
|
},
|
|
43
|
+
/**
|
|
44
|
+
* Configure the auto close behavior of the dropdown:
|
|
45
|
+
* - `true` - the dropdown will be closed by clicking outside or inside the dropdown menu.
|
|
46
|
+
* - `false` - the dropdown will be closed by clicking the toggle button and manually calling hide or toggle method. (Also will not be closed by pressing esc key)
|
|
47
|
+
* - `'inside'` - the dropdown will be closed (only) by clicking inside the dropdown menu.
|
|
48
|
+
* - `'outside'` - the dropdown will be closed (only) by clicking outside the dropdown menu.
|
|
49
|
+
*/
|
|
50
|
+
autoClose: {
|
|
51
|
+
type: [Boolean, String],
|
|
52
|
+
default: true,
|
|
53
|
+
validator: (value: boolean | string) => {
|
|
54
|
+
return typeof value === 'boolean' || ['inside', 'outside'].includes(value)
|
|
55
|
+
},
|
|
56
|
+
},
|
|
54
57
|
/**
|
|
55
58
|
* Sets a darker color scheme to match a dark navbar.
|
|
56
59
|
*/
|
|
@@ -136,25 +139,29 @@ const CDropdown = defineComponent({
|
|
|
136
139
|
'show',
|
|
137
140
|
],
|
|
138
141
|
setup(props, { slots, emit }) {
|
|
139
|
-
const
|
|
142
|
+
const dropdownToggleRef = ref()
|
|
140
143
|
const dropdownMenuRef = ref()
|
|
141
144
|
const placement = ref(props.placement)
|
|
142
145
|
const popper = ref()
|
|
146
|
+
const visible = ref(props.visible)
|
|
147
|
+
|
|
148
|
+
watch(
|
|
149
|
+
() => props.visible,
|
|
150
|
+
() => {
|
|
151
|
+
visible.value = props.visible
|
|
152
|
+
},
|
|
153
|
+
)
|
|
143
154
|
|
|
144
|
-
|
|
155
|
+
provide('config', {
|
|
156
|
+
autoClose: props.autoClose,
|
|
145
157
|
alignment: props.alignment,
|
|
146
158
|
dark: props.dark,
|
|
147
159
|
popper: props.popper,
|
|
148
|
-
visible: props.visible,
|
|
149
160
|
})
|
|
150
161
|
|
|
151
|
-
const { visible } = toRefs(config)
|
|
152
|
-
|
|
153
|
-
provide('config', config)
|
|
154
|
-
|
|
155
162
|
provide('variant', props.variant)
|
|
156
163
|
provide('visible', visible)
|
|
157
|
-
provide('
|
|
164
|
+
provide('dropdownToggleRef', dropdownToggleRef)
|
|
158
165
|
provide('dropdownMenuRef', dropdownMenuRef)
|
|
159
166
|
|
|
160
167
|
if (props.direction === 'dropup') {
|
|
@@ -176,8 +183,8 @@ const CDropdown = defineComponent({
|
|
|
176
183
|
return
|
|
177
184
|
}
|
|
178
185
|
|
|
179
|
-
if (
|
|
180
|
-
popper.value = createPopper(
|
|
186
|
+
if (dropdownToggleRef.value) {
|
|
187
|
+
popper.value = createPopper(dropdownToggleRef.value, dropdownMenuRef.value, {
|
|
181
188
|
placement: placement.value,
|
|
182
189
|
})
|
|
183
190
|
}
|
|
@@ -190,43 +197,35 @@ const CDropdown = defineComponent({
|
|
|
190
197
|
popper.value = undefined
|
|
191
198
|
}
|
|
192
199
|
|
|
193
|
-
const toggleMenu =
|
|
194
|
-
if (props.disabled
|
|
195
|
-
|
|
196
|
-
visible.value = false
|
|
197
|
-
} else {
|
|
198
|
-
visible.value = true
|
|
199
|
-
}
|
|
200
|
+
const toggleMenu = (_visible?: boolean) => {
|
|
201
|
+
if (props.disabled) {
|
|
202
|
+
return
|
|
200
203
|
}
|
|
201
|
-
}
|
|
202
204
|
|
|
203
|
-
|
|
205
|
+
if (typeof _visible == 'boolean') {
|
|
206
|
+
visible.value = _visible
|
|
207
|
+
return
|
|
208
|
+
}
|
|
204
209
|
|
|
205
|
-
|
|
206
|
-
if (props.disabled === false) {
|
|
210
|
+
if (visible.value === true) {
|
|
207
211
|
visible.value = false
|
|
212
|
+
return
|
|
208
213
|
}
|
|
209
|
-
}
|
|
210
214
|
|
|
211
|
-
|
|
212
|
-
if (dropdownRef.value && !dropdownRef.value.contains(event.target as HTMLElement)) {
|
|
213
|
-
hideMenu()
|
|
214
|
-
}
|
|
215
|
+
visible.value = true
|
|
215
216
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
|
|
218
|
+
provide('toggleMenu', toggleMenu)
|
|
219
|
+
|
|
220
|
+
const hideMenu = () => {
|
|
221
|
+
if (props.disabled) {
|
|
222
|
+
return
|
|
219
223
|
}
|
|
224
|
+
|
|
225
|
+
visible.value = false
|
|
220
226
|
}
|
|
221
227
|
|
|
222
|
-
|
|
223
|
-
window.addEventListener('click', handleClickOutside)
|
|
224
|
-
window.addEventListener('keyup', handleKeyup)
|
|
225
|
-
})
|
|
226
|
-
onUnmounted(() => {
|
|
227
|
-
window.removeEventListener('click', handleClickOutside)
|
|
228
|
-
window.removeEventListener('keyup', handleKeyup)
|
|
229
|
-
})
|
|
228
|
+
provide('hideMenu', hideMenu)
|
|
230
229
|
|
|
231
230
|
watch(visible, () => {
|
|
232
231
|
props.popper && (visible.value ? initPopper() : destroyPopper())
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, h, inject,
|
|
1
|
+
import { defineComponent, h, inject, onUnmounted, onUpdated, Ref } from 'vue'
|
|
2
2
|
|
|
3
3
|
const CDropdownMenu = defineComponent({
|
|
4
4
|
name: 'CDropdownMenu',
|
|
@@ -15,11 +15,13 @@ const CDropdownMenu = defineComponent({
|
|
|
15
15
|
},
|
|
16
16
|
},
|
|
17
17
|
setup(props, { slots }) {
|
|
18
|
+
const dropdownToggleRef = inject('dropdownToggleRef') as Ref<HTMLElement>
|
|
18
19
|
const dropdownMenuRef = inject('dropdownMenuRef') as Ref<HTMLElement>
|
|
19
|
-
// eslint-disable-
|
|
20
|
-
const
|
|
20
|
+
const config = inject('config') as any // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
21
|
+
const hideMenu = inject('hideMenu') as () => void
|
|
22
|
+
const visible = inject('visible') as Ref<boolean>
|
|
21
23
|
|
|
22
|
-
const { alignment, dark, popper
|
|
24
|
+
const { autoClose, alignment, dark, popper } = config
|
|
23
25
|
|
|
24
26
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
25
27
|
const alignmentClassNames = (alignment: object | string) => {
|
|
@@ -35,16 +37,57 @@ const CDropdownMenu = defineComponent({
|
|
|
35
37
|
return classNames
|
|
36
38
|
}
|
|
37
39
|
|
|
40
|
+
const handleKeyup = (event: Event) => {
|
|
41
|
+
if (autoClose === false) {
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
if (!dropdownMenuRef.value?.contains(event.target as HTMLElement)) {
|
|
45
|
+
hideMenu()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const handleMouseUp = (event: Event) => {
|
|
49
|
+
if (dropdownToggleRef.value?.contains(event.target as HTMLElement)) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (autoClose === true) {
|
|
54
|
+
hideMenu()
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (autoClose === 'inside' && dropdownMenuRef.value?.contains(event.target as HTMLElement)) {
|
|
59
|
+
hideMenu()
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
autoClose === 'outside' &&
|
|
65
|
+
!dropdownMenuRef.value?.contains(event.target as HTMLElement)
|
|
66
|
+
) {
|
|
67
|
+
hideMenu()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
onUpdated(() => {
|
|
72
|
+
visible.value && window.addEventListener('mouseup', handleMouseUp)
|
|
73
|
+
visible.value && window.addEventListener('keyup', handleKeyup)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
onUnmounted(() => {
|
|
77
|
+
window.removeEventListener('mouseup', handleMouseUp)
|
|
78
|
+
window.removeEventListener('keyup', handleKeyup)
|
|
79
|
+
})
|
|
80
|
+
|
|
38
81
|
return () =>
|
|
39
82
|
h(
|
|
40
83
|
props.component,
|
|
41
84
|
{
|
|
42
85
|
class: [
|
|
43
86
|
'dropdown-menu',
|
|
44
|
-
{ 'dropdown-menu-dark': dark
|
|
45
|
-
alignmentClassNames(alignment
|
|
87
|
+
{ 'dropdown-menu-dark': dark, show: visible.value },
|
|
88
|
+
alignmentClassNames(alignment),
|
|
46
89
|
],
|
|
47
|
-
...((typeof alignment
|
|
90
|
+
...((typeof alignment === 'object' || !popper) && {
|
|
48
91
|
'data-coreui-popper': 'static',
|
|
49
92
|
}),
|
|
50
93
|
ref: dropdownMenuRef,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { defineComponent, h, inject, Ref } from 'vue'
|
|
2
|
-
|
|
1
|
+
import { cloneVNode, defineComponent, h, inject, onMounted, PropType, Ref, ref } from 'vue'
|
|
2
|
+
import { CButton } from '../button'
|
|
3
3
|
import { Color, Shape } from '../props'
|
|
4
|
+
import { Triggers } from '../Types'
|
|
4
5
|
|
|
5
6
|
const CDropdownToggle = defineComponent({
|
|
6
7
|
name: 'CDropdownToggle',
|
|
@@ -35,6 +36,10 @@ const CDropdownToggle = defineComponent({
|
|
|
35
36
|
default: 'button',
|
|
36
37
|
require: false,
|
|
37
38
|
},
|
|
39
|
+
/**
|
|
40
|
+
* Create a custom toggler which accepts any content.
|
|
41
|
+
*/
|
|
42
|
+
custom: Boolean,
|
|
38
43
|
/**
|
|
39
44
|
* Toggle the disabled state for the component.
|
|
40
45
|
*/
|
|
@@ -66,6 +71,16 @@ const CDropdownToggle = defineComponent({
|
|
|
66
71
|
type: Boolean,
|
|
67
72
|
required: false,
|
|
68
73
|
},
|
|
74
|
+
/**
|
|
75
|
+
* Sets which event handlers you’d like provided to your toggle prop. You can specify one trigger or an array of them.
|
|
76
|
+
*
|
|
77
|
+
* @type 'hover' | 'focus' | 'click'
|
|
78
|
+
*/
|
|
79
|
+
trigger: {
|
|
80
|
+
type: String as PropType<Triggers>,
|
|
81
|
+
default: 'click',
|
|
82
|
+
required: false,
|
|
83
|
+
},
|
|
69
84
|
/**
|
|
70
85
|
* Set the button variant to an outlined button or a ghost button.
|
|
71
86
|
*
|
|
@@ -81,60 +96,94 @@ const CDropdownToggle = defineComponent({
|
|
|
81
96
|
},
|
|
82
97
|
},
|
|
83
98
|
setup(props, { slots }) {
|
|
84
|
-
const
|
|
99
|
+
const togglerRef = ref()
|
|
100
|
+
const dropdownToggleRef = inject('dropdownToggleRef') as Ref<HTMLElement>
|
|
85
101
|
const dropdownVariant = inject('variant') as string
|
|
86
|
-
const visible = inject('visible') as boolean
|
|
87
|
-
const toggleMenu = inject('toggleMenu') as () => void
|
|
102
|
+
const visible = inject('visible') as Ref<boolean>
|
|
103
|
+
const toggleMenu = inject('toggleMenu') as (_visible?: boolean) => void
|
|
104
|
+
|
|
88
105
|
const className = [
|
|
89
106
|
{
|
|
90
107
|
'dropdown-toggle': props.caret,
|
|
91
108
|
'dropdown-toggle-split': props.split,
|
|
92
|
-
show: visible,
|
|
93
109
|
active: props.active,
|
|
94
110
|
disabled: props.disabled,
|
|
95
111
|
},
|
|
96
112
|
]
|
|
97
113
|
|
|
98
|
-
const
|
|
99
|
-
'
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
114
|
+
const triggers = {
|
|
115
|
+
...((props.trigger === 'click' || props.trigger.includes('click')) &&
|
|
116
|
+
!props.disabled && {
|
|
117
|
+
onClick: () => toggleMenu(),
|
|
118
|
+
}),
|
|
119
|
+
...((props.trigger === 'focus' || props.trigger.includes('focus')) &&
|
|
120
|
+
!props.disabled && {
|
|
121
|
+
onfocus: () => toggleMenu(true),
|
|
122
|
+
onblur: () => toggleMenu(false),
|
|
123
|
+
}),
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
onMounted(() => {
|
|
127
|
+
if (togglerRef.value) {
|
|
128
|
+
dropdownToggleRef.value = togglerRef.value.$el
|
|
129
|
+
}
|
|
130
|
+
})
|
|
106
131
|
|
|
107
132
|
return () =>
|
|
108
|
-
|
|
133
|
+
props.custom
|
|
134
|
+
? slots.default &&
|
|
135
|
+
slots.default().map((slot) =>
|
|
136
|
+
cloneVNode(slot, {
|
|
137
|
+
ref: (el) => {
|
|
138
|
+
togglerRef.value = el
|
|
139
|
+
},
|
|
140
|
+
...triggers,
|
|
141
|
+
}),
|
|
142
|
+
)
|
|
143
|
+
: dropdownVariant === 'nav-item'
|
|
109
144
|
? h(
|
|
110
145
|
'a',
|
|
111
146
|
{
|
|
112
147
|
active: props.active,
|
|
113
|
-
class: [
|
|
148
|
+
class: [
|
|
149
|
+
'nav-link',
|
|
150
|
+
className,
|
|
151
|
+
{
|
|
152
|
+
show: visible.value,
|
|
153
|
+
},
|
|
154
|
+
],
|
|
114
155
|
disabled: props.disabled,
|
|
115
156
|
href: '#',
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return toggleMenu()
|
|
119
|
-
},
|
|
120
|
-
ref: dropdownRef,
|
|
157
|
+
ref: dropdownToggleRef,
|
|
158
|
+
...triggers,
|
|
121
159
|
},
|
|
122
160
|
{ default: () => slots.default && slots.default() },
|
|
123
161
|
)
|
|
124
162
|
: h(
|
|
125
|
-
|
|
126
|
-
props.component,
|
|
163
|
+
CButton,
|
|
127
164
|
{
|
|
128
|
-
class: [
|
|
165
|
+
class: [
|
|
166
|
+
className,
|
|
167
|
+
{
|
|
168
|
+
show: visible.value,
|
|
169
|
+
},
|
|
170
|
+
],
|
|
129
171
|
active: props.active,
|
|
172
|
+
color: props.color,
|
|
130
173
|
disabled: props.disabled,
|
|
131
|
-
|
|
174
|
+
ref: (el) => {
|
|
175
|
+
togglerRef.value = el
|
|
176
|
+
},
|
|
177
|
+
shape: props.shape,
|
|
178
|
+
size: props.size,
|
|
179
|
+
...triggers,
|
|
132
180
|
...(props.component === 'button' && { type: 'button' }),
|
|
133
|
-
|
|
181
|
+
variant: props.variant,
|
|
134
182
|
},
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
183
|
+
() =>
|
|
184
|
+
props.split
|
|
185
|
+
? h('span', { class: 'visually-hidden' }, 'Toggle Dropdown')
|
|
186
|
+
: slots.default && slots.default(),
|
|
138
187
|
)
|
|
139
188
|
},
|
|
140
189
|
})
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { mount } from '@vue/test-utils'
|
|
2
2
|
import { CDropdownMenu as Component } from '../../../index'
|
|
3
|
-
import {
|
|
3
|
+
import { ref } from 'vue'
|
|
4
4
|
|
|
5
5
|
const ComponentName = 'CDropdownMenu'
|
|
6
6
|
|
|
7
|
-
const config =
|
|
7
|
+
const config = {
|
|
8
8
|
alignment: { lg: 'end' },
|
|
9
9
|
dark: false,
|
|
10
10
|
popper: true,
|
|
11
|
-
|
|
12
|
-
})
|
|
11
|
+
}
|
|
13
12
|
|
|
14
|
-
const customConfig =
|
|
13
|
+
const customConfig = {
|
|
15
14
|
alignment: { lg: 'end' },
|
|
16
15
|
dark: true,
|
|
17
16
|
popper: false,
|
|
18
|
-
|
|
19
|
-
})
|
|
17
|
+
}
|
|
20
18
|
|
|
21
19
|
const defaultWrapper = mount(Component, {
|
|
22
20
|
propsData: {},
|
|
@@ -27,6 +25,7 @@ const defaultWrapper = mount(Component, {
|
|
|
27
25
|
provide: {
|
|
28
26
|
config: config,
|
|
29
27
|
dropdownMenuRef: ref(),
|
|
28
|
+
visible: ref(false),
|
|
30
29
|
},
|
|
31
30
|
},
|
|
32
31
|
})
|
|
@@ -42,6 +41,7 @@ const customWrapper = mount(Component, {
|
|
|
42
41
|
provide: {
|
|
43
42
|
config: customConfig,
|
|
44
43
|
dropdownMenuRef: ref(),
|
|
44
|
+
visible: ref(true),
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
47
|
})
|
|
@@ -18,9 +18,9 @@ const defaultWrapper = mount(Component, {
|
|
|
18
18
|
},
|
|
19
19
|
global: {
|
|
20
20
|
provide: {
|
|
21
|
-
|
|
21
|
+
dropdownToggleRef: ref(),
|
|
22
22
|
variant: 'input-group',
|
|
23
|
-
visible: true,
|
|
23
|
+
visible: ref(true),
|
|
24
24
|
toggleMenu: function () {
|
|
25
25
|
return true
|
|
26
26
|
},
|
|
@@ -44,9 +44,9 @@ const customWrapper = mount(Component, {
|
|
|
44
44
|
},
|
|
45
45
|
global: {
|
|
46
46
|
provide: {
|
|
47
|
-
|
|
47
|
+
dropdownToggleRef: ref(),
|
|
48
48
|
variant: 'nav-item',
|
|
49
|
-
visible: true,
|
|
49
|
+
visible: ref(true),
|
|
50
50
|
toggleMenu: function () {
|
|
51
51
|
return true
|
|
52
52
|
},
|
|
@@ -71,7 +71,6 @@ describe(`Loads and display ${ComponentName} component`, () => {
|
|
|
71
71
|
expect(defaultWrapper.classes('active')).toBe(true)
|
|
72
72
|
expect(defaultWrapper.classes('disabled')).toBe(true)
|
|
73
73
|
expect(defaultWrapper.attributes('disabled')).toBe('')
|
|
74
|
-
expect(defaultWrapper.attributes('active')).toBe('true')
|
|
75
74
|
expect(defaultWrapper.find('span').classes('visually-hidden')).toBe(true)
|
|
76
75
|
expect(defaultWrapper.find('span').text()).toContain('Toggle Dropdown')
|
|
77
76
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`Customize CDropdownToggle component renders correctly 1`] = `"<a active=\\"true\\" class=\\"nav-link dropdown-toggle-split
|
|
3
|
+
exports[`Customize CDropdownToggle component renders correctly 1`] = `"<a active=\\"true\\" class=\\"nav-link dropdown-toggle-split active disabled show\\" disabled=\\"true\\" href=\\"#\\">Default slot</a>"`;
|
|
4
4
|
|
|
5
|
-
exports[`Loads and display CDropdownToggle component renders correctly 1`] = `"<button class=\\"
|
|
5
|
+
exports[`Loads and display CDropdownToggle component renders correctly 1`] = `"<button class=\\"btn btn-outline-warning btn-lg active disabled rounded-pill dropdown-toggle dropdown-toggle-split active disabled show\\" disabled=\\"\\" type=\\"button\\"><span class=\\"visually-hidden\\">Toggle Dropdown</span></button>"`;
|
|
@@ -128,6 +128,7 @@ const CFormCheck = defineComponent({
|
|
|
128
128
|
|
|
129
129
|
const formControl = () => {
|
|
130
130
|
return h('input', {
|
|
131
|
+
...attrs,
|
|
131
132
|
checked: props.modelValue,
|
|
132
133
|
class: [
|
|
133
134
|
props.button ? 'btn-check' : 'form-check-input',
|
|
@@ -140,7 +141,6 @@ const CFormCheck = defineComponent({
|
|
|
140
141
|
indeterminate: props.indeterminate,
|
|
141
142
|
onChange: (event: InputEvent) => handleChange(event),
|
|
142
143
|
type: props.type,
|
|
143
|
-
...attrs,
|
|
144
144
|
})
|
|
145
145
|
}
|
|
146
146
|
const formLabel = () => {
|
|
@@ -181,6 +181,7 @@ const CFormCheck = defineComponent({
|
|
|
181
181
|
'is-invalid': props.invalid,
|
|
182
182
|
'is-valid': props.valid,
|
|
183
183
|
},
|
|
184
|
+
attrs.class,
|
|
184
185
|
],
|
|
185
186
|
},
|
|
186
187
|
[formControl(), props.label && formLabel()],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, h,
|
|
1
|
+
import { defineComponent, h, watch, ref } from 'vue'
|
|
2
2
|
|
|
3
3
|
import { CFormLabel } from './CFormLabel'
|
|
4
4
|
|
|
@@ -81,12 +81,6 @@ const CFormSwitch = defineComponent({
|
|
|
81
81
|
setup(props, { attrs, emit }) {
|
|
82
82
|
const checked = ref(attrs.checked)
|
|
83
83
|
|
|
84
|
-
onMounted(() => {
|
|
85
|
-
if (props.modelValue && typeof props.modelValue === 'boolean') {
|
|
86
|
-
console.log(props.modelValue)
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
|
|
90
84
|
watch(
|
|
91
85
|
() => props.modelValue,
|
|
92
86
|
() => {
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`Customize with label - CFormCheck component renders correctly 1`] = `
|
|
4
|
-
"<input class=\\"btn-check is-invalid is-valid\\" id=\\"uniqueid\\" type=\\"checkbox\\">
|
|
5
|
-
<label class=\\"btn btn-outline-warning btn-lg rounded-circle\\" for=\\"uniqueid\\">some label</label>"
|
|
6
|
-
`;
|
|
3
|
+
exports[`Customize with label - CFormCheck component renders correctly 1`] = `"<input class=\\"btn-check is-invalid is-valid\\" id=\\"uniqueid\\" type=\\"checkbox\\"><label class=\\"btn btn-outline-warning btn-lg rounded-circle\\" for=\\"uniqueid\\">some label</label>"`;
|
|
7
4
|
|
|
8
|
-
exports[`Customize with label in slot - CFormCheck component renders correctly 1`] = `
|
|
9
|
-
"<input class=\\"btn-check is-invalid is-valid\\" id=\\"uniqueid\\" type=\\"checkbox\\">
|
|
10
|
-
<label class=\\"btn btn-outline-warning btn-lg rounded-circle\\" for=\\"uniqueid\\">some label</label>"
|
|
11
|
-
`;
|
|
5
|
+
exports[`Customize with label in slot - CFormCheck component renders correctly 1`] = `"<input class=\\"btn-check is-invalid is-valid\\" id=\\"uniqueid\\" type=\\"checkbox\\"><label class=\\"btn btn-outline-warning btn-lg rounded-circle\\" for=\\"uniqueid\\">some label</label>"`;
|
|
12
6
|
|
|
13
7
|
exports[`Loads and display CFormCheck component renders correctly 1`] = `"<input class=\\"form-check-input\\" type=\\"checkbox\\">"`;
|