Skip to content

Commit

Permalink
Merge pull request #49 from rumenpetrov/challenge-8/gdespolov
Browse files Browse the repository at this point in the history
Challenge 8
  • Loading branch information
despolov authored Oct 4, 2024
2 parents 4145d95 + a826503 commit 1d665a5
Showing 1 changed file with 51 additions and 29 deletions.
80 changes: 51 additions & 29 deletions public/challenge-contributions/8/gdespolov.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,60 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Challenge 8</title>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Challenge 8 - fancy button</title>

<script type="module">
class GiveMeAName extends HTMLElement {
constructor() {
super();

this.render();
<style>
:root {
--button-bg-color: #0abab5;
--button-hover-bg-color: #06706d;
}
</style>

<script type="module">
class FancyButton extends HTMLElement {
constructor() {
super();

const shadow = this.attachShadow({ mode: "open" });
const button = document.createElement("button");

button.textContent = this.getAttribute("label") || "Button";

render() {
this.innerHTML = `
<style>
h2 {
display: block;
background-color: lightgray;
padding: 10px;
const style = document.createElement("style");
style.textContent = `
button {
background-color: var(--button-bg-color, #ff5733);
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
}
</style>
<h2>Hello, I'm a web component!</h2>
`;
button:hover {
background-color: var(--button-hover-bg-color, #000000);
}
`;

shadow.appendChild(style);
shadow.appendChild(button);
}
}
}

customElements.define('give-me-a-name', GiveMeAName);
</script>
</head>
<body>
<h1>This is the template HTML file for this challenge.</h1>
customElements.define("fancy-button", FancyButton);
</script>
</head>

<body>
<fancy-button label="Click Me"></fancy-button>

<give-me-a-name></give-me-a-name>
</body>
</html>
<fancy-button
label="Custom Color Click Me"
style="--button-bg-color: #50c878; --button-hover-bg-color: #307848"
></fancy-button>
</body>
</html>

0 comments on commit 1d665a5

Please sign in to comment.