Current section
Files
Jump to
Current section
Files
lib/phoenix_ui/components/icon/trash.ex
defmodule PhoenixUI.Components.Icon.Trash 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="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</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="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" 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