Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle case where micro style is missing #36

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion assets/heroicons.exs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
use Phoenix.Component

defp svg(assigns) do
case assigns do
# Not all styles have the micro attribute
Map.merge(%{micro: false}, assigns)
|> case do
%{mini: false, solid: false, micro: false} ->
~H"<.svg_outline {@rest}><%%= {:safe, @paths[:outline]} %></.svg_outline>"

Expand Down Expand Up @@ -110,7 +112,7 @@
"""
end

<%= for {func, [outline, solid, mini, micro]} = icon when not is_nil(micro) <- @icons do %>

Check warning on line 115 in assets/heroicons.exs

View workflow job for this annotation

GitHub Actions / Build and test

variable "icon" is unused (if the variable is not meant to be used, prefix it with an underscore)
@doc """
Renders the `<%= func %>` icon.

Expand Down Expand Up @@ -141,7 +143,7 @@
end
<% end %>

<%= for {func, [outline, solid, mini]} = icon <- @icons do %>

Check warning on line 146 in assets/heroicons.exs

View workflow job for this annotation

GitHub Actions / Build and test

variable "icon" is unused (if the variable is not meant to be used, prefix it with an underscore)
@doc """
Renders the `<%= func %>` icon.

Expand Down
4 changes: 3 additions & 1 deletion lib/heroicons.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ defmodule Heroicons do
use Phoenix.Component

defp svg(assigns) do
case assigns do
# Not all styles have the micro attribute
Map.merge(%{micro: false}, assigns)
|> case do
%{mini: false, solid: false, micro: false} ->
~H"<.svg_outline {@rest}><%= {:safe, @paths[:outline]} %></.svg_outline>"

Expand Down
7 changes: 7 additions & 0 deletions test/heroicons_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ defmodule HeroiconsTest do
~s|<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">\n <path stroke-linecap="round" stroke-linejoin="round" d="M12 8.25v-1.5m0 1.5c-1.355 0-2.697.056-4.024.166C6.845 8.51 6 9.473 6 10.608v2.513m6-4.871c1.355 0 2.697.056 4.024.166C17.155 8.51 18 9.473 18 10.608v2.513M15 8.25v-1.5m-6 1.5v-1.5m12 9.75-1.5.75a3.354 3.354 0 0 1-3 0 3.354 3.354 0 0 0-3 0 3.354 3.354 0 0 1-3 0 3.354 3.354 0 0 0-3 0 3.354 3.354 0 0 1-3 0L3 16.5m15-3.379a48.474 48.474 0 0 0-6-.371c-2.032 0-4.034.126-6 .371m12 0c.39.049.777.102 1.163.16 1.07.16 1.837 1.094 1.837 2.175v5.169c0 .621-.504 1.125-1.125 1.125H4.125A1.125 1.125 0 0 1 3 20.625v-5.17c0-1.08.768-2.014 1.837-2.174A47.78 47.78 0 0 1 6 13.12M12.265 3.11a.375.375 0 1 1-.53 0L12 2.845l.265.265Zm-3 0a.375.375 0 1 1-.53 0L9 2.845l.265.265Zm6 0a.375.375 0 1 1-.53 0L15 2.845l.265.265Z"/>\n</svg>|
end

test "default when it has no micro" do
class = "w-6 h-6 mr-2 inline"

assert render_component(&Heroicons.arrow_right_on_rectangle/1, %{class: class}) ==
~s|<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" class="#{class}" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24">\n <path stroke-linecap="round" stroke-linejoin="round" d="M15.75 9V5.25A2.25 2.25 0 0 0 13.5 3h-6a2.25 2.25 0 0 0-2.25 2.25v13.5A2.25 2.25 0 0 0 7.5 21h6a2.25 2.25 0 0 0 2.25-2.25V15m3 0 3-3m0 0-3-3m3 3H9"/>\n</svg>|
end

test "solid" do
assert render_component(&Heroicons.cake/1, %{solid: true}) ==
~s|<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" viewBox="0 0 24 24">\n <path d="m15 1.784-.796.795a1.125 1.125 0 1 0 1.591 0L15 1.784ZM12 1.784l-.796.795a1.125 1.125 0 1 0 1.591 0L12 1.784ZM9 1.784l-.796.795a1.125 1.125 0 1 0 1.591 0L9 1.784ZM9.75 7.547c.498-.021.998-.035 1.5-.042V6.75a.75.75 0 0 1 1.5 0v.755c.502.007 1.002.021 1.5.042V6.75a.75.75 0 0 1 1.5 0v.88l.307.022c1.55.117 2.693 1.427 2.693 2.946v1.018a62.182 62.182 0 0 0-13.5 0v-1.018c0-1.519 1.143-2.829 2.693-2.946l.307-.022v-.88a.75.75 0 0 1 1.5 0v.797ZM12 12.75c-2.472 0-4.9.184-7.274.54-1.454.217-2.476 1.482-2.476 2.916v.384a4.104 4.104 0 0 1 2.585.364 2.605 2.605 0 0 0 2.33 0 4.104 4.104 0 0 1 3.67 0 2.605 2.605 0 0 0 2.33 0 4.104 4.104 0 0 1 3.67 0 2.605 2.605 0 0 0 2.33 0 4.104 4.104 0 0 1 2.585-.364v-.384c0-1.434-1.022-2.7-2.476-2.917A49.138 49.138 0 0 0 12 12.75ZM21.75 18.131a2.604 2.604 0 0 0-1.915.165 4.104 4.104 0 0 1-3.67 0 2.605 2.605 0 0 0-2.33 0 4.104 4.104 0 0 1-3.67 0 2.605 2.605 0 0 0-2.33 0 4.104 4.104 0 0 1-3.67 0 2.604 2.604 0 0 0-1.915-.165v2.494c0 1.035.84 1.875 1.875 1.875h15.75c1.035 0 1.875-.84 1.875-1.875v-2.494Z"/>\n</svg>|
Expand Down
Loading