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

Dynamic icons #21

Open
mplatts opened this issue Oct 18, 2022 · 1 comment
Open

Dynamic icons #21

mplatts opened this issue Oct 18, 2022 · 1 comment

Comments

@mplatts
Copy link

mplatts commented Oct 18, 2022

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
Copy link

aptinio commented Oct 24, 2022

@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" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants