Segmented
Segmented switches between a small number of sibling modes.
@duskmoon-dev/components/segmented 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.
Segmented is most often configured through `options`, `value`, `defaultValue`, `onChange`.
Renders string options with DuskMoon segmented classes
Feature Demos
Feature demos are authored for the component page, then supplemented with behavior scenarios from the component test coverage.
Basic usage
Import the component stylesheet and Segmented from its package subpath, then render it with the core props.
import "@duskmoon-dev/components/styles.css";
import { Segmented } from "@duskmoon-dev/components/segmented";
export function Example() {
return (<Segmented
options={["Overview", "Usage", "API"]}
defaultValue="Usage"
size="lg"
/>);
} Renders string options with DuskMoon segmented classes
test-backedSegmented scenario from the component test coverage: renders string options with duskmoon segmented classes.
import "@duskmoon-dev/components/styles.css";
import { Segmented } from "@duskmoon-dev/components/segmented";
export function SegmentedRendersStringOptionsWithDemo() {
return (<Segmented
options={["Overview", "Usage", "API"]}
defaultValue="Usage"
size="lg"
/>);
} Supports object options and default selection
test-backedSegmented scenario from the component test coverage: supports object options and default selection.
import "@duskmoon-dev/components/styles.css";
import { Segmented } from "@duskmoon-dev/components/segmented";
export function SegmentedSupportsObjectOptionsAndDemo() {
return (<Segmented
options={["Overview", "Usage", "API"]}
defaultValue="Usage"
size="lg"
/>);
} Calls onChange with selected value
test-backedSegmented scenario from the component test coverage: calls onchange with selected value.
import "@duskmoon-dev/components/styles.css";
import { Segmented } from "@duskmoon-dev/components/segmented";
export function SegmentedCallsOnChangeWithSelectedDemo() {
return (<Segmented
options={["Overview", "Usage", "API"]}
defaultValue="Usage"
size="lg"
/>);
} Supports className, block, size, and disabled
test-backedSegmented scenario from the component test coverage: supports classname, block, size, and disabled.
import "@duskmoon-dev/components/styles.css";
import { Segmented } from "@duskmoon-dev/components/segmented";
export function SegmentedSupportsClassNameBlockSizeDemo() {
return (<Segmented
options={["Overview", "Usage", "API"]}
defaultValue="Usage"
size="lg"
/>);
} Forwards root ref
test-backedSegmented scenario from the component test coverage: forwards root ref.
import "@duskmoon-dev/components/styles.css";
import { Segmented } from "@duskmoon-dev/components/segmented";
export function SegmentedForwardsRootRefDemo() {
return (<Segmented
options={["Overview", "Usage", "API"]}
defaultValue="Usage"
size="lg"
/>);
} Theme aware
Docs previews inherit the DuskMoon data-theme value. Use the header switch to compare light and dark rendering.
<div data-theme="sunshine">
<Segmented
options={["Overview", "Usage", "API"]}
defaultValue="Usage"
size="lg"
/>
</div>
<div data-theme="moonlight">
<Segmented
options={["Overview", "Usage", "API"]}
defaultValue="Usage"
size="lg"
/>
</div> API
The API reference below lists every parsed exported type or interface for Segmented. Start with `options`, `value`, `defaultValue`, `onChange` for common usage.
packages/components/src/components/segmented/Segmented.types.ts
Scenarios: packages/components/src/components/segmented/Segmented.test.tsx | Prop | Type | Required | Description |
|---|---|---|---|
options | SegmentedOption[] | Yes | options configures Segmented. |
value | SegmentedValue | No | value configures Segmented. |
defaultValue | SegmentedValue | No | defaultValue configures Segmented. |
onChange | (value: SegmentedValue) => void | No | onChange configures Segmented. |
disabled | boolean | No | disabled configures Segmented. |
block | boolean | No | block configures Segmented. |
size | SegmentedSize | No | size configures Segmented. |
| Prop | Type | Required | Description |
|---|---|---|---|
label | ReactNode | Yes | label configures Segmented. |
value | SegmentedValue | Yes | value configures Segmented. |
icon | ReactNode | No | icon configures Segmented. |
disabled | boolean | No | disabled configures Segmented. |
className | string | No | className configures Segmented. |
string | number "sm" | "md" | "lg" SegmentedValue | SegmentedOptionObject