DocsComponentsForms
Segmented
React example follows below.
ts
import { Segmented } from "@grassroot/ui-react"; const views = [ { value: "grid", label: "Grid" }, { value: "list", label: "List" }, { value: "board", label: "Board" },]; const [value, setValue] = React.useState("grid"); <Segmented options={views} value={value} onValueChange={setValue} />ts
<script setup lang="ts">import { ref } from "vue";import { Segmented } from "@grassroot/ui-vue"; const views = [ { value: "grid", label: "Grid" }, { value: "list", label: "List" }, { value: "board", label: "Board" },]; const value = ref("grid");</script> <template> <Segmented v-model="value" :options="views" /></template>ts
import { Component, signal } from "@angular/core";import { GrassrootSegmented } from "@grassroot/ui-angular"; @Component({ selector: "app-example", standalone: true, imports: [GrassrootSegmented], template: ` <grassroot-segmented [options]="views" [value]="value()" (valueChange)="value.set($event)" /> `,})export class ExampleComponent { readonly views = [ { value: "grid", label: "Grid" }, { value: "list", label: "List" }, { value: "board", label: "Board" }, ]; readonly value = signal("grid");}ts
<script lang="ts"> import { Segmented } from "@grassroot/ui-svelte"; const views = [ { value: "grid", label: "Grid" }, { value: "list", label: "List" }, { value: "board", label: "Board" }, ]; let value = $state("grid");</script> <Segmented options={views} value={value} onValueChange={(next) => (value = next)} />ts
import { createSignal } from "solid-js";import { Segmented } from "@grassroot/ui-solid"; const views = [ { value: "grid", label: "Grid" }, { value: "list", label: "List" }, { value: "board", label: "Board" },]; export function Example() { const [value, setValue] = createSignal("grid"); return ( <> <Segmented options={views} value={value()} onValueChange={setValue} /> </> );}Installation
bash
pnpm dlx grassroot add ui/segmentedbash
npx grassroot@latest add ui/segmentedbash
yarn dlx grassroot add ui/segmentedbash
bunx grassroot add ui/segmentedAPI Reference
| Prop | Type | Default |
|---|---|---|
optionsrequired | SegmentedOption[] | — |
nameShared radio group name. Auto-generated if omitted. | string | undefined | — |
value | string | undefined | — |
defaultValue | string | undefined | — |
onValueChange | ((value: string) => void) | undefined | — |
className | string | undefined | — |