Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Use dropdown component in /sites page (#3572)
Uku Taht677b4f2e7963
diff --git a/assets/js/liveview/dropdown.js b/assets/js/liveview/dropdown.jsindex 490b3217f0..18175bb3f9 100644--- a/assets/js/liveview/dropdown.js+++ b/assets/js/liveview/dropdown.js@@ -17,10 +17,4 @@ export default () => ({this.open = falsefocusAfter && focusAfter.focus()},-- onPanelClick(e) {- if (e.target.tagName === 'A') {- this.close()- }- }})diff --git a/lib/plausible_web/components/generic.ex b/lib/plausible_web/components/generic.exindex e1b35f4684..bc595fe604 100644--- a/lib/plausible_web/components/generic.ex+++ b/lib/plausible_web/components/generic.ex@@ -2,7 +2,7 @@ defmodule PlausibleWeb.Components.Generic do@moduledoc """Generic reusable components"""- use Phoenix.Component+ use Phoenix.Component, global_prefixes: ~w(x-)@notice_themes %{yellow: %{@@ -68,7 +68,7 @@ defmodule PlausibleWeb.Components.Generic dodef docs_info(assigns) do~H"""<a href={"https://plausible.io/docs/#{@slug}"} rel="noreferrer" target="_blank">- <Heroicons.information_circle class="text-gray-400 w-6 h-6 absolute top-0 right-0 text-gray-400" />+ <Heroicons.information_circle class="text-gray-400 w-6 h-6 absolute top-0 right-0" /></a>"""end@@ -161,36 +161,28 @@ defmodule PlausibleWeb.Components.Generic dodef dropdown(assigns) do~H"""- <div class="flex justify-center">+ <div+ x-data="dropdown"+ x-on:keydown.escape.prevent.stop="close($refs.button)"+ x-on:focusin.window="! $refs.panel.contains($event.target) && close()"+ >+ <button x-ref="button" x-on:click="toggle()" type="button" class={List.first(@button).class}>+ <%= render_slot(List.first(@button)) %>+ </button><div- x-data="dropdown"- x-on:keydown.escape.prevent.stop="close($refs.button)"- x-on:focusin.window="! $refs.panel.contains($event.target) && close()"- x-id="['dropdown-button']"- class="relative"+ x-ref="panel"+ x-show="open"+ x-transition:enter="transition ease-out duration-100"+ x-transition:enter-start="opacity-0 scale-95"+ x-transition:enter-end="opacity-100 scale-100"+ x-transition:leave="transition ease-in duration-75"+ x-transition:leave-start="opacity-100 scale-100"+ x-transition:leave-end="opacity-0 scale-95"+ x-on:click.outside="close($refs.button)"+ style="display: none;"+ class={List.first(@panel).class}>- <button- x-ref="button"- x-on:click="toggle()"- x-bind:aria-expanded="open"- x-bind:aria-controls="$id('dropdown-button')"- type="button"- class={List.first(@button).class}- >- <%= render_slot(List.first(@button)) %>- </button>- <div- x-ref="panel"- x-show="open"- x-transition.origin.top.left- x-on:click.outside="close($refs.button)"- x-on:click="onPanelClick"- x-bind:id="$id('dropdown-button')"- style="display: none;"- class={List.first(@panel).class}- >- <%= render_slot(List.first(@panel)) %>- </div>+ <%= render_slot(List.first(@panel)) %></div></div>"""@@ -198,6 +190,7 @@ defmodule PlausibleWeb.Components.Generic doattr :href, :string, required: trueattr :new_tab, :boolean, default: false+ attr :rest, :globalslot :inner_block, required: truedef dropdown_link(assigns) do@@ -205,7 +198,9 @@ defmodule PlausibleWeb.Components.Generic do<.unstyled_linknew_tab={@new_tab}href={@href}- class="w-full justify-between text-gray-700 dark:text-gray-300 block px-3.5 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-700 hover:text-gray-900 dark:hover:text-gray-100"+ x-on:click="close()"+ class="w-full inline-flex text-gray-700 dark:text-gray-300 px-3.5 py-1.5 hover:bg-gray-100 dark:hover:bg-gray-700 hover:text-gray-900 dark:hover:text-gray-100"+ {@rest}><%= render_slot(@inner_block) %></.unstyled_link>@@ -227,7 +222,7 @@ defmodule PlausibleWeb.Components.Generic do<.linkid={@id}class={[- "inline-flex items-center gap-x-0.5",+ "justify-between items-center gap-x-0.5",@class]}href={@href}@@ -241,7 +236,7 @@ defmodule PlausibleWeb.Components.Generic do"""else~H"""- <.link class={@class} href={@href}>+ <.link class={@class} href={@href} {@rest}><%= render_slot(@inner_block) %></.link>"""diff --git a/lib/plausible_web/live/sites.ex b/lib/plausible_web/live/sites.exindex c8284788ee..bf8d9d8d7f 100644--- a/lib/plausible_web/live/sites.ex+++ b/lib/plausible_web/live/sites.ex@@ -3,7 +3,7 @@ defmodule PlausibleWeb.Live.Sites doLiveView for sites index."""- use Phoenix.LiveView+ use Phoenix.LiveView, global_prefixes: ~w(x-)use PlausibleWeb.Live.Flashalias Phoenix.LiveView.JS@@ -250,54 +250,23 @@ defmodule PlausibleWeb.Live.Sites dodef ellipsis_menu(assigns) do~H"""- <div x-data="dropdown">- <a- x-on:click="toggle()"- x-ref="button"- x-bind:aria-expanded="open"- x-bind:aria-controls="$id('dropdown-button')"- class="absolute top-0 right-0 h-10 w-10 rounded-md hover:cursor-pointer text-gray-400 dark:text-gray-600 hover:text-black dark:hover:text-indigo-400"- >- <Heroicons.ellipsis_vertical- class="absolute top-3 right-3 w-4 h-4"- aria-expanded="false"- aria-haspopup="true"- />- </a>-- <div- x-ref="panel"- x-show="open"- x-bind:id="$id('dropdown-button')"- x-on:click.outside="close($refs.button)"- x-on:click="onPanelClick"- x-transition.origin.top.right- x-transition.duration.100ms- class="absolute top-7 right-3 z-10 mt-2 w-40 origin-top-right rounded-md bg-white dark:bg-gray-900 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"- style="display: none;"- role="menu"- aria-orientation="vertical"- aria-label={"#{@site.domain} menu button"}- tabindex="-1"- >+ <.dropdown>+ <:button class="absolute top-0 right-0 h-10 w-10 rounded-md hover:cursor-pointer text-gray-400 dark:text-gray-600 hover:text-black dark:hover:text-indigo-400">+ <Heroicons.ellipsis_vertical class="absolute top-3 right-3 w-4 h-4" />+ </:button>+ <:panel class="absolute top-7 right-3 z-10 mt-2 w-40 rounded-md bg-white dark:bg-gray-900 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"><div class="py-1 text-sm" role="none">- <.unstyled_link+ <.dropdown_link:if={List.first(@site.memberships).role != :viewer}href={"/#{URI.encode_www_form(@site.domain)}/settings/general"}- class="text-gray-500 flex px-4 py-2 hover:bg-gray-100 hover:text-gray-800 dark:text-gray-500 dark:hover:text-gray-100 dark:hover:bg-indigo-900 cursor-pointer"- role="menuitem"- tabindex="-1"><Heroicons.cog_6_tooth class="mr-3 h-5 w-5" /><span>Settings</span>- </.unstyled_link>-- <button- type="button"- class="w-full text-gray-500 flex px-4 py-2 hover:bg-gray-100 hover:text-gray-800 dark:text-gray-500 dark:hover:text-gray-100 dark:hover:bg-indigo-900 cursor-pointer"- role="menuitem"- tabindex="-1"- x-on:click="close($refs.button)"+ </.dropdown_link>++ <.dropdown_link+ href="#"+ x-on:click.preventphx-click={JS.hide(transition: {"duration-500", "opacity-100", "opacity-0"},@@ -316,10 +285,10 @@ defmodule PlausibleWeb.Live.Sites do<.icon_pin :if={[email protected]_at} class="pt-1 mr-3 h-5 w-5" /><span :if={[email protected]_at}>Pin Site</span>- </button>+ </.dropdown_link></div>- </div>- </div>+ </:panel>+ </.dropdown>"""enddiff --git a/test/plausible_web/live/sites_test.exs b/test/plausible_web/live/sites_test.exsindex 3cdbfa69df..3c6bdc8992 100644--- a/test/plausible_web/live/sites_test.exs+++ b/test/plausible_web/live/sites_test.exs@@ -74,7 +74,7 @@ defmodule PlausibleWeb.Live.SitesTest doassert text_of_element(html,- ~s/li[data-domain="#{site.domain}"] button/+ ~s/li[data-domain="#{site.domain}"] a[phx-value-domain]/) == "Pin Site"end@@ -83,7 +83,7 @@ defmodule PlausibleWeb.Live.SitesTest do{:ok, lv, _html} = live(conn, "/sites")- button_selector = ~s/li[data-domain="#{site.domain}"] button/+ button_selector = ~s/li[data-domain="#{site.domain}"] a[phx-value-domain]/html =lv@@ -114,7 +114,7 @@ defmodule PlausibleWeb.Live.SitesTest do{:ok, lv, _html} = live(conn, "/sites")- button_selector = ~s/li[data-domain="#{site.domain}"] button/+ button_selector = ~s/li[data-domain="#{site.domain}"] a[phx-value-domain]/html =lv