From 1ecf24b0b4ad1b330c1ac9709663b5d9844a395e Mon Sep 17 00:00:00 2001 From: Wayne Duran Date: Mon, 9 Aug 2021 10:23:22 +0800 Subject: [PATCH] feat: worksheet header --- src/components/MultiPaperPage.tsx | 20 +------ src/components/PaperPage.tsx | 19 +++++-- .../AdditionFillTheBlanksPage.tsx | 2 +- .../additionFillTheBlanks/PreviewAftb.tsx | 54 +++++++++++++++---- 4 files changed, 62 insertions(+), 33 deletions(-) diff --git a/src/components/MultiPaperPage.tsx b/src/components/MultiPaperPage.tsx index 59f1f61..ae6b4e1 100644 --- a/src/components/MultiPaperPage.tsx +++ b/src/components/MultiPaperPage.tsx @@ -1,24 +1,9 @@ -import { makeStyles } from '@material-ui/core'; import React, { ReactNode, ElementType, createElement, useState, useEffect, useRef, } from 'react'; import { usePaperOptions } from './PaperOptionsProvider'; import PaperPage from './PaperPage'; -const styles = makeStyles(() => ({ - wrapper: { - }, - curtain: { - transition: '0.3s opacity', - }, - curtainDown: { - opacity: 0, - }, - curtainUp: { - opacity: 1, - }, -})); - interface WrapperBuilder { contentWrapper?: ElementType | null; contentWrapperClassName?: string; @@ -83,13 +68,11 @@ function MultiPaperPage({ contentWrapper, contentWrapperClassName, data, builder, itemSelector, }: MultiPaperPageProps): JSX.Element { - const { curtainUp, curtainDown, curtain } = styles(); const wrapperRef = useRef(null); const { options } = usePaperOptions(); const [isReady, setIsReady] = useState(false); const [dataPages, setDataPages] = useState([data]); const [attemptsToFix, setAttemptsTofix] = useState(0); - const curtainClasses = `${curtain} ${isReady ? curtainUp : curtainDown}`; useEffect(() => { setDataPages([data]); @@ -138,13 +121,14 @@ function MultiPaperPage({ }, [dataPages, options]); return ( -
+
{ dataPages.map((dataPage, index) => ( { index === 0 ? header : null } { diff --git a/src/components/PaperPage.tsx b/src/components/PaperPage.tsx index 53bec15..a0fa61d 100644 --- a/src/components/PaperPage.tsx +++ b/src/components/PaperPage.tsx @@ -10,9 +10,11 @@ const paperPageStyles = makeStyles(() => ({ overflow: 'hidden', pageBreakBefore: 'always', breakBefore: 'always', + transition: '0.3s opacity', + opacity: 1, - '&:first-child': { - pageBreakBefore: 'avoid', + '&.not-ready': { + opacity: 0, }, '@media print': { @@ -26,6 +28,10 @@ const paperPageStyles = makeStyles(() => ({ boxShadow: 'none', margin: 0, }, + + '.print-ready &:first-child': { + pageBreakBefore: 'avoid', + }, }, content: { @@ -49,9 +55,12 @@ interface PaperPreviewProps { children: ReactNode; noFlexWrap?: boolean; pageId?: string; + ready?: boolean; } -function PaperPage({ children, noFlexWrap, pageId }: PaperPreviewProps): JSX.Element { +function PaperPage({ + children, noFlexWrap, pageId, ready = true, +}: PaperPreviewProps): JSX.Element { const { options } = usePaperOptions(); const { margin, orientation, scale, paperSize, @@ -67,10 +76,11 @@ function PaperPage({ children, noFlexWrap, pageId }: PaperPreviewProps): JSX.Ele } const dimensionStyles = paperSize.dimensionsStr(orientation); + const pageClassNames = `printable-paper ${!ready ? 'not-ready' : ''} ${classes.paper}`; return ( { return ( ({ + header: { + display: 'flex', + }, + headerName: { + flexGrow: 4, + display: 'flex', + paddingRight: '2em', + }, + label: { + flexGrow: 0, + fontWeight: 'normal', + paddingRight: '0.3em', + }, + headerDate: { + flexGrow: 2, + display: 'flex', + }, + headerBlank: { + flexGrow: 1, + borderBottom: '1px solid black', + }, + instructions: { + marginBottom: 0, + marginTop: '10mm', + fontSize: '16px', + }, heading: { textAlign: 'center', }, list: { - margin: '10mm 0 0 0', + margin: '5mm 0 0 0', padding: 0, fontSize: '20px', columnCount: 2, @@ -26,7 +52,7 @@ const pageStyles = makeStyles(() => ({ counterReset: 'problem 0', '& > li': { - padding: '8mm 8mm 8mm 6mm', + padding: '6mm 0 6mm 6mm', marginLeft: '10mm', counterIncrement: 'problem', }, @@ -55,13 +81,21 @@ const PreviewAftb = ({ <> - Addition: Fill in the Blanks - + <> +
+
+ Name: + +
+
+ Date: + +
+
+

+ Complete the addition facts by filling in the blanks. +

+ )} contentWrapper="ol" contentWrapperClassName={`${classes.list} problems`}