mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 22:27:16 +01:00
- Rename SideMenu to NavMenu with visible group title labels and selected item highlighting - Update react-zen to 0.242.0 and fix responsive breakpoints (xs -> base) - Style floating tooltips with inverted background across WorldMap, charts, and WeeklyTraffic - Add CSS variables for primary color and use IconLabel consistently - Remove stray console.log from LoadingPanel Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { Button, Icon, Text, Tooltip, TooltipTrigger } from '@umami/react-zen';
|
|
import Papa from 'papaparse';
|
|
import { useMessages } from '@/components/hooks';
|
|
import { Download } from '@/components/icons';
|
|
|
|
export function DownloadButton({
|
|
filename = 'data',
|
|
data,
|
|
}: {
|
|
filename?: string;
|
|
data?: any;
|
|
onClick?: () => void;
|
|
}) {
|
|
const { formatMessage, labels } = useMessages();
|
|
|
|
const handleClick = async () => {
|
|
downloadCsv(`${filename}.csv`, Papa.unparse(data));
|
|
};
|
|
|
|
return (
|
|
<TooltipTrigger delay={0}>
|
|
<Button variant="quiet" onClick={handleClick} isDisabled={!data || data.length === 0}>
|
|
<Icon>
|
|
<Download />
|
|
</Icon>
|
|
</Button>
|
|
<Tooltip>
|
|
<Text size="sm">{formatMessage(labels.download)}</Text>
|
|
</Tooltip>
|
|
</TooltipTrigger>
|
|
);
|
|
}
|
|
|
|
function downloadCsv(filename: string, data: any) {
|
|
const blob = new Blob([data], { type: 'text/csv' });
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = filename;
|
|
a.click();
|
|
|
|
URL.revokeObjectURL(url);
|
|
}
|