/** * Segmented (web). A compact single-select control — a row of segments * with one active. For 2–4 mutually exclusive views (Review / Pack, * Edit / Score / Preview, theme mode). Sliding highlight tracks the * selection. * * */ import { type CSSProperties } from "react"; import { useTheme } from "@plyxui/styles"; import { radius, spacing } from "@plyxui/core"; export type SegmentedSize = "sm" | "md"; export interface SegmentedOption { label: string; value: T; disabled?: boolean; } export interface SegmentedProps { options: SegmentedOption[]; value: T; onChange: (value: T) => void; size?: SegmentedSize; fullWidth?: boolean; className?: string; style?: CSSProperties; } const heightMap: Record = { sm: 30, md: 36 }; export function Segmented({ options, value, onChange, size = "md", fullWidth, className, style, }: SegmentedProps) { const { colors } = useTheme(); const idx = Math.max(0, options.findIndex((o) => o.value === value)); const h = heightMap[size]; return (
{/* sliding highlight */} {options.map((o) => { const active = o.value === value; return ( ); })}
); }