Skip to content

Commit

Permalink
adds gatsby-node config
Browse files Browse the repository at this point in the history
  • Loading branch information
Martskin committed Aug 23, 2019
1 parent 2b25c00 commit 8431f46
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@
*/

// You can delete this file if you're not using it
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /html2canvas/,
use: loaders.null(),
},
],
},
})
}
}
20 changes: 20 additions & 0 deletions src/components/boxModelVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,31 @@ function BoxModelVisualizer({ margin, border, padding, element }) {
}, [])

function savePNG() {
const boxModel = document.getElementById("box-model")

html2canvas(boxModel).then(function(canvas) {
saveAs(canvas.toDataURL(), 'box-model.png');
})
}

function saveAs(uri, filename) {
let link = document.createElement('a');

if (typeof link.download === 'string') {
link.href = uri;
link.download = filename;

//Firefox requires the link to be in the body
document.body.appendChild(link);

//simulate click
link.click();

//remove the link when done
document.body.removeChild(link);
} else {
window.open(uri);
}
}

function truthyHelper(val) {
Expand Down

0 comments on commit 8431f46

Please sign in to comment.