/** * Segmented (native). Row of pressable segments; the active one gets a * raised surface. No sliding layer (RN layout math) — the active * background is enough and reads cleanly. */ import { Pressable, Text, View, type ViewStyle } from "react-native"; 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; style?: ViewStyle; } const heightMap: Record = { sm: 30, md: 36 }; export function Segmented({ options, value, onChange, size = "md", fullWidth, style, }: SegmentedProps) { const { colors } = useTheme(); const h = heightMap[size]; return ( {options.map((o) => { const active = o.value === value; return ( !o.disabled && onChange(o.value)} style={{ flex: fullWidth ? 1 : undefined, justifyContent: "center", alignItems: "center", paddingHorizontal: spacing[3], borderRadius: radius.sm, backgroundColor: active ? colors.surfaceFill : "transparent", opacity: o.disabled ? 0.5 : 1, }} > {o.label} ); })} ); }