Skip to main content
A radio button component with smooth transitions and customizable content.

Basic Usage

import { RadioButton } from '@adoptaunabuelo/react-components';
import { useState } from 'react';

function PaymentMethod() {
  const [selected, setSelected] = useState('credit-card');

  return (
    <div>
      <RadioButton
        id="credit-card"
        selected={selected === 'credit-card'}
        onClick={() => setSelected('credit-card')}
      >
        Credit Card
      </RadioButton>
      
      <RadioButton
        id="paypal"
        selected={selected === 'paypal'}
        onClick={() => setSelected('paypal')}
      >
        PayPal
      </RadioButton>
      
      <RadioButton
        id="bank-transfer"
        selected={selected === 'bank-transfer'}
        onClick={() => setSelected('bank-transfer')}
      >
        Bank Transfer
      </RadioButton>
    </div>
  );
}

Using RadioButtonList

For managing multiple radio buttons, use the RadioButtonList component:
import { RadioButtonList } from '@adoptaunabuelo/react-components';
import { useState } from 'react';

function SingleSelection() {
  const [selectedOption, setSelectedOption] = useState('option1');

  return (
    <RadioButtonList
      type="single"
      options={[
        {
          id: 'option1',
          children: 'Option 1',
          selected: true
        },
        {
          id: 'option2',
          children: 'Option 2'
        },
        {
          id: 'option3',
          children: 'Option 3'
        },
        {
          id: 'option4',
          children: 'Option 4'
        }
      ]}
      onChange={(selectedId) => setSelectedOption(selectedId)}
    />
  );
}

Multiple Selection Mode

<RadioButtonList
  type="multiple"
  options={[
    { id: 'option1', children: 'Option 1' },
    { id: 'option2', children: 'Option 2' },
    { id: 'option3', children: 'Option 3' }
  ]}
  onChange={(selectedIds) => console.log(selectedIds)}
/>

Disabled State

<RadioButton
  id="disabled-option"
  selected={false}
  disabled={true}
>
  Disabled Option
</RadioButton>

Custom Styles

<RadioButton
  id="custom-option"
  selected={isSelected}
  onClick={handleClick}
  style={{ padding: '16px', backgroundColor: '#f0f0f0' }}
>
  Custom Styled Option
</RadioButton>

Props

RadioButton Props

selected
boolean
default:"false"
Whether the radio button is selected.
disabled
boolean
default:"false"
Disables the radio button and shows a soft border color.
id
string
Unique identifier for the radio button (used as role attribute).
onClick
(event: React.MouseEvent<HTMLDivElement>) => void
Callback fired when the radio button is clicked.
children
ReactNode
Content to display next to the radio button.
style
CSSProperties
Custom styles for the container.
Also supports all standard HTML div attributes.

RadioButtonList Props

type
'single' | 'multiple'
default:"single"
Selection mode:
  • single: Only one option can be selected at a time
  • multiple: Multiple options can be selected
options
Array<RadioButtonOption>
required
Array of radio button options.Each option object:
  • id (string, required): Unique identifier
  • children (ReactNode, required): Content to display
  • selected (boolean, optional): Initial selected state
  • disabled (boolean, optional): Whether the option is disabled
onChange
(selected: string | string[]) => void
Callback fired when selection changes:
  • For type="single": Receives the selected option’s id (string)
  • For type="multiple": Receives array of selected option ids (string[])

Features

  • Smooth Transitions: All state changes are animated with 0.1s linear transitions
  • Visual Feedback: Clear visual distinction between selected and unselected states
  • Circular Design: 18px outer circle with 10px inner circle indicator
  • Primary Color: Uses primary background color from the theme
  • Disabled State: Shows soft border when disabled
  • Accessible: Uses semantic HTML and proper role attributes
  • Flexible Content: Supports any React content as children

Styling

Circle Dimensions

  • Outer Circle: 18px width/height with 50% border radius
  • Inner Circle: 10px width/height with 50% border radius
  • Spacing: 12px margin right between circle and content

Colors

  • Border: 2px solid primary color (or soft color when disabled)
  • Inner Circle (Selected): Primary background color
  • Inner Circle (Unselected): White background

Container

  • Margin: 24px vertical margin
  • Cursor: Pointer (changes to default when disabled)
  • User Select: None (prevents text selection)

Build docs developers (and LLMs) love