Installation
npx @park-ui/cli@next add radio-button-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 { radioButtonGroup } from 'styled-system/recipes'
const { withProvider, withContext } = createStyleContext(radioButtonGroup)
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 radioButtonGroup = defineSlotRecipe({
  className: 'radio-button-group',
  slots: radioGroupAnatomy.keys(),
  base: {
    root: {
      display: 'flex',
      flexWrap: 'wrap',
    },
    item: {
      alignItems: 'center',
      appearance: 'none',
      borderColor: 'border.default',
      borderRadius: 'l2',
      borderWidth: '1px',
      cursor: 'pointer',
      display: 'inline-flex',
      fontWeight: 'semibold',
      justifyContent: 'center',
      outline: 'none',
      position: 'relative',
      userSelect: 'none',
      verticalAlign: 'middle',
      whiteSpace: 'nowrap',
      _hover: {
        background: 'gray.a2',
      },
      _checked: {
        cursor: 'default',
      },
      _disabled: {
        borderColor: 'gray.6',
        color: 'gray.6',
        cursor: 'not-allowed',
      },
    },
    itemText: {
      display: 'inline-flex',
      alignItems: 'center',
    },
  },
  defaultVariants: {
    size: 'md',
    variant: 'solid',
  },
  variants: {
    variant: {
      solid: {
        item: {
          _checked: {
            background: 'colorPalette.solid.bg',
            borderColor: 'colorPalette.solid.bg',
            color: 'colorPalette.solid.fg',
            _hover: {
              color: 'colorPalette.solid.fg',
              background: 'colorPalette.solid.bg',
            },
          },
        },
      },
      outline: {
        item: {
          _checked: {
            borderColor: 'colorPalette.solid.bg',
            boxShadow: '0 0 0 1px var(--colors-color-palette-solid-bg)',
            _hover: {
              background: 'initial',
            },
          },
        },
      },
    },
    size: {
      sm: {
        root: {
          gap: '2',
        },
        item: {
          h: '9',
          minW: '9',
          textStyle: 'sm',
          px: '3.5',
          '& svg': {
            width: '4.5',
            height: '4.5',
          },
        },
        itemText: {
          gap: '2',
        },
      },
      md: {
        root: {
          gap: '3',
        },
        item: {
          h: '10',
          minW: '10',
          textStyle: 'sm',
          px: '4',
          '& svg': {
            width: '5',
            height: '5',
          },
        },
        itemText: {
          gap: '2',
        },
      },
      lg: {
        root: {
          gap: '3',
        },
        item: {
          h: '11',
          minW: '11',
          textStyle: 'md',
          px: '4.5',
          '& svg': {
            width: '5',
            height: '5',
          },
        },
        itemText: {
          gap: '2',
        },
      },
      xl: {
        root: {
          gap: '3',
        },
        item: {
          h: '12',
          minW: '12',
          textStyle: 'md',
          px: '5',
          '& svg': {
            width: '5',
            height: '5',
          },
        },
        itemText: {
          gap: '2.5',
        },
      },
    },
  },
})
Usage
import { RadioButtonGroup } from '@/components/ui'
<RadioButtonGroup.Root>
  <RadioButtonGroup.Label>Radio Button Group</RadioButtonGroup.Label>
  <RadioButtonGroup.Item value="option1">
    <RadioButtonGroup.ItemText>Option 1</RadioButtonGroup.ItemText>
    <RadioButtonGroup.ItemControl />
  </RadioButtonGroup.Item>
  <RadioButtonGroup.Item value="option2">
    <RadioButtonGroup.ItemText>Option 2</RadioButtonGroup.ItemText>
    <RadioButtonGroup.ItemControl />
  </RadioButtonGroup.Item>
</RadioButtonGroup.Root>
Props
| Prop | Default | Type | 
|---|---|---|
| variant | 'solid' | 'solid' | 'outline' | 
| size | 'md' | 'sm' | 'md' | 'lg' | 'xl' |