PeakUIPro

RadioButtonGroup

Single-choice group of card-style radios

Usage

import {RadioButtonGroup} from "@peakui-pro/react";

Anatomy

import {RadioButtonGroup} from "@peakui-pro/react";

// `Item` takes every core `Radio` prop. Its `className` styles the card; the other props
// reach the radio around it. Put a core `Label` and `Description` inside `ItemContent`.
export default () => (
  <RadioButtonGroup>
    <RadioButtonGroup.Item value="a">
      <RadioButtonGroup.Indicator />
      <RadioButtonGroup.ItemIcon />
      <RadioButtonGroup.ItemContent />
    </RadioButtonGroup.Item>
  </RadioButtonGroup>
);

Examples

Grid Layout

No Indicator

Custom Indicator

Icon Cards

With Icons

Disabled Group

Delivery And Payment

Render Prop Children

Controlled

Subscription Plans

Customization

Tailwind CSS

<RadioButtonGroup className="grid-cols-3 [--radio-button-group-item-radius:var(--radius-xl)]" layout="grid">
  <RadioButtonGroup.Item className="data-[selected=true]:bg-accent-soft" value="a" />
</RadioButtonGroup>

Global CSS

@layer components {
  .radio-button-group {
    --radio-button-group-item-radius: var(--radius-xl);
  }

  .radio-button-group__item[data-selected="true"] {
    --button-group-card-ring: 0 0 0 2px var(--color-success);
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The RadioButtonGroup component uses these CSS classes (view source styles):

Base & Layout Classes

  • .radio-button-group - The group
  • .radio-button-group--grid - Grid layout

Element Classes

  • .radio-button-group__item - The card: the radio's clickable label
  • .radio-button-group__indicator - The corner control or custom icon
  • .radio-button-group__item-content - The column holding the text
  • .radio-button-group__item-icon - The leading icon box

Slots

  • [data-slot="radio-group"] - The root, the core group's own slot
  • [data-slot="radio"] - The field around a card, the core's own slot
  • [data-slot="radio-content"] - The card
  • [data-slot="radio-control"] - The default indicator
  • [data-slot="radio-button-group-indicator"] - A custom indicator
  • [data-slot="radio-button-group-item-content"] - The content column
  • [data-slot="radio-button-group-item-icon"] - The icon box

CSS Variables

VariablePurpose
--radio-button-group-item-radiusCorner radius of a card; defaults to var(--radius-2xl)
--button-group-card-ringThe ring around a card; set by the card, shared with CheckboxButtonGroup

Interactive States

The card supports both CSS pseudo-classes and data attributes:

  • Hover: [data-hovered]
  • Selected: [data-selected] (accent ring)
  • Focus: [data-focus-visible]
  • Disabled: [data-disabled]

API Reference

RadioButtonGroup

PropTypeDefaultDescription
layout'flex' | 'grid''flex'A column of cards, or a grid; set its columns with a grid-cols-* class
variant'primary' | 'secondary''primary'The core group's variant, passed to every radio
valuestring | null-The selected value, controlled
defaultValuestring-The selected value, uncontrolled
onChange(value: string) => void-Called when the selection changes
isDisabledbooleanfalseDims and disables every item
classNamestring | ((values: RadioGroupRenderProps) => string)-Additional classes
...restRadioGroupRootProps-Every core RadioGroup prop

RadioButtonGroup.Item

PropTypeDefaultDescription
valuestring-The value this card selects
childrenReactNode | ((state: RadioFieldRenderProps) => ReactNode)-The card's content, or a function of its state
classNamestring | ((state: RadioButtonRenderProps) => string)-Additional classes for the card
...restOmit<RadioRootProps, 'children' | 'className'>-Every core Radio prop, applied to the field around the card

RadioButtonGroup.Indicator

PropTypeDefaultDescription
childrenReactNode-With none, the core radio dot; with children, a custom icon shown only while selected
classNamestring-Additional classes
...restComponentProps<'span'>-Native <span> attributes

RadioButtonGroup.ItemContent

PropTypeDefaultDescription
childrenReactNode-The title and description
classNamestring-Additional classes
...restComponentProps<'div'>-Native <div> attributes

RadioButtonGroup.ItemIcon

PropTypeDefaultDescription
childrenReactNode-The icon
classNamestring-Additional classes
...restComponentProps<'div'>-Native <div> attributes

Render Props

RadioButtonGroup.Item

PropTypeDescription
isSelectedbooleanWhether the card is selected
isDisabledbooleanWhether the card is disabled
isFocusVisiblebooleanWhether keyboard focus is on the card
isHoveredbooleanWhether the pointer is over the card

On this page