'use client'; import { useRef, useEffect, useState } from 'react'; /** * SegmentedControl - A switch-style tab component following Liquid Glass design */ interface SegmentedControlProps { options: { label: string; value: T }[]; value: T; onChange: (value: T) => void; className?: string; } export function SegmentedControl({ options, value, onChange, className = '', }: SegmentedControlProps) { const containerRef = useRef(null); const [indicatorStyle, setIndicatorStyle] = useState({ left: 0, width: 0 }); useEffect(() => { const updateIndicator = () => { if (!containerRef.current) return; const activeElement = containerRef.current.querySelector( `[data-value="${value}"]` ) as HTMLElement; if (activeElement) { setIndicatorStyle({ left: activeElement.offsetLeft, width: activeElement.offsetWidth, }); } }; updateIndicator(); // Update on window resize as well window.addEventListener('resize', updateIndicator); return () => window.removeEventListener('resize', updateIndicator); }, [value, options]); return (
{/* Sliding Indicator */}
{/* Segment Buttons */} {options.map((option) => ( ))}
); }