Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript Rewrite #42

Merged
merged 16 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .babelrc

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
### custom ###

# parcel cache
.parcel-cache/
# build output
build/
dist/
# test coverage output
coverage/

Expand Down
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
language: node_js
# default is the very old 0.10.48; match local version instead
node_js: '10.16.0'
# default is the very old 0.10.48; use oldest LTS instead
node_js: 12

before_script: npm run lint
before_script:
- npm run lint
- npm run tsc
script: npm test -- --coverage
after_script:
# upload coverage reports to CodeCov
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[![dm](https://img.shields.io/npm/dm/react-signature-canvas.svg)](https://npmjs.org/package/react-signature-canvas)
[![dw](https://img.shields.io/npm/dw/react-signature-canvas.svg)](https://npmjs.org/package/react-signature-canvas)
<br><!-- status / activity -->
[![typings](https://img.shields.io/npm/types/react-signature-canvas.svg)](src/index.tsx)
[![build status](https://img.shields.io/travis/com/agilgur5/react-signature-canvas/main.svg)](https://app.travis-ci.com/github/agilgur5/react-signature-canvas/branches)
[![code coverage](https://img.shields.io/codecov/c/gh/agilgur5/react-signature-canvas/main.svg)](https://codecov.io/gh/agilgur5/react-signature-canvas)
<br>
Expand All @@ -26,7 +27,7 @@ Originally, this was just an _unopinionated_ fork of [react-signature-pad](https
Hence the naming difference.
Nowadays, this repo / library has significantly evolved, introducing new features, fixing various bugs, and now wrapping the upstream `signature_pad` to have its updates and bugfixes baked in.

This fork also allows you to directly pass [props](#props) to the underlying canvas element, has new, documented [API methods](#api) you can use, has new, documented [props](#props) you can pass to it, has a [live demo](https://agilgur5.github.io/react-signature-canvas/), has a [CodeSandbox playground](https://codesandbox.io/s/github/agilgur5/react-signature-canvas/tree/cra-example), and has [100% test coverage](https://codecov.io/gh/agilgur5/react-signature-canvas).
This fork also allows you to directly pass [props](#props) to the underlying canvas element, has new, documented [API methods](#api) you can use, has new, documented [props](#props) you can pass to it, has a [live demo](https://agilgur5.github.io/react-signature-canvas/), has a [CodeSandbox playground](https://codesandbox.io/s/github/agilgur5/react-signature-canvas/tree/cra-example), has [100% test coverage](https://codecov.io/gh/agilgur5/react-signature-canvas), and is [written in TypeScript](src/index.tsx).

## Installation

Expand Down Expand Up @@ -106,7 +107,7 @@ The API methods are _mostly_ just wrappers around [`signature_pad`'s API](https:

You can interact with the example in a few different ways:

1. Run `npm start` and navigate to [http://localhost:8080/](http://localhost:8080/).<br>
1. Run `npm start` and navigate to [http://localhost:1234/](http://localhost:1234/).<br>
Hosted locally via the [`example/`](example/) directory
1. [View the live demo here](https://agilgur5.github.io/react-signature-canvas/).<br>
Hosted via the [`gh-pages` branch](https://github.com/agilgur5/react-signature-canvas/tree/gh-pages), a standalone version of the code in [`example/`](example/)
Expand Down
24 changes: 24 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @type {import('@babel/core').ConfigFunction} */
module.exports = api => {
// eslint-disable-next-line dot-notation -- this conflicts with tsc, possibly due to outdated ESLint
api.cache.using(() => process.env['NODE_ENV']) // cache based on NODE_ENV

// normally use browserslistrc, but for Jest, use current version of Node
const isTest = api.env('test')
const jestTargets = { targets: { node: 'current' } }
/** @type {[import('@babel/core').PluginTarget, import('@babel/core').PluginOptions]} */
const presetEnv = ['@babel/preset-env', { bugfixes: true }]
if (isTest) presetEnv[1] = { ...presetEnv[1], ...jestTargets }

return {
presets: [
presetEnv,
'@babel/preset-typescript',
'@babel/preset-react'
],
plugins: [
// used with @rollup/plugin-babel
'@babel/plugin-transform-runtime'
]
}
}
4 changes: 2 additions & 2 deletions example/index.html → example/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
</head>
<body>
<div id='container'></div>
<script src='build/bundle.js'></script>
<script type='module' src='../src/index.js'></script>
</body>
</html>
</html>
11 changes: 6 additions & 5 deletions example/app.js → example/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { Component } from 'react'
import ReactDOM from 'react-dom'

import SignaturePad from '../src/index.js'
import SignaturePad from '../../src/index.tsx'

import styles from './styles.cssm'
import * as styles from './styles.module.css'

class App extends Component {
state = { trimmedDataURL: null }
Expand All @@ -15,8 +15,9 @@ class App extends Component {
}

trim = () => {
this.setState({ trimmedDataURL: this.sigPad.getTrimmedCanvas()
.toDataURL('image/png') })
this.setState({
trimmedDataURL: this.sigPad.getTrimmedCanvas().toDataURL('image/png')
})
}

render () {
Expand All @@ -35,7 +36,7 @@ class App extends Component {
</button>
</div>
{trimmedDataURL
? <img className={styles.sigImage}
? <img className={styles.sigImage} alt='signature'
src={trimmedDataURL} />
: null}
</div>
Expand Down
File renamed without changes.
18 changes: 0 additions & 18 deletions jest.config.js

This file was deleted.

19 changes: 19 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Config } from '@jest/types'
import { defaults } from 'jest-config'

const config: Config.InitialOptions = {
injectGlobals: false, // use @jest/globals
testEnvironment: 'jsdom',
setupFilesAfterEnv: [
// configure enzyme w/ react adapter
'<rootDir>/test/config/configure-enzyme.js',
// polyfill window.resizeTo
'window-resizeto/polyfill'
],
coveragePathIgnorePatterns: [
...defaults.coveragePathIgnorePatterns,
'<rootDir>/test/' // ignore any test helper files
]
}

export default config
Loading