Files
bambuddy/frontend/src/components/MetricToggle.tsx
T
AneoPsy 5216bebca7 refactor(stats): improve Color Distribution card layout and toggle
Use MetricToggle component with new exclude prop instead of inline
buttons, default to weight-first order, and redesign chart layout
with centered donut, total label, and 2-column legend grid.
2026-03-01 03:11:28 -10:00

40 lines
1.0 KiB
TypeScript

import { useTranslation } from 'react-i18next';
export type Metric = 'weight' | 'prints' | 'time';
const METRICS: Metric[] = ['weight', 'prints', 'time'];
interface MetricToggleProps {
value: Metric;
onChange: (metric: Metric) => void;
exclude?: Metric[];
}
export function MetricToggle({ value, onChange, exclude }: MetricToggleProps) {
const { t } = useTranslation();
const labels: Record<Metric, string> = {
weight: t('stats.filamentByWeight'),
prints: t('stats.filamentByPrints'),
time: t('stats.filamentByTime'),
};
const metrics = exclude ? METRICS.filter(m => !exclude.includes(m)) : METRICS;
return (
<div className="flex gap-0.5 bg-bambu-dark rounded-lg p-0.5">
{metrics.map(m => (
<button
key={m}
onClick={() => onChange(m)}
className={`px-2 py-0.5 text-xs rounded-md transition-colors ${
value === m ? 'bg-bambu-green text-white' : 'text-bambu-gray hover:text-white'
}`}
>
{labels[m]}
</button>
))}
</div>
);
}