Radio

A clickable element that can be used to get a true or false value.

The Radio component is a very basic component that can be parametrized by its size, tone, shadow and other properties.

import { Radio, RadioGroup } from '@rewind-ui/core';

function App() {
  return (
    <RadioGroup orientation="vertical" initialValue="1" name="example">
      <Radio label="Apple" value="1" />
      <Radio label="Banana" value="2" />
      <Radio label="Orange" value="3" />
    </RadioGroup>
  );
}

Import


Import the Radio and RadioGroup components using the following import statement.

import { Radio, RadioGroup } from '@rewind-ui/core';

Tones & Colors


The following tones are supported: solid and light.

The only difference between the above tones is the unchecked state. The solid tone has a white background and the light tone has a light gray background.

The available color values are: white, blue, red, green, yellow, purple, gray, dark and black.

Solid

<View>
  <Radio label="Unchecked" defaultChecked={false} />
  <Radio label="Blue" color="blue" defaultChecked={true} />
  <Radio label="Red" color="red" defaultChecked={true} />
  <Radio label="Green" color="green" defaultChecked={true} />
  <Radio label="Yellow" color="yellow" defaultChecked={true} />
  <Radio label="Purple" color="purple" defaultChecked={true} />
  <Radio label="Gray" color="gray" defaultChecked={true} />
  <Radio label="Dark" color="dark" defaultChecked={true} />
  <Radio label="Black" color="black" defaultChecked={true} />
</View>

Light

<View>
  <Radio tone="light" label="Unchecked" defaultChecked={false} />
  <Radio tone="light" label="Blue" color="blue" defaultChecked={true} />
  <Radio tone="light" label="Red" color="red" defaultChecked={true} />
  <Radio tone="light" label="Green" color="green" defaultChecked={true} />
  <Radio tone="light" label="Yellow" color="yellow" defaultChecked={true} />
  <Radio tone="light" label="Purple" color="purple" defaultChecked={true} />
  <Radio tone="light" label="Gray" color="gray" defaultChecked={true} />
  <Radio tone="light" label="Dark" color="dark" defaultChecked={true} />
  <Radio tone="light" label="Black" color="black" defaultChecked={true} />
</View>

Sizes


Available size values are: sm, md, lg and xl.

<View>
  <Radio label="Small" size="sm" defaultChecked={true} />
  <Radio label="Medium" size="md" defaultChecked={true} />
  <Radio label="Large" size="lg" defaultChecked={true} />
  <Radio label="Extra large" size="xl" defaultChecked={true} />
</View>

Radiuses


Available radius values are: none, sm, md, lg and full.

<View>
  <Radio label="None" radius="none" defaultChecked={true} />
  <Radio label="Small" radius="sm" defaultChecked={true} />
  <Radio label="Medium" radius="md" defaultChecked={true} />
  <Radio label="Large" radius="lg" defaultChecked={true} />
  <Radio label="Full" radius="full" defaultChecked={true} />
</View>

States


Checkbox component supports disabled and error states. The error state is enabled automatically by passing an error message to the error prop.

Something went wrong...
<View>
  <Radio label="Disabled" disabled />
  <Radio label="Click me!" error="Something went wrong..." />
</View>

Description


The description prop can be used to display a description below the checkbox.

This is a description
<View>
  <Radio label="Click me!" description="This is a description" />
</View>

Furthermore, a ReactNode can be passed to the description prop to display a more complex description that may contain multiple jsx elements.

This is a purple description
<View>
  <Radio
    label="Click me!"
    description={<span className="text-purple-500 bg-purple-50 p-1 rounded">This is a purple description</span>}
  />
</View>

Similar styling can be achieved by using the descriptionClassName prop.

This is a pink description
<View>
  <Radio
    label="Click me!"
    descriptionClassName="text-pink-500 bg-pink-50 p-1 rounded"
    description="This is a pink description"
  />
</View>

Ring


You can add a ring to the Checkbox by setting the withRing prop to true.

<View>
  <Radio label="Click me!" withRing={true} />
  <Radio label="Click me!" withRing={false} />
</View>

Radio Group


The RadioGroup component can be used to group multiple Radio components together.

Initial value

When using the Radio component without a RadioGroup component, the defaultChecked prop can be used to set the initial value of the Radio component. When using the Radio component within a RadioGroup component, the initialValue prop of the RadioGroup component can be used to set the initial value of the group.

Orientation

The orientation of the RadioGroup can be set to horizontal or vertical.

<View>
  <RadioGroup name="horizontal" orientation="horizontal" initialValue="1">
    <Radio label="Apple" value="1" />
    <Radio label="Banana" value="2" />
    <Radio label="Orange" value="3" />
  </RadioGroup>

  <RadioGroup name="vertical" orientation="vertical" initialValue="1">
    <Radio label="Apple" value="1" />
    <Radio label="Banana" value="2" />
    <Radio label="Orange" value="3" />
  </RadioGroup>
</View>

API Reference


Properties

Radio

PropTypeDescriptionDefault
colorRadioColorSets the colordark
disabledbooleanDisables the checkboxfalse
descriptionstring or ReactNodeDescription contentundefined
descriptionClassNamestringDescription span element classesundefined
errorstring or ReactNodeError contentundefined
errorClassNamestringError span element classesundefined
labelstring or ReactNodeLabel contentundefined
labelClassNamestringLabel element classesundefined
radiusRadioRadiusSets the border radiusnormal
sizeRadioSizeSets the checkbox sizebase
toneRadioToneSets the color tonesolid
withRingbooleanShows a ring around the checkbox on active statetrue

RadioGroup

PropTypeDescriptionDefault
initialValuestringSets the radios initial valueundefined
namestringSets the radios nameundefined
orientationRadioGroupOrientationSets the radio group orientationhorizontal

Events

RadioGroup

EventTypeDescription
onChange(value: string) => voidFires when the selected radio is changed

Types

Radio

type RadioColor =
  | 'blue'
  | 'red'
  | 'green'
  | 'yellow'
  | 'purple'
  | 'gray'
  | 'dark'
  | 'black';
type RadioRadius = 'none' | 'sm' | 'base' | 'md' | 'lg' | 'full';
type RadioSize = 'sm' | 'md' | 'lg' | 'xl';
type RadioTone = 'solid' | 'light';

RadioGroup

type RadioGroupOrientation = 'horizontal' | 'vertical';

Accessibility


The Radio and RadioGroup components adhere to the WAI-ARIA Radio Group Pattern.