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] import ChiyaWeb.DarkModeToggle @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 """ attr :class, :string, default: "text-theme-primary" 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 attr :note, :map, required: true attr :class_tag, :string, default: "" attr :linked, :boolean, default: true def tags(assigns) do ~H""" <%= for tag <- @note.tags do %> <%= if assigns.linked do %> <%= tag.name %> <% else %> <%= tag.name %> <% end %> <.dot class="text-theme-base/50 last:hidden" /> <% end %> """ end @doc """ Renders a note-header with title. """ attr :class, :string, default: nil attr :class_title, :string, default: nil attr :class_subtitle, :string, default: nil slot :subtitle, required: false def header(assigns) do ~H"""

<%= render_slot(@inner_block) %>

<%= render_slot(@subtitle) %>

""" end attr :layout, :atom, default: :list attr :notes, :list, required: true attr :show_content, :boolean, default: true def note_list(assigns) do case assigns.layout do :gallery -> note_list_gallery(assigns) :microblog -> note_list_microblog(assigns) _ -> note_list_default(assigns) end end attr :notes, :list, required: true @doc """ Default note list that renders a list of rounded boxes, which show the note title and an excerpt of the content """ def note_list_default(assigns) do ~H"""
<%= for note <- assigns.notes do %>
<%= note.name %> <%= pretty_date(note.published_at) %>
<%= if assigns.show_content do %>

<%= String.slice(note.content, 0..150) %>

<% end %> <%= if not Enum.empty?(note.tags) do %> <.tags note={note} linked={false} /> <% end %>
<% end %>
""" end attr :notes, :list, required: true def note_list_microblog(assigns) do ~H"""
<%= for note <- assigns.notes do %>
<.featured_images note={note} />
<%= if(note.kind == :bookmark) do %> <%= note.name %> <% end %>
<%= raw(render(note.content)) %>
<.divider /> <% end %>
""" end attr :notes, :list, required: true def note_list_gallery(assigns) do ~H""" """ end attr :user, :map, required: true def site_header(assigns) do ~H""" """ end attr :note, :map, required: true def featured_images(assigns) do images = main_images(assigns.note) case Enum.count(images) do 0 -> ~H"""
""" 1 -> assigns = assign(assigns, :image, List.first(images)) ~H"""
<.featured_image image={assigns.image} size={:full} class="rounded-lg" />
""" 2 -> assigns = assigns |> assign(:first, Enum.at(images, 0)) |> assign(:second, Enum.at(images, 1)) ~H"""
<.featured_image image={assigns.first} size={:full} class="rounded-l flex-1 w-full" /> <.featured_image image={assigns.second} size={:full} class="rounded-r flex-1 w-full" />
""" 3 -> assigns = assigns |> assign(:first, Enum.at(images, 0)) |> assign(:second, Enum.at(images, 1)) |> assign(:third, Enum.at(images, 2)) ~H"""
<.featured_image image={assigns.first} size={:thumb} class="flex-1 w-full rounded-l" /> <.featured_image image={assigns.second} size={:thumb} class="flex-1 w-full" /> <.featured_image image={assigns.third} size={:thumb} class="flex-1 w-full rounded-r" />
""" _ -> assigns = assigns |> assign(:first, Enum.at(images, 0)) |> assign(:second, Enum.at(images, 1)) |> assign(:third, Enum.at(images, 2)) |> assign(:fourth, Enum.at(images, 3)) ~H"""
<.featured_image image={assigns.first} size={:thumb} class="flex-1 w-full rounded-tl-lg" /> <.featured_image image={assigns.second} size={:thumb} class="flex-1 w-full rounded-tr-lg" />
<.featured_image image={assigns.third} size={:thumb} class="flex-1 w-full rounded-bl-lg" /> <.featured_image image={assigns.fourth} size={:thumb} class="flex-1 w-full rounded-br-lg" />
""" end end attr :image, :map, required: true attr :class, :string attr :size, :atom, default: :thumb defp featured_image(assigns) do ~H""" """ end defp gallery_name(note), do: "gallery-#{note.id}" defp main_images(note), do: Enum.filter(note.images, fn image -> image.featured end) end