♻️(frontend) allow responsive avatar

Until this commit, avatar got a fixed size. Make them
responsive, to fit their parent container.

It's necessary in a placeholder context.
This commit is contained in:
lebaudantoine
2024-08-22 22:58:08 +02:00
committed by aleb_the_flash
parent 98ae9af84a
commit 2d0d30ce01
2 changed files with 49 additions and 29 deletions

View File

@@ -1,40 +1,51 @@
import { css } from '@/styled-system/css'
import { cva, RecipeVariantProps } from '@/styled-system/css'
import React from 'react'
export type AvatarProps = React.HTMLAttributes<HTMLSpanElement> & {
name?: string
size?: number
bgColor?: string
textColor?: string
}
const avatar = cva({
base: {
backgroundColor: 'transparent',
color: 'white',
display: 'flex',
borderRadius: '50%',
justifyContent: 'center',
alignItems: 'center',
userSelect: 'none',
cursor: 'default',
flexGrow: 0,
flexShrink: 0,
},
variants: {
context: {
list: {
width: '32px',
height: '32px',
fontSize: '0.8rem',
},
placeholder: {
width: '100%',
height: '100%',
},
},
},
defaultVariants: {
context: 'list',
},
})
export const Avatar = ({
name,
size = 32,
bgColor,
textColor = 'white',
}: AvatarProps) => {
export type AvatarProps = React.HTMLAttributes<HTMLDivElement> & {
name?: string
bgColor?: string
} & RecipeVariantProps<typeof avatar>
export const Avatar = ({ name, bgColor, context, ...props }: AvatarProps) => {
const initial = name?.trim()?.charAt(0).toUpperCase() || ''
return (
<div
className={css({
backgroundColor: 'transparent',
color: textColor,
display: 'flex',
borderRadius: '50%',
justifyContent: 'center',
alignItems: 'center',
userSelect: 'none',
cursor: 'default',
flexGrow: 0,
flexShrink: 0,
})}
style={{
width: `${size}px`,
height: `${size}px`,
fontSize: `${size * 0.4}px`,
backgroundColor: bgColor,
}}
className={avatar({ context })}
{...props}
>
{initial}
</div>

View File

@@ -30,9 +30,18 @@ export const ParticipantPlaceholder = ({
style={{
borderRadius: '50%',
animation: isSpeaking ? 'pulse 1s infinite' : undefined,
width: '80%',
maxWidth: '150px',
height: 'auto',
aspectRatio: '1/1',
fontSize: '50px',
}}
>
<Avatar name={participant.name} bgColor={participantColor} />
<Avatar
name={participant.name}
bgColor={participantColor}
context="placeholder"
/>
</div>
</StyledParticipantPlaceHolder>
)