From d5111dfd5b0afebf9078b7af09d8713d59fbf18b Mon Sep 17 00:00:00 2001 From: Tomoki Morita Date: Fri, 16 Aug 2024 19:36:37 +0900 Subject: [PATCH] add close button on drawer --- src/pages/popover/_styles.module.css | 15 +++++++++++++++ src/pages/popover/index.astro | 22 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/pages/popover/_styles.module.css b/src/pages/popover/_styles.module.css index cbe7e7f..1918cfb 100644 --- a/src/pages/popover/_styles.module.css +++ b/src/pages/popover/_styles.module.css @@ -88,6 +88,21 @@ html:has(.drawer:popover-open) { } } +.drawerFooterButton { + background: rgb(var(--gray-600)); + border: 1px solid rgb(var(--gray-400) / 10%); + color: rgb(var(--gray-100)); + font-size: 0.925rem; + padding: 0.3rem 0.75rem; +} + +@media (min-width: 768px) { + .drawerFooterButton { + font-size: 1.0625rem; + padding: 0.5rem 1rem; + } +} + .toastButton { background: rgb(var(--gray-700)); border: 1px solid rgb(var(--gray-600)); diff --git a/src/pages/popover/index.astro b/src/pages/popover/index.astro index e353164..5b8f932 100644 --- a/src/pages/popover/index.astro +++ b/src/pages/popover/index.astro @@ -41,13 +41,18 @@ const title = "popover"; class={styles.drawerButton} popovertarget="drawerTarget">show drawer -
+
how to close this drawer
you can close the drawer by pressing the key, and you can also be dismissed by selecting outside the drawer area too.
+
+ +
@@ -90,6 +95,21 @@ const title = "popover"; let selector = ""; + // drawer + selector = "#drawerTarget"; + const drawer = document.querySelector(selector); + if (!drawer) throw new Error(`${selector} does not exists.`); + + selector = `.${styles.drawerFooterButton}`; + const drawerFooterButton = + document.querySelector(selector); + if (!drawerFooterButton) throw new Error(`${selector} does not exists.`); + + drawerFooterButton.addEventListener("click", () => { + drawer.hidePopover(); + }); + + // toast selector = "#toastButton"; const toastButton = document.querySelector(selector); if (!toastButton) throw new Error(`${selector} does not exists.`);