mirror of
https://github.com/jlengrand/web-components-workshop-deprecated.git
synced 2026-03-10 08:51:23 +00:00
Creates first custom element
Also updates README
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# Introduction to Web Components
|
||||
|
||||
This repo was created to support [a workshop](https://www.meetup.com/Coffee-Code-and-Chat/events/244822183/) given in Utrecht in November 2017.
|
||||
|
||||
## Slides and Work Material
|
||||
|
||||
https://docs.google.com/document/d/1nUVRp7ehON0bMOlSowUZLbOZmS_OjUepsuIATImniS8/edit?usp=sharing
|
||||
[Slides are here](https://docs.google.com/presentation/d/1h_wp7a_xbjJxeNLu6_Dd8Q4fBy2zA6jc1AjZrNqSEjo/edit?usp=sharing)
|
||||
24
index.html
Normal file
24
index.html
Normal file
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>WebComponents workshop</h1>
|
||||
<p>In this workshop, we will create new custom HTML Components</p>
|
||||
|
||||
<hello-world></hello-world>
|
||||
|
||||
<button onclick="removeHelloWorld()">Click me</button>
|
||||
|
||||
<script src="src/components/hello-world.js"></script>
|
||||
<script>
|
||||
function removeHelloWorld(){
|
||||
console.log("Called!");
|
||||
|
||||
const helloElement = document.getElementsByTagName("hello-world")[0];
|
||||
helloElement.parentNode.removeChild(helloElement);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
21
src/components/hello-world.js
Normal file
21
src/components/hello-world.js
Normal file
@@ -0,0 +1,21 @@
|
||||
class HelloWorldElement extends HTMLElement {
|
||||
|
||||
constructor(){
|
||||
super()
|
||||
|
||||
this.innerHTML = `<h1>Hello Meetup !</h1>`;
|
||||
}
|
||||
|
||||
connectedCallback(){
|
||||
console.log("I'm here!");
|
||||
}
|
||||
|
||||
disconnectedCallback(){
|
||||
console.log("I'm gone!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
window.customElements.define(
|
||||
'hello-world',
|
||||
HelloWorldElement);
|
||||
@@ -1,30 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>WebComponents workshop</h1>
|
||||
|
||||
<p>In this workshop, we will create new custom HTML Components and publish them online.</p>
|
||||
|
||||
<meetup-button></meetup-button>
|
||||
|
||||
<script>
|
||||
var newDrawer = document.createElement('app-drawer');
|
||||
var button = document.createElement('button');
|
||||
button.innerHTML = "A simple button";
|
||||
button.setAttribute("style", "background-image: linear-gradient(to right, #f6d365 0%, #fda085 51%, #f6d365 100%);");
|
||||
button.style.padding = "30px";
|
||||
button.style.backgroundImage
|
||||
|
||||
newDrawer.appendChild(button);
|
||||
document.body.appendChild(newDrawer);
|
||||
document.querySelector('button').addEventListener('click', function() {
|
||||
console.log("Button clicked");
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user