Skip to content
This repository was archived by the owner on Jan 4, 2024. It is now read-only.

Commit 97ec5c4

Browse files
authored
Print page break (#123)
* fix docs serve in start task * rename test root components * add in prettier config * update print utility snapshots * add print page break component and styling
1 parent b950f7c commit 97ec5c4

File tree

15 files changed

+108
-11
lines changed

15 files changed

+108
-11
lines changed

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "es5"
5+
}

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
_The format of this document is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)._
22

3+
## [v1.3.0](https://github.com/RaspberryPiFoundation/Bits/compare/v1.2.2...v1.3.0) - 2019-11-06
4+
5+
### Added
6+
7+
- `PrintPageBreak` component
8+
- `c-print-page-break` styling
9+
- `.prettierrc` config
10+
11+
### Fixed
12+
13+
- `NoPrint` and `PrintOnly` test root components and snapshots
14+
- Changed `docs:serve` to `docs` in npm `start` task
15+
316
## [v1.2.2](https://github.com/RaspberryPiFoundation/Bits/compare/v1.2.1...v1.2.2) - 2019-10-14
417

518
### Changed

lib/Bits.css

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Author: The Raspberry Pi Foundation
77
Author URI: https://raspberrypi.org
8-
Version: 1.2.2
8+
Version: 1.3.0
99
*/
1010

1111

@@ -1129,6 +1129,14 @@ strong {
11291129
box-shadow: 0 0 0.3rem 0 rgba(0, 0, 0, 0.25);
11301130
padding: 10px; }
11311131

1132+
@media screen {
1133+
.c-print-page-break {
1134+
display: none !important; } }
1135+
1136+
@media print {
1137+
.c-print-page-break {
1138+
page-break-before: always; } }
1139+
11321140

11331141

11341142

lib/Bits.min.css

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Bits.min.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type": "git",
1111
"url": "https://github.com/RaspberryPiFoundation/Bits.git"
1212
},
13-
"version": "1.2.2",
13+
"version": "1.3.0",
1414
"main": "lib/index.js",
1515
"files": [
1616
"lib",
@@ -28,7 +28,7 @@
2828
"prepublishOnly": "npm run build",
2929
"rollup": "rollup -c",
3030
"rollup:watch": "rollup -c -w",
31-
"start": "npm-run-all rollup:watch gulp:watch docs:serve",
31+
"start": "npm-run-all rollup:watch gulp:watch docs",
3232
"test": "jest --env=jsdom --notify --watch",
3333
"test-coverage": "jest --env=jsdom --coverage",
3434
"docs": "styleguidist server",

src/components/NoPrint/NoPrint.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let noPrint
77
const children = 'Whatever'
88
const className = 'some-extra-class-name'
99

10-
describe('<Slice />', () => {
10+
describe('<NoPrint />', () => {
1111
describe('Renders...', () => {
1212
beforeEach(() => {
1313
noPrint = shallow(<NoPrint>{children}</NoPrint>)

src/components/NoPrint/__snapshots__/NoPrint.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`<Slice /> Renders... matches its snapshot 1`] = `
3+
exports[`<NoPrint /> Renders... matches its snapshot 1`] = `
44
<Base
55
className="u-no-print"
66
tagName="div"

src/components/PrintOnly/PrintOnly.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let printOnly
77
const children = 'Whatever'
88
const className = 'some-extra-class-name'
99

10-
describe('<Slice />', () => {
10+
describe('<PrintOnly />', () => {
1111
describe('Renders...', () => {
1212
beforeEach(() => {
1313
printOnly = shallow(<PrintOnly>{children}</PrintOnly>)
@@ -25,7 +25,7 @@ describe('<Slice />', () => {
2525
describe('With classNames', () => {
2626
it('adds the correct className', () => {
2727
printOnly = shallow(
28-
<PrintOnly className={className}>{children}</PrintOnly>,
28+
<PrintOnly className={className}>{children}</PrintOnly>
2929
)
3030
expect(printOnly.find('.u-print-only')).toHaveClassName(className)
3131
})

src/components/PrintOnly/__snapshots__/PrintOnly.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`<Slice /> Renders... matches its snapshot 1`] = `
3+
exports[`<PrintOnly /> Renders... matches its snapshot 1`] = `
44
<Base
55
className="u-print-only"
66
tagName="div"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@media screen {
2+
.c-print-page-break {
3+
display: none !important;
4+
}
5+
}
6+
7+
@media print {
8+
.c-print-page-break {
9+
page-break-before: always;
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { shallow } from 'enzyme'
2+
import PrintPageBreak from '../PrintPageBreak'
3+
import React from 'react'
4+
5+
let printPageBreak
6+
7+
const className = 'some-extra-class-name'
8+
9+
describe('<PrintPageBreak />', () => {
10+
describe('Renders...', () => {
11+
beforeEach(() => {
12+
printPageBreak = shallow(<PrintPageBreak />)
13+
})
14+
15+
it('without crashing', () => {
16+
expect(printPageBreak.find('.c-print-page-break')).toExist()
17+
})
18+
19+
it('matches its snapshot', () => {
20+
expect(printPageBreak).toMatchSnapshot()
21+
})
22+
})
23+
24+
describe('With classNames', () => {
25+
it('adds the correct className', () => {
26+
printPageBreak = shallow(<PrintPageBreak className={className} />)
27+
expect(printPageBreak.find('.c-print-page-break')).toHaveClassName(
28+
className
29+
)
30+
})
31+
})
32+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<PrintPageBreak /> Renders... matches its snapshot 1`] = `
4+
<Base
5+
className="c-print-page-break"
6+
tagName="div"
7+
/>
8+
`;
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Base } from 'react-iotacss'
2+
import classnames from 'classnames'
3+
import PropTypes from 'prop-types'
4+
import React from 'react'
5+
6+
/**
7+
* Places a component, hidden from display which forces a page break before it when printing
8+
*/
9+
export const PrintPageBreak = ({ children, className, ...props }) => {
10+
const classNames = classnames(className, 'c-print-page-break')
11+
12+
return <Base className={classNames} {...props} />
13+
}
14+
15+
PrintPageBreak.propTypes = {
16+
className: PropTypes.string,
17+
}
18+
19+
export default PrintPageBreak

src/styles/components/index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@import '../../components/Link/Link';
88
@import '../../components/Pagination/Pagination';
99
@import '../../components/Panel/Panel';
10+
@import '../../components/PrintPageBreak/PrintPageBreak';
1011
@import '../../components/Slice/Slice';
1112
@import '../../components/Wysiwyg/Wysiwyg';
1213

0 commit comments

Comments
 (0)