| 37 | |
| 38 | // Deterministic colour from name |
| 39 | function getAvatarColor(name: string): string { |
| 40 | const colours = [ |
| 41 | 'bg-brand-700 text-brand-200', |
| 42 | 'bg-violet-800 text-violet-200', |
| 43 | 'bg-indigo-800 text-indigo-200', |
| 44 | 'bg-blue-800 text-blue-200', |
| 45 | 'bg-cyan-800 text-cyan-200', |
| 46 | 'bg-teal-800 text-teal-200', |
| 47 | 'bg-emerald-800 text-emerald-200', |
| 48 | 'bg-amber-800 text-amber-200', |
| 49 | 'bg-rose-800 text-rose-200', |
| 50 | ] |
| 51 | let hash = 0 |
| 52 | for (let i = 0; i < name.length; i++) { |
| 53 | hash = (hash * 31 + name.charCodeAt(i)) & 0xffffffff |
| 54 | } |
| 55 | return colours[Math.abs(hash) % colours.length] |
| 56 | } |
| 57 | |
| 58 | function Avatar({ className, size, src, alt, name, ...props }: AvatarProps) { |
| 59 | const [imgError, setImgError] = React.useState(false) |