2022-11-10 15:06:02 +00:00
|
|
|
import { Show, createMemo } from 'solid-js'
|
|
|
|
import './DialogCard.module.scss'
|
|
|
|
import styles from './DialogAvatar.module.scss'
|
|
|
|
import { clsx } from 'clsx'
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
name: string
|
2022-11-21 05:06:53 +00:00
|
|
|
url?: string
|
2022-11-10 15:06:02 +00:00
|
|
|
online?: boolean
|
2022-11-21 05:06:53 +00:00
|
|
|
size?: 'small'
|
2022-11-10 15:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const colors = [
|
|
|
|
'#001219',
|
|
|
|
'#005f73',
|
|
|
|
'#0a9396',
|
|
|
|
'#94d2bd',
|
|
|
|
'#ee9b00',
|
|
|
|
'#ca6702',
|
|
|
|
'#ae2012',
|
|
|
|
'#9b2226',
|
2022-11-15 09:45:55 +00:00
|
|
|
'#668cff',
|
|
|
|
'#c34cfe',
|
|
|
|
'#e699ff',
|
|
|
|
'#6633ff'
|
2022-11-10 15:06:02 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
const getById = (letter: string) =>
|
2022-11-15 12:48:42 +00:00
|
|
|
colors[Math.abs(Number(BigInt(letter.toLowerCase().codePointAt(0) - 97) % BigInt(colors.length)))]
|
2022-11-10 15:06:02 +00:00
|
|
|
|
|
|
|
const DialogAvatar = (props: Props) => {
|
2022-11-15 12:48:42 +00:00
|
|
|
const nameFirstLetter = props.name.slice(0, 1)
|
2022-11-10 15:06:02 +00:00
|
|
|
const randomBg = createMemo(() => {
|
|
|
|
return getById(nameFirstLetter)
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2022-11-21 05:06:53 +00:00
|
|
|
class={clsx(styles.DialogAvatar, props.online && styles.online, `${styles[props.size]}`)}
|
2022-11-10 15:06:02 +00:00
|
|
|
style={{ 'background-color': `${randomBg()}` }}
|
|
|
|
>
|
|
|
|
<Show when={props.url} fallback={() => <div class={styles.letter}>{nameFirstLetter}</div>}>
|
2022-11-23 04:12:11 +00:00
|
|
|
<div class={styles.imageHolder} style={{ 'background-image': `url(${props.url})` }} />
|
2022-11-10 15:06:02 +00:00
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DialogAvatar
|