diff --git a/app/javascript/controllers/dropdown_controller.js b/app/javascript/controllers/dropdown_controller.js new file mode 100644 index 0000000..fba9cb1 --- /dev/null +++ b/app/javascript/controllers/dropdown_controller.js @@ -0,0 +1,23 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + static targets = ["menu", "trigger"] + + toggle() { + this.menuTarget.classList.contains("hidden") ? this.open() : this.close() + } + + open() { + this.menuTarget.classList.remove("hidden") + if (this.hasTriggerTarget) this.triggerTarget.setAttribute("aria-expanded", "true") + } + + close() { + this.menuTarget.classList.add("hidden") + if (this.hasTriggerTarget) this.triggerTarget.setAttribute("aria-expanded", "false") + } + + closeOnOutsideClick(event) { + if (!this.element.contains(event.target)) this.close() + } +} diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index b5f3f09..e47e452 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -37,17 +37,30 @@ <% end %>
- <% if Rails.env.development? %> - <%= link_to "Mailer previews", "/rails/mailers", class: "text-ink-soft hover:text-ink" %> - <% end %> <% if authenticated? %> - <%= link_to "About you", users_story_path, class: "text-ink-soft hover:text-ink" %> - <%= link_to "Explore options", scenarios_path, class: "text-ink-soft hover:text-ink" %> - <% if Current.user&.admin_of?(Current.organization) %> - <%= link_to "Admin Dashboard", admin_dashboard_path, class: "text-ink-soft hover:text-ink" %> - <% end %> - <%= link_to "Profile", users_profile_path, class: "text-ink-soft hover:text-ink" %> - <%= button_to "Sign out", session_path, method: :delete, class: "text-ink-soft hover:text-ink cursor-pointer" %> + <%= link_to "Dashboard", dashboard_path, class: "text-ink-soft hover:text-ink" %> +
+ + +
<% elsif Current.organization %> <%= link_to "Log in", new_session_path, class: "text-ink-soft hover:text-ink" %> <%= link_to "Explore the legacy builder platform", new_registration_path, diff --git a/test/controllers/dashboards_controller_test.rb b/test/controllers/dashboards_controller_test.rb index b58e23c..cf7fcf9 100644 --- a/test/controllers/dashboards_controller_test.rb +++ b/test/controllers/dashboards_controller_test.rb @@ -13,8 +13,8 @@ class DashboardsControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_select "h1", "Welcome to your workspace" - assert_select "a[href=?]", users_story_path, text: "About you" - assert_select "a[href=?]", scenarios_path, text: "Explore options" + assert_select "a[href=?] h3", users_story_path, text: "About you" + assert_select "a[href=?] h3", scenarios_path, text: "Explore options" # The nav brand/logo links back to the dashboard for signed-in users. assert_select "nav a[href=?]", dashboard_path end