2021-02-25 17:53:44 -05:00
|
|
|
defmodule Bones73kWeb.IconHelpers do
|
|
|
|
@moduledoc """
|
|
|
|
Generate SVG sprite use tags for SVG icons
|
|
|
|
"""
|
|
|
|
|
|
|
|
use Phoenix.HTML
|
|
|
|
alias Bones73kWeb.Router.Helpers, as: Routes
|
|
|
|
|
|
|
|
def icon_div(conn, name, div_opts \\ [], svg_opts \\ []) do
|
|
|
|
content_tag(:div, tag_opts(name, div_opts)) do
|
|
|
|
icon_svg(conn, name, svg_opts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def icon_svg(conn, name, opts \\ []) do
|
|
|
|
content_tag(:svg, tag_opts(name, opts)) do
|
2021-02-25 18:21:43 -05:00
|
|
|
tag(:use, "xlink:href": Routes.static_path(conn, "/images/icons.svg##{name}"))
|
2021-02-25 17:53:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp tag_opts(name, opts) do
|
2021-02-25 18:21:43 -05:00
|
|
|
Keyword.update(opts, :class, name, fn c -> "#{c} #{name}" end)
|
2021-02-25 17:53:44 -05:00
|
|
|
end
|
|
|
|
end
|