main
|
Last change
on this file was b62cefc, checked in by kikisrbinoska <srbinoskakristina07@…>, 4 months ago |
|
Added frontend and imporoved AI Suggestions service
|
-
Property mode
set to
100644
|
|
File size:
1.4 KB
|
| Rev | Line | |
|---|
| [b62cefc] | 1 | import React from 'react'
|
|---|
| 2 |
|
|---|
| 3 | interface AvatarProps {
|
|---|
| 4 | name: string
|
|---|
| 5 | image?: string
|
|---|
| 6 | size?: 'sm' | 'md' | 'lg' | 'xl'
|
|---|
| 7 | className?: string
|
|---|
| 8 | }
|
|---|
| 9 |
|
|---|
| 10 | const sizeMap = {
|
|---|
| 11 | sm: 'w-8 h-8 text-xs',
|
|---|
| 12 | md: 'w-10 h-10 text-sm',
|
|---|
| 13 | lg: 'w-16 h-16 text-xl',
|
|---|
| 14 | xl: 'w-24 h-24 text-3xl',
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | const colors = [
|
|---|
| 18 | 'from-indigo-500 to-violet-500',
|
|---|
| 19 | 'from-violet-500 to-purple-500',
|
|---|
| 20 | 'from-pink-500 to-rose-500',
|
|---|
| 21 | 'from-emerald-500 to-teal-500',
|
|---|
| 22 | 'from-amber-500 to-orange-500',
|
|---|
| 23 | 'from-cyan-500 to-blue-500',
|
|---|
| 24 | ]
|
|---|
| 25 |
|
|---|
| 26 | function getColorIndex(name: string): number {
|
|---|
| 27 | let hash = 0
|
|---|
| 28 | for (let i = 0; i < name.length; i++) hash = name.charCodeAt(i) + ((hash << 5) - hash)
|
|---|
| 29 | return Math.abs(hash) % colors.length
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | export const Avatar: React.FC<AvatarProps> = ({ name, image, size = 'md', className = '' }) => {
|
|---|
| 33 | const initials = name
|
|---|
| 34 | .split(' ')
|
|---|
| 35 | .map(p => p[0])
|
|---|
| 36 | .slice(0, 2)
|
|---|
| 37 | .join('')
|
|---|
| 38 | .toUpperCase()
|
|---|
| 39 | const colorClass = colors[getColorIndex(name)]
|
|---|
| 40 |
|
|---|
| 41 | if (image) {
|
|---|
| 42 | return (
|
|---|
| 43 | <img
|
|---|
| 44 | src={image}
|
|---|
| 45 | alt={name}
|
|---|
| 46 | className={`${sizeMap[size]} rounded-full object-cover ring-2 ring-slate-700 ${className}`}
|
|---|
| 47 | />
|
|---|
| 48 | )
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | return (
|
|---|
| 52 | <div
|
|---|
| 53 | className={`${sizeMap[size]} rounded-full bg-gradient-to-br ${colorClass} flex items-center justify-center font-semibold text-white ring-2 ring-slate-700 flex-shrink-0 ${className}`}
|
|---|
| 54 | >
|
|---|
| 55 | {initials}
|
|---|
| 56 | </div>
|
|---|
| 57 | )
|
|---|
| 58 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.