defmodule PlausibleWeb.Components.Generic do
@moduledoc """
Generic reusable components
"""
use Phoenix.Component, global_prefixes: ~w(x-)
@notice_themes %{
yellow: %{
bg: "bg-yellow-50 dark:bg-yellow-100",
icon: "text-yellow-400",
title_text: "text-yellow-800 dark:text-yellow-900",
body_text: "text-yellow-700 dark:text-yellow-800"
},
red: %{
bg: "bg-red-100",
icon: "text-red-700",
title_text: "text-red-800 dark:text-red-900",
body_text: "text-red-700 dark:text-red-800"
}
}
@button_themes %{
"primary" => "bg-indigo-600 text-white hover:bg-indigo-700 focus-visible:outline-indigo-600",
"bright" =>
"border border-gray-200 bg-gray-100 dark:bg-gray-300 text-gray-800 hover:bg-gray-200 focus-visible:outline-gray-100",
"danger" =>
"border border-gray-300 dark:border-gray-500 text-red-700 bg-white dark:bg-gray-800 hover:text-red-500 dark:hover:text-red-400 focus:border-blue-300 active:text-red-800"
}
@button_base_class "inline-flex items-center justify-center gap-x-2 rounded-md px-3.5 py-2.5 text-sm font-semibold shadow-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"
attr(:type, :string, default: "button")
attr(:theme, :string, default: "primary")
attr(:class, :string, default: "")
attr(:disabled, :boolean, default: false)
attr(:rest, :global)
slot(:inner_block)
def button(assigns) do
assigns =
assign(assigns,
button_base_class: @button_base_class,
theme_class: @button_themes[assigns.theme]
)
~H"""
"""
end
attr(:href, :string, required: true)
attr(:class, :string, default: "")
attr(:theme, :string, default: "primary")
attr(:disabled, :boolean, default: false)
attr(:rest, :global)
slot(:inner_block)
def button_link(assigns) do
theme_class =
if assigns.disabled do
"bg-gray-400 text-white dark:text-white dark:text-gray-400 dark:bg-gray-700 cursor-not-allowed"
else
@button_themes[assigns.theme]
end
onclick =
if assigns.disabled do
"return false;"
else
assigns[:onclick]
end
assigns =
assign(assigns,
onclick: onclick,
button_base_class: @button_base_class,
theme_class: theme_class
)
~H"""
<.link
href={@href}
onclick={@onclick}
class={[
@button_base_class,
@theme_class,
@class
]}
{@rest}
>
<%= render_slot(@inner_block) %>
"""
end
attr(:slug, :string, required: true)
def docs_info(assigns) do
~H"""
<%= render_slot(@inner_block) %>
<%= render_slot(@inner_block) %>