From 79e297d3b3980a84e87814e2481a7d6bd8b0f613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Rodrigues?= Date: Sat, 9 Mar 2024 23:45:17 +0000 Subject: [PATCH 01/14] feat: dropdown component --- assets/js/app.js | 18 ++++++ .../components/calendar/calendar.ex | 23 +++++--- lib/atomic_web/components/dropdown.ex | 59 +++++++++++++++++++ storybook/components/dropdown.story.exs | 36 +++++++++++ 4 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 lib/atomic_web/components/dropdown.ex create mode 100644 storybook/components/dropdown.story.exs diff --git a/assets/js/app.js b/assets/js/app.js index 8c30db156..39df3de12 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -34,6 +34,7 @@ let Hooks = { StickyScroll: StickyScroll }; + Hooks.ScrollToTop = { mounted() { this.el.addEventListener("click", e => { @@ -46,6 +47,23 @@ Hooks.ScrollToTop = { } } + +Hooks.Dropdown = { + mounted() { + this.el.addEventListener("click", e => { + e.preventDefault() + if(this.el.nextElementSibling.classList.contains("hidden")) { + this.el.nextElementSibling.classList.remove("hidden") + this.el.classList.add("block") + } + else { + this.el.nextElementSibling.classList.add("hidden") + this.el.classList.remove("block") + } + }) + } +} + let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") let liveSocket = new LiveSocket("/live", Socket, { params: { _csrf_token: csrfToken }, diff --git a/lib/atomic_web/components/calendar/calendar.ex b/lib/atomic_web/components/calendar/calendar.ex index bab991229..1df1a64d1 100644 --- a/lib/atomic_web/components/calendar/calendar.ex +++ b/lib/atomic_web/components/calendar/calendar.ex @@ -5,6 +5,7 @@ defmodule AtomicWeb.Components.Calendar do import AtomicWeb.CalendarUtils import AtomicWeb.Components.CalendarMonth import AtomicWeb.Components.CalendarWeek + import AtomicWeb.Components.Dropdown alias Timex.Duration @@ -85,14 +86,20 @@ defmodule AtomicWeb.Components.Calendar do