Current section
Files
Jump to
Current section
Files
lib/phoenix_ui/components/icon/cog.ex
defmodule PhoenixUI.Components.Icon.Cog do
@moduledoc false
use Phoenix.Component
@default_color "primary"
@default_size :md
### Variants ##########################
def outline(assigns), do: assigns |> assign(:variant, :outline) |> build_component()
def solid(assigns), do: assigns |> assign(:variant, :solid) |> build_component()
### Normalize Assigns ##########################
defp build_component(assigns) do
assigns
|> assign_new(:color, fn -> @default_color end)
|> assign_new(:size, fn -> @default_size end)
|> apply_root_assigns()
|> generate_markup()
end
### Markup ##########################
defp generate_markup(%{variant: :outline} = assigns) do
~H"""
<svg {@root_attrs} class={@root_class} xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
</svg>
"""
end
defp generate_markup(%{variant: :solid} = assigns) do
~H"""
<svg {@root_attrs} class={@root_class} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path fill-rule="evenodd" d="M11.49 3.17c-.38-1.56-2.6-1.56-2.98 0a1.532 1.532 0 01-2.286.948c-1.372-.836-2.942.734-2.106 2.106.54.886.061 2.042-.947 2.287-1.561.379-1.561 2.6 0 2.978a1.532 1.532 0 01.947 2.287c-.836 1.372.734 2.942 2.106 2.106a1.532 1.532 0 012.287.947c.379 1.561 2.6 1.561 2.978 0a1.533 1.533 0 012.287-.947c1.372.836 2.942-.734 2.106-2.106a1.533 1.533 0 01.947-2.287c1.561-.379 1.561-2.6 0-2.978a1.532 1.532 0 01-.947-2.287c.836-1.372-.734-2.942-2.106-2.106a1.532 1.532 0 01-2.287-.947zM10 13a3 3 0 100-6 3 3 0 000 6z" clip-rule="evenodd"/>
</svg>
"""
end
### Root Assigns ##########################
defp apply_root_assigns(assigns) do
framework = Application.get_env(:phoenix_ui, :css_framework)
attrs =
Map.drop(assigns, [
:__changed__,
:class,
:color,
:element,
:inner_block,
:size,
:variant
])
class =
Enum.join(
[
get_color_css(framework, assigns),
get_size_css(framework, assigns),
Map.get(assigns, :class)
],
" "
)
assign(assigns,
root_attrs: attrs,
root_class: class
)
end
defp get_color_css(:tailwind_css, %{color: color}), do: "text-#{color}-500"
defp get_size_css(:tailwind_css, %{size: :xs}), do: "h-2 w-2"
defp get_size_css(:tailwind_css, %{size: :sm}), do: "h-4 w-4"
defp get_size_css(:tailwind_css, %{size: :md}), do: "h-6 w-6"
defp get_size_css(:tailwind_css, %{size: :lg}), do: "h-8 w-8"
end