mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-17 19:36:28 +02:00
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.
40 lines
1.0 KiB
TypeScript
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>
|
|
);
|
|
}
|