♻️(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:
committed by
aleb_the_flash
parent
98ae9af84a
commit
2d0d30ce01
@@ -1,40 +1,51 @@
|
|||||||
import { css } from '@/styled-system/css'
|
import { cva, RecipeVariantProps } from '@/styled-system/css'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
export type AvatarProps = React.HTMLAttributes<HTMLSpanElement> & {
|
const avatar = cva({
|
||||||
name?: string
|
base: {
|
||||||
size?: number
|
backgroundColor: 'transparent',
|
||||||
bgColor?: string
|
color: 'white',
|
||||||
textColor?: string
|
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 = ({
|
export type AvatarProps = React.HTMLAttributes<HTMLDivElement> & {
|
||||||
name,
|
name?: string
|
||||||
size = 32,
|
bgColor?: string
|
||||||
bgColor,
|
} & RecipeVariantProps<typeof avatar>
|
||||||
textColor = 'white',
|
|
||||||
}: AvatarProps) => {
|
export const Avatar = ({ name, bgColor, context, ...props }: AvatarProps) => {
|
||||||
const initial = name?.trim()?.charAt(0).toUpperCase() || ''
|
const initial = name?.trim()?.charAt(0).toUpperCase() || ''
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={css({
|
|
||||||
backgroundColor: 'transparent',
|
|
||||||
color: textColor,
|
|
||||||
display: 'flex',
|
|
||||||
borderRadius: '50%',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
userSelect: 'none',
|
|
||||||
cursor: 'default',
|
|
||||||
flexGrow: 0,
|
|
||||||
flexShrink: 0,
|
|
||||||
})}
|
|
||||||
style={{
|
style={{
|
||||||
width: `${size}px`,
|
|
||||||
height: `${size}px`,
|
|
||||||
fontSize: `${size * 0.4}px`,
|
|
||||||
backgroundColor: bgColor,
|
backgroundColor: bgColor,
|
||||||
}}
|
}}
|
||||||
|
className={avatar({ context })}
|
||||||
|
{...props}
|
||||||
>
|
>
|
||||||
{initial}
|
{initial}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -30,9 +30,18 @@ export const ParticipantPlaceholder = ({
|
|||||||
style={{
|
style={{
|
||||||
borderRadius: '50%',
|
borderRadius: '50%',
|
||||||
animation: isSpeaking ? 'pulse 1s infinite' : undefined,
|
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>
|
</div>
|
||||||
</StyledParticipantPlaceHolder>
|
</StyledParticipantPlaceHolder>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user