Created
July 26, 2019 04:25
-
-
Save bengfarrell/c3909d35a13150ea71c097780bbc00fe to your computer and use it in GitHub Desktop.
Lit-html and SVG
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
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
<script type="module"> | |
import { html, render } from 'https://unpkg.com/lit-html'; | |
/** UNCOMMENT THE FOLLOWING AND COMMENT OUT THE IMPORT TO NOT USE LIT-HTML | |
const html = function(strings, ...values) { | |
let str = ''; | |
strings.forEach((string, i) => { | |
str += string + values[i]; | |
}); | |
return str; | |
}; | |
const render = function(template, el) { el.innerHTML = template; } | |
**/ | |
const rectangle = html`<rect x="100" y="100" width="50" height="50" stroke="red" fill="green"></rect>`; | |
const template = html` | |
<svg viewBox="0 0 500 500"> | |
<circle cx="50" cy="50" r="50" stroke="red" fill="red"></circle> | |
${rectangle} | |
</svg>`; | |
render(template, document.getElementById('container')); | |
</script> | |
</head> | |
<body> | |
<div id="container"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment