import { CloseButton } from "@chakra-ui/react"
const Demo = () => {
return <CloseButton />
}
Usage
import { CloseButton } from "@chakra-ui/react"
<CloseButton />
Examples
Sizes
Use the size
prop to change the size of the close button.
import { CloseButton, For, HStack } from "@chakra-ui/react"
const Demo = () => {
return (
<HStack gap="4" wrap="wrap">
<For each={["2xs", "xs", "sm", "md", "lg", "xl"]}>
{(size) => <CloseButton variant="outline" size={size} />}
</For>
</HStack>
)
}
Variants
Use the variant
prop to change the appearance of the close button.
import { CloseButton, HStack } from "@chakra-ui/react"
const Demo = () => {
return (
<HStack>
<CloseButton variant="ghost" />
<CloseButton variant="outline" />
<CloseButton variant="subtle" />
<CloseButton variant="solid" />
</HStack>
)
}
Custom Icon
Pass the custom icon to the children
of the CloseButton
component.
import { CloseButton } from "@chakra-ui/react"
import { HiX } from "react-icons/hi"
const Demo = () => {
return (
<CloseButton variant="ghost" aria-label="Close">
<HiX />
</CloseButton>
)
}
Props
Prop | Default | Type |
---|---|---|
colorPalette | 'gray' | 'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent' The color palette of the component |
size | 'md' | 'xs' | 'sm' | 'md' | 'lg' The size of the component |
variant | 'solid' | 'solid' | 'subtle' | 'surface' | 'outline' | 'ghost' | 'plain' The variant of the component |
loading | boolean | |
loadingText | React.ReactNode |