defmodule ChiyaWeb.PublicComponents do use Phoenix.Component use Phoenix.VerifiedRoutes, endpoint: ChiyaWeb.Endpoint, router: ChiyaWeb.Router, statics: ChiyaWeb.static_paths() import ChiyaWeb.Format import ChiyaWeb.Markdown, only: [render: 1] import Phoenix.HTML, only: [raw: 1] @doc """ Renders a [Hero Icon](https://heroicons.com). Hero icons come in three styles – outline, solid, and mini. By default, the outline style is used, but solid an mini may be applied by using the `-solid` and `-mini` suffix. You can customize the size and colors of the icons by setting width, height, and background color classes. Icons are extracted from your `priv/hero_icons` directory and bundled within your compiled app.css by the plugin in your `assets/tailwind.config.js`. ## Examples <.icon name="hero-cake" /> <.icon name="hero-cake-solid" /> <.icon name="hero-cake-mini" /> <.icon name="hero-bolt" class="bg-blue-500 w-10 h-10" /> """ attr :name, :string, required: true attr :class, :string, default: nil def icon(%{name: "hero-" <> _} = assigns) do ~H""" """ end @doc """ Renders a middot as divider """ def dot(assigns), do: ~H""" · """ @doc """ Renders a horizontal line """ def line(assigns), do: ~H"""
""" attr :text, :string, default: "⌘" def divider(assigns) do ~H"""
<%= assigns.text %>
""" end @doc """ Renders a note-header with title. """ attr :class, :string, default: nil attr :inline, :boolean, default: false slot :inner_block, required: true slot :subtitle slot :actions def header(assigns) do ~H"""

<%= render_slot(@inner_block) %> <%= render_slot(@subtitle) %>

<%= render_slot(@subtitle) %>

<%= render_slot(@actions) %>
""" end attr :layout, :atom, default: :list attr :notes, :list, required: true def note_list(assigns) do case assigns.layout do :gallery -> ~H""" """ :microblog -> ~H"""
<%= for note <- assigns.notes do %>
<% image = main_image(note) %> <%= if image do %>
<% end %>
<%= raw(render(note.content)) %>
<.dot /> Permalink <%= if not Enum.empty?(note.images) do %> <.dot /> <.icon name="hero-photo" /> <% end %>
<.divider /> <% end %>
""" # default, show headings only _ -> ~H"""
<%= for note <- assigns.notes do %> <%= note.name %> <%= pretty_date(note.published_at) %> <% end %>
""" end end # def comment_form(assigns) do # ~H""" # <.simple_form :let={f} for={@changeset} action="" class="bg-theme-background -m-3"> # <.error :if={@changeset.action}> # Oops, something went wrong! Please check the errors below. # # <.input # field={f[:author_name]} # type="text" # placeholder="Name" # class="bg-theme-background dark:bg-theme-background border-theme-base/20 dark:border-theme-base/20 text-theme-base dark:text-theme-base placeholder-theme-base/40 dark:placeholder-theme-base/60 dark:focus:border-theme-base/60 dark:focus:border-theme-base/60" # /> # <.input # field={f[:content]} # type="textarea" # placeholder="Content" # rows="3" # class="bg-theme-background dark:bg-theme-background border-theme-base/20 dark:border-theme-base/20 text-theme-base dark:text-theme-base placeholder-theme-base/60 dark:placeholder-theme-base/60 focus:border-theme-base/60 dark:focus:border-theme-base/60" # /> # <.input field={f[:note_id]} type="hidden" /> # <:actions> # <.button>Submit Comment # # # """ # end # def comment_list(assigns) do # ~H""" # <%= if not Enum.empty?(assigns.note.comments) do %> # <.line /> #

<%= Enum.count(assigns.note.comments) %> Comments

# # <% else %> # <.line /> #

No comments yet.

# <% end %> # """ # end defp gallery_name(note), do: "gallery-#{note.id}" defp main_image(note), do: note.images |> Enum.filter(fn image -> image.featured end) |> List.first() end