import { HStack } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
const Demo = () => {
return (
<RadioCardRoot defaultValue="next">
<RadioCardLabel>Select framework</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
label={item.title}
description={item.description}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{ value: "next", title: "Next.js", description: "Best for apps" },
{ value: "vite", title: "Vite", description: "Best for SPAs" },
{ value: "astro", title: "Astro", description: "Best for static sites" },
]
Setup
If you don't already have the snippet, run the following command to add the
radio-card
snippet
npx @chakra-ui/cli snippet add radio-card
The snippet includes a closed component composition for the RadioCard
component.
Usage
A RadioCard is a form element with a larger interaction surface represented as a card.
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
<RadioCardRoot>
<RadioCardLabel />
<RadioCardItem />
</RadioCardRoot>
Examples
Sizes
Use the size
prop to change the size of the radio card.
import { For, HStack, Stack } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
const Demo = () => {
return (
<Stack gap="8">
<For each={["sm", "md", "lg"]}>
{(size) => (
<RadioCardRoot key={size} size={size} defaultValue="next">
<RadioCardLabel>size = ({size})</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
label={item.title}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)}
</For>
</Stack>
)
}
const items = [
{ value: "next", title: "Next.js" },
{ value: "vite", title: "Vite" },
]
Colors
Use the colorPalette
prop to change the color of the radio card.
import { For, HStack, Stack } from "@chakra-ui/react"
import { colorPalettes } from "compositions/lib/color-palettes"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
const Demo = () => {
return (
<Stack gap="8">
<For each={colorPalettes}>
{(colorPalette) => (
<RadioCardRoot
key={colorPalette}
colorPalette={colorPalette}
defaultValue="next"
>
<RadioCardLabel>Select Framework</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
label={item.title}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)}
</For>
</Stack>
)
}
const items = [
{ value: "next", title: "Next.js" },
{ value: "vite", title: "Vite" },
]
Icon
Here's an example of using a label, description and icon within the
RadioCardItem
.
import { HStack, Icon } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
import { LuArrowRight, LuCircleOff, LuLock } from "react-icons/lu"
const Demo = () => {
return (
<RadioCardRoot defaultValue="next">
<RadioCardLabel>Select permission</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
icon={
<Icon fontSize="2xl" color="fg.muted" mb="2">
{item.icon}
</Icon>
}
label={item.title}
description={item.description}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{
icon: <LuArrowRight />,
value: "allow",
title: "Allow",
description: "This user can access the system",
},
{
icon: <LuCircleOff />,
value: "deny",
title: "Deny",
description: "This user will be denied access to the system",
},
{
icon: <LuLock />,
value: "lock",
title: "Lock",
description: "This user will be locked out of the system",
},
]
No Indicator
Here's an example of setting the indicator
prop to null
to hide the
indicator.
import { HStack, Icon } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
import { RiAppleFill, RiBankCardFill, RiPaypalFill } from "react-icons/ri"
const Demo = () => {
return (
<RadioCardRoot
orientation="horizontal"
align="center"
justify="center"
maxW="lg"
defaultValue="paypal"
>
<RadioCardLabel>Payment method</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
label={item.title}
icon={
<Icon fontSize="2xl" color="fg.subtle">
{item.icon}
</Icon>
}
indicator={false}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{ value: "paypal", title: "Paypal", icon: <RiPaypalFill /> },
{ value: "apple-pay", title: "Apple Pay", icon: <RiAppleFill /> },
{ value: "card", title: "Card", icon: <RiBankCardFill /> },
]
No Indicator (Vertical)
Here's an example of a RadioCard with no indicator and content aligned vertically.
import { HStack, Icon } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
import { RiAppleFill, RiBankCardFill, RiPaypalFill } from "react-icons/ri"
const Demo = () => {
return (
<RadioCardRoot
orientation="vertical"
align="center"
maxW="400px"
defaultValue="paypal"
>
<RadioCardLabel>Payment method</RadioCardLabel>
<HStack>
{items.map((item) => (
<RadioCardItem
label={item.title}
icon={
<Icon fontSize="2xl" color="fg.muted">
{item.icon}
</Icon>
}
indicator={false}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{ value: "paypal", title: "Paypal", icon: <RiPaypalFill /> },
{ value: "apple-pay", title: "Apple Pay", icon: <RiAppleFill /> },
{ value: "card", title: "Card", icon: <RiBankCardFill /> },
]
Centered
Here's an example of a RadioCard with centered text.
import { HStack, Icon } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
import { LuClock, LuDollarSign, LuTrendingUp } from "react-icons/lu"
const Demo = () => {
return (
<RadioCardRoot orientation="vertical" align="center" defaultValue="next">
<RadioCardLabel>Select contract type</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
icon={
<Icon fontSize="2xl" color="fg.muted" mb="2">
{item.icon}
</Icon>
}
label={item.title}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{ icon: <LuDollarSign />, value: "fixed", title: "Fixed Rate" },
{ icon: <LuTrendingUp />, value: "milestone", title: "Milestone" },
{ icon: <LuClock />, value: "hourly", title: "Hourly" },
]
Composition
Here's an example of composing the RadioCard with the Group
component.
import { Group } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
const Demo = () => {
return (
<RadioCardRoot defaultValue="next" gap="4" maxW="sm">
<RadioCardLabel>How well do you know React?</RadioCardLabel>
<Group attached orientation="vertical">
{items.map((item) => (
<RadioCardItem
width="full"
indicatorPlacement="start"
label={item.title}
description={item.description}
key={item.value}
value={item.value}
/>
))}
</Group>
</RadioCardRoot>
)
}
const items = [
{
value: "advanced",
title: "Advanced",
description: "I love complex things",
},
{
value: "professional",
title: "Professional",
description: "I can hack simple things",
},
{
value: "beginner",
title: "Beginner",
description: "I don't write code",
},
]
Addon
Pass the addon
prop to the RadioCardItem
component to add metadata below the
item content.
import { HStack } from "@chakra-ui/react"
import {
RadioCardItem,
RadioCardLabel,
RadioCardRoot,
} from "@/components/ui/radio-card"
const Demo = () => {
return (
<RadioCardRoot defaultValue="next">
<RadioCardLabel>Select framework</RadioCardLabel>
<HStack align="stretch">
{items.map((item) => (
<RadioCardItem
label={item.title}
description={item.description}
key={item.value}
value={item.value}
addon="Some addon text"
/>
))}
</HStack>
</RadioCardRoot>
)
}
const items = [
{ value: "next", title: "Next.js", description: "Best for apps" },
{ value: "vite", title: "Vite", description: "Best for SPAs" },
{ value: "astro", title: "Astro", description: "Best for static sites" },
]
Props
Root
Prop | Default | Type |
---|---|---|
colorPalette | 'gray' | 'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent' The color palette of the component |
size | 'md' | 'sm' | 'md' | 'lg' The size of the component |
variant | 'outline' | 'plain' | 'subtle' | 'outline' The variant of the component |
as | React.ElementType The underlying element to render. | |
asChild | boolean Use the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. | |
unstyled | boolean Whether to remove the component's style. |