diff --git a/lib/chiya_web.ex b/lib/chiya_web.ex index 6de6716..6a8b18d 100644 --- a/lib/chiya_web.ex +++ b/lib/chiya_web.ex @@ -58,7 +58,7 @@ defmodule ChiyaWeb do layout: {ChiyaWeb.Layouts, :app} # Import admin components - import ChiyaWeb.AdminComponents + import ChiyaWeb.CoreComponents unquote(html_helpers()) end @@ -69,7 +69,7 @@ defmodule ChiyaWeb do use Phoenix.LiveComponent # Import admin components - import ChiyaWeb.AdminComponents + import ChiyaWeb.CoreComponents unquote(html_helpers()) end @@ -84,7 +84,7 @@ defmodule ChiyaWeb do only: [get_csrf_token: 0, view_module: 1, view_template: 1] # Import admin components - import ChiyaWeb.AdminComponents + import ChiyaWeb.CoreComponents # Include general helpers for rendering HTML unquote(html_helpers()) @@ -112,7 +112,6 @@ defmodule ChiyaWeb do # HTML escaping functionality import Phoenix.HTML # Core UI components and translation - import ChiyaWeb.CoreComponents import ChiyaWeb.Gettext # Shortcut for generating JS commands diff --git a/lib/chiya_web/components/admin_components.ex b/lib/chiya_web/components/admin_components.ex deleted file mode 100644 index f29e041..0000000 --- a/lib/chiya_web/components/admin_components.ex +++ /dev/null @@ -1,126 +0,0 @@ -defmodule ChiyaWeb.AdminComponents do - use Phoenix.Component - - use Phoenix.VerifiedRoutes, - endpoint: ChiyaWeb.Endpoint, - router: ChiyaWeb.Router, - statics: ChiyaWeb.static_paths() - - import ChiyaWeb.CoreComponents - - @doc """ - Renders a horizontal line - """ - def line(assigns) do - ~H""" -
- """ - end - - @doc """ - Renders a UI for uploading files - """ - - attr :upload, :map, required: true - attr :cancel_upload, :string, default: "cancel-upload" - - def live_upload(assigns) do - ~H""" -
- <.live_file_input upload={@upload} class="dark:text-gray-300" /> - -
- <%= for entry <- @upload.entries do %> -
-
- <.live_img_preview entry={entry} /> -
<%= entry.client_name %>
-
- -
- <%!-- entry.progress will update automatically for in-flight entries --%> - - <%= entry.progress %>% - - - <%!-- a regular click event whose handler will invoke Phoenix.LiveView.cancel_upload/3 --%> - -
- - <%!-- Phoenix.Component.upload_errors/2 returns a list of error atoms --%> - <%= for err <- upload_errors(@upload, entry) do %> -

<%= upload_error_to_string(err) %>

- <% end %> -
- <% end %> -
-
- """ - end - - @doc """ - Renders the admin menu bar - """ - - attr :current_user, :map, required: true - attr :settings, :map, required: true - - def admin_bar(assigns) do - ~H""" - - """ - end - - defp upload_error_to_string(:too_large), do: "Too large" - defp upload_error_to_string(:too_many_files), do: "You have selected too many files" - defp upload_error_to_string(:not_accepted), do: "You have selected an unacceptable file type" -end diff --git a/lib/chiya_web/components/core_components.ex b/lib/chiya_web/components/core_components.ex index d43e82a..4924063 100644 --- a/lib/chiya_web/components/core_components.ex +++ b/lib/chiya_web/components/core_components.ex @@ -653,6 +653,118 @@ defmodule ChiyaWeb.CoreComponents do """ end + @doc """ + Renders a horizontal line + """ + def line(assigns) do + ~H""" +
+ """ + end + + @doc """ + Renders a UI for uploading files + """ + + attr :upload, :map, required: true + attr :cancel_upload, :string, default: "cancel-upload" + + def live_upload(assigns) do + ~H""" +
+ <.live_file_input upload={@upload} class="dark:text-gray-300" /> + +
+ <%= for entry <- @upload.entries do %> +
+
+ <.live_img_preview entry={entry} /> +
<%= entry.client_name %>
+
+ +
+ <%!-- entry.progress will update automatically for in-flight entries --%> + + <%= entry.progress %>% + + + <%!-- a regular click event whose handler will invoke Phoenix.LiveView.cancel_upload/3 --%> + +
+ + <%!-- Phoenix.Component.upload_errors/2 returns a list of error atoms --%> + <%= for err <- upload_errors(@upload, entry) do %> +

<%= upload_error_to_string(err) %>

+ <% end %> +
+ <% end %> +
+
+ """ + end + + @doc """ + Renders the admin menu bar + """ + + attr :current_user, :map, required: true + attr :settings, :map, required: true + + def admin_bar(assigns) do + ~H""" + + """ + end + ## JS Commands def show(js \\ %JS{}, selector) do @@ -734,4 +846,9 @@ defmodule ChiyaWeb.CoreComponents do def translate_errors(errors, field) when is_list(errors) do for {^field, {msg, opts}} <- errors, do: translate_error({msg, opts}) end + + defp upload_error_to_string(:too_large), do: "Too large" + defp upload_error_to_string(:too_many_files), do: "You have selected too many files" + defp upload_error_to_string(:not_accepted), do: "You have selected an unacceptable file type" + end diff --git a/lib/chiya_web/components/layouts.ex b/lib/chiya_web/components/layouts.ex index f7fe4e1..2ff0c0c 100644 --- a/lib/chiya_web/components/layouts.ex +++ b/lib/chiya_web/components/layouts.ex @@ -1,7 +1,7 @@ defmodule ChiyaWeb.Layouts do use ChiyaWeb, :html - import ChiyaWeb.PublicComponents + import ChiyaWeb.PublicComponents, only: [divider: 1] embed_templates "layouts/*" end diff --git a/lib/chiya_web/components/public_components.ex b/lib/chiya_web/components/public_components.ex index 24f3f8a..dde1679 100644 --- a/lib/chiya_web/components/public_components.ex +++ b/lib/chiya_web/components/public_components.ex @@ -9,7 +9,35 @@ defmodule ChiyaWeb.PublicComponents do import ChiyaWeb.Format import ChiyaWeb.Markdown, only: [render: 1] import Phoenix.HTML, only: [raw: 1] - import ChiyaWeb.CoreComponents + + @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 @@ -164,58 +192,58 @@ defmodule ChiyaWeb.PublicComponents do 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_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 /> + # def comment_list(assigns) do + # ~H""" + # <%= if not Enum.empty?(assigns.note.comments) do %> + # <.line /> -

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

+ #

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

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

No comments yet.

- <% end %> - """ - end + #

No comments yet.

+ # <% end %> + # """ + # end defp gallery_name(note), do: "gallery-#{note.id}"