Skip to content

Commit

Permalink
Add png component
Browse files Browse the repository at this point in the history
  • Loading branch information
pomber committed Nov 24, 2024
1 parent 3128671 commit 7e7b78d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions apps/web/app/landing/download.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use client"
import * as htmlToImage from "html-to-image"

export function Download({ selector }: { selector: string }) {
const onClick = async () => {
const nodes = document.querySelectorAll(selector) as any
for (const node of nodes) {
const dataUrl = await htmlToImage.toPng(node as HTMLElement)
var img = new Image()
img.src = dataUrl
document.getElementById("out")!.appendChild(img)
}
}
return (
<div>
<button onClick={onClick}>As PNG</button>
<div id="out" className="min-w-6 min-h-6 border"></div>
</div>
)
}
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"diff": "^5.1.0",
"dotenv": "^16.4.1",
"estree-util-to-js": "^2.0.0",
"html-to-image": "^1.11.11",
"lucide-react": "^0.303.0",
"next": "14.1.0",
"next-docs-mdx": "7.1.2",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7e7b78d

Please sign in to comment.