import { IconButton } from "@chakra-ui/react"
import { LuSearch } from "react-icons/lu"
export const IconButtonBasic = () => {
return (
<IconButton aria-label="Search database">
<LuSearch />
</IconButton>
)
}
Anatomy
import { IconButton } from '@chakra-ui/react'<IconButton aria-label="Search database">
<LuSearch />
</IconButton>Examples
Sizes
Use the size prop to change the size of the icon button. You can set the
value to xs, sm, md, or lg.
xs
sm
md
lg
import { For, HStack, IconButton, Text, VStack } from "@chakra-ui/react"
import { LuPhone } from "react-icons/lu"
export const IconButtonWithSizes = () => {
return (
<HStack wrap="wrap" gap="8">
<For each={["xs", "sm", "md", "lg"]}>
{(size) => (
<VStack key={size}>
<IconButton
aria-label="Search database"
variant="outline"
size={size}
>
<LuPhone />
</IconButton>
<Text textStyle="sm">{size}</Text>
</VStack>
)}
</For>
</HStack>
)
}
Variants
Use the variant prop to change the visual style of the icon button. You can
set the value to solid, subtle, surface, outline or ghost.
solid
subtle
surface
outline
ghost
import { For, HStack, IconButton, Text, VStack } from "@chakra-ui/react"
import { LuVoicemail } from "react-icons/lu"
export const IconButtonWithVariants = () => {
return (
<HStack wrap="wrap" gap="8">
<For each={["solid", "subtle", "surface", "outline", "ghost"]}>
{(variant) => (
<VStack key={variant}>
<IconButton
aria-label="Call support"
key={variant}
variant={variant}
>
<LuVoicemail />
</IconButton>
<Text textStyle="sm">{variant}</Text>
</VStack>
)}
</For>
</HStack>
)
}
Color
Use the colorPalette prop to change the color of the icon button.
import { For, HStack } from '@chakra-ui/react'
import { IconButton } from '#components/ui/icon-button'
import { LuSearch } from 'react-icons/lu'
import { colorPalettes } from '../lib/color-palettes'
export const IconButtonWithColors = () => {
return (
<HStack wrap="wrap">
<For each={colorPalettes}>
{(c) => (
<IconButton aria-label="Search database" key={c} colorPalette={c}>
<LuSearch />
</IconButton>
)}
</For>
</HStack>
)
}
Rounded
Use the rounded="full" prop to make the icon button fully rounded.
import { IconButton } from "@chakra-ui/react"
import { LuVoicemail } from "react-icons/lu"
export const IconButtonRounded = () => {
return (
<IconButton aria-label="Call support" rounded="full">
<LuVoicemail />
</IconButton>
)
}
Props
| Prop | Default | Type |
|---|---|---|
colorPalette | 'gray' | 'gray' | 'zinc' | 'neutral' | 'stone' | 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose' | 'presence' | 'status' | 'sidebar' | 'sidebar.accent' | 'accent' | 'slate'The color palette of the component |
size | 'md' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'The size of the component |
variant | 'surface' | 'solid' | 'subtle' | 'glass' | 'surface' | 'outline' | 'ghost' | 'plain'The variant of the component |
loading | boolean | |
loadingText | React.ReactNode |