-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from rumenpetrov/challenge-8/gdespolov
Challenge 8
- Loading branch information
Showing
1 changed file
with
51 additions
and
29 deletions.
There are no files selected for viewing
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
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> |