File size: 958 Bytes
04735a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import Image from 'next/image';
import React from 'react';

export interface AvatarProps {
  name?: string | null;
  avatar?: string | null;
}

function getUserInitials(name: string) {
  const [firstName, lastName] = name.split(' ');
  return lastName ? `${firstName[0]}${lastName[0]}` : firstName.slice(0, 2);
}

const Avatar: React.FC<AvatarProps> = ({ name, avatar }) => {
  return (
    <>
      {avatar ? (
        <Image
          className="size-6 transition-opacity duration-300 rounded-full select-none ring-1 ring-zinc-100/10 hover:opacity-80"
          src={avatar ?? ''}
          alt={name ?? 'Avatar'}
          height={48}
          width={48}
        />
      ) : (
        <div className="flex items-center justify-center text-xs font-medium uppercase rounded-full select-none size-7 shrink-0 bg-muted/50 text-muted-foreground">
          {name ? getUserInitials(name) : 'VA'}
        </div>
      )}
    </>
  );
};

export default Avatar;