Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Consolidate dropdowns (#4934)

Uku Taht304f1cb14f1d
diff --git a/assets/tailwind.config.js b/assets/tailwind.config.js
index 1f8213e674..e1a029ef9b 100644
--- a/assets/tailwind.config.js
+++ b/assets/tailwind.config.js
@@ -55,5 +55,6 @@ module.exports = {
plugin(({ addVariant }) => addVariant("phx-click-loading", [".phx-click-loading&", ".phx-click-loading &"])),
plugin(({ addVariant }) => addVariant("phx-submit-loading", [".phx-submit-loading&", ".phx-submit-loading &"])),
plugin(({ addVariant }) => addVariant("phx-change-loading", [".phx-change-loading&", ".phx-change-loading &"])),
+ plugin(({ addVariant }) => addVariant("ui-disabled", ["&[data-ui-state~=\"disabled\"]", ":where([data-ui-state~=\"disabled\"]) &"])),
]
}
diff --git a/lib/plausible_web/components/generic.ex b/lib/plausible_web/components/generic.ex
index 9aadcdf72c..81fd13eee2 100644
--- a/lib/plausible_web/components/generic.ex
+++ b/lib/plausible_web/components/generic.ex
@@ -221,26 +221,29 @@ defmodule PlausibleWeb.Components.Generic do
"""
end
+ attr :class, :string, default: ""
+
slot :button, required: true do
attr(:class, :string)
end
- slot :panel, required: true do
+ slot :menu, required: true do
attr(:class, :string)
end
def dropdown(assigns) do
+ assigns = assign(assigns, :menu_class, assigns.menu |> List.first() |> Map.get(:class, ""))
+
~H"""
<div
x-data="dropdown"
x-on:keydown.escape.prevent.stop="close($refs.button)"
- x-on:focusin.window="! $refs.panel.contains($event.target) && close()"
+ class="relative inline-block text-left"
>
<button x-ref="button" x-on:click="toggle()" type="button" class={List.first(@button).class}>
<%= render_slot(List.first(@button)) %>
</button>
<div
- x-ref="panel"
x-show="open"
x-transition:enter="transition ease-out duration-100"
x-transition:enter-start="opacity-0 scale-95"
@@ -250,36 +253,64 @@ defmodule PlausibleWeb.Components.Generic do
x-transition:leave-end="opacity-0 scale-95"
x-on:click.outside="close($refs.button)"
style="display: none;"
- class={List.first(@panel).class}
+ class={[
+ "origin-top-right absolute z-50 right-0 mt-2 p-1 w-max rounded-md shadow-lg overflow-hidden bg-white dark:bg-gray-800 ring-1 ring-black ring-opacity-5 focus:outline-none",
+ @menu_class
+ ]}
>
- <%= render_slot(List.first(@panel)) %>
+ <%= render_slot(List.first(@menu)) %>
</div>
</div>
"""
end
- attr(:href, :string, required: true)
+ attr(:href, :string)
+ attr(:class, :string, default: "")
attr(:new_tab, :boolean, default: false)
- attr(:rest, :global)
+ attr(:disabled, :boolean, default: false)
+ attr(:rest, :global, include: ~w(method))
slot(:inner_block, required: true)
- def dropdown_link(assigns) do
- 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"
-
- class =
- if assigns.new_tab do
- "#{class} justify-between"
+ @base_class "block rounded-lg text-sm/6 text-gray-900 ui-disabled:text-gray-500 dark:text-gray-100 dark:ui-disabled:text-gray-400 px-3.5 py-1.5"
+ @clickable_class "hover:bg-gray-100 dark:hover:bg-gray-700"
+ def dropdown_item(assigns) do
+ assigns =
+ if assigns[:disabled] do
+ assign(assigns, :state, "disabled")
else
- class
+ assign(assigns, :state, "")
end
- assigns = assign(assigns, :class, class)
+ if assigns[:href] && !assigns[:disabled] do
+ assigns = assign(assigns, :class, [assigns[:class], @base_class, @clickable_class])
+
+ ~H"""
+ <.unstyled_link
+ class={@class}
+ new_tab={@new_tab}
+ href={@href}
+ x-on:click="close()"
+ data-ui-state={@state}
+ {@rest}
+ >
+ <%= render_slot(@inner_block) %>
+ </.unstyled_link>
+ """
+ else
+ assigns = assign(assigns, :class, [assigns[:class], @base_class])
+
+ ~H"""
+ <div data-ui-state={@state} class={@class}>
+ <%= render_slot(@inner_block) %>
+ </div>
+ """
+ end
+ end
+ def dropdown_divider(assigns) do
~H"""
- <.unstyled_link new_tab={@new_tab} href={@href} x-on:click="close()" class={@class} {@rest}>
- <%= render_slot(@inner_block) %>
- </.unstyled_link>
+ <div class="mx-3.5 my-1 h-px border-0 bg-gray-950/5 sm:mx-3 dark:bg-white/10" role="separator">
+ </div>
"""
end
@@ -453,8 +484,10 @@ defmodule PlausibleWeb.Components.Generic do
attr(:id, :string, default: "shuttle")
defp icon_class(link_assigns) do
- if String.contains?(link_assigns[:class], "text-sm") or
- String.contains?(link_assigns[:class], "text-xs") do
+ classes = List.wrap(link_assigns[:class]) |> Enum.join(" ")
+
+ if String.contains?(classes, "text-sm") or
+ String.contains?(classes, "text-xs") do
["w-3 h-3"]
else
["w-4 h-4"]
diff --git a/lib/plausible_web/live/sites.ex b/lib/plausible_web/live/sites.ex
index 377f9f711e..30efda8f50 100644
--- a/lib/plausible_web/live/sites.ex
+++ b/lib/plausible_web/live/sites.ex
@@ -220,7 +220,9 @@ defmodule PlausibleWeb.Live.Sites do
</div>
</.unstyled_link>
- <.ellipsis_menu site={@site} />
+ <div class="absolute right-0 top-2">
+ <.ellipsis_menu site={@site} />
+ </div>
</li>
"""
end
@@ -228,43 +230,44 @@ defmodule PlausibleWeb.Live.Sites do
def ellipsis_menu(assigns) do
~H"""
<.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 class="size-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 size-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">
- <.dropdown_link
- :if={List.first(@site.memberships).role != :viewer}
- href={"/#{URI.encode_www_form(@site.domain)}/settings/general"}
- >
- <Heroicons.cog_6_tooth class="mr-3 h-5 w-5" />
- <span>Settings</span>
- </.dropdown_link>
-
- <.dropdown_link
- href="#"
- x-on:click.prevent
- phx-click={
- JS.hide(
- transition: {"duration-500", "opacity-100", "opacity-0"},
- to: "#site-card-#{hash_domain(@site.domain)}",
- time: 500
- )
- |> JS.push("pin-toggle")
- }
- phx-value-domain={@site.domain}
- >
- <.icon_pin
- :if={@site.pinned_at}
- class="pt-1 mr-3 h-5 w-5 text-red-400 stroke-red-500 dark:text-yellow-600 dark:stroke-yellow-700"
- />
- <span :if={@site.pinned_at}>Unpin Site</span>
+ <:menu class="!mt-0 mr-4 min-w-40">
+ <!-- adjust position because click area is much bigger than icon. Default positioning from click area looks weird -->
+ <.dropdown_item
+ :if={List.first(@site.memberships).role != :viewer}
+ href={"/#{URI.encode_www_form(@site.domain)}/settings/general"}
+ class="!flex items-center gap-x-2"
+ >
+ <Heroicons.cog_6_tooth class="size-4" />
+ <span>Settings</span>
+ </.dropdown_item>
+
+ <.dropdown_item
+ href="#"
+ x-on:click.prevent
+ phx-click={
+ JS.hide(
+ transition: {"duration-500", "opacity-100", "opacity-0"},
+ to: "#site-card-#{hash_domain(@site.domain)}",
+ time: 500
+ )
+ |> JS.push("pin-toggle")
+ }
+ phx-value-domain={@site.domain}
+ class="!flex items-center gap-x-2"
+ >
+ <.icon_pin
+ :if={@site.pinned_at}
+ class="size-4 text-red-400 stroke-red-500 dark:text-yellow-600 dark:stroke-yellow-700"
+ />
+ <span :if={@site.pinned_at}>Unpin Site</span>
- <.icon_pin :if={[email protected]_at} class="pt-1 mr-3 h-5 w-5" />
- <span :if={[email protected]_at}>Pin Site</span>
- </.dropdown_link>
- </div>
- </:panel>
+ <.icon_pin :if={[email protected]_at} class="size-4" />
+ <span :if={[email protected]_at}>Pin Site</span>
+ </.dropdown_item>
+ </:menu>
</.dropdown>
"""
end
diff --git a/lib/plausible_web/templates/layout/_header.html.heex b/lib/plausible_web/templates/layout/_header.html.heex
index 6ca73f09fe..bd5aeabb5b 100644
--- a/lib/plausible_web/templates/layout/_header.html.heex
+++ b/lib/plausible_web/templates/layout/_header.html.heex
@@ -65,39 +65,51 @@
class="w-7 rounded-full"
/>
</:button>
- <:panel class="absolute right-0 z-10 mt-2 w-60 origin-top-right divide-y divide-gray-100 dark:divide-gray-400 rounded-md bg-white dark:bg-gray-800 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none">
- <div class="px-3.5 py-3" role="none">
- <p class="block text-sm text-gray-500 dark:text-gray-400" role="none">
- Signed in as
- </p>
+ <:menu>
+ <.dropdown_item>
+ <div class="text-xs text-gray-500 dark:text-gray-400">Signed in as</div>
<p class="truncate font-medium text-gray-900 dark:text-gray-100" role="none">
<%= @conn.assigns[:current_user].email %>
</p>
- </div>
- <div class="py-1.5" role="none">
- <.dropdown_link href={Routes.settings_path(@conn, :index)}>
- Account Settings
- </.dropdown_link>
- <.dropdown_link new_tab href="https://plausible.io/docs">
- Help Center
- </.dropdown_link>
- <%= if ee?() do %>
- <.dropdown_link new_tab href="https://plausible.io/contact">
- Contact Support
- </.dropdown_link>
- <.dropdown_link new_tab href={feedback_link(@conn.assigns[:current_user])}>
- Feature Requests
- </.dropdown_link>
- <% else %>
- <.dropdown_link new_tab href="https://github.com/plausible/analytics">
- Github Repo
- </.dropdown_link>
- <% end %>
- </div>
- <div class="py-1.5" role="none">
- <.dropdown_link href="/logout">Log Out</.dropdown_link>
- </div>
- </:panel>
+ </.dropdown_item>
+ <.dropdown_divider />
+ <.dropdown_item href={Routes.settings_path(@conn, :index)}>
+ Account Settings
+ </.dropdown_item>
+ <.dropdown_item
+ class="!flex justify-between gap-x-12"
+ new_tab
+ href="https://plausible.io/docs"
+ >
+ Help Center
+ </.dropdown_item>
+ <.dropdown_item
+ :if={ee?()}
+ class="!flex justify-between gap-x-12"
+ new_tab
+ href="https://plausible.io/contact"
+ >
+ Contact Support
+ </.dropdown_item>
+ <.dropdown_item
+ :if={ee?()}
+ class="!flex justify-between gap-x-12"
+ new_tab
+ href={feedback_link(@conn.assigns[:current_user])}
+ >
+ Feature Requests
+ </.dropdown_item>
+ <.dropdown_item
+ :if={ce?()}
+ class="!flex justify-between gap-x-12"
+ new_tab
+ href="https://github.com/plausible/analytics"
+ >
+ Github Repo
+ </.dropdown_item>
+ <.dropdown_divider />
+ <.dropdown_item href="/logout">Log Out</.dropdown_item>
+ </:menu>
</.dropdown>
</li>
<%= if @conn.assigns[:current_user] && ee?() do %>
diff --git a/lib/plausible_web/templates/site/settings_people.html.heex b/lib/plausible_web/templates/site/settings_people.html.heex
index 516e9cd6c5..e1f3a4a794 100644
--- a/lib/plausible_web/templates/site/settings_people.html.heex
+++ b/lib/plausible_web/templates/site/settings_people.html.heex
@@ -42,85 +42,35 @@
</p>
</div>
- <div x-data="{open: false}" @click.away="open = false" x-cloak class="relative">
- <button
- @click="open = !open"
- class="inline-flex items-center shadow-sm px-2.5 py-0.5 border border-gray-300 dark:border-gray-500 text-sm leading-5 font-medium rounded-full bg-white dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800"
- >
+ <.dropdown class="relative">
+ <:button class="bg-transparent text-gray-800 dark:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-700 focus-visible:outline-gray-100 whitespace-nowrap truncate inline-flex items-center gap-x-2 font-medium rounded-md px-3.5 py-2.5 text-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 disabled:bg-gray-400 dark:disabled:text-white dark:disabled:text-gray-400 dark:disabled:bg-gray-700">
<%= membership.role |> to_string() |> String.capitalize() %>
- <svg
- class="w-4 h-4 pt-px ml-1"
- fill="currentColor"
- viewBox="0 0 20 20"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- fill-rule="evenodd"
- d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"
- clip-rule="evenodd"
- >
- </path>
- </svg>
- </button>
- <ul
- x-show="open"
- x-transition:leave="transition ease-in duration-100"
- x-transition:leave-start="opacity-100"
- x-transition:leave-end="opacity-0"
- class="origin-top-right absolute z-50 right-0 mt-2 w-72 rounded-md shadow-lg overflow-hidden bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-400 ring-1 ring-black ring-opacity-5 focus:outline-none"
- tabindex="-1"
- role="listbox"
- aria-labelledby="listbox-label"
- aria-activedescendant="listbox-option-0"
- >
+ <Heroicons.chevron_down mini class="size-4 mt-0.5" />
+ </:button>
+ <:menu class="max-w-60">
<%= if membership.role == :owner do %>
- <li class="p-4 cursor-default group flex justify-between" role="option">
- <div>
- <p class="text-sm font-medium text-gray-900 dark:text-gray-100">
- Owner
- </p>
- <p class="mt-1 text-sm text-gray-500 dark:text-gray-400">
- Site owner cannot be assigned to any other role
- </p>
+ <.dropdown_item disabled={true}>
+ <div>Owner</div>
+ <div class="text-gray-500 dark:text-gray-400 text-xs/5">
+ Site owner cannot be assigned to any other role
</div>
-
- <span class="text-indigo-500">
- <svg
- class="h-5 w-5"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 20 20"
- fill="currentColor"
- aria-hidden="true"
- >
- <path
- fill-rule="evenodd"
- d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
- clip-rule="evenodd"
- />
- </svg>
- </span>
- </li>
- <%= if @conn.assigns[:site_role] == :owner do %>
- <li
- class="select-none hover:bg-gray-100 dark:hover:bg-gray-900 text-red-600"
- role="option"
- >
- <.unstyled_link
- class="inline-block w-full text-sm p-4 text-red-600 font-medium"
- href={
- Routes.membership_path(
- @conn,
- :transfer_ownership_form,
- @site.domain
- )
- }
- >
- Transfer ownership
- </.unstyled_link>
- </li>
- <% end %>
+ </.dropdown_item>
+ <.dropdown_divider />
+ <.dropdown_item
+ :if={@conn.assigns[:site_role] == :owner}
+ class="text-red-600 dark:text-red-500 hover:text-red-600"
+ href={
+ Routes.membership_path(
+ @conn,
+ :transfer_ownership_form,
+ @site.domain
+ )
+ }
+ >
+ Transfer ownership
+ </.dropdown_item>
<% else %>
- <.unstyled_link
+ <.dropdown_item
href={
Routes.membership_path(
@conn,
@@ -131,36 +81,14 @@
)
}
method="put"
- class="p-4 flex justify-between group hover:bg-indigo-500"
+ disabled={membership.role == "admin"}
>
- <div>
- <p class="text-sm font-medium text-gray-900 dark:text-gray-100 group-hover:text-white">
- Admin
- </p>
- <p class="mt-1 text-sm text-gray-500 dark:text-gray-400 group-hover:text-gray-100 dark:group-hover:text-white">
- View stats and edit site settings
- </p>
+ <div>Admin</div>
+ <div class="text-gray-500 dark:text-gray-400 text-xs/5">
+ View stats and edit site settings
</div>
-
- <%= if membership.role == "admin" do %>
- <span class="text-indigo-500 group-hover:text-white">
- <svg
- class="h-5 w-5"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 20 20"
- fill="currentColor"
- aria-hidden="true"
- >
- <path
- fill-rule="evenodd"
- d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
- clip-rule="evenodd"
- />
- </svg>
- </span>
- <% end %>
- </.unstyled_link>
- <.unstyled_link
+ </.dropdown_item>
+ <.dropdown_item
href={
Routes.membership_path(
@conn,
@@ -171,37 +99,15 @@
)
}
method="put"
- class="p-4 flex justify-between group hover:bg-indigo-500"
+ disabled={membership.role == "viewer"}
>
- <div>
- <p class="text-sm font-medium text-gray-900 dark:text-gray-100 group-hover:text-white">
- Viewer
- </p>
- <p class="mt-1 text-sm text-gray-500 dark:text-gray-400 group-hover:text-gray-100 dark:group-hover:text-white">
- View stats only
- </p>
+ <div>Viewer</div>
+ <div class="text-gray-500 dark:text-gray-400 text-xs/5">
+ View stats only
</div>
-
- <%= if membership.role == "viewer" do %>
- <span class="text-indigo-500 group-hover:text-white">
- <svg
- class="h-5 w-5"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 20 20"
- fill="currentColor"
- aria-hidden="true"
- >
- <path
- fill-rule="evenodd"
- d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
- clip-rule="evenodd"
- />
- </svg>
- </span>
- <% end %>
- </.unstyled_link>
-
- <.unstyled_link
+ </.dropdown_item>
+ <.dropdown_divider />
+ <.dropdown_item
href={
Routes.membership_path(
@conn,
@@ -210,14 +116,14 @@
membership.user.id
)
}
+ class="text-red-600 hover:text-red-600"
method="delete"
- class="p-4 flex hover:bg-gray-100 dark:hover:bg-gray-900 text-red-600"
>
- <p class="text-red-600 font-medium text-sm">Remove member</p>
- </.unstyled_link>
+ Remove member
+ </.dropdown_item>
<% end %>
- </ul>
- </div>
+ </:menu>
+ </.dropdown>
</div>
</li>
<% end %>