defmodule Doggo do @moduledoc """ Collection of Phoenix Components. """ use Phoenix.Component alias Phoenix.HTML.Form alias Phoenix.LiveView.JS ## Components @doc """ The action bar offers users quick access to primary actions within the application. It is typically positioned to float above other content. ## Example <.action_bar> <:item label="Edit" on_click={JS.push("edit")}> <.icon size={:small}> <:item label="Move" on_click={JS.push("move")}> <.icon size={:small}> <:item label="Archive" on_click={JS.push("archive")}> <.icon size={:small}> """ @doc type: :component attr :class, :any, default: [], doc: "Additional CSS classes. Can be a string or a list of strings." attr :rest, :global, doc: "Any additional HTML attributes." slot :item do attr :label, :string, required: true attr :on_click, JS, required: true end def action_bar(assigns) do ~H"""
<.link :for={item <- @item} phx-click={item.on_click} title={item.label}> <%= render_slot(item) %>
""" end @doc """ The app bar is typically located at the top of the interface and provides access to key features and navigation options. ## Usage <.app_bar title="Page title"> <:navigation label="Open menu" on_click={JS.push("toggle-menu")}> <.icon> <:action label="Search" on_click={JS.push("search")}> <.icon> <:action label="Like" on_click={JS.push("like")}> <.icon> """ @doc type: :component attr :title, :string, default: nil, doc: "The page title. Will be set as `h1`." attr :class, :any, default: [], doc: "Additional CSS classes. Can be a string or a list of strings." attr :rest, :global, doc: "Any additional HTML attributes." slot :navigation, doc: """ Slot for a single button left of the title, typically used for a menu button that toggles a drawer, or for a back link. """ do attr :label, :string, required: true attr :on_click, JS, required: true end slot :action, doc: "Slot for action buttons right of the title." do attr :label, :string, required: true attr :on_click, JS, required: true end def app_bar(assigns) do ~H"""
<.link :for={navigation <- @navigation} phx-click={navigation.on_click} title={navigation.label} > <%= render_slot(navigation) %>

<%= @title %>

<.link :for={action <- @action} phx-click={action.on_click} title={action.label} > <%= render_slot(action) %>
""" end @doc """ Renders a breadcrumb navigation. ## Example <.breadcrumb> <:item patch="/categories">Categories <:item patch="/categories/1">Reviews <:item patch="/categories/1/articles/1">The Movie """ @doc type: :component attr :aria_label, :string, default: "breadcrumb" attr :class, :any, default: [], doc: "Additional CSS classes. Can be a string or a list of strings." attr :rest, :global, doc: "Any additional HTML attributes." slot :item, required: true do attr :navigate, :string attr :patch, :string attr :href, :string end def breadcrumb(%{item: items} = assigns) do [last_item | rest] = Enum.reverse(items) assigns = assign(assigns, :item, Enum.reverse([{:current, last_item} | rest])) ~H""" """ end defp breadcrumb_link(%{item: {:current, current_item}} = assigns) do assigns = assign(assigns, :item, current_item) ~H""" <.link navigate={@item[:navigate]} patch={@item[:patch]} href={@item[:href]} aria-current="page" > <%= render_slot(@item) %> """ end defp breadcrumb_link(assigns) do ~H""" <.link navigate={@item[:navigate]} patch={@item[:patch]} href={@item[:href]}> <%= render_slot(@item) %> """ end @doc """ Renders a button. ## Examples <.button>Confirm <.button type="submit" variant={:secondary} size={:medium} shape={:pill}> Submit """ @doc type: :component attr :type, :string, values: ["button", "reset", "submit"], default: "button" attr :variant, :atom, values: [:primary, :secondary, :info, :success, :warning, :danger], default: :primary attr :fill, :atom, values: [:solid, :outline, :text], default: :solid attr :size, :atom, values: [:small, :normal, :medium, :large], default: :normal attr :shape, :atom, values: [nil, :circle, :pill], default: nil attr :disabled, :boolean, default: nil attr :rest, :global, include: ~w(autofocus form name value) slot :inner_block, required: true def button(assigns) do ~H""" """ end @doc """ Renders a link (``) that has the role and style of a button. ## Examples <.button_link patch={~p"/confirm"}>Confirm <.button_link navigate={~p"/registration"} variant={:primary} shape={:pill}> Submit """ @doc type: :component attr :variant, :atom, values: [:primary, :secondary, :info, :success, :warning, :danger], default: :primary attr :fill, :atom, values: [:solid, :outline, :text], default: :solid attr :size, :atom, values: [:small, :normal, :medium, :large], default: :normal attr :shape, :atom, values: [nil, :circle, :pill], default: nil attr :disabled, :boolean, default: false, doc: """ Since `` tags cannot have a `disabled` attribute, this attribute toggles the `"is-disabled"` class. """ attr :rest, :global, include: [ # HTML attributes "download", "hreflang", "referrerpolicy", "rel", "target", "type", # Phoenix.LiveView.Component.link/1 attributes "navigate", "patch", "href", "replace", "method", "csrf_token" ] slot :inner_block, required: true def button_link(assigns) do ~H""" <.link role="button" class={[ variant_class(@variant), size_class(@size), shape_class(@shape), fill_class(@fill), @disabled && "is-disabled" ]} {@rest} > <%= render_slot(@inner_block) %> """ end @doc """ Renders a `DateTime` or `NaiveDateTime` in a `