-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Added a new signature pad element and styling for the new element #1576
Open
keerthi-balaji
wants to merge
8
commits into
kevinchappell:master
Choose a base branch
from
keerthi-balaji:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d33611d
Added signature pad element and added styling for it before and after…
keerthi-balaji 73cbed6
Merge pull request #1 from keerthi-balaji/signaturePad
keerthi-balaji 4ed922c
Fixed the label, placed the clear button within the canvas, renamed t…
keerthi-balaji e0bb509
Added a method to stop signature pad from being dragged around prerende
keerthi-balaji aa4a6b1
Merge pull request #3 from kevinchappell/master
keerthi-balaji 91fa1e6
Merge pull request #2 from keerthi-balaji/signaturePad
keerthi-balaji e3efb04
Saved the signature to form data and created the tests
keerthi-balaji 01575d8
Merge pull request #5 from keerthi-balaji/SignaturePad
keerthi-balaji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import control from '../control' | ||
|
||
/** | ||
* SignaturePad class | ||
* @extends control | ||
*/ | ||
export default class controlSignaturePad extends control { | ||
/** | ||
* definition | ||
* @return {Object} | ||
*/ | ||
static get definition() { | ||
return { | ||
icon: '🖊️', | ||
i18n: { | ||
default: 'Signature Pad', | ||
}, | ||
} | ||
} | ||
|
||
/** | ||
* build a signature pad DOM element | ||
* @return {Object} DOM Element to be injected into the form. | ||
*/ | ||
build() { | ||
this.canvas = this.markup('canvas', null, { className: 'signature-pad' }) | ||
this.clearButton = this.markup('button', 'Clear', { type: 'button', className: 'clear-button' }) | ||
this.clearButton.addEventListener('click', () => { | ||
const context = this.canvas.getContext('2d') | ||
context.clearRect(0, 0, this.canvas.width, this.canvas.height) | ||
|
||
// Clear any existing drawing data | ||
this.clearCanvas() | ||
|
||
}) | ||
this.labelSpan = this.markup('span', this.config.label || 'Signature', { className: 'form-label' }) | ||
|
||
// Created a container div and wrap the canvas inside it | ||
const container = this.markup('div', [this.canvas], { className: 'signature-container' }) | ||
|
||
return [this.labelSpan, container, this.clearButton] | ||
|
||
} | ||
|
||
/** | ||
* Clear the canvas and any existing drawing data | ||
*/ | ||
clearCanvas() { | ||
const context = this.canvas.getContext('2d') | ||
|
||
context.beginPath() // Start a new path to clear previous strokes | ||
|
||
context.clearRect(0, 0, this.canvas.width, this.canvas.height) | ||
} | ||
|
||
/** | ||
* onRender callback | ||
* @param {Object} evt Event object | ||
*/ | ||
onRender(evt) { | ||
this.canvas.width = this.canvas.parentElement.offsetWidth | ||
this.canvas.height = 150 // Fixed height for the canvas | ||
|
||
const context = this.canvas.getContext('2d') | ||
context.strokeStyle = '#000' | ||
context.lineWidth = 2 | ||
|
||
let isDrawing = false | ||
this.canvas.addEventListener('mousedown', e => { | ||
isDrawing = true | ||
context.moveTo(e.offsetX, e.offsetY) | ||
}) | ||
this.canvas.addEventListener('mousemove', e => { | ||
if (isDrawing) { | ||
context.lineTo(e.offsetX, e.offsetY) | ||
context.stroke() | ||
} | ||
}) | ||
this.canvas.addEventListener('mouseup', () => { | ||
isDrawing = false | ||
}) | ||
this.canvas.addEventListener('mouseout', () => { | ||
isDrawing = false | ||
}) | ||
return evt | ||
} | ||
} | ||
control.register('signaturePad', controlSignaturePad) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,21 @@ | |
height: auto; | ||
} | ||
} | ||
.signature-container { | ||
border: 2px solid #000; | ||
padding: 10px; | ||
margin-bottom: 10px; | ||
border-radius: 5px; | ||
} | ||
|
||
.signature-pad { | ||
//display: block; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✂️ |
||
width: 100%; | ||
height: 100%; | ||
} | ||
.signature-pad.custom-style { | ||
border: 2px solid #000; | ||
background-color: #f9f9f9; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✂️