Skip to content

Commit

Permalink
feat: avatar component (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 authored Dec 20, 2024
1 parent 716dbdd commit 77e4d4e
Show file tree
Hide file tree
Showing 9 changed files with 647 additions and 20 deletions.
1 change: 1 addition & 0 deletions assets/css/components.css
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import "components/avatar.css";
@import "components/field.css";
27 changes: 27 additions & 0 deletions assets/css/components/avatar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Avatar */

.safira-avatar {
@apply font-medium leading-none flex shrink-0 items-center justify-center select-none;
}

/* Avatar - sizes */

.safira-avatar--xs {
@apply h-8 w-8 text-xs;
}

.safira-avatar--sm {
@apply h-12 w-12 text-lg;
}

.safira-avatar--md {
@apply h-16 w-16 text-lg;
}

.safira-avatar--lg {
@apply h-20 w-20 text-4xl;
}

.safira-avatar--xl {
@apply h-24 w-24 text-4xl;
}
4 changes: 3 additions & 1 deletion lib/safira_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ defmodule SafiraWeb do
use Phoenix.LiveView,
layout: {SafiraWeb.Layouts, :app}

import SafiraWeb.Components.Avatar
import SafiraWeb.Components.Button

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

import SafiraWeb.Components.Avatar
import SafiraWeb.Components.EnsurePermissions
import SafiraWeb.BackofficeHelpers

Expand All @@ -84,7 +86,7 @@ defmodule SafiraWeb do
def live_component do
quote do
use Phoenix.LiveComponent

import SafiraWeb.Components.Avatar
unquote(html_helpers())
end
end
Expand Down
606 changes: 606 additions & 0 deletions lib/safira_web/components/avatar.ex

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions lib/safira_web/components/sidebar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule SafiraWeb.Components.Sidebar do
use SafiraWeb, :component

import SafiraWeb.CoreComponents
import SafiraWeb.Components.Avatar
alias Phoenix.LiveView.JS

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

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

attr :user, :map, required: true

defp user_dropdown(assigns) do
~H"""
<!-- User account dropdown -->
Expand All @@ -190,8 +193,8 @@ defmodule SafiraWeb.Components.Sidebar do
>
<span class={"flex w-full justify-between items-center #{@icon_color}"}>
<span class="flex min-w-0 items-center justify-between space-x-3">
<%= for img <- @img do %>
<img class="w-10 h-10 rounded-full flex-shrink-0" alt="" {assigns_to_attributes(img)} />
<%= for _img <- @img do %>
<.avatar size={:sm} handle={@user.handle} />
<% end %>
<span class="flex-1 flex flex-col min-w-0">
<span class={"#{@title |> Enum.at(0) |> Map.get(:color)} text-sm font-medium truncate"}>
Expand Down
5 changes: 1 addition & 4 deletions lib/safira_web/live/backoffice/attendee_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
<.table id="attendees-table" items={@streams.attendees} meta={@meta} params={@params}>
<:col :let={{_id, user}} sortable field={:name} label="Name">
<div class="flex gap-4 flex-center items-center">
<img
class="rounded-full h-10"
src={"https://github.com/identicons/#{user.handle |> String.slice(0..2)}.png"}
/>
<.avatar handle={user.handle} />
<div class="self-center">
<p class="text-base font-semibold"><%= user.name %></p>
<p class="font-normal">@<%= user.handle %></p>
Expand Down
5 changes: 1 addition & 4 deletions lib/safira_web/live/backoffice/attendee_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
</.button>
</:actions>
<div class="flex flex-col items-center gap-4 w-full sm:w-fit py-8">
<img
class="rounded-full w-48 h-48"
src={"https://github.com/identicons/#{@attendee.user.handle |> String.slice(0..2)}.png"}
/>
<.avatar size={:xl} handle={@attendee.user.handle} />
<div>
<h1 class="text-xl font-semibold"><%= @attendee.user.name %></h1>
<p class="text-sm">@<%= @attendee.user.handle %></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ defmodule SafiraWeb.Backoffice.ScheduleLive.SpeakerLive.Index do
src={Uploaders.Speaker.url({speaker.picture, speaker}, :original)}
/>
<% else %>
<img
class="rounded-full h-10"
src={"https://github.com/identicons/#{speaker.name |> String.slice(0..2)}.png"}
/>
<.avatar handle={speaker.name} />
<% end %>
<div class="self-center">
<p class="text-base font-semibold"><%= speaker.name %></p>
Expand Down
5 changes: 1 addition & 4 deletions lib/safira_web/live/backoffice/staff_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
<.table id="staffs-table" items={@streams.staffs} meta={@meta} params={@params}>
<:col :let={{_id, user}} sortable field={:name} label="Name">
<div class="flex gap-4 flex-center items-center">
<img
class="rounded-full h-10"
src={"https://github.com/identicons/#{user.handle |> String.slice(0..2)}.png"}
/>
<.avatar handle={user.handle} />
<div class="self-center">
<p class="text-base font-semibold"><%= user.name %></p>
<p class="font-normal">@<%= user.handle %></p>
Expand Down

0 comments on commit 77e4d4e

Please sign in to comment.