-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fedc1f
commit 674572d
Showing
5 changed files
with
60 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule AtomicWeb.Components.Socials do | ||
@moduledoc false | ||
|
||
use AtomicWeb, :component | ||
|
||
attr :entity, :map, required: true | ||
|
||
def socials(assigns) do | ||
assigns = assign(assigns, :socials_with_values, get_social_values(assigns.entity)) | ||
|
||
~H""" | ||
<div class="grid grid-cols-2 gap-2 md:flex md:flex-row"> | ||
<%= for {social, icon, url_base, social_value} <- @socials_with_values do %> | ||
<%= if social_value do %> | ||
<div class="flex flex-row items-center gap-x-2"> | ||
<img src={"/images/" <> icon} class="h-5 w-5" alt={Atom.to_string(social)} /> | ||
<.link class="capitalize text-blue-500" target="_blank" href={url_base <> social_value}> | ||
<%= Atom.to_string(social) %> | ||
</.link> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
""" | ||
end | ||
|
||
defp get_social_values(entity) do | ||
get_socials() | ||
|> Enum.map(fn {social, icon, url_base} -> | ||
social_value = Map.get(entity, social) | ||
{social, icon, url_base, social_value} | ||
end) | ||
end | ||
|
||
def get_socials do | ||
[ | ||
{:tiktok, "tiktok.svg", "https://tiktok.com/"}, | ||
{:instagram, "instagram.svg", "https://instagram.com/"}, | ||
{:facebook, "facebook.svg", "https://facebook.com/"}, | ||
{:x, "x.svg", "https://x.com/"} | ||
] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters