'use client';
import { ButtonHTMLAttributes } from 'react';
interface SegmentedControlOption {
value: string;
label: string;
description?: string;
disabled?: boolean;
}
interface SegmentedControlProps {
options: SegmentedControlOption[];
value: string;
onChange?: (value: string) => void;
}
export default function SegmentedControl({
options,
value,
onChange,
}: SegmentedControlProps) {
const handleSelect = (optionValue: string, optionDisabled?: boolean) => {
if (!onChange || optionDisabled) return;
if (optionValue === value) return;
onChange(optionValue);
};
return (
{options.map((option) => {
const isSelected = option.value === value;
const baseClasses =
'flex-1 min-w-[140px] px-3 py-1.5 text-xs font-medium rounded-full transition-colors text-left';
const selectedClasses = isSelected
? 'bg-primary-blue text-white'
: 'text-gray-300 hover:text-white hover:bg-charcoal-outline/80';
const disabledClasses = option.disabled
? 'opacity-50 cursor-not-allowed hover:bg-transparent hover:text-gray-300'
: '';
const buttonProps: ButtonHTMLAttributes
= {
type: 'button',
onClick: () => handleSelect(option.value, option.disabled),
'aria-pressed': isSelected,
disabled: option.disabled,
};
return (
);
})}
);
}