Skip to main content

Radio

Quick start

Here's a quick start guide to get started with the Radio component, Radios are for selecting one option from many.

Importing Component

import { Radio, RadioGroup } from "@hover-design/react";

Code Snippets and Examples

Simple Radio
import { Radio, RadioGroup } from "@hover-design/react";

const Demo = () => {
const [radioVal, setRadioVal] = useState("honeypot");

return (
<div>
<label>
<Radio
name="antColony"
value="honeypot"
checked={radioVal == "honeypot"}
onChange={(e) => setRadioVal(e.target.value)}
/>
Honeypot
</label>
<label>
<Radio
name="antColony"
value="rover"
checked={radioVal == "rover"}
onChange={(e) => setRadioVal(e.target.value)}
/>
Rover
</label>
<label>
<Radio
name="antColony"
value="weaver"
checked={radioVal == "weaver"}
isDisabled
onChange={(e) => setRadioVal(e.target.value)}
/>
Weaver
</label>
</div>
);
};
Radio Group
<RadioGroup orientation="vertical">
<label>
<Radio name="antColony" value="honeypot" checked />
Honeypot
</label>
<label>
<Radio name="antColony" value="rover" />
Rover
</label>
<label>
<Radio name="antColony" value="weaver" isDisabled />
Weaver
</label>
</RadioGroup>
Radio with styles
<div>
<Radio
name="antColony"
value="rover"
checked
radioSize="xs"
selectedStyles={{
borderColor: "rgb(25, 113, 194)",
backgroundColor: "rgb(25, 113, 194)"
}}
/>
<Radio name="antColony" value="weaver" radioSize="sm" checked />
<Radio
name="antColony"
value="honeypot"
checked
radioSize="md"
selectedStyles={{
borderColor: "rgb(224, 49, 49)",
backgroundColor: "rgb(224, 49, 49)"
}}
/>
</div>

Radio Props Reference

KeytypeOptional?
valuestring;Yes
namestring;Yes
radioSizexs sm md lg xl stringYes
isDisabledbooleanYes
baseStylesbaseStyles objectYes
disabledStylesdisabledStyles objectYes
selectedStylesselectedStyles objectYes
Customizing Radio Base, Selected and Disabled

You can customize the base, selected and disabled styles of the radio by passing in the baseStyles, selectedStyles and disabledStyles props. Refer this Spec for this:

baseStyles

PropertyDescriptionDefault
backgroundColorBackground of Radiorgb(250, 250, 250)
borderColorBorder Colorrgb(204, 204, 204)

selectedStyles

PropertyDescriptionDefault
backgroundColorSelected Radio BackgroundColorrgb(250, 250, 250)
borderColorSelected Border Colorrgb(204, 204, 204)

disabledStyles

PropertyDescriptionDefault
colorDisabled Radio Colorrgb(250, 250, 250)
backgroundColorDisabled Radio BackgroundColorrgb(250, 128, 5)
borderColorDisabled Radio Border Colorrgb(174, 68, 10)

RadioGroup Props Reference

KeytypeOptional?
childrenReact.ReactNodeNo
spacingxs sm md lg xl stringYes
orientationvertical horizontalYes
refRefObject<HTMLButtonElement>;Yes