/* ───────────────────────────────────────────────────────────────────────── PixelSegmented — segmented control for toggling between options. ───────────────────────────────────────────────────────────────────────── */ import React, { forwardRef } from 'react'; import { Tone, Surface, Option, cn, toneMap, focusRing, surfaceClasses, useEffectiveSurface, } from '../common'; /** Public prop bag for {@link PixelSegmented}. */ export interface PixelSegmentedProps { /** Caption rendered above the segmented control. Omitted when empty. */ label?: string; /** Active option value. */ value: string; /** Segment items. */ options: Option[]; /** Fires with the new value when a segment is clicked. */ onChange: (next: string) => void; /** Disables every segment. */ disabled?: boolean; /** Visual tone for the active segment. Default: `'green'`. */ tone?: Tone; /** Surface variant. Inherits from `PxlKitSurfaceProvider` when omitted. */ surface?: Surface; /** Form-serialization name. */ name?: string; /** Marks the field as required for native form validation. */ required?: boolean; /** Accessible name for the group; use it when no visible `label` is rendered. */ 'aria-label'?: string; } export const PixelSegmented = forwardRef(function PixelSegmented( { label, value, options, onChange, disabled = false, tone = 'green', surface: surfaceProp, name, required, 'aria-label': ariaLabel, }, ref, ) { const surface = useEffectiveSurface(surfaceProp); const s = surfaceClasses(surface); const groupName = ariaLabel || label || undefined; return (
{name && } {label &&

{label}

}
{options.map((opt) => { const isActive = value === opt.value; return ( ); })}
); });