Examples
Switch a view
Use a short set of mutually exclusive view options.
ListGridMap
Project view selection
import { Segmented } from "@phuctech/ui/components/segmented";
const viewOptions = [{ value: "list", label: "List" }, { value: "grid", label: "Grid" }, { value: "map", label: "Map" }];
export function Example() {
return <Segmented label="Project view" options={viewOptions} defaultValue="list" />;
}
Controlled choice
Keep the active time period in feature state.
WeekMonthQuarter
Controlled reporting period
"use client";
import { useState } from "react";
import { Segmented } from "@phuctech/ui/components/segmented";
const periodOptions = [{ value: "week", label: "Week" }, { value: "month", label: "Month" }, { value: "quarter", label: "Quarter" }];
export function Example() {
const [period, setPeriod] = useState("month");
return <Segmented label="Reporting period" options={periodOptions} value={period} onValueChange={setPeriod} />;
}
Vertical options
Use vertical orientation for narrow side panels.
OverviewActivitySettings
Vertical workspace section
import { Segmented } from "@phuctech/ui/components/segmented";
const options = [{ value: "overview", label: "Overview" }, { value: "activity", label: "Activity" }, { value: "settings", label: "Settings" }];
export function Example() {
return <Segmented label="Workspace section" options={options} defaultValue="overview" orientation="vertical" />;
}
Try the segments
Inspect a compact time-scale selector.
DayWeekMonth
Segmented property playground
import { Segmented } from "@phuctech/ui/components/segmented";
const options = [{ value: "day", label: "Day" }, { value: "week", label: "Week" }, { value: "month", label: "Month" }];
export function Example() {
return <Segmented label="Calendar scale" options={options} defaultValue="week" />;
}
Usage
import { Segmented } from "@phuctech/ui/components/segmented";
<Segmented label="Project view" options={views} defaultValue="list" />Provide a short group of mutually exclusive options. If options need search, descriptions, or long text, use RadioGroup or Select.
API
Accessibility
Segmented uses radio roles and roving focus. Arrow keys follow the selected orientation, and each option label supplies its accessible name. Do not communicate the selected view through color alone.
Related
- RadioGroup supports richer choice layouts.
- Tabs switches between labeled content panels.