Skip to content

Commit

Permalink
refactor: clean up icon component
Browse files Browse the repository at this point in the history
  • Loading branch information
woylie committed Oct 25, 2023
1 parent cf2f3d9 commit b5a7414
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions lib/doggo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,47 +126,23 @@ defmodule Doggo do
attr :rest, :global, doc: "Any additional HTML attributes."

def icon(assigns) do
unless assigns.icon_position in [:left, :right] do
raise """
Invalid icon position
Allowed values: :left, :right
Got: #{inspect(assigns.icon_position)}
"""
end

~H"""
<span
class={["icon", icon_size_class(@size), @class]}
aria-label={@label}
{@rest}
>
<%= if @text && @icon_position == :right do %>
<span><%= @text %></span>
<% end %>
<span :if={@text && @icon_position == :right}><%= @text %></span>
<svg aria-hidden="true"><use xlink:href={"#{@sprite_url}##{@name}"} /></svg>
<%= if @text && @icon_position == :left do %>
<span><%= @text %></span>
<% end %>
<span :if={@text && @icon_position == :left}><%= @text %></span>
</span>
"""
end

defp icon_size_class(:medium), do: "is-medium"
defp icon_size_class(:small), do: "is-small"
defp icon_size_class(:large), do: "is-large"
defp icon_size_class(:normal), do: nil

defp icon_size_class(size) do
raise """
Invalid icon size
Allowed sizes: :small, :normal, :medium, :large
Got: #{inspect(size)}
"""
end
defp icon_size_class(:normal), do: "is-normal"

@doc """
Renders a list of properties, i.e. key/value pairs.
Expand Down

0 comments on commit b5a7414

Please sign in to comment.