Skip to content

Commit

Permalink
Add timestamp to print view
Browse files Browse the repository at this point in the history
  • Loading branch information
jamdelion committed Oct 22, 2024
1 parent 48b9686 commit c547078
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions editor.planx.uk/src/components/PrintButton.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
import PrintIcon from "@mui/icons-material/Print";
import Button from "@mui/material/Button";
import { styled } from "@mui/material/styles";
import Typography from "@mui/material/Typography";
import React from "react";

const StyledPrintButton = styled(Button)(() => ({
"@media print": {
display: "none",
},
}));

const StyledTimestamp = styled(Typography)(() => ({
display: "none",
"@media print": {
display: "block",
},
}));

const PrintedAt = () => {
return (
<StyledTimestamp>
Printed at {new Date().toLocaleString("en-GB")}
</StyledTimestamp>
);
};

export const PrintButton = () => {
return (
<Button
variant="contained"
color="secondary"
startIcon={<PrintIcon />}
size="large"
onClick={() => window.print()}
>
Print this page
</Button>
<>
<StyledPrintButton
variant="contained"
color="secondary"
startIcon={<PrintIcon />}
size="large"
onClick={() => window.print()}
>
Print this page
</StyledPrintButton>

<PrintedAt />
</>
);
};

0 comments on commit c547078

Please sign in to comment.