From ee9c40391ffc4a35d520441f72ae5283b6b2e0fd Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Tue, 9 Feb 2021 14:26:05 +0100 Subject: [PATCH] WIP: mise en place de template et d'interactions avec Stimulus --- .../controllers/hello_controller.js | 7 ------ .../controllers/main_nav_controller.js | 25 +++++++++++++++++++ app/javascript/stylesheets/application.scss | 16 ++++++++++++ app/views/emails/index.html.erb | 4 +-- app/views/emails/show.html.erb | 4 +-- app/views/filters/index.html.erb | 4 +-- app/views/filters/show.html.erb | 4 +-- app/views/layouts/application.html.erb | 22 ++++++++-------- 8 files changed, 59 insertions(+), 27 deletions(-) delete mode 100644 app/javascript/controllers/hello_controller.js create mode 100644 app/javascript/controllers/main_nav_controller.js diff --git a/app/javascript/controllers/hello_controller.js b/app/javascript/controllers/hello_controller.js deleted file mode 100644 index 612a01f..0000000 --- a/app/javascript/controllers/hello_controller.js +++ /dev/null @@ -1,7 +0,0 @@ -import { Controller } from "stimulus" - -export default class extends Controller { - connect() { - this.element.textContent = "Hello World!" - } -} diff --git a/app/javascript/controllers/main_nav_controller.js b/app/javascript/controllers/main_nav_controller.js new file mode 100644 index 0000000..8727798 --- /dev/null +++ b/app/javascript/controllers/main_nav_controller.js @@ -0,0 +1,25 @@ +import { Controller } from "stimulus" + +export default class extends Controller { + static targets = [ "userButton", "userMenu" ] + + toggle_user_menu () { + if (this.userButtonTarget.getAttribute('aria-expanded') == "false") { + // Show + this.userButtonTargets.forEach((element, index) => { + element.setAttribute('aria-expanded', 'true'); + }) + this.userMenuTargets.forEach((element, index) => { + element.classList.remove("hidden") + }) + } else { + // Hide + this.userButtonTargets.forEach((element, index) => { + element.setAttribute('aria-expanded', 'false'); + }) + this.userMenuTargets.forEach((element, index) => { + element.classList.add("hidden") + }) + } + } +} diff --git a/app/javascript/stylesheets/application.scss b/app/javascript/stylesheets/application.scss index 76fcadc..add2ff0 100644 --- a/app/javascript/stylesheets/application.scss +++ b/app/javascript/stylesheets/application.scss @@ -1,3 +1,19 @@ @import "tailwindcss/base"; @import "tailwindcss/components"; @import "tailwindcss/utilities"; + + +@layer base { + h1 { + @apply text-3xl font-bold leading-tight text-gray-900; + } +} + +@layer components { + .nav-tab--current { + @apply bg-gray-900 text-white px-3 py-2 rounded-md text-sm font-medium; + } + .nav-tab { + @apply text-gray-300 hover:bg-gray-700 hover:text-white px-3 py-2 rounded-md text-sm font-medium; + } +} diff --git a/app/views/emails/index.html.erb b/app/views/emails/index.html.erb index f568ab5..73a8f72 100644 --- a/app/views/emails/index.html.erb +++ b/app/views/emails/index.html.erb @@ -1,5 +1,5 @@ -<% content_for :main_title do %> - Emails +<% content_for :main_header do %> +

Emails

<% end %>

<%= notice %>

diff --git a/app/views/emails/show.html.erb b/app/views/emails/show.html.erb index 2638e49..ed368b9 100644 --- a/app/views/emails/show.html.erb +++ b/app/views/emails/show.html.erb @@ -1,5 +1,5 @@ -<% content_for :main_title do %> - Email # +<% content_for :main_header do %> +

Email #

<% end %>

<%= notice %>

diff --git a/app/views/filters/index.html.erb b/app/views/filters/index.html.erb index c50b37c..43e9c40 100644 --- a/app/views/filters/index.html.erb +++ b/app/views/filters/index.html.erb @@ -1,5 +1,5 @@ -<% content_for :main_title do %> - Filters +<% content_for :main_header do %> +

Filters

<% end %>

<%= notice %>

diff --git a/app/views/filters/show.html.erb b/app/views/filters/show.html.erb index a6ee319..7964a13 100644 --- a/app/views/filters/show.html.erb +++ b/app/views/filters/show.html.erb @@ -1,5 +1,5 @@ -<% content_for :main_title do %> - Filter #<%= @filter.id %> +<% content_for :main_header do %> +

Filter #<%= @filter.id %>

<% end %>

<%= notice %>

diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4899831..70fc5be 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,7 +13,7 @@
-