-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(html): Add example of
<dialog>
(#2212)
* dialog * Update live-examples/html-examples/interactive-elements/dialog.html --------- Co-authored-by: Queen Vinyl Da.i'gyu-Kazotetsu <[email protected]> Co-authored-by: Brian Thomas Smith <[email protected]>
- Loading branch information
1 parent
900b899
commit e97aa1d
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
live-examples/html-examples/interactive-elements/css/dialog.css
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.card { | ||
text-align: center; | ||
width: 80%; | ||
background-color: bisque; | ||
padding: 1em; | ||
font-weight: bold; | ||
} | ||
|
||
dialog::backdrop { | ||
background-color: grey; | ||
} | ||
|
||
.won { | ||
font-weight: bold; | ||
color: deeppink; | ||
font-size: 1.3em; | ||
text-align: center; | ||
} |
13 changes: 13 additions & 0 deletions
13
live-examples/html-examples/interactive-elements/dialog.html
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="card"> | ||
<p class="question">Would you like to try your luck in a throw of the dice?</p> | ||
<p>Everyone has a chance to win.</p> | ||
<button id="showDialogBtn">Yes, let's give it a try</button> | ||
</div> | ||
|
||
<dialog id="favDialog"> | ||
<form method="dialog"> | ||
<p class="won">You have won! Congratulations!</p> | ||
<p class="lost">I am sorry to say, but you have lost...</p> | ||
<button id="closeBtn">Close dialog</button> | ||
</form> | ||
</dialog> |
24 changes: 24 additions & 0 deletions
24
live-examples/html-examples/interactive-elements/js/dialog.js
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const showDialogBtn = document.getElementById('showDialogBtn'); | ||
const favDialog = document.getElementById('favDialog'); | ||
|
||
function rollDice() { | ||
return Math.floor(Math.random() * 3) === 0; | ||
} | ||
|
||
function changeHidden(className, hidden) { | ||
const elements = document.getElementsByClassName(className); | ||
for (const e of elements) { | ||
if (hidden) { | ||
e.classList.add('hidden'); | ||
} else { | ||
e.classList.remove('hidden'); | ||
} | ||
} | ||
} | ||
|
||
showDialogBtn.addEventListener('click', () => { | ||
const won = rollDice(); | ||
changeHidden('won', !won); | ||
changeHidden('lost', won); | ||
favDialog.showModal(); | ||
}); |
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