fix(core): center align user avatar in doc property (#12908)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Added an option to center-align user labels in components displaying
user information, improving visual alignment of avatars and usernames.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Cats Juice 2025-06-24 13:01:56 +08:00 committed by GitHub
parent 4e6f40b30e
commit 616e755dde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -46,6 +46,7 @@ const CreatedByUpdatedByAvatar = (props: {
id={userId} id={userId}
size={props.size} size={props.size}
showName={props.showName} showName={props.showName}
align="center"
tooltip={ tooltip={
props.type === 'CreatedBy' ? CreatedUsernameTip : UpdatedUsernameTip props.type === 'CreatedBy' ? CreatedUsernameTip : UpdatedUsernameTip
} }
@ -198,7 +199,12 @@ export const ModifiedByGroupHeader = ({
return ( return (
<PlainTextDocGroupHeader groupId={groupId} docCount={docCount}> <PlainTextDocGroupHeader groupId={groupId} docCount={docCount}>
<div className={styles.userLabelContainer}> <div className={styles.userLabelContainer}>
<PublicUserLabel id={userId} size={20} showName={false} /> <PublicUserLabel
id={userId}
size={20}
showName={false}
align="center"
/>
</div> </div>
</PlainTextDocGroupHeader> </PlainTextDocGroupHeader>
); );

View File

@ -2,7 +2,12 @@ import { Avatar, Tooltip } from '@affine/component';
import { useCurrentServerService } from '@affine/core/components/providers/current-server-scope'; import { useCurrentServerService } from '@affine/core/components/providers/current-server-scope';
import { useI18n } from '@affine/i18n'; import { useI18n } from '@affine/i18n';
import { useLiveData } from '@toeverything/infra'; import { useLiveData } from '@toeverything/infra';
import { type ComponentType, useLayoutEffect, useMemo } from 'react'; import {
type ComponentType,
type CSSProperties,
useLayoutEffect,
useMemo,
} from 'react';
import { PublicUserService } from '../services/public-user'; import { PublicUserService } from '../services/public-user';
import * as styles from './public-user.css'; import * as styles from './public-user.css';
@ -12,11 +17,13 @@ export const PublicUserLabel = ({
size = 20, size = 20,
showName = true, showName = true,
tooltip: NameTip, tooltip: NameTip,
align = 'baseline',
}: { }: {
id: string; id: string;
size?: number; size?: number;
showName?: boolean; showName?: boolean;
tooltip?: ComponentType<{ userName: string }>; tooltip?: ComponentType<{ userName: string }>;
align?: CSSProperties['alignItems'];
}) => { }) => {
const serverService = useCurrentServerService(); const serverService = useCurrentServerService();
const publicUser = useMemo(() => { const publicUser = useMemo(() => {
@ -59,7 +66,7 @@ export const PublicUserLabel = ({
) : null ) : null
} }
> >
<span className={styles.publicUserLabel}> <span className={styles.publicUserLabel} style={{ alignItems: align }}>
<Avatar <Avatar
url={user?.avatar} url={user?.avatar}
name={user?.name ?? ''} name={user?.name ?? ''}