Phoenix LiveView library

One component.
Seven+ icon libraries.

Icon library for Phoenix LiveView that scans your templates at compile time, downloads only the icons you actually use, and inlines the SVGs as compiled function clauses. Zero runtime overhead, no unused icons bundled, no Node.js required.

Installation

Three steps, without any JavaScript tooling.

  1. 1

    Add the dependency

    mix.exs
    defp deps do
      [{:phx_icons, "~> 0.3.0"}]
    end
  2. 2

    Pick your providers

    config.exs
    config :phx_icons,
      providers: %{
        "heroicons" => {PhxIcons.Providers.Heroicons, "2.2.0"},
        "lucide" => {PhxIcons.Providers.Lucide, "0.469.0"}
      }
  3. 3

    Hook it into your components

    core_components.ex
    defmodule MyAppWeb.CoreComponents do
      use Phoenix.Component
      use PhxIcons
    end

Providers

Prefix the icon name with the provider.

Heroicons

heroicons:* 2.2.0 heroicons.com

Hand-crafted icons by the makers of Tailwind CSS.

heart
bell
check
arrow-left

Lucide

lucide:* 0.469.0 lucide.dev

A community fork of Feather with clean, consistent strokes.

heart
bell
check
arrow-left

Tabler

tabler:* 3.41.1 tabler.io

Over 5,000 free icons with outline and filled styles.

star
bell
check
bolt

Phosphor

phosphor:* 2.0.8 phosphoricons.com

Six weights: thin, light, regular, bold, fill, and duotone.

heart
bell
check
arrow-left

Simple Icons

simple-icons:* 16.16.0 simpleicons.org

Brand logos. Add fill-current because they are filled shapes.

GitHub github
Elixir elixir
Docker docker
Tailwind CSS tailwindcss

Flagpack

flagpack:* 2.1.0 flagpack.xyz

Country flags. You can alias names, e.g. "gb" => "gb-ukm".

de
at
gb
us

Reicon

reicon:* b5eb77801d65f2754d2fbd3837b979be6a4f26d3 reicon.dev

One icon set in outline and filled styles.

heart
bell
check
arrow-left

Sizing & color

Icons inherit currentColor, so you size and tint them with plain Tailwind utilities.

size-4
size-6
size-8
size-12

Animations

Because the SVG is inlined, Tailwind's transition and animation utilities apply to it directly.

scale + color
animate-ping
animate-spin
animate-pulse

Pre-downloading icons

You can also pre-download all icons from a provider, a specific list, or extra icons in addition to the icons discovered in your codebase.

config.exs
config :phx_icons,
  providers: %{
    # Download all icons upfront
    "heroicons" => {PhxIcons.Providers.Heroicons, "2.2.0", download: :all},
    # Download a specific set
    "lucide" => {PhxIcons.Providers.Lucide, "0.469.0", download: ~w(search check x)},
    # Download discovered icons plus these extra icons
    "tabler" => {PhxIcons.Providers.Tabler, "3.41.1", download: {:also, ~w(settings user)}}
  }

Custom providers

Implement the PhxIcons.Provider behaviour.

custom_icons.ex
defmodule MyApp.Providers.CustomIcons do
  @behaviour PhxIcons.Provider

  @impl true
  def release_url(version) do
    "https://github.com/org/repo/archive/refs/tags/v#{version}.zip"
  end

  @impl true
  def svg_path(version, icon_name, _opts) do
    "repo-#{version}/icons/#{icon_name}.svg"
  end
end

Optionally implement transform/1 to rewrite each SVG before it's stored, e.g. replacing hardcoded fills with currentColor. This is how the built-in Reicon provider does it:

custom_icons.ex
@impl true
def transform(svg) do
  String.replace(svg, ~s(fill="#000000"), ~s(fill="currentColor"))
end

Then register it in your config.

config.exs
config :phx_icons,
  providers: %{
    "custom" => {MyApp.Providers.CustomIcons, "1.0.0"}
  }

Testing

PhxIcons ships with test helpers to assert icons are rendered.

core_components_test.exs
import PhxIcons.Test

html = render_component(&MyAppWeb.CoreComponents.icon/1, name: "heroicons:heart")
assert_icon(html, "heroicons:heart")
refute_icon(html, "heroicons:x-mark")