1
- import { h , defineComponent , PropType , VNode } from "vue"
1
+ import { h , defineComponent , PropType , VNode , type DefineComponent } from "vue"
2
2
import { CButton } from "./button"
3
- import { ButtonProps } from "./button.utils"
3
+ import type { ButtonProps } from "./button.utils"
4
4
import { CIcon } from "@chakra-ui/c-icon"
5
+ import { chakra } from "@chakra-ui/vue-system"
5
6
6
7
const IconButtonProps = {
7
8
// ...BUTTON_PROPS,
8
- icon : String as PropType < string > ,
9
- isRound : Boolean as PropType < boolean > ,
9
+ icon : String as PropType < CIconButtonProps [ "icon" ] > ,
10
+ isRound : Boolean as PropType < CIconButtonProps [ "isRound" ] > ,
10
11
ariaLabel : {
11
- type : String as PropType < string > ,
12
+ type : String as PropType < CIconButtonProps [ "ariaLabel" ] > ,
12
13
required : true ,
13
14
} ,
14
15
}
15
16
16
17
export interface CIconButtonProps extends ButtonProps {
17
- icon : string
18
+ icon : string | object | typeof chakra . svg | DefineComponent
18
19
isRound ?: boolean
19
20
ariaLabel : string
20
21
}
@@ -27,22 +28,34 @@ export interface CIconButtonProps extends ButtonProps {
27
28
export const CIconButton = defineComponent ( {
28
29
name : "CIconButton" ,
29
30
props : IconButtonProps ,
30
- setup ( props , { attrs } ) {
31
+ setup ( props , { attrs, slots } ) {
31
32
if ( ! props . ariaLabel ) {
32
33
console . error (
33
34
`chakra-ui: The \`aria-label\` prop is required for the <c-icon-button />`
34
35
)
35
36
}
36
37
37
- return ( ) => (
38
- < CButton
39
- padding = { "0" }
40
- rounded = { props . isRound ? "rounded" : "md" }
41
- aria-label = { props . ariaLabel }
42
- { ...attrs }
43
- >
44
- < CIcon aria-hidden focusable = { 0 } name = { props . icon } />
45
- </ CButton >
46
- )
38
+ return ( ) => {
39
+ const children = slots ?. default ?.( )
40
+ return (
41
+ < CButton
42
+ padding = { "0" }
43
+ rounded = { props . isRound ? "rounded" : "md" }
44
+ aria-label = { props . ariaLabel }
45
+ { ...attrs }
46
+ >
47
+ { ! ! children ? (
48
+ children
49
+ ) : typeof props . icon === "string" ? (
50
+ < CIcon aria-hidden focusable = { 0 } name = { props . icon } />
51
+ ) : (
52
+ < CIcon __label = "button__icon" { ...attrs } >
53
+ { /* @ts -ignore */ }
54
+ < props . icon />
55
+ </ CIcon >
56
+ ) }
57
+ </ CButton >
58
+ )
59
+ }
47
60
} ,
48
61
} )
0 commit comments