radio-group.tsx

Overview

The radio-group.tsx file defines two React functional components, RadioGroup and RadioGroupItem, which serve as styled wrappers around Radix UI's RadioGroupPrimitive components. These components provide accessible, customizable radio group UI elements with consistent styling and behavior, leveraging the underlying Radix UI primitives and additional styling utilities.

This file is designed for use in React applications that require radio input groups with enhanced visual styling and accessibility compliance. It abstracts the complexity of Radix UI primitives, providing a simpler and consistent interface tailored to the application's design system.


Components

RadioGroup

A wrapper component around RadioGroupPrimitive.Root that renders a container for a group of radio items.

Props

Description

Usage Example

<RadioGroup value={selectedValue} onValueChange={setSelectedValue}>
  <RadioGroupItem value="option1" />
  <RadioGroupItem value="option2" />
  <RadioGroupItem value="option3" />
</RadioGroup>

RadioGroupItem

A wrapper component around RadioGroupPrimitive.Item that represents an individual radio button item.

Props

Description

Usage Example

<RadioGroupItem value="option1" />

This should be used inside a RadioGroup to represent each selectable option.


Implementation Details


Interaction with Other Parts of the System


Mermaid Component Diagram

componentDiagram
    component RadioGroup {
        +props: RadioGroupPrimitive.Root props
        +renders RadioGroupPrimitive.Root
        +applies grid layout and gap
        +data-slot="radio-group"
    }

    component RadioGroupItem {
        +props: RadioGroupPrimitive.Item props
        +renders RadioGroupPrimitive.Item
        +applies border, focus, invalid, dark mode styles
        +data-slot="radio-group-item"
        +contains RadioGroupPrimitive.Indicator with CircleIcon
    }

    RadioGroup *-- RadioGroupItem : contains >
    RadioGroupItem o-- CircleIcon : uses >
    RadioGroup --|> RadioGroupPrimitive.Root : wraps >
    RadioGroupItem --|> RadioGroupPrimitive.Item : wraps >
    RadioGroupItem --> RadioGroupPrimitive.Indicator : contains >

Summary

The radio-group.tsx file provides styled, accessible radio group components based on Radix UI primitives, integrating custom styling and iconography for selection indication. It promotes reusable, consistent, and accessible radio inputs within the React application UI, while being simple to use and extend. The components interact closely with the Radix UI library and the project's styling utilities to deliver a polished user experience.