Segmented
A switch between a few views or modes of the same thing.
import { Segmented } from "@forgeron/ui";import { Segmented } from "@forgeron/ui";
import { useState } from "react";
export default function Views() {
const [view, setView] = useState("board");
return (
<Segmented
label="View"
value={view}
onChange={setView}
options={[
{ value: "list", label: "List" },
{ value: "board", label: "Board" },
{ value: "calendar", label: "Calendar" },
]}
/>
);
}import { GridViewIcon, Menu01Icon } from "@forgeron/icons";
import { Icon, Segmented } from "@forgeron/ui";
import { useState } from "react";
export default function Icons() {
const [view, setView] = useState("grid");
return (
<Segmented
label="Layout"
iconOnly
value={view}
onChange={setView}
options={[
{ value: "grid", label: <Icon icon={GridViewIcon} size={12} />, ariaLabel: "Grid" },
{ value: "list", label: <Icon icon={Menu01Icon} size={12} />, ariaLabel: "List" },
]}
/>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Names the group, e.g. View. |
options | { value, label, ariaLabel? }[] | — | The segments. |
value | string | — | The chosen one. |
onChange | (value: string) => void | — | On a click. |
iconOnly | boolean | — | Square segments for icons. |
className | string | — | Extra classes. |