Skip to content

Commit

Permalink
feat: Add material design icons community version.
Browse files Browse the repository at this point in the history
  • Loading branch information
GSMLG-BOT committed Dec 3, 2022
1 parent f90f6ad commit 2ee18ad
Show file tree
Hide file tree
Showing 7,207 changed files with 7,328 additions and 7 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
26 changes: 26 additions & 0 deletions apps/phoenix_webcomponent/lib/mix/tasks/gen_icon.ex
@@ -0,0 +1,26 @@
defmodule Mix.Tasks.PhxWc.GenIcons do
# Generate Material Design Icons
# try to define with macro, it's too slow

@moduledoc """
Generate Phoenix.WebComponent.MaterialDesignIcons fron 7000+ svg files
"""
use Mix.Task

@shortdoc "Generate Phoenix.WebComponent.MaterialDesignIcons.ex file"
def run(_) do
Mix.Task.run("app.start")

icons =
File.ls!(Application.app_dir(:phoenix_webcomponent, "priv/mdi/svg"))
|> Enum.filter(&String.ends_with?(&1, ".svg"))
|> Enum.map(&String.trim(&1, ".svg"))

quoted = EEx.compile_file("#{__DIR__}/material_design_icons.eex")
{result, _bindings} = Code.eval_quoted(quoted, icons: icons)

fl = Path.expand("../../phoenix_webcomponent/material_design_icons.ex", __DIR__)

File.write!(fl, result)
end
end
28 changes: 28 additions & 0 deletions apps/phoenix_webcomponent/lib/mix/tasks/material_design_icons.eex
@@ -0,0 +1,28 @@
defmodule Phoenix.WebComponent.MaterialDesignIcons do
@moduledoc """
Render 7000+ Material Design Icons
"""
use Phoenix.WebComponent, :html

# alias Phoenix.LiveView.JS

@icons ~W(<%= icons |> Enum.join(" ") %>)

@spec icons() :: [String.t()]
def icons(), do: @icons

<%= for name <- icons do %>
def <%= String.replace(name, "-", "_") %>(assigns) do
assigns =
assigns
|> assign_new(:id, fn -> false end)
|> assign_new(:class, fn -> false end)

~H"""
<svg xmlns="http://www.w3.org/2000/svg" id={@id} class={@class} viewBox="0 0 24 24">
<%= File.read!(Application.app_dir(:phoenix_webcomponent, "priv/mdi/svg/#{name}.svg")) |> String.replace(~r/<svg[^>]+>/, "") |> String.replace("</svg>", "") %>
</svg>
"""
end
<% end %>
end
1 change: 1 addition & 0 deletions apps/phoenix_webcomponent/lib/phoenix_webcomponent.ex
Expand Up @@ -77,6 +77,7 @@ defmodule Phoenix.WebComponent do
import Phoenix.WebComponent.Markdown
import Phoenix.WebComponent.Pagination
import Phoenix.WebComponent.Table
import Phoenix.WebComponent.Icons
end
end

Expand Down
42 changes: 42 additions & 0 deletions apps/phoenix_webcomponent/lib/phoenix_webcomponent/icons.ex
@@ -0,0 +1,42 @@
defmodule Phoenix.WebComponent.Icons do
@moduledoc """
Render 7000+ Material Design Icons
"""
use Phoenix.WebComponent, :html

# alias Phoenix.LiveView.JS

@icons File.ls!(Application.app_dir(:phoenix_webcomponent, "priv/mdi/svg"))
|> Enum.filter(&String.ends_with?(&1, ".svg"))
|> Enum.map(&String.trim(&1, ".svg"))
|> Enum.sort(:asc)

@spec mdi_icons() :: [String.t()]
def mdi_icons(), do: @icons

@doc """
Render 7000+ Material Design Icons
"""
def wc_mdi(assigns) do
assigns =
assigns
|> assign_new(:id, fn -> false end)
|> assign_new(:class, fn -> false end)

name = assigns.name

inner_svg =
File.read!(Application.app_dir(:phoenix_webcomponent, "priv/mdi/svg/#{name}.svg"))
|> String.replace(~r/<svg[^>]+>/, "")
|> String.replace("</svg>", "")

assigns = assigns |> assign(:inner_svg, inner_svg)

~H"""
<svg xmlns="http://www.w3.org/2000/svg" id={@id} class={@class} viewBox="0 0 24 24">
<%= raw(@inner_svg) %>
</svg>
"""
end
end
Expand Up @@ -36,6 +36,7 @@ defmodule Phoenix.WebComponent.Markdown do
|> assign_new(:id, fn -> false end)
|> assign_new(:class, fn -> false end)
|> assign_new(:debug, fn -> false end)
|> assign_new(:content, fn -> "" end)

~H"""
<remark-element id={@id} debug={@debug} class={@class}><%= @content %></remark-element>
Expand Down
Expand Up @@ -23,8 +23,6 @@ defmodule Phoenix.WebComponent.Pagination do
|> assign_new(:total, fn -> 0 end)
|> assign_new(:update_event, fn -> "update_current_page" end)

# IO.inspect(assigns)

max_page =
if assigns.total > 0 do
(assigns.total / assigns.page_size) |> ceil
Expand Down
1 change: 1 addition & 0 deletions apps/phoenix_webcomponent/priv/mdi/svg/ab-testing.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/phoenix_webcomponent/priv/mdi/svg/abacus.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/phoenix_webcomponent/priv/mdi/svg/abjad-arabic.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/phoenix_webcomponent/priv/mdi/svg/abjad-hebrew.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/phoenix_webcomponent/priv/mdi/svg/abugida-thai.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/phoenix_webcomponent/priv/mdi/svg/access-point.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/phoenix_webcomponent/priv/mdi/svg/account-alert.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/phoenix_webcomponent/priv/mdi/svg/account-badge.svg
1 change: 1 addition & 0 deletions apps/phoenix_webcomponent/priv/mdi/svg/account-box.svg

0 comments on commit 2ee18ad

Please sign in to comment.