Skip to content
Open
Binary file added src/dialog/images/spider-1.avif
Binary file not shown.
Binary file added src/dialog/images/spider-2.avif
Binary file not shown.
Binary file added src/dialog/images/spider-3.avif
Binary file not shown.
102 changes: 102 additions & 0 deletions src/dialog/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Baseline Dialog Demo</title>
<link rel="stylesheet" href="./style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link
href="https://fonts.googleapis.com/css2?family=Commissioner:[email protected]&amp;family=Hedvig+Letters+Serif:[email protected]&amp;display=swap"
rel="stylesheet">
</head>

<body>
<main>
<article>
<h1 data-heading="main"> Popping up with the <code>dialog</code> element</h1>
<section>
<h2 data-heading> Less JS, More Jumping Spiders
</h2>
<ul class="gallery">
<li class="gallery-item">
<img src='images/spider-1.avif' alt='Macro close-up of brown jumping spider on the edge of a leaf.'>
<button data-button="show-dialog icon favorite">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"
fill="currentColor">
<path
d="M12.0006 18.26L4.94715 22.2082L6.52248 14.2799L0.587891 8.7918L8.61493 7.84006L12.0006 0.5L15.3862 7.84006L23.4132 8.7918L17.4787 14.2799L19.054 22.2082L12.0006 18.26Z">
</path>
</svg>
<span class="visually-hidden">Save as Favorite </span>
</button>
</li>
<li class="gallery-item">
<img src='images/spider-2.avif' alt='Macro close-up of brown jumping spider on a leaf.'>
<button data-button="show-dialog icon favorite">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"
fill="currentColor">
<path
d="M12.0006 18.26L4.94715 22.2082L6.52248 14.2799L0.587891 8.7918L8.61493 7.84006L12.0006 0.5L15.3862 7.84006L23.4132 8.7918L17.4787 14.2799L19.054 22.2082L12.0006 18.26Z">
</path>
</svg>
<span class="visually-hidden">Save as Favorite </span>
</button>
</li>
<li class="gallery-item">
<img src='images/spider-3.avif' alt='Close-up of white jumping spider on bright red background.'>
<button data-button="show-dialog icon favorite">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"
fill="currentColor">
<path
d="M12.0006 18.26L4.94715 22.2082L6.52248 14.2799L0.587891 8.7918L8.61493 7.84006L12.0006 0.5L15.3862 7.84006L23.4132 8.7918L17.4787 14.2799L19.054 22.2082L12.0006 18.26Z">
</path>
</svg>
<span class="visually-hidden">Save as Favorite </span>
</button>
</li>
</ul>
</section>
</article>

<dialog aria-labelledby="dialog-title" aria-describedby="description">
<h2 id="dialog-title" data-heading="dialog">Yay! You found a favorite!
</h2>
<p id="description">Sign up with your e-mail address to start adding to your favorites list.</p>
<form method="dialog">
<div data-field>
<label for="email">Enter your email</label>
<button id="popover-trigger" data-button="popover-trigger icon" type="button" popovertarget="privacy-popover">
<span class="visually-hidden">How we handle your e-mail</span>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" focusable="false"
aria-hidden="true">
<path
d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM11 7H13V9H11V7ZM11 11H13V17H11V11Z">
</path>
</svg>

</button>
<div id="privacy-popover" popover data-popover>
<p> As with all of your information, we promise not to sell your e-mail address. </p>
</div>
</div>
<input type="email" id="email" autofocus required autocomplete="email" />
<div class="form-action">
<button data-button> Sign Up </button>
<button id="close" data-button> Close </button>
</div>
</form>
</dialog>
</main>
<aside>
<p>Photo credits, in order: <a
href="https://unsplash.com/photos/brown-jumping-spider-on-green-leaf-bdHfhlThd_k">Erik Karits</a>, <a
href="https://unsplash.com/photos/closeup-photo-of-brown-and-black-spider-on-leaf-P5SObFf8e5Q">Wynand Uys</a>,
and <a href="https://unsplash.com/photos/a-close-up-of-a-spider-on-a-red-surface-yZlthNy4AF0">Brian
Wangenheim</a>, via Unsplash.</p>
</aside>
<script src="./script.js"></script>
</body>

</html>
15 changes: 15 additions & 0 deletions src/dialog/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const openDialogBtns = document.querySelectorAll(
`[data-button*="show-dialog"]`
);
const dialog = document.querySelector('dialog');
const closeDialogBtn = document.getElementById('close');

openDialogBtns.forEach((openDialogBtn) => {
openDialogBtn.addEventListener('click', () => {
dialog.showModal();
});

closeDialogBtn.addEventListener('click', () => {
dialog.close();
});
});
Loading