Skip to content

Commit 77e4d4e

Browse files
feat: avatar component (#439)
1 parent 716dbdd commit 77e4d4e

File tree

9 files changed

+647
-20
lines changed

9 files changed

+647
-20
lines changed

assets/css/components.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
@import "components/avatar.css";
12
@import "components/field.css";

assets/css/components/avatar.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Avatar */
2+
3+
.safira-avatar {
4+
@apply font-medium leading-none flex shrink-0 items-center justify-center select-none;
5+
}
6+
7+
/* Avatar - sizes */
8+
9+
.safira-avatar--xs {
10+
@apply h-8 w-8 text-xs;
11+
}
12+
13+
.safira-avatar--sm {
14+
@apply h-12 w-12 text-lg;
15+
}
16+
17+
.safira-avatar--md {
18+
@apply h-16 w-16 text-lg;
19+
}
20+
21+
.safira-avatar--lg {
22+
@apply h-20 w-20 text-4xl;
23+
}
24+
25+
.safira-avatar--xl {
26+
@apply h-24 w-24 text-4xl;
27+
}

lib/safira_web.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ defmodule SafiraWeb do
6363
use Phoenix.LiveView,
6464
layout: {SafiraWeb.Layouts, :app}
6565

66+
import SafiraWeb.Components.Avatar
6667
import SafiraWeb.Components.Button
6768

6869
unquote(html_helpers())
@@ -74,6 +75,7 @@ defmodule SafiraWeb do
7475
use Phoenix.LiveView,
7576
layout: {SafiraWeb.Layouts, :backoffice}
7677

78+
import SafiraWeb.Components.Avatar
7779
import SafiraWeb.Components.EnsurePermissions
7880
import SafiraWeb.BackofficeHelpers
7981

@@ -84,7 +86,7 @@ defmodule SafiraWeb do
8486
def live_component do
8587
quote do
8688
use Phoenix.LiveComponent
87-
89+
import SafiraWeb.Components.Avatar
8890
unquote(html_helpers())
8991
end
9092
end

lib/safira_web/components/avatar.ex

Lines changed: 606 additions & 0 deletions
Large diffs are not rendered by default.

lib/safira_web/components/sidebar.ex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ defmodule SafiraWeb.Components.Sidebar do
55
use SafiraWeb, :component
66

77
import SafiraWeb.CoreComponents
8+
import SafiraWeb.Components.Avatar
89
alias Phoenix.LiveView.JS
910

1011
attr :pages, :list, default: []
@@ -143,7 +144,7 @@ defmodule SafiraWeb.Components.Sidebar do
143144

144145
def sidebar_account_dropdown(assigns) do
145146
~H"""
146-
<.user_dropdown id={@id} border={@border} icon_color={@icon_color}>
147+
<.user_dropdown id={@id} border={@border} icon_color={@icon_color} user={@user}>
147148
<:img src={"https://github.com/identicons/#{@user.handle |> String.slice(0..2)}.png"} />
148149
<:title color={@title_color}><%= @user.name %></:title>
149150
<:subtitle color={@subtitle_color}>@<%= @user.handle %></:subtitle>
@@ -175,6 +176,8 @@ defmodule SafiraWeb.Components.Sidebar do
175176
attr :method, :any
176177
end
177178

179+
attr :user, :map, required: true
180+
178181
defp user_dropdown(assigns) do
179182
~H"""
180183
<!-- User account dropdown -->
@@ -190,8 +193,8 @@ defmodule SafiraWeb.Components.Sidebar do
190193
>
191194
<span class={"flex w-full justify-between items-center #{@icon_color}"}>
192195
<span class="flex min-w-0 items-center justify-between space-x-3">
193-
<%= for img <- @img do %>
194-
<img class="w-10 h-10 rounded-full flex-shrink-0" alt="" {assigns_to_attributes(img)} />
196+
<%= for _img <- @img do %>
197+
<.avatar size={:sm} handle={@user.handle} />
195198
<% end %>
196199
<span class="flex-1 flex flex-col min-w-0">
197200
<span class={"#{@title |> Enum.at(0) |> Map.get(:color)} text-sm font-medium truncate"}>

lib/safira_web/live/backoffice/attendee_live/index.html.heex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
<.table id="attendees-table" items={@streams.attendees} meta={@meta} params={@params}>
1414
<:col :let={{_id, user}} sortable field={:name} label="Name">
1515
<div class="flex gap-4 flex-center items-center">
16-
<img
17-
class="rounded-full h-10"
18-
src={"https://github.com/identicons/#{user.handle |> String.slice(0..2)}.png"}
19-
/>
16+
<.avatar handle={user.handle} />
2017
<div class="self-center">
2118
<p class="text-base font-semibold"><%= user.name %></p>
2219
<p class="font-normal">@<%= user.handle %></p>

lib/safira_web/live/backoffice/attendee_live/show.html.heex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
</.button>
66
</:actions>
77
<div class="flex flex-col items-center gap-4 w-full sm:w-fit py-8">
8-
<img
9-
class="rounded-full w-48 h-48"
10-
src={"https://github.com/identicons/#{@attendee.user.handle |> String.slice(0..2)}.png"}
11-
/>
8+
<.avatar size={:xl} handle={@attendee.user.handle} />
129
<div>
1310
<h1 class="text-xl font-semibold"><%= @attendee.user.name %></h1>
1411
<p class="text-sm">@<%= @attendee.user.handle %></p>

lib/safira_web/live/backoffice/schedule_live/speaker_live/index.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ defmodule SafiraWeb.Backoffice.ScheduleLive.SpeakerLive.Index do
3636
src={Uploaders.Speaker.url({speaker.picture, speaker}, :original)}
3737
/>
3838
<% else %>
39-
<img
40-
class="rounded-full h-10"
41-
src={"https://github.com/identicons/#{speaker.name |> String.slice(0..2)}.png"}
42-
/>
39+
<.avatar handle={speaker.name} />
4340
<% end %>
4441
<div class="self-center">
4542
<p class="text-base font-semibold"><%= speaker.name %></p>

lib/safira_web/live/backoffice/staff_live/index.html.heex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
<.table id="staffs-table" items={@streams.staffs} meta={@meta} params={@params}>
2424
<:col :let={{_id, user}} sortable field={:name} label="Name">
2525
<div class="flex gap-4 flex-center items-center">
26-
<img
27-
class="rounded-full h-10"
28-
src={"https://github.com/identicons/#{user.handle |> String.slice(0..2)}.png"}
29-
/>
26+
<.avatar handle={user.handle} />
3027
<div class="self-center">
3128
<p class="text-base font-semibold"><%= user.name %></p>
3229
<p class="font-normal">@<%= user.handle %></p>

0 commit comments

Comments
 (0)