From 8eb71d41440b78030e6e190176ad3498250aa24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C4=8Curda?= Date: Wed, 8 Jan 2025 11:37:45 +0100 Subject: [PATCH] fixup! Feat(web): Introduce Drawer component #DS-1580 --- .../web/src/scss/components/Drawer/index.html | 80 ++++++++++++++++++- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/packages/web/src/scss/components/Drawer/index.html b/packages/web/src/scss/components/Drawer/index.html index fd49cd7a9c..d17418447d 100644 --- a/packages/web/src/scss/components/Drawer/index.html +++ b/packages/web/src/scss/components/Drawer/index.html @@ -4,6 +4,13 @@ document.addEventListener("DOMContentLoaded", () => { const radios = document.querySelectorAll('input[name="drawer-alignment"]'); const drawer = document.getElementById("drawer-example"); + const backdropCheckbox = document.getElementById("drawer-is-closable-on-backdrop-click"); + const escapeKeyCheckbox = document.getElementById("drawer-is-closable-on-escape-key"); + const contentTextArea = document.getElementById("drawer-content"); + const drawerContentDiv = drawer.querySelector("[data-drawer-demo-content]"); + + let isClosableOnBackdropClick = backdropCheckbox.checked; + let isClosableOnEscapeKey = escapeKeyCheckbox.checked; radios.forEach(radio => { radio.addEventListener("change", () => { @@ -16,9 +23,48 @@ } }); }); + + backdropCheckbox.addEventListener("change", () => { + isClosableOnBackdropClick = backdropCheckbox.checked; + }); + + escapeKeyCheckbox.addEventListener("change", () => { + isClosableOnEscapeKey = escapeKeyCheckbox.checked; + }); + + contentTextArea.addEventListener("input", () => { + drawerContentDiv.textContent = contentTextArea.value; + }); + + const closeDrawer = () => { + drawer.close(); + drawer.setAttribute("aria-expanded", "false"); + }; + + const openDrawerButton = document.querySelector('button[data-test-id="drawer-basic"]'); + openDrawerButton.addEventListener("click", () => { + drawer.show(); + drawer.setAttribute("aria-expanded", "true"); + + drawer.addEventListener("click", (event) => { + if (isClosableOnBackdropClick && event.target === drawer) { + closeDrawer(); + } + }); + + document.addEventListener("keydown", (event) => { + if (isClosableOnEscapeKey && event.key === "Escape") { + closeDrawer(); + } + }); + }); + + const closeButton = drawer.querySelector(".DrawerCloseButton"); + closeButton.addEventListener("click", closeDrawer); }); +
@@ -27,7 +73,7 @@

Drawer

-
+
Drawer alignment:
+
+
+ + +
+ + +
+ Can contain HTML. +
+
+
+
+ -
Drawer content
+
Drawer content