Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed align right issue on avatar component #67494

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 68 additions & 83 deletions packages/block-library/src/avatar/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ const AvatarInspectorControls = ( {
</InspectorControls>
);

const AvatarLinkWrapper = ( { children, isLink } ) =>
isLink ? (
<a
href="#avatar-pseudo-link"
className="wp-block-avatar__link"
onClick={ ( event ) => event.preventDefault() }
>
{ children }
</a>
) : (
children
);

const ResizableAvatar = ( {
setAttributes,
attributes,
Expand All @@ -98,43 +111,46 @@ const ResizableAvatar = ( {
);
return (
<div { ...blockProps }>
<ResizableBox
size={ {
width: attributes.size,
height: attributes.size,
} }
showHandle={ isSelected }
onResizeStop={ ( event, direction, elt, delta ) => {
setAttributes( {
size: parseInt(
attributes.size + ( delta.height || delta.width ),
10
),
} );
} }
lockAspectRatio
enable={ {
top: false,
right: ! isRTL(),
bottom: true,
left: isRTL(),
} }
minWidth={ avatar.minSize }
maxWidth={ avatar.maxSize }
>
<img
src={ doubledSizedSrc }
alt={ avatar.alt }
className={ clsx(
'avatar',
'avatar-' + attributes.size,
'photo',
'wp-block-avatar__image',
borderProps.className
) }
style={ borderProps.style }
/>
</ResizableBox>
<AvatarLinkWrapper isLink={ attributes.isLink }>
<ResizableBox
size={ {
width: attributes.size,
height: attributes.size,
} }
showHandle={ isSelected }
onResizeStop={ ( event, direction, elt, delta ) => {
setAttributes( {
size: parseInt(
attributes.size +
( delta.height || delta.width ),
10
),
} );
} }
lockAspectRatio
enable={ {
top: false,
right: ! isRTL(),
bottom: true,
left: isRTL(),
} }
minWidth={ avatar.minSize }
maxWidth={ avatar.maxSize }
>
<img
src={ doubledSizedSrc }
alt={ avatar.alt }
className={ clsx(
'avatar',
'avatar-' + attributes.size,
'photo',
'wp-block-avatar__image',
borderProps.className
) }
style={ borderProps.style }
/>
</ResizableBox>
</AvatarLinkWrapper>
</div>
);
};
Expand All @@ -150,29 +166,13 @@ const CommentEdit = ( { attributes, context, setAttributes, isSelected } ) => {
attributes={ attributes }
selectUser={ false }
/>
{ attributes.isLink ? (
<a
href="#avatar-pseudo-link"
className="wp-block-avatar__link"
onClick={ ( event ) => event.preventDefault() }
>
<ResizableAvatar
attributes={ attributes }
avatar={ avatar }
blockProps={ blockProps }
isSelected={ isSelected }
setAttributes={ setAttributes }
/>
</a>
) : (
<ResizableAvatar
attributes={ attributes }
avatar={ avatar }
blockProps={ blockProps }
isSelected={ isSelected }
setAttributes={ setAttributes }
/>
) }
<ResizableAvatar
attributes={ attributes }
avatar={ avatar }
blockProps={ blockProps }
isSelected={ isSelected }
setAttributes={ setAttributes }
/>
</>
);
};
Expand All @@ -193,29 +193,14 @@ const UserEdit = ( { attributes, context, setAttributes, isSelected } ) => {
avatar={ avatar }
setAttributes={ setAttributes }
/>
{ attributes.isLink ? (
<a
href="#avatar-pseudo-link"
className="wp-block-avatar__link"
onClick={ ( event ) => event.preventDefault() }
>
<ResizableAvatar
attributes={ attributes }
avatar={ avatar }
blockProps={ blockProps }
isSelected={ isSelected }
setAttributes={ setAttributes }
/>
</a>
) : (
<ResizableAvatar
attributes={ attributes }
avatar={ avatar }
blockProps={ blockProps }
isSelected={ isSelected }
setAttributes={ setAttributes }
/>
) }

<ResizableAvatar
attributes={ attributes }
avatar={ avatar }
blockProps={ blockProps }
isSelected={ isSelected }
setAttributes={ setAttributes }
/>
</>
);
};
Expand Down
Loading