-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathavatar.ex
More file actions
61 lines (53 loc) · 1.41 KB
/
avatar.ex
File metadata and controls
61 lines (53 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
defmodule AtomicWeb.Components.Avatar do
@moduledoc false
use AtomicWeb, :component
attr :src, :string, default: nil, doc: "The URL of the image to display."
attr :name, :string, required: true, doc: "The name of the entity associated with the avatar."
attr :type, :atom,
values: [:user, :organization, :company],
default: :user,
doc: "The type of entity associated with the avatar."
attr :size, :atom,
values: [:xs, :sm, :md, :lg, :xl],
default: :md,
doc: "The size of the avatar."
attr :color, :atom,
default: :primary,
values: [
:primary,
:secondary,
:info,
:success,
:warning,
:danger,
:gray,
:light_gray,
:pure_white,
:white,
:light,
:dark
],
doc: "Button color."
attr :class, :string, default: "", doc: "Additional classes to apply to the component."
def avatar(assigns) do
~H"""
<span class={generate_classes(assigns)}>
<%= if @src do %>
<img src={@src} class={"atomic-avatar--#{assigns.type} h-full w-full z-0"} />
<% else %>
<%= extract_initials(@name) %>
<% end %>
</span>
"""
end
defp generate_classes(assigns) do
[
"atomic-avatar",
assigns.src && "atomic-avatar--src",
"atomic-avatar--#{assigns.color}",
"atomic-avatar--#{assigns.size}",
"atomic-avatar--#{assigns.type}",
assigns.class
]
end
end