mveytsman / heroicons_elixir

Phoenix components for Heroicons! 🛡️
MIT License
118 stars 28 forks source link

Dynamic icons #21

Open mplatts opened 1 year ago

mplatts commented 1 year ago

Is there an easy way to pass in the icon name as an argument?

eg:

<Heroicons.icon name="academic-cap" class="h-4 w-4" />
aptinio commented 1 year ago

@mplatts, I got this to work:

use Phoenix.Component

attr :rest, :global,
  doc: "the arbitrary HTML attributes for the svg container",
  include: ~w(fill stroke stroke-width)

attr :name, :atom, required: true
attr :outline, :boolean, default: true
attr :solid, :boolean, default: false
attr :mini, :boolean, default: false

def icon(assigns) do
  apply(Heroicons, assigns.name, [assigns])
end
<.icon name={:academic_cap} class="h-4 w-4" />