SegmentedControl.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { cn } from '@/lib/utils'
  2. interface SegmentedControlProps<T extends string> {
  3. options: readonly { value: T; label: string }[]
  4. value: T
  5. onChange: (value: T) => void
  6. size?: 'sm' | 'md'
  7. className?: string
  8. ariaLabel?: string
  9. }
  10. /** Segmented control estilo Tabs (design.md §10.8) — rangos temporales y filtros. */
  11. export function SegmentedControl<T extends string>({
  12. options,
  13. value,
  14. onChange,
  15. size = 'md',
  16. className,
  17. ariaLabel,
  18. }: SegmentedControlProps<T>) {
  19. return (
  20. <div
  21. role="tablist"
  22. aria-label={ariaLabel}
  23. className={cn(
  24. 'inline-flex items-center gap-0.5 rounded-lg border border-border bg-elevated p-1',
  25. className,
  26. )}
  27. >
  28. {options.map((opt) => {
  29. const active = opt.value === value
  30. return (
  31. <button
  32. key={opt.value}
  33. type="button"
  34. role="tab"
  35. aria-selected={active}
  36. onClick={() => onChange(opt.value)}
  37. className={cn(
  38. 'rounded-md font-medium transition-colors duration-150',
  39. size === 'sm' ? 'h-6 px-2 text-caption' : 'h-7 px-3 text-xs',
  40. active
  41. ? 'bg-accent-soft text-accent'
  42. : 'text-text-secondary hover:bg-hover hover:text-text-primary',
  43. )}
  44. >
  45. {opt.label}
  46. </button>
  47. )
  48. })}
  49. </div>
  50. )
  51. }
  52. export const TIME_RANGE_OPTIONS = [
  53. { value: '1h', label: '1h' },
  54. { value: '24h', label: '24h' },
  55. { value: '7d', label: '7d' },
  56. { value: '30d', label: '30d' },
  57. ] as const