Add checkbox for one datacard per page

This commit is contained in:
NilsUeter
2023-05-07 21:35:00 +02:00
parent b11c1c64bc
commit a9f5c71501
3 changed files with 37 additions and 14 deletions
+14 -1
View File
@@ -8,6 +8,7 @@ import Demo1 from "./assets/Demo1.png";
function App() { function App() {
const [error, setError] = useState(); const [error, setError] = useState();
const [roster, setRoster] = useState(); const [roster, setRoster] = useState();
const [onePerPage, setOnePerPage] = useState(false);
const uploadRef = useRef(); const uploadRef = useRef();
async function handleFileSelect(event) { async function handleFileSelect(event) {
const files = event?.target?.files; const files = event?.target?.files;
@@ -129,10 +130,22 @@ function App() {
Print roster Print roster
</button> </button>
</div> </div>
<div
className="print-display-none"
style={{ display: roster ? "" : "none", width: "100%" }}
>
<label style={{ display: "flex", alignItems: "center", gap: 4 }}>
<input
type="checkbox"
onChange={(e) => setOnePerPage(e.target.checked)}
/>
One Datacard per Page when printing
</label>
</div>
<div className="print-display-none" style={{ color: "red" }}> <div className="print-display-none" style={{ color: "red" }}>
{error} {error}
</div> </div>
<Roster roster={roster} /> <Roster roster={roster} onePerPage={onePerPage} />
<button <button
className="print-display-none" className="print-display-none"
style={{ display: roster ? "none" : "" }} style={{ display: roster ? "none" : "" }}
+15 -9
View File
@@ -4,7 +4,7 @@ import rangedIcon from "./assets/rangedIcon.png";
import { Arrow, wavyLine } from "./assets/icons"; import { Arrow, wavyLine } from "./assets/icons";
import { Weapons } from "./Weapons"; import { Weapons } from "./Weapons";
export const Roster = ({ roster }) => { export const Roster = ({ roster, onePerPage }) => {
if (!roster) { if (!roster) {
return null; return null;
} }
@@ -21,6 +21,7 @@ export const Roster = ({ roster }) => {
}} }}
> >
<div <div
className="print-display-none"
style={{ style={{
backgroundColor: "var(--primary-color)", backgroundColor: "var(--primary-color)",
color: "#fff", color: "#fff",
@@ -34,7 +35,7 @@ export const Roster = ({ roster }) => {
{name} [{cost.commandPoints} CP] {name} [{cost.commandPoints} CP]
</div> </div>
{forces.map((force, index) => ( {forces.map((force, index) => (
<Force key={index} force={force} /> <Force key={index} force={force} onePerPage={onePerPage} />
))} ))}
</div> </div>
); );
@@ -87,7 +88,7 @@ const getPrimaryColor = (catalog) => {
} }
}; };
const Force = ({ force }) => { const Force = ({ force, onePerPage }) => {
const { units, rules, catalog } = force; const { units, rules, catalog } = force;
return ( return (
@@ -97,14 +98,19 @@ const Force = ({ force }) => {
}} }}
> >
{units.map((unit, index) => ( {units.map((unit, index) => (
<Unit key={index} unit={unit} catalog={catalog} /> <Unit
key={index}
unit={unit}
catalog={catalog}
onePerPage={onePerPage}
/>
))} ))}
<ForceRules rules={rules} /> <ForceRules rules={rules} onePerPage={onePerPage} />
</div> </div>
); );
}; };
const Unit = ({ unit, catalog }) => { const Unit = ({ unit, catalog, onePerPage }) => {
let { let {
name, name,
weapons, weapons,
@@ -145,7 +151,7 @@ const Unit = ({ unit, catalog }) => {
return ( return (
<div <div
className="avoid-page-break" className={"avoid-page-break " + (onePerPage ? "page-break" : "")}
style={{ style={{
fontWeight: 500, fontWeight: 500,
border: "2px solid var(--primary-color)", border: "2px solid var(--primary-color)",
@@ -773,10 +779,10 @@ const getSpellClassNames = (spells, index) => {
return classes.join(" "); return classes.join(" ");
}; };
const ForceRules = ({ rules }) => { const ForceRules = ({ rules, onePerPage }) => {
return ( return (
<div <div
className="avoid-page-break" className={"avoid-page-break " + (onePerPage ? "page-break" : "")}
style={{ style={{
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
+8 -4
View File
@@ -153,16 +153,20 @@ button:focus-visible {
background-color: #d0d1d3; background-color: #d0d1d3;
} }
.avoid-page-break {
break-inside: avoid;
}
.page-break {
break-before: page;
}
@media print { @media print {
.print-display-none, .print-display-none,
.print-display-none > * { .print-display-none > * {
display: none; display: none;
} }
.avoid-page-break {
break-inside: avoid;
}
#root { #root {
min-width: 1000px; min-width: 1000px;
} }