# Segmented control

Tabs, filter or nav links on one bordered track, with a sliding pill, a badge note on a segment, an underline variant and an overflow menu.

Section: Components / Navigation
Page: https://ui.heyramzi.com/components/segmented
Import path: `@heyramzi/ui/components/segmented`

## Import

```ts
import { AnimatedTabs, SegmentedFilter } from "@heyramzi/ui/components/segmented";
import { LANGUAGE_FLAGS } from "@heyramzi/ui/components/language-flag";
```

## Usage

```svelte
<AnimatedTabs tabs={views} bind:value={tab} ariaLabel="View" />
<SegmentedFilter
  options={[
    { value: "all", label: "All" },
    { value: "open", label: "Open", count: 4 },
  ]}
  bind:value={filter}
  ariaLabel="Status"
/>
```

## Demo

```svelte
<script lang="ts">
	import { AnimatedTabs, SegmentedFilter } from "@heyramzi/ui/components/segmented";
	import { LANGUAGE_FLAGS } from "@heyramzi/ui/components/language-flag";

	const views = [
		{ value: "board", label: "Board" },
		{ value: "list", label: "List", count: 12 },
		{ value: "timeline", label: "Timeline" },
	];

	let tab = $state("board");
	let rule = $state("board");
	let filter = $state("all");
	let cycle = $state("monthly");
	let language = $state("fr");
</script>

<div class="flex flex-col items-start gap-6">
	<AnimatedTabs tabs={views} bind:value={tab} ariaLabel="View" />
	<!-- The underline variant: bare labels over a hairline, the rule travels. -->
	<AnimatedTabs tabs={views} bind:value={rule} ariaLabel="View" variant="underline" />
	<SegmentedFilter
		options={[
			{ value: "all", label: "All" },
			{ value: "open", label: "Open", count: 4 },
			{ value: "done", label: "Done" },
		]}
		bind:value={filter}
		ariaLabel="Status"
		block={false}
	/>
	<!-- A badge is a short note after the label, such as a saving. -->
	<SegmentedFilter
		options={[
			{ value: "monthly", label: "Monthly" },
			{ value: "yearly", label: "Yearly", badge: "Save 20%" },
		]}
		bind:value={cycle}
		ariaLabel="Billing"
		block={false}
	/>
	<!-- An image draws a flag before each language code. -->
	<SegmentedFilter
		options={[
			{ value: "en", label: "EN", image: LANGUAGE_FLAGS.en },
			{ value: "fr", label: "FR", image: LANGUAGE_FLAGS.fr },
		]}
		bind:value={language}
		ariaLabel="Language"
		block={false}
	/>
</div>
```

## API

### AnimatedTabs

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `tabs` | `readonly TabDef<T>[]` |  | required |
| `value` | `T` |  | bindable |
| `onValueChange` | `(value: T) => void` |  |  |
| `placement` | `"toolbar"` \| `"section"` \| `"inline"` | `"toolbar"` |  |
| `block` | `boolean` | `false` |  |
| `variant` | `"pill"` \| `"underline"` | `"pill"` |  |
| `ariaLabel` | `string` |  |  |
| `toolbar` | `import("svelte").Snippet` |  |  |
| `lead` | `import("svelte").Snippet` |  |  |
| `listWrapperClass` | `string` |  |  |
| `hideSingle` | `boolean` | `false` |  |
| `max` | `number` | `SEGMENT_MAX` |  |
| `moreLabel` | `string` |  |  |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `Tabs.Root` from `bits-ui`, except `onValueChange, value`.

### SegmentedFilter

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `options` | `readonly TabDef<T>[]` |  | required |
| `value` | `T` |  | required. bindable |
| `onValueChange` | `(value: T) => void` |  |  |
| `counts` | `Partial<Record<T, number>>` |  |  |
| `ariaLabel` | `string` |  | required |
| `block` | `boolean` | `true` | Fill the row rather than sit at its natural width. On for the list-page filter strip, off for a segment sitting in a toolbar beside others. |
| `max` | `number \| "none"` | `SEGMENT_MAX` | Objects the row may draw before its tail becomes a menu. See `collapse.ts`. `"none"` never folds. |
| `moreLabel` | `string` |  | What the menu segment says. Translate at the call site. |
| `iconOnly` | `boolean` | `false` | An option with an `image` or `icon` draws the mark alone; its label moves to `aria-label` and the title. For a cramped toolbar of well-known brand marks. |
| `class` | `string` |  |  |

### SegmentedTrack

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `fill` | `boolean` | `false` | Fill the row rather than sit at its natural width. |
| `variant` | `"pill"` \| `"underline"` | `"pill"` | `pill`, a grey track with a white thumb that slides, or `underline`, a travelling rule. |
| `class` | `string` |  |  |
| `children` | `Snippet` |  | required |
| `after` | `Snippet` |  | A last segment that isn't an item: today the overflow trigger. It's inside the track but outside the ARIA container, so a `tablist` owns only tabs. |

### SectionRuns

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `strip` | `SectionStrip` |  | required |
| `class` | `string` |  | The host row's own constraints: order, width, container queries. |

### SegmentedNav

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `items` | `readonly SegmentedNavItem[]` |  | required |
| `current` | `string` |  | required. The href that is current. Compared after trailing slashes are dropped. |
| `ariaLabel` | `string` |  | required |
| `block` | `boolean` | `false` | Fill the row rather than sit at its natural width. |
| `class` | `string` |  |  |
