Current section
Files
Jump to
Current section
Files
lib/phoenix_ui/components/icon/translate.ex
defmodule PhoenixUI.Components.Icon.Translate 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="M3 5h12M9 3v2m1.048 9.5A18.022 18.022 0 016.412 9m6.088 9h7M11 21l5-10 5 10M12.751 5C11.783 10.77 8.07 15.61 3 18.129"/>
</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="M7 2a1 1 0 011 1v1h3a1 1 0 110 2H9.578a18.87 18.87 0 01-1.724 4.78c.29.354.596.696.914 1.026a1 1 0 11-1.44 1.389c-.188-.196-.373-.396-.554-.6a19.098 19.098 0 01-3.107 3.567 1 1 0 01-1.334-1.49 17.087 17.087 0 003.13-3.733 18.992 18.992 0 01-1.487-2.494 1 1 0 111.79-.89c.234.47.489.928.764 1.372.417-.934.752-1.913.997-2.927H3a1 1 0 110-2h3V3a1 1 0 011-1zm6 6a1 1 0 01.894.553l2.991 5.982a.869.869 0 01.02.037l.99 1.98a1 1 0 11-1.79.895L15.383 16h-4.764l-.724 1.447a1 1 0 11-1.788-.894l.99-1.98.019-.038 2.99-5.982A1 1 0 0113 8zm-1.382 6h2.764L13 11.236 11.618 14z" 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