Skip to content

Commit 2f96ef2

Browse files
committed
refactor: update shared props types handling
1 parent e579fd7 commit 2f96ef2

File tree

7 files changed

+35
-18
lines changed

7 files changed

+35
-18
lines changed

packages/coreui-vue/src/components/form/CFormControlWrapper.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import { CFormFloating } from './CFormFloating'
44
import { CFormLabel } from './CFormLabel'
55
import { CFormText } from './CFormText'
66

7+
type CFormControlValidationProps = InstanceType<typeof CFormControlValidation>['$props']
8+
9+
interface CFormControlWrapperProps {
10+
floatingLabel?: string
11+
id?: string
12+
label?: string
13+
text?: string
14+
}
15+
716
const CFormControlWrapper = defineComponent({
817
name: 'CFormControlWrapper',
918
inheritAttrs: false,
@@ -32,7 +41,7 @@ const CFormControlWrapper = defineComponent({
3241
*/
3342
text: String,
3443
},
35-
setup(props, { slots }) {
44+
setup(props: CFormControlWrapperProps & CFormControlValidationProps, { slots }) {
3645
const formControlValidation = () =>
3746
h(
3847
CFormControlValidation,

packages/coreui-vue/src/components/form/CFormInput.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ const CFormInput = defineComponent({
130130
h(
131131
CFormControlWrapper,
132132
{
133-
describedby: attrs['aria-describedby'],
133+
...(typeof attrs['aria-describedby'] === 'string' && {
134+
describedby: attrs['aria-describedby'],
135+
}),
134136
feedback: props.feedback,
135137
feedbackInvalid: props.feedbackInvalid,
136138
feedbackValid: props.feedbackValid,

packages/coreui-vue/src/components/form/CFormSelect.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ const CFormSelect = defineComponent({
119119
h(
120120
CFormControlWrapper,
121121
{
122-
describedby: attrs['aria-describedby'],
122+
...(typeof attrs['aria-describedby'] === 'string' && {
123+
describedby: attrs['aria-describedby'],
124+
}),
123125
feedback: props.feedback,
124126
feedbackInvalid: props.feedbackInvalid,
125127
feedbackValid: props.feedbackValid,

packages/coreui-vue/src/components/form/CFormTextarea.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ const CFormTextarea = defineComponent({
106106
h(
107107
CFormControlWrapper,
108108
{
109-
describedby: attrs['aria-describedby'],
109+
...(typeof attrs['aria-describedby'] === 'string' && {
110+
describedby: attrs['aria-describedby'],
111+
}),
110112
feedback: props.feedback,
111113
feedbackInvalid: props.feedbackInvalid,
112114
feedbackValid: props.feedbackValid,

packages/coreui-vue/src/components/nav/CNavItem.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import { defineComponent, h } from 'vue'
22

33
import { CNavLink } from './CNavLink'
44

5+
type CNavLinkProps = Omit<InstanceType<typeof CNavLink>['$props'], 'as'>
6+
7+
interface CNavItemProps {
8+
as: string
9+
}
10+
511
const CNavItem = defineComponent({
612
name: 'CNavItem',
713
props: {
@@ -14,12 +20,11 @@ const CNavItem = defineComponent({
1420
default: 'li',
1521
},
1622
},
17-
setup(props, { slots }) {
23+
setup(props: CNavLinkProps & CNavItemProps, { slots }) {
1824
return () =>
1925
h(
2026
props.as,
2127
{
22-
as: props.component,
2328
class: 'nav-item',
2429
},
2530
props.href

packages/coreui-vue/src/components/toast/CToastClose.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { defineComponent, h, inject } from 'vue'
22
import { CCloseButton } from '../close-button/CCloseButton'
33

4+
type CCloseButtonProps = InstanceType<typeof CCloseButton>['$props']
5+
6+
interface CToastCloseProps {
7+
as: string
8+
}
9+
410
const CToastClose = defineComponent({
511
name: 'CToastClose',
612
props: {
@@ -16,7 +22,7 @@ const CToastClose = defineComponent({
1622
*/
1723
'close',
1824
],
19-
setup(props, { slots, emit }) {
25+
setup(props: CToastCloseProps & CCloseButtonProps, { slots, emit }) {
2026
// eslint-disable-next-line no-unused-vars
2127
const updateVisible = inject('updateVisible') as (visible: boolean) => void
2228
const handleClose = () => {

packages/coreui-vue/src/components/toast/CToastHeader.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,11 @@ const CToastHeader = defineComponent({
99
*/
1010
closeButton: Boolean,
1111
},
12-
emits: [
13-
/**
14-
* Event called after clicking the close button.
15-
*/
16-
'close',
17-
],
18-
setup(props, { slots, emit }) {
12+
setup(props, { slots }) {
1913
return () =>
2014
h('div', { class: 'toast-header' }, [
2115
slots.default && slots.default(),
22-
props.closeButton &&
23-
h(CToastClose, {
24-
onClose: () => emit('close'),
25-
}),
16+
props.closeButton && h(CToastClose),
2617
])
2718
},
2819
})

0 commit comments

Comments
 (0)