feat: init boring avatars (#3615)

This commit is contained in:
Liyas Thomas
2023-12-04 13:20:26 +05:30
committed by GitHub
parent b43531f200
commit 259cd48dbb
7 changed files with 41 additions and 116 deletions

View File

@@ -134,15 +134,10 @@
:on-shown="() => tippyActions.focus()"
>
<HoppSmartPicture
v-if="currentUser.photoURL"
v-tippy="{
theme: 'tooltip',
}"
:url="currentUser.photoURL"
:alt="
currentUser.displayName ||
t('profile.default_hopp_displayname')
"
:name="currentUser.uid"
:title="
currentUser.displayName ||
currentUser.email ||
@@ -153,20 +148,6 @@
network.isOnline ? 'bg-green-500' : 'bg-red-500'
"
/>
<HoppSmartPicture
v-else
v-tippy="{ theme: 'tooltip' }"
:title="
currentUser.displayName ||
currentUser.email ||
t('profile.default_hopp_displayname')
"
:initial="currentUser.displayName || currentUser.email"
indicator
:indicator-styles="
network.isOnline ? 'bg-green-500' : 'bg-red-500'
"
/>
<template #content="{ hide }">
<div
ref="tippyActions"

View File

@@ -6,19 +6,9 @@
class="inline-flex"
>
<HoppSmartPicture
v-if="member.user.photoURL"
v-tippy="{ theme: 'tooltip' }"
:url="member.user.photoURL"
:title="getUserName(member)"
:alt="getUserName(member)"
class="ring-2 ring-primary"
@click="handleClick()"
/>
<HoppSmartPicture
v-else
v-tippy="{ theme: 'tooltip' }"
:title="getUserName(member)"
:initial="getUserName(member)"
:name="member.user.uid"
:title="getUserName(member as TeamMember)"
class="ring-2 ring-primary"
@click="handleClick()"
/>
@@ -59,7 +49,7 @@ const emit = defineEmits<{
const getUserName = (member: TeamMember): string =>
member.user.displayName ||
member.user.email ||
t("profile.default_hopp_displayName")
t("profile.default_hopp_displayname")
const maxMembersSoftLimit = 4
const maxMembersHardLimit = 6
@@ -77,7 +67,7 @@ const remainingSlicedMembers = computed(
props.teamMembers
.slice(maxMembersSoftLimit)
.slice(0, maxMembersHardLimit)
.map((member) => getUserName(member))
.map((member) => getUserName(member as TeamMember))
.join(`,<br>`) +
(props.teamMembers.length - (maxMembersSoftLimit + maxMembersHardLimit) > 0
? `,<br>${t("team.more_members", {

View File

@@ -21,27 +21,15 @@
</HoppSmartPlaceholder>
<div v-else class="space-y-8">
<div
class="-mb-11 h-24 rounded bg-primaryLight md:h-32"
class="-mb-12 h-24 rounded bg-primaryLight md:h-32"
style="background-image: url(/images/cover.svg)"
></div>
<div class="flex flex-col justify-between space-y-8 px-4 md:flex-row">
<div class="flex items-end">
<HoppSmartPicture
v-if="currentUser.photoURL"
:url="currentUser.photoURL"
:alt="
currentUser.displayName || t('profile.default_displayname')
"
class="ring-4 ring-primary"
size="16"
rounded="lg"
/>
<HoppSmartPicture
v-else
:initial="currentUser.displayName || currentUser.email"
rounded="lg"
size="16"
class="ring-4 ring-primary"
:name="currentUser.uid"
class="ring-8 ring-primary"
:size="64"
/>
<div class="ml-4">
<label class="heading">

View File

@@ -33,28 +33,16 @@
:on-shown="() => tippyActions!.focus()"
>
<HoppSmartPicture
v-if="currentUser.photoURL"
v-tippy="{
theme: 'tooltip',
}"
:url="currentUser.photoURL"
:alt="currentUser.displayName ?? `${t('app.no_name')}`"
:name="currentUser.uid"
:title="
currentUser.displayName ??
currentUser.email ??
`${t('app.no_name')}`
"
/>
<HoppSmartPicture
v-else
v-tippy="{ theme: 'tooltip' }"
:title="
currentUser.displayName ??
currentUser.email ??
`${t('app.no_name')}`
"
:initial="currentUser.displayName ?? currentUser.email"
/>
<template #content="{ hide }">
<div
ref="tippyActions"

View File

@@ -17,6 +17,7 @@
"vue": "^3.2.25"
},
"dependencies": {
"@boringer-avatars/vue3": "^0.2.1",
"@fontsource-variable/inter": "^5.0.5",
"@fontsource-variable/material-symbols-rounded": "^5.0.5",
"@fontsource-variable/roboto-mono": "^5.0.6",
@@ -96,4 +97,4 @@
"./helpers/treeAdapter.ts": "./src/helpers/treeAdapter.ts"
},
"types": "./dist/index.d.ts"
}
}

View File

@@ -1,72 +1,38 @@
<template>
<div
tabindex="0"
class="relative flex items-center justify-center cursor-pointer focus:outline-none focus-visible:ring focus-visible:ring-primaryDark"
:class="[`rounded-${rounded}`, `w-${size} h-${size}`]"
class="relative rounded-full flex items-center justify-center cursor-pointer focus:outline-none focus-visible:ring focus-visible:ring-primaryDark"
>
<img
v-if="url"
class="absolute object-cover object-center transition bg-primaryDark"
:class="[`rounded-${rounded}`, `w-${size} h-${size}`]"
:src="url"
:alt="alt"
loading="lazy"
referrerpolicy="no-referrer"
<Avatar
:size="size"
:name="name"
:square="false"
:colors="['#FFAD08', '#EDD75A', '#73B06F', '#0C8F8F', '#405059']"
variant="beam"
/>
<div
v-else
class="absolute flex items-center justify-center object-cover object-center transition bg-primaryDark text-accentContrast"
:class="[`rounded-${rounded}`, `w-${size} h-${size}`]"
:style="`background-color: ${initial ? toHex(initial) : '#480000'}`"
>
<template v-if="initial && initial.charAt(0).toUpperCase()">
{{ initial.charAt(0).toUpperCase() }}
</template>
<icon-lucide-user v-else />
</div>
<span
v-if="indicator"
class="border-primary border-2 h-2.5 -top-0.5 -right-0.5 w-2.5 absolute"
:class="[`rounded-${rounded}`, indicatorStyles]"
class="border-primary rounded-full border-2 h-2.5 -top-0.5 -right-0.5 w-2.5 absolute"
:class="indicatorStyles"
></span>
<!-- w-5 h-5 rounded-lg -->
</div>
</template>
<script setup lang="ts">
import { Avatar } from "@boringer-avatars/vue3";
withDefaults(
defineProps<{
url: string
alt: string
name: string
indicator: boolean
indicatorStyles: string
rounded: string
size: string
initial: string | undefined | null
size: number
}>(),
{
url: "",
alt: "Profile picture",
name: "",
indicator: false,
indicatorStyles: "bg-green-500",
rounded: "full",
size: "5",
initial: "",
size: 24,
}
)
const toHex = (initial: string) => {
let hash = 0
if (initial.length === 0) return hash
for (let i = 0; i < initial.length; i++) {
hash = initial.charCodeAt(i) + ((hash << 5) - hash)
hash = hash & hash
}
let color = "#"
for (let i = 0; i < 3; i++) {
const value = (hash >> (i * 8)) & 255
color += `00${value.toString(16)}`.slice(-2)
}
return color
}
</script>