Radio
Radio captures one choice from a mutually exclusive set.
@duskmoon-dev/components/radio Usage
When to use
- Use it inside forms, filters, settings, and any workflow that captures user input.
- Prefer controlled props when the value must stay synchronized with application state.
Implementation notes
Features
Documents default values, value props, and change callbacks for form integration.
Surfaces status, size, disabled, and option data patterns where the component supports them.
Radio is most often configured through `color`, `size`, `error`, `loading`.
Renders with default classes
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Colors
Radio supports the full semantic color palette: primary, secondary, tertiary, accent, neutral, base, info, success, warning, error.
import "@duskmoon-dev/components/styles.css";
import { Radio } from "@duskmoon-dev/components/radio";
const colors = [
"primary",
"secondary",
"tertiary",
"accent",
"neutral",
"base",
"info",
"success",
"warning",
"error"
] as const;
export function RadioColorsDemo() {
return (<div style={{ display: "grid", gap: 8 }}>
{colors.map((color) => (
<Radio key={color} name={`radio-${color}`} color={color} defaultChecked>
{color}
</Radio>
))}
</div>);
} Basic usage
Import the component stylesheet and Radio from its package subpath, then render it with the core props.
import "@duskmoon-dev/components/styles.css";
import { Radio } from "@duskmoon-dev/components/radio";
export function Example() {
return (<Radio
color="primary"
onChange={(value) => console.log(value)}
>
DuskMoon Radio
</Radio>);
} Renders with default classes
test-backedRadio scenario from the component test coverage: renders with default classes.
import "@duskmoon-dev/components/styles.css";
import { Radio } from "@duskmoon-dev/components/radio";
export function RadioRendersWithDefaultClassesDemo() {
return (<Radio
// Renders with default classes
color="primary"
onChange={(value) => console.log(value)}
>
DuskMoon Radio
</Radio>);
} Supports checked state
test-backedRadio scenario from the component test coverage: supports checked state.
import "@duskmoon-dev/components/styles.css";
import { Radio } from "@duskmoon-dev/components/radio";
export function RadioSupportsCheckedStateDemo() {
return (<Radio
// Supports checked state
color="primary"
onChange={(value) => console.log(value)}
>
DuskMoon Radio
</Radio>);
} Calls native change handler
test-backedRadio scenario from the component test coverage: calls native change handler.
import "@duskmoon-dev/components/styles.css";
import { Radio } from "@duskmoon-dev/components/radio";
export function RadioCallsNativeChangeHandlerDemo() {
return (<Radio
// Calls native change handler
color="primary"
onChange={(value) => console.log(value)}
>
DuskMoon Radio
</Radio>);
} Applies size, color, error, loading, and label position classes
test-backedRadio scenario from the component test coverage: applies size, color, error, loading, and label position classes.
import "@duskmoon-dev/components/styles.css";
import { Radio } from "@duskmoon-dev/components/radio";
export function RadioAppliesSizeColorErrorDemo() {
return (<Radio
// Applies size, color, error, loading, and label position classes
color="primary"
onChange={(value) => console.log(value)}
>
DuskMoon Radio
</Radio>);
} Forwards input ref
test-backedRadio scenario from the component test coverage: forwards input ref.
import "@duskmoon-dev/components/styles.css";
import { Radio } from "@duskmoon-dev/components/radio";
export function RadioForwardsInputRefDemo() {
return (<Radio
// Forwards input ref
color="primary"
onChange={(value) => console.log(value)}
>
DuskMoon Radio
</Radio>);
} Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
<div data-theme="sunshine">
<Radio
color="primary"
onChange={(value) => console.log(value)}
>
DuskMoon Radio
</Radio>
</div>
<div data-theme="moonlight">
<Radio
color="primary"
onChange={(value) => console.log(value)}
>
DuskMoon Radio
</Radio>
</div> API
The API reference below lists every parsed exported type or interface for Radio. Start with `color`, `size`, `error`, `loading` for common usage.
packages/components/src/components/radio/Radio.types.ts
Scenarios: packages/components/src/components/radio/Radio.test.tsx | Prop | Type | Required | Description |
|---|---|---|---|
color | RadioColor | No | color configures Radio. |
size | RadioSize | No | size configures Radio. |
error | boolean | No | error configures Radio. |
loading | boolean | No | loading configures Radio. |
labelPosition | RadioLabelPosition | No | labelPosition configures Radio. |
className | string | No | className configures Radio. |
children | ReactNode | No | children configures Radio. |
onChange | (event: ChangeEvent<HTMLInputElement>) => void | No | onChange configures Radio. |
| "primary" | "secondary" | "tertiary" | "accent" | "neutral" | "base" | "info" | "success" | "warning" | "error" "sm" | "md" | "lg" "left" | "right"