Skip to content

Commit 45043a7

Browse files
committed
adding usePrint hook
1 parent b344bad commit 45043a7

File tree

11 files changed

+138
-12
lines changed

11 files changed

+138
-12
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
## v1.3.0 (2021-09-15)
2+
3+
#### Features :moneybag:
4+
5+
- [PR](https://github.com/craig1123/react-recipes/pull/55) Added usePrint hook, tests, and documenation
6+
17
## v1.2.0 (2021-09-12)
28

39
#### Features :moneybag:
410

5-
- [PR](https://github.com/craig1123/react-recipes/pull/54) Added useLocation hook. Tests + documenation as well
11+
- [PR](https://github.com/craig1123/react-recipes/pull/54) Added useLocation hook, tests, and documenation
612

713
## v1.1.0 (2020-11-25)
814

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ yarn add react-recipes
4444
| 🍐 [`useIsClient`](./docs/useIsClient.md) | isClient | - |
4545
| 🥧 [`useKeyPress`](./docs/useKeyPress.md) | keyPressed | (targetKey) |
4646
| 🍱 [`useLocalStorage`](./docs/useLocalStorage.md) | [storedValue, setValue] | (key, initialValue) |
47+
| 📍 [`useLocation`](./docs/useLocation.md) | { push, replace, pathname, search } | - |
4748
| 🍋 [`useLockBodyScroll`](./docs/useLockBodyScroll.md) | - | - |
4849
| 🍉 [`useMedia`](./docs/useMedia.md) | value | (queries, values, defaultValue) |
4950
| 🥭 [`useMultiKeyPress`](./docs/useMultiKeyPress.md) | keysPressed | (targetKey) |
5051
| 🔔 [`useNotification`](./docs/useNotification.md) | fireNotify | (title, options) |
5152
| 🥑 [`useOnClickOutside`](./docs/useOnClickOutside.md) | - | (ref, callback) |
5253
| 🥒 [`useOnlineStatus`](./docs/useOnlineStatus.md) | onlineStatus | - |
5354
| 🍿 [`usePrevious`](./docs/usePrevious.md) | previous | (value) |
55+
| 🖨 [`usePrint`](./docs/usePrint.md) | { ref, handlePrint } | (style = {}) |
5456
| 🍣 [`useScript`](./docs/useScript.md) | [loaded, error] | (src) |
5557
| 🍖 [`useSpeechRecognition`](./docs/useSpeechRecognition.md) | { supported, listen, listening, stop } | ({ onEnd, onResult, onError }) |
5658
| 🍗 [`useSpeechSynthesis`](./docs/useSpeechSynthesis.md) | { supported, speak, speaking, cancel, voices, pause, resume } | ({ onEnd, onResult, onError, onBoundary, onPause, onResume }) |
@@ -59,4 +61,3 @@ yarn add react-recipes
5961
| 🥖 [`useWindowScroll`](./docs/useWindowScroll.md) | { x, y } | - |
6062
| 🥮 [`useWindowSize`](./docs/useWindowSize.md) | { height, width } | (initialWidth, initialHeight) |
6163
| 🥝 [`useWorker`](./docs/useWorker.md) | worker instance | (scriptPath, workerOptions, attributes) |
62-
| :pushpin: [`useLocation`](./docs/useLocation.md) | { push, replace, pathname, search } | - |

__tests__/useCopyClipboard.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
21
import React from 'react';
3-
import {
4-
cleanup, fireEvent, render, act,
5-
} from '@testing-library/react';
2+
import { cleanup, fireEvent, render, act } from '@testing-library/react';
63
import useClipboard from '../src/useCopyClipboard';
74

85
afterEach(cleanup);
96

107
// mock copying to clipboard
11-
jest.mock('../utils/copyToClipboard.js', () => jest.fn(text => !!text));
12-
8+
jest.mock('../utils/copyToClipboard.js', () => jest.fn((text) => !!text));
139

1410
describe('useClipboard', () => {
1511
test('`isCopied` becomes false after `successDuration` time ellapses', () => {

__tests__/useEventListener.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import '@testing-library/dom';
66

77
import useEventListener from '../src/useEventListener';
88

9-
109
const mouseMoveEvent = { clientX: 100, clientY: 200 };
1110
let hackHandler = null;
1211

__tests__/useFullScreen.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-return-assign */
12
import React, { createRef } from 'react';
23
import { act, cleanup, renderHook } from '@testing-library/react-hooks';
34
import { fireEvent, render } from '@testing-library/react';

__tests__/usePrint.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { renderHook } from '@testing-library/react-hooks';
2+
import usePrint from '../src/usePrint';
3+
4+
describe('usePrint', () => {
5+
it('mocks window.print', () => {
6+
window.print = jest.fn();
7+
const { result } = renderHook(() => usePrint());
8+
result.current.handlePrint();
9+
expect(window.print).toBeCalled();
10+
});
11+
});

docs/useLocation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# :pushpin: `useLocation`
1+
# 📍 `useLocation`
22

33
Read and manipulate window.location
44

docs/usePrint.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 🖨 `usePrint`
2+
3+
Preview and Print any block of html
4+
5+
## Arguments
6+
7+
- `style: Object`: style to be passed to the preview
8+
9+
## Returns
10+
11+
```
12+
{
13+
ref: Ref: Click outside of this element,
14+
handlePrint: Function - will start the print preview process
15+
}
16+
```
17+
18+
## Usage
19+
20+
```jsx
21+
import { usePrint } from 'react-recipes';
22+
23+
const App = () => {
24+
const { ref, handlePrint } = usePrint();
25+
26+
return (
27+
<div ref={ref}>
28+
Hello World
29+
<button onClick={handlePrint} type="button">
30+
Print This Block
31+
</button>
32+
</div>
33+
);
34+
};
35+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-recipes",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "A React Hooks utility library containing popular customized hooks",
55
"author": "@craig1123",
66
"sideEffects": false,

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ export { default as useInterval } from './useInterval';
1414
export { default as useIsClient } from './useIsClient';
1515
export { default as useKeyPress } from './useKeyPress';
1616
export { default as useLocalStorage } from './useLocalStorage';
17+
export { default as useLocation } from './useLocation';
1718
export { default as useLockBodyScroll } from './useLockBodyScroll';
1819
export { default as useMedia } from './useMedia';
1920
export { default as useMultiKeyPress } from './useMultiKeyPress';
2021
export { default as useNotification } from './useNotification';
2122
export { default as useOnClickOutside } from './useOnClickOutside';
2223
export { default as useOnlineStatus } from './useOnlineStatus';
2324
export { default as usePrevious } from './usePrevious';
25+
export { default as usePrint } from './usePrint';
2426
export { default as useScript } from './useScript';
2527
export { default as useSpeechRecognition } from './useSpeechRecognition';
2628
export { default as useSpeechSynthesis } from './useSpeechSynthesis';
@@ -29,4 +31,3 @@ export { default as useWhyDidYouUpdate } from './useWhyDidYouUpdate';
2931
export { default as useWindowScroll } from './useWindowScroll';
3032
export { default as useWindowSize } from './useWindowSize';
3133
export { default as useWorker } from './useWorker';
32-
export { default as useLocation } from './useLocation';

0 commit comments

Comments
 (0)