Skip to content

Commit

Permalink
feat: Add print button for content
Browse files Browse the repository at this point in the history
  • Loading branch information
freshavocado7 committed Apr 12, 2024
1 parent 9b884a8 commit 76077f6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
35 changes: 31 additions & 4 deletions frontend/src/components/InstanceView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import React, { useEffect, useRef, useState } from "react";
import { SVGDisplay } from "./SVGDisplay";
import { Spinner } from "./Spinner";
import { Button } from "./Button";

export const InstanceView = ({ templateName, objectID, endpoint }) => {
const [details, setDetails] = useState([]);
const [loading, setLoading] = useState(true);
const contentRef = useRef(null);
const [isHovering, setIsHovering] = useState(false);

useEffect(() => {
setLoading(true);
Expand Down Expand Up @@ -41,7 +43,8 @@ export const InstanceView = ({ templateName, objectID, endpoint }) => {
});
setDetails(contentItems);
setLoading(false);
if (contentRef.current) contentRef.current.scrollIntoView();
if (contentRef.current)
contentRef.current.scrollIntoView();
})
.catch((error) => {
setLoading(false);
Expand All @@ -57,16 +60,40 @@ export const InstanceView = ({ templateName, objectID, endpoint }) => {
return (
<div
ref={contentRef}
className="html-content bg-white shadow-lg dark:shadow-white text-gray-700 mx-auto md:my-8 p-8 md:w-[210mm] max-w-full max-h-full overflow-auto print:shadow-none print:m-0 print:p-0 print:bg-transparent"
className={`html-content bg-white shadow-lg dark:shadow-white text-gray-700 mx-auto md:my-8 p-8 md:w-[210mm] max-w-full max-h-full overflow-auto print:shadow-none print:m-0 print:p-0 print:bg-transparent relative box-border border-4 ${
isHovering
? "border-grey-700 shadow-md z-50"
: "border-transparent"
}`}
onMouseEnter={() => setIsHovering(true)}
onMouseLeave={() => setIsHovering(false)}
>
{isHovering && (
<Button
style={{
position: "absolute",
top: 0,
right: 0,
margin: "1rem",
padding: "0.5rem",
}}
onClick={() => window.print()}
>
Print Content
</Button>
)}
{details.map((item, idx) => {
if (item.type === "SVGDisplay") {
return <SVGDisplay key={idx} content={item.content} />;
return (
<SVGDisplay key={idx} content={item.content} />
);
} else {
return (
<div
key={idx}
dangerouslySetInnerHTML={{ __html: item.content }}
dangerouslySetInnerHTML={{
__html: item.content,
}}
/>
);
}
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ ul {
}
.print\\:hidden {
display: none !important;
}
}
.html-content {
border: none !important;
box-shadow: none !important;
}
@page { margin: 15mm; }
}

0 comments on commit 76077f6

Please sign in to comment.