Radio
A set of checkable buttons where only one can be selected at a time. Perfect for single-choice selections with keyboard navigation, accessibility features, and customizable sizing options.
Import
import { RadioGroup, Radio } from "@sparrowengg/twigs-react";Usage
const RadioExample = () => {
const [selectedValue, setSelectedValue] = useState("option1");
return (
<Box css={{ display: "flex", flexDirection: "column", gap: "$6", alignItems: "center" }}>
<Box css={{ display: "flex", flexDirection: "column", gap: "$4", alignItems: "flex-start" }}>
<Text css={{ fontSize: "$md", fontWeight: "$6" }}>Choose your preference:</Text>
<RadioGroup
value={selectedValue}
onChange={setSelectedValue}
css={{ display: "flex", flexDirection: "column", gap: "$3" }}
>
<Radio value="option1" size="sm">
Small radio option
</Radio>
<Radio value="option2" size="md">
Medium radio option
</Radio>
<Radio value="option3" size="sm" disabled>
Disabled radio option
</Radio>
</RadioGroup>
</Box>
<Box css={{ display: "flex", flexDirection: "column", gap: "$4", alignItems: "flex-start" }}>
<Text css={{ fontSize: "$md", fontWeight: "$6" }}>Default selection:</Text>
<RadioGroup
defaultValue="default"
css={{ display: "flex", flexDirection: "column", gap: "$3" }}
>
<Radio value="default" size="md">
Default option
</Radio>
<Radio value="comfortable" size="md">
Comfortable option
</Radio>
<Radio value="compact" size="md">
Compact option
</Radio>
</RadioGroup>
</Box>
</Box>
);
};Props
RadioGroup
| Prop | Type | Default |
|---|---|---|
value? | string | - |
defaultValue? | string | - |
onChange? | (value: string) => void | - |
disabled? | boolean | false |
required? | boolean | false |
name? | string | - |
orientation? | 'horizontal' | 'vertical' | - |
dir? | 'ltr' | 'rtl' | - |
loop? | boolean | true |
asChild? | boolean | false |
Radio
| Prop | Type | Default |
|---|---|---|
value? | string | - |
size? | 'sm' | 'md' | 'sm' |
disabled? | boolean | false |
required? | boolean | false |
id? | string | - |
containerRef? | React.Ref<HTMLDivElement> | - |
css? | object | - |
Data Attributes
These props are used for the conditional rendering of the components
Applicable - RadioGroup
| Prop | Type | Default |
|---|---|---|
[data-disabled]? | boolean | - |
Applicable - Radio
| Prop | Type | Default |
|---|---|---|
[data-state]? | 'checked' | 'unchecked' | - |
[data-disabled]? | boolean | - |
Input
A versatile input component with multiple sizes, variants, and icon support. Perfect for forms, search interfaces, and data entry with comprehensive styling options and accessibility features.
Select
A powerful dropdown component for selecting single or multiple options from a list. Perfect for forms, filters, and data selection with search functionality, async loading, and customizable styling options.