Skip to content

Commit

Permalink
fix: maximum grid width was hanging past right edge of paper in print…
Browse files Browse the repository at this point in the history
… preview (#1657)

Switching to a responsive grid has changed the geometries of the items just slightly, so that in print preview - full width items would hang over the right edge of the paper (the actual print still looked ok). Solution was to reduce the width of the print grid (StaticGrid). Other changes are refactoring - using a single variable to hold the A4 landscape page width.
  • Loading branch information
jenniferarnesen authored Mar 19, 2021
1 parent 613ae75 commit 7faf5c2
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/components/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
--item-header-margin-top: 8px;
--item-header-margin-bottom: 8px;
--item-content-padding: 4px;

/* print variables */
/* for A4 landscape (297x210mm) */
/* (29.7 /2.54) * 96 pixels/inch - 20px print margin */
/* changing this number could have consequences for a multipage printout */
--a4-landscape-width-px: 1102px;
}

body {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dashboard/styles/PrintActionsBar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
display: flex;
justify-content: space-between;
width: auto;
max-width: 1102px;
max-width: var(--a4-landscape-width-px);
}

.link {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dashboard/styles/PrintDashboard.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
border-radius: 3px;
box-shadow: 0px 0px 3px 0px var(--colors-grey500);
margin-bottom: 50px;
width: 1102px;
width: var(--a4-landscape-width-px);
}

@media only screen and (max-width: 480px) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dashboard/styles/PrintInfo.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}

.divider {
width: 1102px;
width: var(--a4-landscape-width-px);;
height: 1px;
margin: var(--spacers-dp16) 0;
border: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
border-radius: 3px;
box-shadow: 0px 0px 3px 0px var(--colors-grey500);
margin-bottom: 50px;
width: 1102px;
width: var(--a4-landscape-width-px);
}

@media only screen and (max-width: 480px) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/Dashboard/styles/print.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ header.hidden {
}

.react-grid-item.PAGEBREAK {
width: 1120px !important;
width: calc(var(--a4-landscape-width-px) + 18px) !important;
border: none !important;
box-shadow: none !important;
background-color: #f4f6f8;
Expand All @@ -27,7 +27,7 @@ header.hidden {
position: absolute;
top: -3px;
left: 3px;
width: 1102px;
width: var(--a4-landscape-width-px);
height: 3px;
box-shadow: 0px 0px 3px 0px #6e7a8a;
}
Expand All @@ -37,7 +37,7 @@ header.hidden {
position: absolute;
bottom: -3px;
left: 3px;
width: 1102px;
width: var(--a4-landscape-width-px);
height: 3px;
box-shadow: 0px 0px 3px 0px #6e7a8a;
}
Expand Down
10 changes: 8 additions & 2 deletions src/components/ItemGrid/StaticGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import {
MARGIN_PX,
GRID_COLUMNS,
} from '../../modules/gridUtil'
import { A4_LANDSCAPE_WIDTH_PX } from '../../modules/printUtils'

import 'react-grid-layout/css/styles.css'
import 'react-resizable/css/styles.css'

import './styles/ItemGrid.css'

const PAGE_PADDING_PX = 24

const StaticGrid = ({
layout,
children,
Expand All @@ -34,6 +35,11 @@ const StaticGrid = ({
)
}

const style = window.getComputedStyle(document.documentElement)
const pageWidthPx = parseInt(
style.getPropertyValue('--a4-landscape-width-px').replace('px', '')
)

return (
<>
{isLoading ? (
Expand All @@ -47,7 +53,7 @@ const StaticGrid = ({
margin={MARGIN_PX}
cols={GRID_COLUMNS}
rowHeight={GRID_ROW_HEIGHT_PX}
width={A4_LANDSCAPE_WIDTH_PX}
width={pageWidthPx - PAGE_PADDING_PX}
compactType={GRID_COMPACT_TYPE}
isDraggable={false}
isResizable={false}
Expand Down
6 changes: 0 additions & 6 deletions src/modules/printUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import sortBy from 'lodash/sortBy'
import { orArray } from './util'
import { itemTypeMap } from './itemTypes'

// for A4 landscape (297x210mm)
// 794 px = (21cm / 2.54) * 96 pixels/inch
// 1122 px = 29.7 /2.54 * 96 pixels/inch
// const a4LandscapeHeightPx = 794
export const A4_LANDSCAPE_WIDTH_PX = 1102

export const getTransformYPx = elStyle => {
if (!elStyle || !elStyle.transform) {
return null
Expand Down

0 comments on commit 7faf5c2

Please sign in to comment.