Installation
npx @park-ui/cli add radio-card-group1
Add Component
Copy the code snippet below into you components folder.
'use client'
import { RadioGroup } from '@ark-ui/react/radio-group'
import type { ComponentProps } from 'react'
import { createStyleContext } from 'styled-system/jsx'
import { radioCardGroup } from 'styled-system/recipes'
const { withProvider, withContext } = createStyleContext(radioCardGroup)
export type RootProps = ComponentProps<typeof Root>
export const Root = withProvider(RadioGroup.Root, 'root')
export const RootProvider = withProvider(RadioGroup.RootProvider, 'root')
export const Indicator = withContext(RadioGroup.Indicator, 'indicator')
export const Item = withContext(RadioGroup.Item, 'item')
export const ItemControl = withContext(RadioGroup.ItemControl, 'itemControl')
export const ItemText = withContext(RadioGroup.ItemText, 'itemText')
export const Label = withContext(RadioGroup.Label, 'label')
export const ItemHiddenInput = RadioGroup.ItemHiddenInput
export { RadioGroupContext as Context } from '@ark-ui/react/radio-group'
2
Integrate Recipe
Integrate this recipe in to your Panda config.
import { radioGroupAnatomy } from '@ark-ui/react/radio-group'
import { defineSlotRecipe } from '@pandacss/dev'
export const radioCardGroup = defineSlotRecipe({
className: 'radio-card-group',
slots: radioGroupAnatomy.keys(),
base: {
root: {
display: 'flex',
flexDirection: 'column',
gap: '1.5',
width: 'full',
},
item: {
alignItems: 'center',
borderRadius: 'l2',
cursor: 'pointer',
display: 'flex',
justifyContent: 'space-between',
userSelect: 'none',
width: 'full',
},
label: {
textStyle: 'label',
},
itemControl: {
alignItems: 'center',
borderRadius: 'full',
display: 'inline-flex',
flexShrink: '0',
justifyContent: 'center',
verticalAlign: 'top',
_after: {
content: '""',
display: 'block',
borderRadius: 'full',
},
_focusVisible: {
focusVisibleRing: 'outside',
},
},
itemText: {
textStyle: 'label',
},
},
defaultVariants: {
variant: 'outline',
size: 'md',
},
variants: {
variant: {
subtle: {
item: {
background: 'gray.subtle.bg',
color: 'gray.subtle.fg',
_checked: {
background: 'colorPalette.subtle.bg',
color: 'colorPalette.subtle.fg',
},
},
itemControl: {
borderWidth: '1px',
borderColor: 'gray.subtle.border',
_checked: {
borderColor: 'colorPalette.solid.bg',
_after: {
bg: 'colorPalette.solid.bg',
},
},
},
},
outline: {
item: {
borderWidth: '1px',
borderColor: 'gray.outline.border',
_checked: {
boxShadow: '0 0 0 1px var(--shadow-color)',
boxShadowColor: 'colorPalette.solid.bg',
borderColor: 'colorPalette.solid.bg',
},
},
itemControl: {
borderWidth: '1px',
borderColor: 'gray.outline.border',
_checked: {
bg: 'colorPalette.solid.bg',
borderColor: 'colorPalette.solid.bg',
_after: {
background: 'colorPalette.solid.fg',
},
},
},
},
surface: {
item: {
borderWidth: '1px',
background: 'gray.surface.bg',
borderColor: 'gray.surface.border',
color: 'gray.surface.fg',
_checked: {
boxShadow: '0 0 0 1px var(--shadow-color)',
boxShadowColor: 'colorPalette.solid.bg',
borderColor: 'colorPalette.solid.bg',
},
},
itemControl: {
borderWidth: '1px',
borderColor: 'gray.outline.border',
_checked: {
background: 'colorPalette.solid.bg',
borderColor: 'colorPalette.solid.bg',
_after: {
background: 'colorPalette.solid.fg',
},
},
},
},
solid: {
item: {
borderWidth: '1px',
_checked: {
bg: 'colorPalette.solid.bg',
color: 'colorPalette.solid.fg',
borderColor: 'colorPalette.solid.bg',
},
},
itemControl: {
borderWidth: '1px',
borderColor: 'gray.outline.border',
_checked: {
background: 'colorPalette.solid.fg',
borderColor: 'colorPalette.solid.fg',
_after: {
bg: 'colorPalette.solid.bg',
},
},
},
},
},
size: {
md: {
item: { gap: '2', p: '4' },
itemControl: { boxSize: '5', _after: { boxSize: '2' } },
itemText: { textStyle: 'sm' },
},
},
},
})
Usage
import { RadioCardGroup } from '@/components/ui'
<RadioCardGroup.Root>
<RadioCardGroup.Label />
<RadioCardGroup.Item>
<RadioCardGroup.ItemHiddenInput />
<RadioCardGroup.ItemText />
<RadioCardGroup.ItemControl />
</RadioCardGroup.Item>
</RadioCardGroup.Root>
Examples
Variants
Use the variant prop to change the appearance of the radio cards.
Props
| Prop | Default | Type |
|---|---|---|
variant | 'outline' | 'subtle' | 'outline' | 'surface' | 'solid' |
size | 'md' | 'md' |