Radio component consists of two main elements: RadioGroup and RadioBox. The RadioGroup manages the state and context of radio buttons, while the RadioBox represents each individual option. It's ideal for exclusive selections where only one option can be chosen at a time.tsx
import { RadioGroup, RadioBox } from "@arkyn/components";
RadioGroup containing the name property along with one or more RadioBox elements with unique values.tsx
<RadioGroup name="basic-radio" label="Choose an option"><RadioBox value="option1">Option 1</RadioBox><RadioBox value="option2">Option 2</RadioBox><RadioBox value="option3">Option 3</RadioBox></RadioGroup>
sm, md, and lg, applied through the RadioGroup and inherited by the RadioBox elements.RadioBox elements within the RadioGroup using the size property.tsx
<RadioGroup name="radio-sm" label="Small size" size="sm"><RadioBox value="small1">Small option 1</RadioBox><RadioBox value="small2">Small option 2</RadioBox></RadioGroup><RadioGroup name="radio-md" label="Medium size" size="md"><RadioBox value="medium1">Medium option 1</RadioBox><RadioBox value="medium2">Medium option 2</RadioBox></RadioGroup><RadioGroup name="radio-lg" label="Large size" size="lg"><RadioBox value="large1">Large option 1</RadioBox><RadioBox value="large2">Large option 2</RadioBox></RadioGroup>
RadioBox. (The size defined in the RadioGroup will continue to be the default for the others.)tsx
<RadioGroup name="mixed-sizes" label="Priorities" size="md"><RadioBox value="low" size="sm">Low Priority</RadioBox><RadioBox value="medium">Medium Priority</RadioBox><RadioBox value="high" size="lg">High Priority</RadioBox></RadioGroup>
tsx
<RadioGroup name="disabled-group" label="Disabled options" disabled><RadioBox value="option1">Option 1</RadioBox><RadioBox value="option2">Option 2</RadioBox><RadioBox value="option3">Option 3</RadioBox></RadioGroup>
RadioBox prevents it from being selected, but the others remain interactive.tsx
<RadioGroup name="disabled-options" label="Payment options"><RadioBox value="credit">Credit Card</RadioBox><RadioBox value="pix" disabled>PIX (Under maintenance)</RadioBox></RadioGroup>
errorMessage property, it will take precedence over messages from the form provider.tsx
<RadioGroupname="required-radio"label="Select your gender"showAsteriskerrorMessage="Please select an option"><RadioBox value="male"><User size={16} style={{ marginRight: "8px" }} />Male</RadioBox><RadioBox value="female"><User size={16} style={{ marginRight: "8px" }} />Female</RadioBox><RadioBox value="other"><User size={16} style={{ marginRight: "8px" }} />Other</RadioBox></RadioGroup>
onChange property of the RadioGroup that will be called whenever the selected value changes. The function receives the new selected value as an argumenttsx
const [selectedValue, setSelectedValue] = useState("");const handleRadioChange = (value: string) => {console.log("Selected value:", value);setSelectedValue(value);// Additional logic based on the valueif (value === "premium") {// Enable premium features}};<RadioGroupname="subscription"label="Subscription plan"onChange={handleRadioChange}value={selectedValue}><RadioBox value="basic">Basic</RadioBox><RadioBox value="premium">Premium</RadioBox><RadioBox value="enterprise">Enterprise</RadioBox></RadioGroup>;
name - string (required)
Field name for form handling and radio button groupinglabel - string
Label text to be displayed above the radio groupshowAsterisk - boolean
Whether to show asterisk in the label for required fieldserrorMessage - string
Error message to be displayed below the groupvalue - string
Controlled value for the selected optiondefaultValue - string (default: "")
Default selected value for uncontrolled usageonChange - (value: string) => void
Callback function called when selection changessize - "sm" | "md" | "lg" (default: "md")
Size variant for all radio buttons in the groupclassName - string
Additional CSS classes for stylingvalue - string (required)
Unique value for this radio option within the groupisError - boolean
Error state indicator for stylingsize - "sm" | "md" | "lg"
Overrides the size inherited from RadioGroupdisabled - boolean
Whether this specific option is disabledchildren - ReactNode
Content to be displayed next to the radio buttonclassName - string
Additional CSS classes for stylingdiv properties (except onChange), and
the RadioBox supports all HTML button properties.value property is required in each RadioBox and must be unique within the group