-
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 #11 from rumenpetrov/challenge-2/asavov
challenge-2/asavov
- Loading branch information
Showing
1 changed file
with
155 additions
and
9 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,11 +1,157 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Challenge 2</title> | ||
</head> | ||
<body> | ||
<h1>This is the template HTML file for this challenge.</h1> | ||
</body> | ||
</html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Challenge 2 AS</title> | ||
<style> | ||
* { | ||
border: 0; | ||
padding: 0; | ||
margin: 0; | ||
line-height: 1.6; | ||
font-family: Arial, sans-serif; | ||
} | ||
h3 { | ||
font-size: 1.296rem; | ||
} | ||
p { | ||
font-size: 1rem; | ||
} | ||
dialog { | ||
opacity: 0; | ||
transform: scaleY(0); | ||
transition: opacity 0.3s ease-out, transform 0.3s ease-out; | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
border-radius: 4px; | ||
width: 400px; | ||
} | ||
|
||
dialog[open] { | ||
opacity: 1; | ||
transform: scaleY(1); | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
border-radius: 4px; | ||
border: 1px solid grey; | ||
} | ||
|
||
dialog::backdrop { | ||
opacity: 0.7; | ||
transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; | ||
} | ||
.dialog-header { | ||
display: flex; | ||
justify-content: space-between; | ||
padding: 15px 10px; | ||
align-items: center; | ||
} | ||
.dialog-bottom-buttons { | ||
gap: 5px; | ||
display: flex; | ||
justify-content: flex-end; | ||
padding: 15px 10px; | ||
} | ||
.x-button { | ||
width: 15px; | ||
height: 15px; | ||
background-color: white; | ||
cursor: pointer; | ||
} | ||
hr { | ||
border-bottom: 1px solid grey; | ||
} | ||
.show-dialog-btn { | ||
display: block; | ||
margin: 50vh auto 0 auto; | ||
border-radius: 4px; | ||
padding: 6px 16px; | ||
background-color: rgb(144, 202, 249); | ||
box-shadow: rgba(0, 0, 0, 0.2) 0px 3px 1px -2px, | ||
rgba(0, 0, 0, 0.14) 0px 2px 2px 0px, | ||
rgba(0, 0, 0, 0.12) 0px 1px 5px 0px; | ||
cursor: pointer; | ||
} | ||
p { | ||
padding: 15px 10px; | ||
} | ||
.dialog-bottom-buttons button { | ||
border-radius: 4px; | ||
padding: 6px 16px; | ||
cursor: pointer; | ||
} | ||
.dialog-bottom-buttons button:first-child { | ||
background-color: grey; | ||
color: white; | ||
} | ||
.dialog-bottom-buttons button:nth-child(2) { | ||
background-color: rgba(0, 60, 255, 0.733); | ||
color: white; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<dialog> | ||
<div class="dialog-header"> | ||
<h3>Modal title</h3> | ||
<button class="x-button"> | ||
<img | ||
src="https://rumenpetrov.github.io/fe-hunger-games/challenge-resources/close.svg" | ||
alt="Close Icon" | ||
/> | ||
</button> | ||
</div> | ||
<hr class="divider" /> | ||
<p>Modal body text goes here</p> | ||
<hr class="divider" /> | ||
<div class="dialog-bottom-buttons"> | ||
<button autofocus>Close</button> | ||
<button>Save changes</button> | ||
</div> | ||
</dialog> | ||
<button class="show-dialog-btn">Show the dialog</button> | ||
<script> | ||
const dialog = document.querySelector("dialog"); | ||
const showButton = document.querySelector("dialog + button"); | ||
const closeButton = document.querySelector( | ||
".dialog-bottom-buttons button:first-child" | ||
); | ||
const saveButton = document.querySelector( | ||
".dialog-bottom-buttons button:nth-child(2)" | ||
); | ||
const image = document.querySelector("img"); | ||
|
||
showButton.addEventListener("click", () => { | ||
console.log("show modal"); | ||
dialog.showModal(); | ||
}); | ||
|
||
closeButton.addEventListener("click", () => { | ||
console.log("close modal from close button"); | ||
dialog.close(); | ||
}); | ||
|
||
image.addEventListener("click", () => { | ||
console.log("close modal from X icon"); | ||
dialog.close(); | ||
}); | ||
|
||
dialog.addEventListener("click", (event) => { | ||
if (event.target === dialog) { | ||
console.log("close modal when backdrop is clicked"); | ||
dialog.close(); | ||
} | ||
}); | ||
|
||
saveButton.addEventListener("click", () => { | ||
console.log("save modal"); | ||
dialog.close(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |