1- import { h , defineComponent , PropType , VNode } from "vue"
1+ import { h , defineComponent , PropType , VNode , type DefineComponent } from "vue"
22import { CButton } from "./button"
3- import { ButtonProps } from "./button.utils"
3+ import type { ButtonProps } from "./button.utils"
44import { CIcon } from "@chakra-ui/c-icon"
5+ import { chakra } from "@chakra-ui/vue-system"
56
67const IconButtonProps = {
78 // ...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" ] > ,
1011 ariaLabel : {
11- type : String as PropType < string > ,
12+ type : String as PropType < CIconButtonProps [ "ariaLabel" ] > ,
1213 required : true ,
1314 } ,
1415}
1516
1617export interface CIconButtonProps extends ButtonProps {
17- icon : string
18+ icon : string | object | typeof chakra . svg | DefineComponent
1819 isRound ?: boolean
1920 ariaLabel : string
2021}
@@ -27,22 +28,34 @@ export interface CIconButtonProps extends ButtonProps {
2728export const CIconButton = defineComponent ( {
2829 name : "CIconButton" ,
2930 props : IconButtonProps ,
30- setup ( props , { attrs } ) {
31+ setup ( props , { attrs, slots } ) {
3132 if ( ! props . ariaLabel ) {
3233 console . error (
3334 `chakra-ui: The \`aria-label\` prop is required for the <c-icon-button />`
3435 )
3536 }
3637
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+ }
4760 } ,
4861} )
0 commit comments