({
items,
value,
onChange
}: SegmentedControlProps)
| 10 | }; |
| 11 | |
| 12 | export function SegmentedControl({ |
| 13 | items, |
| 14 | value, |
| 15 | onChange |
| 16 | }: SegmentedControlProps) { |
| 17 | const id = useId(); |
| 18 | |
| 19 | return ( |
| 20 | <div className="relative p-0.75 rounded-[0.6rem] border bg-gray-100 border-[#EDEDED] dark:border-gray-800 flex text-sm dark:bg-gray-900"> |
| 21 | {items.map(item => ( |
| 22 | <button |
| 23 | key={item.value} |
| 24 | type="button" |
| 25 | onClick={() => onChange(item.value)} |
| 26 | className={`relative z-10 px-2.5 py-1.5 rounded-lg transition-colors duration-200 cursor-pointer ${ |
| 27 | value === item.value |
| 28 | ? "text-[#1F2937] dark:text-white/85" |
| 29 | : "text-[#6B7280] hover:text-gray-800 dark:hover:text-gray-300" |
| 30 | }`} |
| 31 | > |
| 32 | {value === item.value && ( |
| 33 | <motion.div |
| 34 | layoutId={`segment-${id}`} |
| 35 | className="absolute inset-0 bg-white dark:bg-gray-950 rounded-lg shadow-tab-active -z-10" |
| 36 | initial={false} |
| 37 | transition={{ |
| 38 | type: "spring", |
| 39 | stiffness: 500, |
| 40 | damping: 40 |
| 41 | }} |
| 42 | /> |
| 43 | )} |
| 44 | <span className="relative">{item.label}</span> |
| 45 | </button> |
| 46 | ))} |
| 47 | </div> |
| 48 | ); |
| 49 | } |
nothing calls this directly
no test coverage detected