Current section
Files
Jump to
Current section
Files
lib/phoenix_ui/components/icon/document_remove.ex
defmodule PhoenixUI.Components.Icon.DocumentRemove 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="M9 13h6m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</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="M6 2a2 2 0 00-2 2v12a2 2 0 002 2h8a2 2 0 002-2V7.414A2 2 0 0015.414 6L12 2.586A2 2 0 0010.586 2H6zm1 8a1 1 0 100 2h6a1 1 0 100-2H7z" 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