mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 03:36:36 +08:00
chore: size of AvatarProps should not be number
This commit is contained in:
parent
ee2b021395
commit
53277d77c9
@ -19,7 +19,7 @@ export type AvatarSize = keyof typeof avatarSizeClasses
|
|||||||
export type AvatarProps = {
|
export type AvatarProps = {
|
||||||
name: string
|
name: string
|
||||||
avatar: string | null
|
avatar: string | null
|
||||||
size?: AvatarSize | number
|
size?: AvatarSize
|
||||||
className?: string
|
className?: string
|
||||||
textClassName?: string
|
textClassName?: string
|
||||||
onError?: (hasError: boolean) => void
|
onError?: (hasError: boolean) => void
|
||||||
@ -28,14 +28,11 @@ export type AvatarProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AvatarRootProps = React.ComponentPropsWithRef<typeof BaseAvatar.Root> & {
|
type AvatarRootProps = React.ComponentPropsWithRef<typeof BaseAvatar.Root> & {
|
||||||
size?: AvatarSize | number
|
size?: AvatarSize
|
||||||
hasAvatar?: boolean
|
hasAvatar?: boolean
|
||||||
backgroundColor?: string
|
backgroundColor?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const isAvatarPresetSize = (size: AvatarSize | number): size is AvatarSize =>
|
|
||||||
typeof size === 'string'
|
|
||||||
|
|
||||||
function AvatarRoot({
|
function AvatarRoot({
|
||||||
size = 'md',
|
size = 'md',
|
||||||
className,
|
className,
|
||||||
@ -45,7 +42,6 @@ function AvatarRoot({
|
|||||||
...props
|
...props
|
||||||
}: AvatarRootProps) {
|
}: AvatarRootProps) {
|
||||||
const resolvedStyle: React.CSSProperties = {
|
const resolvedStyle: React.CSSProperties = {
|
||||||
...(typeof size === 'number' ? { width: `${size}px`, height: `${size}px` } : {}),
|
|
||||||
...(backgroundColor && !hasAvatar ? { backgroundColor } : {}),
|
...(backgroundColor && !hasAvatar ? { backgroundColor } : {}),
|
||||||
...style,
|
...style,
|
||||||
}
|
}
|
||||||
@ -64,7 +60,7 @@ function AvatarRoot({
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AvatarFallbackProps = React.ComponentPropsWithRef<typeof BaseAvatar.Fallback> & {
|
type AvatarFallbackProps = React.ComponentPropsWithRef<typeof BaseAvatar.Fallback> & {
|
||||||
size?: AvatarSize | number
|
size?: AvatarSize
|
||||||
textClassName?: string
|
textClassName?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,9 +72,6 @@ function AvatarFallback({
|
|||||||
...props
|
...props
|
||||||
}: AvatarFallbackProps) {
|
}: AvatarFallbackProps) {
|
||||||
const resolvedStyle: React.CSSProperties = {
|
const resolvedStyle: React.CSSProperties = {
|
||||||
...(typeof size === 'number'
|
|
||||||
? { fontSize: `${Math.round(size * 0.4)}px`, lineHeight: 1 }
|
|
||||||
: {}),
|
|
||||||
...style,
|
...style,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +79,7 @@ function AvatarFallback({
|
|||||||
<BaseAvatar.Fallback
|
<BaseAvatar.Fallback
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex size-full items-center justify-center font-medium text-white',
|
'flex size-full items-center justify-center font-medium text-white',
|
||||||
isAvatarPresetSize(size) && avatarSizeClasses[size].text,
|
avatarSizeClasses[size].text,
|
||||||
textClassName,
|
textClassName,
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user