mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
## Problem We don't have any one defined way of displaying segmented controls. This PR looks at unifying and using underlying primtives to put something together. Open to comment. ## Solution Improves upon the shadcn toggle group, which has a specific use case. ## Review instructions Run the design system and find "Segmented Controls" in the Fragment Components. Test [here](https://design-system-git-feat-button-group-component-draft-supabase.vercel.app/design-system/docs/components/toggle-group#segmented). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary * **New Features** * Added segmented toggle groups with default, text, outline, and primary tones. * Single-select groups display a sliding selection indicator; multi-select groups highlight selected items individually. * Groups can keep the selected option active; deselection is enabled by default. * Added examples for tone variations and a status filter. * **Documentation** * Updated segmented-control guidance and props tables, including usage recommendations, accessibility labeling, and filter options. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
33 lines
950 B
TypeScript
33 lines
950 B
TypeScript
'use client'
|
|
|
|
import * as React from 'react'
|
|
import { ToggleGroup, ToggleGroupItem } from 'ui'
|
|
|
|
const TONES = ['text', 'outline', 'primary'] as const
|
|
|
|
export default function ToggleGroupSegmented() {
|
|
const [view, setView] = React.useState('data')
|
|
|
|
return (
|
|
<div className="flex flex-col gap-4">
|
|
{TONES.map((tone) => (
|
|
<div key={tone} className="flex items-center gap-4">
|
|
<span className="w-16 shrink-0 text-xs text-foreground-lighter">{tone}</span>
|
|
<ToggleGroup
|
|
type="single"
|
|
variant="segmented"
|
|
tone={tone}
|
|
value={view}
|
|
onValueChange={setView}
|
|
allowDeselect={false}
|
|
aria-label={`Table view (${tone})`}
|
|
>
|
|
<ToggleGroupItem value="data">Data</ToggleGroupItem>
|
|
<ToggleGroupItem value="definition">Definition</ToggleGroupItem>
|
|
</ToggleGroup>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)
|
|
}
|