Segmented Control
Row of mutually exclusive options.
Import
Section titled “Import”import { SegmentedControl, SegmentedControlItem } from "@pelagornis/page/components";Example
Section titled “Example”The preview above renders this file. Copy it into src/components/ to start from it.
import { useState } from "react";import { SegmentedControl, SegmentedControlItem, Stack, Text } from "@pelagornis/page/components";
export default function SegmentedControlDemo() { const [view, setView] = useState("grid");
return ( <Stack gap="sizeSmall" align="center"> <SegmentedControl value={view} onValueChange={setView} aria-label="View"> <SegmentedControlItem value="grid">Grid</SegmentedControlItem> <SegmentedControlItem value="list">List</SegmentedControlItem> <SegmentedControlItem value="board">Board</SegmentedControlItem> </SegmentedControl> <Text variant="captionMd">View: {view}</Text> </Stack> );}Use in MDX
Section titled “Use in MDX”Segmented Control is composed from parts that share React state. Children written in MDX are rendered as separate islands, so the parts can’t reach each other. Put the composition in a .tsx file, like the example above, and import that file instead.
---title: Example---
import SegmentedControlExample from "../../components/SegmentedControlExample";
<SegmentedControlExample client:load />client:load hydrates the island on page load. Use client:visible for content far down the page.
Use in Markdoc
Section titled “Use in Markdoc”Markdoc tags render Astro components, and this one needs client state. Wrap the example in an .astro file that hydrates it, then register that file as a tag.
---import SegmentedControlExample from "../SegmentedControlExample";---
<SegmentedControlExample client:load />import { component, defineMarkdocConfig } from "@astrojs/markdoc/config";import starlightMarkdoc from "@astrojs/starlight-markdoc";import pageMarkdoc from "@pelagornis/page/markdoc";
export default defineMarkdocConfig({ extends: [starlightMarkdoc(), pageMarkdoc()], tags: { "segmented-control-example": { render: component("./src/components/markdoc/SegmentedControlExample.astro"), selfClosing: true, }, },});{% segmented-control-example /%}Anatomy
Section titled “Anatomy”Parts of the component and the data-refineui role each one renders.
| Part | Role |
|---|---|
root | segmented-control |
indicator | segmented-control-indicator |
item | segmented-control-item |
States
Section titled “States”States the component styles. Component states are exposed as data attributes.
| Kind | States |
|---|---|
| Pseudo | focus-visible |
Keyboard
Section titled “Keyboard”Keys the component handles when it has focus.
| Key | Action |
|---|---|
| Enter | activate |
| Space | activate |
Reference
Section titled “Reference”- RefineUI · Segmented Control for design guidance and token detail.
- Use in MDX and Use in Markdoc for the general rules.