Skip to content

qonvoy/tablerone

 
 

Repository files navigation

Tablerone

Renders Tabler Icons by downloading individual icons to the priv directory of the parent application during development, and loading them from files at runtime.

Installation

def deps do
  [
    {:tablerone, "~> 0.4.0"}
  ]
end

Usage

In config.exs, configure tablerone with the :otp_app of the parent application, so that icons can be loaded from the proper priv directory at run time.

import Config

config :tablerone, :otp_app, <:my_app>

Run the mix task to download one or more icons.

mix tablerone.download --type <filled | outline> <icon-name> <icon-name-2> ...

An example heex component for rendering the icon.

attr :name, :atom, required: true
attr :type, :atom, required: true, values: [:filled, :outline]
attr :class, :list, default: []

defp icon(assigns) do
  name = assigns[:name]
  type = assigns[:type]

  icon_contents = Tablerone.icon(name, type)

  assigns =
    assign_new(assigns, :icon_contents, fn ->
      class = [class: assigns[:class]] |> Phoenix.HTML.attributes_escape() |> Phoenix.HTML.safe_to_string()
      String.replace(icon_contents, ~r{class="[^"]+"}, class)
    end)

  ~H"""
  <%= Phoenix.HTML.raw(@icon_contents) %>
  """
end

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 98.7%
  • Other 1.3%