forked from blackjk3/react-signature-pad
-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
index.js
46 lines (38 loc) · 1.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import SignaturePad from '../../src/index.tsx'
import * as styles from './styles.module.css'
class App extends Component {
state = { trimmedDataURL: null }
sigPad = {}
clear = () => {
this.sigPad.clear()
}
trim = () => {
this.setState({
trimmedDataURL: this.sigPad.getTrimmedCanvas().toDataURL('image/png')
})
}
render () {
const { trimmedDataURL } = this.state
return <div className={styles.container}>
<div className={styles.sigContainer}>
<SignaturePad canvasProps={{ className: styles.sigPad }}
ref={(ref) => { this.sigPad = ref }} />
</div>
<div>
<button className={styles.buttons} onClick={this.clear}>
Clear
</button>
<button className={styles.buttons} onClick={this.trim}>
Trim
</button>
</div>
{trimmedDataURL
? <img className={styles.sigImage} alt='signature'
src={trimmedDataURL} />
: null}
</div>
}
}
ReactDOM.render(<App />, document.getElementById('container'))