Packages

A complimentary UI library for the Phoenix Framework and Phoenix LiveView.

Current section

Files

Jump to
phoenix_ui lib phoenix_ui components icon shield_exclamation.ex
Raw

lib/phoenix_ui/components/icon/shield_exclamation.ex

defmodule PhoenixUI.Components.Icon.ShieldExclamation 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="M20.618 5.984A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016zM12 9v2m0 4h.01"/>
</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="M10 1.944A11.954 11.954 0 012.166 5C2.056 5.649 2 6.319 2 7c0 5.225 3.34 9.67 8 11.317C14.66 16.67 18 12.225 18 7c0-.682-.057-1.35-.166-2.001A11.954 11.954 0 0110 1.944zM11 14a1 1 0 11-2 0 1 1 0 012 0zm0-7a1 1 0 10-2 0v3a1 1 0 102 0V7z" 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