Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,082 Bytes
e4d3d8a |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 |
"use client"
import RSA from "react-string-avatar"
export type DefaultAvatarProps = {
username?: string
initials?: string
bgColor?: string
textColor?: string
roundShape?: boolean
cornerRadius?: number
pictureFormat?: string
pictureResolution?: number
width?: number
pixelated?: boolean
wrapper?: boolean
wrapperStyle?: Record<string, any>
}
export type DefaultAvatarComponent = (props: DefaultAvatarProps) => JSX.Element
const ReactStringAvatar = RSA as DefaultAvatarComponent
export default function DefaultAvatarImpl({
username,
initials: customInitials,
...props
}: DefaultAvatarProps): JSX.Element {
const usernameInitials = `${username || ""}`
.trim()
.replaceAll("_", " ")
.replaceAll("-", " ")
.replace(/([a-z])([A-Z])/g, '$1 $2') // split the camel case
.split(" ") // split words
.map(u => u.trim()[0]) // take first char
.slice(0, 2) // keep first 2 chars
.join("")
.toUpperCase()
return (
<ReactStringAvatar
initials={customInitials || usernameInitials}
{...props}
/>
)
} |