Select framework
'use client'
import { HStack } from '@chakra-ui/react'
import { RadioCard } from '#components/ui/radio-card'
export const RadioCardBasic = () => {
return (
<RadioCard.Root defaultValue="next">
<RadioCard.Label>Select framework</RadioCard.Label>
<HStack align="stretch">
{items.map((item) => (
<RadioCard.Item
label={item.title}
description={item.description}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCard.Root>
)
}
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' },
]
Anatomy
A RadioCard is a form element with a larger interaction surface represented as a card.
import { RadioCard } from '#components/ui/radio-card'<RadioCard.Root>
<RadioCard.Label />
<RadioCard.Item />
</RadioCard.Root>Examples
Sizes
Use the size prop to change the size of the radio card.
size = (sm)
size = (md)
size = (lg)
'use client'
import { For, HStack, Stack } from '@chakra-ui/react'
import { RadioCard } from '#components/ui/radio-card'
export const RadioCardWithSizes = () => {
return (
<Stack gap="8">
<For each={['sm', 'md', 'lg']}>
{(size) => (
<RadioCard.Root key={size} size={size} defaultValue="next">
<RadioCard.Label>size = ({size})</RadioCard.Label>
<HStack align="stretch">
{items.map((item) => (
<RadioCard.Item
label={item.title}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCard.Root>
)}
</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.
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
Select Framework
'use client'
import { For, HStack, Stack } from '@chakra-ui/react'
import { RadioCard } from '#components/ui/radio-card'
import { colorPalettes } from '../lib/color-palettes'
export const RadioCardWithColors = () => {
return (
<Stack gap="8">
<For each={colorPalettes}>
{(colorPalette) => (
<RadioCard.Root
key={colorPalette}
colorPalette={colorPalette}
defaultValue="next"
>
<RadioCard.Label>Select Framework</RadioCard.Label>
<HStack align="stretch">
{items.map((item) => (
<RadioCard.Item
label={item.title}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCard.Root>
)}
</For>
</Stack>
)
}
const items = [
{ value: 'next', title: 'Next.js' },
{ value: 'vite', title: 'Vite' },
]
Icon
Here's an example of a RadioCard with an icon.
Select permission
'use client'
import { HStack, Icon } from '@chakra-ui/react'
import { RadioCard } from '#components/ui/radio-card'
import { LuArrowRight, LuCircleOff, LuLock } from 'react-icons/lu'
export const RadioCardWithIcon = () => {
return (
<RadioCard.Root defaultValue="next">
<RadioCard.Label>Select permission</RadioCard.Label>
<HStack align="stretch">
{items.map((item) => (
<RadioCard.Item
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>
</RadioCard.Root>
)
}
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',
},
]
Centered
Here's an example of a RadioCard with centered text.
Select contract type
'use client'
import { HStack, Icon } from '@chakra-ui/react'
import { RadioCard } from '#components/ui/radio-card'
import { LuClock, LuDollarSign, LuTrendingUp } from 'react-icons/lu'
export const RadioCardCentered = () => {
return (
<RadioCard.Root orientation="vertical" align="center" defaultValue="next">
<RadioCard.Label>Select contract type</RadioCard.Label>
<HStack align="stretch">
{items.map((item) => (
<RadioCard.Item
icon={
<Icon fontSize="2xl" color="fg.muted" mb="2">
{item.icon}
</Icon>
}
label={item.title}
key={item.value}
value={item.value}
/>
))}
</HStack>
</RadioCard.Root>
)
}
const items = [
{ icon: <LuDollarSign />, value: 'fixed', title: 'Fixed Rate' },
{ icon: <LuTrendingUp />, value: 'milestone', title: 'Milestone' },
{ icon: <LuClock />, value: 'hourly', title: 'Hourly' },
]
Addon
Use the RadioCardItemAddon component to add an addon below the radio card
content.
Select framework
'use client'
import { HStack } from '@chakra-ui/react'
import { RadioCard } from '#components/ui/radio-card'
export const RadioCardWithAddon = () => {
return (
<RadioCard.Root defaultValue="next">
<RadioCard.Label>Select framework</RadioCard.Label>
<HStack align="stretch">
{items.map((item) => (
<RadioCard.Item
label={item.title}
description={item.description}
key={item.value}
value={item.value}
addon="Some addon text"
/>
))}
</HStack>
</RadioCard.Root>
)
}
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' | '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' | 'sm' | 'md' | 'lg'The size of the component |
variant | 'outline' | 'surface' | 'subtle' | 'outline' | 'solid'The variant of the component |
align | 'start' | 'start' | 'end' | 'center'The align of the component |
orientation | 'horizontal' | 'vertical' | 'horizontal'The orientation of the component |
justify | 'start' | 'end' | 'center'The justify of the component | |
as | React.ElementTypeThe underlying element to render. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. | |
unstyled | booleanWhether to remove the component's style. |