defmodule Backpex.HTML.Layout do @moduledoc """ Contains all Backpex layout components. """ use BackpexWeb, :html alias Backpex.Router @doc """ Renders an app shell representing the base of your layout. """ @doc type: :component attr :fluid, :boolean, default: false, doc: "toggles fluid layout" slot :inner_block slot :topbar, doc: "content to be displayed in the topbar" do attr :class, :string, doc: "additional class that will be added to the component" end slot :sidebar, doc: "content to be displayed in the sidebar" do attr :class, :string, doc: "additional class that will be added to the component" end slot :footer, doc: "content to be displayed in the footer" def app_shell(assigns) do ~H"""
<%= @title %>
<% end %><%= @text %>
""" end @doc """ Filters fields by certain panel. ## Examples iex> Backpex.HTML.Layout.visible_fields_by_panel([field1: %{panel: :default}, field2: %{panel: :panel}], :default, nil) [field1: %{panel: :default}] iex> Backpex.HTML.Layout.visible_fields_by_panel([field1: %{panel: :default, visible: fn _assigns -> false end}, field2: %{panel: :panel}], :default, nil) [] iex> Backpex.HTML.Layout.visible_fields_by_panel([field1: %{panel: :default}], :panel, nil) [] """ def visible_fields_by_panel(fields, panel, assigns) do fields |> Keyword.filter(fn {_name, field_options} -> get_panel(field_options) == panel and visible?(field_options, assigns) end) end defp get_panel(%{panel: panel} = _field), do: panel defp get_panel(_field), do: :default defp visible?(%{visible: visible} = _field_options, assigns), do: visible.(assigns) defp visible?(_field_options, _assigns), do: true defp get_align_class(align) do case align do :top -> "sm:self-start" :center -> "sm:self-center" :bottom -> "sm:self-end" _align -> "sm:self-center" end end end