CLI previewInstall commands shown on this site are not released yet.

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/segmented
bash
npx grassroot@latest add ui/segmented
bash
yarn dlx grassroot add ui/segmented
bash
bunx grassroot add ui/segmented

API Reference

SegmentedProps
PropTypeDefault
optionsrequiredSegmentedOption[]
nameShared radio group name. Auto-generated if omitted.string | undefined
valuestring | undefined
defaultValuestring | undefined
onValueChange((value: string) => void) | undefined
classNamestring | undefined