MetricToggle.tsx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { useTranslation } from 'react-i18next';
  2. export type Metric = 'weight' | 'prints' | 'time';
  3. const METRICS: Metric[] = ['weight', 'prints', 'time'];
  4. interface MetricToggleProps {
  5. value: Metric;
  6. onChange: (metric: Metric) => void;
  7. exclude?: Metric[];
  8. }
  9. export function MetricToggle({ value, onChange, exclude }: MetricToggleProps) {
  10. const { t } = useTranslation();
  11. const labels: Record<Metric, string> = {
  12. weight: t('stats.filamentByWeight'),
  13. prints: t('stats.filamentByPrints'),
  14. time: t('stats.filamentByTime'),
  15. };
  16. const metrics = exclude ? METRICS.filter(m => !exclude.includes(m)) : METRICS;
  17. return (
  18. <div className="flex gap-0.5 bg-bambu-dark rounded-lg p-0.5">
  19. {metrics.map(m => (
  20. <button
  21. key={m}
  22. onClick={() => onChange(m)}
  23. className={`px-2 py-0.5 text-xs rounded-md transition-colors ${
  24. value === m ? 'bg-bambu-green text-white' : 'text-bambu-gray hover:text-white'
  25. }`}
  26. >
  27. {labels[m]}
  28. </button>
  29. ))}
  30. </div>
  31. );
  32. }