Skip to content

Commit

Permalink
feat(html): Add example of <template> (#2219)
Browse files Browse the repository at this point in the history
* template

* lint & typo

* Add angle brackets

---------

Co-authored-by: Estelle Weyl <estelle@openwebdocs.org>
  • Loading branch information
NiedziolkaMichal and estelle committed Jul 26, 2023
1 parent 6355aad commit 2e344a6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions live-examples/html-examples/interactive-elements/css/template.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.info-icon {
display: inline-block;
background-color: #2296f3;
border-radius: 50%;
height: 1.5em;
width: 1.5em;
margin-right: 0.5em;
text-align: center;
color: white;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const insertBtn = document.getElementById('insert-btn');
const container = document.getElementById('container');
const template = document.getElementById('content-to-insert');

insertBtn.addEventListener('click', () => {
const content = template.content.cloneNode(true);;
container.appendChild(content);
});
11 changes: 11 additions & 0 deletions live-examples/html-examples/interactive-elements/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
"title": "HTML Demo: <summary>",
"type": "tabbed",
"height": "tabbed-shorter"
},
"template": {
"exampleCode": "./live-examples/html-examples/interactive-elements/template.html",
"cssExampleSrc": "./live-examples/html-examples/interactive-elements/css/template.css",
"jsExampleSrc": "./live-examples/html-examples/interactive-elements/js/template.js",
"fileName": "template.html",
"title": "HTML Demo: <template>",
"type": "tabbed",
"defaultTab": "html",
"tabs": "html,css,js",
"height": "tabbed-shorter"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<button id="insert-btn">Send Notification</button>

<p id="container"></p>

<template id="content-to-insert">
<p class="info-box">
<span class="info-icon">i</span><b>You have received a new friend invitation!</b>
</p>
</template>

0 comments on commit 2e344a6

Please sign in to comment.