FPSMS-frontend
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

52 wiersze
1.3 KiB

  1. "use client";
  2. import { Card, CardContent, Typography, Stack, Button } from "@mui/material";
  3. import FileDownload from "@mui/icons-material/FileDownload";
  4. import { exportChartToXlsx } from "./exportChartToXlsx";
  5. export default function ChartCard({
  6. title,
  7. filters,
  8. children,
  9. exportFilename,
  10. exportData,
  11. }: {
  12. title: string;
  13. filters?: React.ReactNode;
  14. children: React.ReactNode;
  15. /** If provided with exportData, shows "匯出 Excel" button. */
  16. exportFilename?: string;
  17. exportData?: Record<string, unknown>[];
  18. }) {
  19. const handleExport = () => {
  20. if (exportFilename && exportData) {
  21. exportChartToXlsx(exportData, exportFilename);
  22. }
  23. };
  24. return (
  25. <Card sx={{ mb: 3 }}>
  26. <CardContent>
  27. <Stack direction="row" flexWrap="wrap" alignItems="center" gap={2} sx={{ mb: 2 }}>
  28. <Typography variant="h6" component="span">
  29. {title}
  30. </Typography>
  31. {filters}
  32. {exportFilename && exportData && (
  33. <Button
  34. size="small"
  35. variant="outlined"
  36. startIcon={<FileDownload />}
  37. onClick={handleExport}
  38. sx={{ ml: "auto" }}
  39. >
  40. 匯出 Excel
  41. </Button>
  42. )}
  43. </Stack>
  44. {children}
  45. </CardContent>
  46. </Card>
  47. );
  48. }