Skip to content

Commit dff5a26

Browse files
authored
Merge pull request #65 from michaeldzjap/feature/update-project
Update project
2 parents 6545b47 + 60aaeed commit dff5a26

22 files changed

+857
-1410
lines changed

.eslintignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 81 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ jobs:
99
os: [ubuntu-latest]
1010
node-version: [20.x, 21.x]
1111
steps:
12-
- name: Check out repository code
13-
uses: actions/checkout@v3
14-
- name: Use Node.js ${{ matrix.node-version }}
15-
uses: actions/setup-node@v3
16-
with:
17-
node-version: ${{ matrix.node-version }}
18-
cache: 'npm'
19-
- name: Install
20-
run: npm ci
21-
- name: Lint
22-
run: npm run lint
23-
- name: Build
24-
run: npm run prod
25-
- name: Test
26-
run: npm run test
27-
- name: Upload coverage report
28-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.node-version == '21.x' }}
29-
uses: codecov/codecov-action@v3
30-
- name: SonarCloud Scan
31-
if: ${{ matrix.os == 'ubuntu-latest' && matrix.node-version == '21.x' }}
32-
uses: sonarsource/sonarcloud-github-action@master
33-
env:
34-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
12+
- name: Check out repository code
13+
uses: actions/checkout@v3
14+
- name: Use Node.js ${{ matrix.node-version }}
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version: ${{ matrix.node-version }}
18+
cache: 'npm'
19+
- name: Install
20+
run: npm ci
21+
- name: Lint
22+
run: npm run lint
23+
- name: Build
24+
run: npm run prod
25+
- name: Test
26+
run: npm run test
27+
- name: Upload coverage report
28+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.node-version == '21.x' }}
29+
uses: codecov/codecov-action@v3
30+
- name: SonarCloud Scan
31+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.node-version == '21.x' }}
32+
uses: sonarsource/sonarcloud-github-action@master
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.prettierrc.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,29 @@
88
[![License](https://img.shields.io/npm/l/react-signature-pad-wrapper.svg)](https://github.com/michaeldzjap/react-signature-pad-wrapper/blob/master/LICENSE)
99

1010
# react-signature-pad-wrapper
11+
1112
A React wrapper for [signature pad](https://github.com/szimek/signature_pad).
1213

1314
## Installation
15+
1416
This package is available through npm:
17+
1518
```
1619
npm install --save react-signature-pad-wrapper
1720
```
1821

1922
## Usage
20-
This package implements exactly the same interface as the original *signature_pad* package and adds a couple of extra features that make responsive behaviour a little easier to deal with. For a complete overview of the available options and callables see the documentation for [signature pad](https://github.com/szimek/signature_pad).
23+
24+
This package implements exactly the same interface as the original _signature_pad_ package and adds a couple of extra features that make responsive behaviour a little easier to deal with. For a complete overview of the available options and callables see the documentation for [signature pad](https://github.com/szimek/signature_pad).
2125

2226
Import the component like (ES6):
27+
2328
```javascript
24-
import SignaturePad from 'react-signature-pad-wrapper'
29+
import SignaturePad from 'react-signature-pad-wrapper';
2530
```
2631

2732
Options may be passed as a component property during initialization:
33+
2834
```javascript
2935
...
3036
render() {
@@ -34,14 +40,17 @@ render() {
3440
```
3541

3642
or they can be set during runtime:
43+
3744
```javascript
3845
...
3946
render() {
4047
return <SignaturePad ref={this.signaturePadRef} />;
4148
}
4249
...
4350
```
51+
4452
then from somewhere else in the code (assuming the ref is defined):
53+
4554
```javascript
4655
// Call an instance method
4756
this.signaturePad.clear();
@@ -54,7 +63,9 @@ this.signaturePad.penColor = 'rgb(66, 133, 244)';
5463
```
5564

5665
## Responsiveness
66+
5767
The HTML canvas object sucks when it comes to responsiveness. The approach taken with this plugin is to use a fixed size canvas when a height and width (in pixels) is explicitly passed in as a component property:
68+
5869
```javascript
5970
...
6071
render() {
@@ -64,28 +75,35 @@ render() {
6475
```
6576

6677
If you want the component to be responsive, simply ommit the width and height property:
78+
6779
```javascript
6880
...
6981
render() {
7082
return <SignaturePad />;
7183
}
7284
...
7385
```
86+
7487
The canvas width and height will now be updated whenever the window is resized (using a debounced handler). Changing the width and height properties of a HTML canvas object will erase its current content.
7588

7689
If you'd like to keep what is currently drawn on the canvas you can pass a `redrawOnResize` property to the component and set it to `true` (`redrawOnResize` is `false` by default):
90+
7791
```javascript
7892
...
7993
render() {
8094
return <SignaturePad redrawOnResize />;
8195
}
8296
...
8397
```
98+
8499
This will save the current canvas content to a base64 data string before performing the resize operation and load it in the canvas right after the resize operation finishes. **Note**: the repeated saving and loading of image data when resizing often will degrade the quality rapidly. There is no easy solution around this unfortunately. Resampling the image data is imagined to help significantly, but this is a rather costly operation in general and not something you would ideally do with JavaScript in the browser on every resize event (even if throttled/debounced).
85100

86101
## Example
102+
87103
This project includes a simple example that demonstrates a responsive sketch pad. To build the example:
104+
88105
```shell
89106
cd example && npm run build
90107
```
108+
91109
Then open `example/index.html` in a browser of your choice.

__tests__/.eslintrc.json

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
{
2-
"env": {
3-
"node": true,
4-
"jest/globals": true
5-
},
6-
"plugins": [
7-
"jest"
8-
],
9-
"extends": [
10-
"plugin:jest/recommended",
11-
"plugin:jest-dom/recommended"
12-
]
13-
}
14-
2+
"env": {
3+
"node": true,
4+
"jest/globals": true
5+
},
6+
"plugins": ["jest"],
7+
"extends": ["plugin:jest/recommended", "plugin:jest-dom/recommended"]
8+
}

codecov.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
ignore:
2-
- "__tests__/**/*"
3-
- "example/**/*"
2+
- '__tests__/**/*'
3+
- 'example/**/*'

eslint.config.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @ts-check
2+
3+
import eslint from '@eslint/js';
4+
import prettierConfig from 'eslint-config-prettier';
5+
import jest from 'eslint-plugin-jest';
6+
import jestDom from 'eslint-plugin-jest-dom';
7+
import react from 'eslint-plugin-react';
8+
import globals from 'globals';
9+
import tseslint from 'typescript-eslint';
10+
11+
export default [
12+
{
13+
ignores: ['coverage/**', 'dist/**', 'example/dist/**', '__tests__/**'],
14+
},
15+
{
16+
plugins: {
17+
react,
18+
},
19+
languageOptions: {
20+
parserOptions: {
21+
ecmaFeatures: {
22+
jsx: true,
23+
},
24+
},
25+
globals: {
26+
...globals.browser,
27+
},
28+
},
29+
},
30+
...tseslint.config(eslint.configs.recommended, ...tseslint.configs.recommended, prettierConfig),
31+
...tseslint.config({
32+
files: ['__tests__/**'],
33+
plugins: { jest },
34+
...jest.configs['flat/recommended'],
35+
...jestDom.configs['flat/recommended'],
36+
}),
37+
];

example/Layout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class Layout extends React.PureComponent {
4141
}
4242

4343
if (signaturePad.isEmpty()) {
44-
// eslint-disable-next-line no-alert
4544
alert('Please provide a signature first.');
4645
} else {
4746
window.open(signaturePad.toDataURL());

example/index.html

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en" class="theme-light">
3-
<head>
4-
<meta charset="utf-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<meta name="viewport" content="width=device-width, initial-scale=1">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
77

8-
<title>React-Signature-Pad Example</title>
8+
<title>React-Signature-Pad Example</title>
99

10-
<link rel="stylesheet" type="text/css" href="./node_modules/bulma/css/bulma.css">
10+
<link rel="stylesheet" type="text/css" href="./node_modules/bulma/css/bulma.css" />
1111

12-
<style>
13-
canvas {
14-
cursor: crosshair;
15-
}
16-
</style>
12+
<style>
13+
canvas {
14+
cursor: crosshair;
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
<div id="root"></div>
1720

18-
</head>
19-
<body>
20-
<div id="root"></div>
21-
22-
<!-- Scripts -->
23-
<script src="./dist/vendor.js"></script>
24-
<script src="./dist/bundle.js"></script>
25-
</body>
21+
<!-- Scripts -->
22+
<script src="./dist/vendor.js"></script>
23+
<script src="./dist/bundle.js"></script>
24+
</body>
2625
</html>

0 commit comments

Comments
 (0)