defmodule AutogenticWeb.CoreComponents do @moduledoc """ Provides core UI components for Autogentic. """ use Phoenix.Component alias Phoenix.LiveView.JS use Gettext, backend: AutogenticWeb.Gettext @doc """ Renders a simple button. """ attr :type, :string, default: nil attr :class, :string, default: nil attr :rest, :global, include: ~w(disabled form name value) slot :inner_block, required: true def button(assigns) do ~H""" """ end @doc """ Renders an icon. """ attr :name, :string, required: true attr :class, :string, default: nil def icon(%{name: "hero-" <> _} = assigns) do ~H""" """ end @doc """ Renders flash notices. """ attr :id, :string, default: "flash" attr :flash, :map, default: %{} attr :title, :string, default: nil attr :kind, :atom, values: [:info, :error] attr :rest, :global slot :inner_block def flash(assigns) do ~H"""
hide("##{@id}")} role="alert" class={[ "fixed top-2 right-2 mr-2 w-80 sm:w-96 z-50 rounded-lg p-3 ring-1", @kind == :info && "bg-emerald-50 text-emerald-800 ring-emerald-500 fill-cyan-900", @kind == :error && "bg-rose-50 text-rose-900 shadow-md ring-rose-500 fill-rose-900" ]} {@rest} >

<.icon :if={@kind == :info} name="hero-information-circle-mini" class="h-4 w-4" /> <.icon :if={@kind == :error} name="hero-exclamation-circle-mini" class="h-4 w-4" /> <%= @title %>

<%= msg %>

""" end @doc """ Shows the flash group with standard titles and content. """ attr :flash, :map, required: true def flash_group(assigns) do ~H""" <.flash kind={:info} title="Success!" flash={@flash} /> <.flash kind={:error} title="Error!" flash={@flash} /> """ end @doc """ Renders a header with title. """ attr :class, :string, default: nil slot :inner_block, required: true slot :subtitle slot :actions def header(assigns) do ~H"""

<%= render_slot(@inner_block) %>

<%= render_slot(@subtitle) %>

<%= render_slot(@actions) %>
""" end ## JS Commands def show(js \\ %JS{}, selector) do JS.show(js, to: selector, transition: {"transition-all transform ease-out duration-300", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95", "opacity-100 translate-y-0 sm:scale-100"} ) end def hide(js \\ %JS{}, selector) do JS.hide(js, to: selector, time: 200, transition: {"transition-all transform ease-in duration-200", "opacity-100 translate-y-0 sm:scale-100", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"} ) end end