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

Aligments: explore idea on image block #20656

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
34 changes: 8 additions & 26 deletions packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
__experimentalImageSizeControl as ImageSizeControl,
__experimentalImageURLInputUI as ImageURLInputUI,
} from '@wordpress/block-editor';
import { Component, Fragment } from '@wordpress/element';
import { Component } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { getPath } from '@wordpress/url';
import { withViewportMatch } from '@wordpress/viewport';
Expand Down Expand Up @@ -405,9 +405,6 @@ export class ImageEdit extends Component {
src={ url }
/>
);
const needsAlignmentWrapper = [ 'center', 'left', 'right' ].includes(
align
);

const mediaPlaceholder = (
<MediaPlaceholder
Expand All @@ -430,29 +427,19 @@ export class ImageEdit extends Component {
<>
{ controls }
<Block.div
className={ classnames( className, {
[ `align${ align }` ]:
! needsAlignmentWrapper && align,
} ) }
className={ classnames( className, `align${ align }` ) }
>
{ needsAlignmentWrapper ? (
<div className={ `align${ align }` }>
{ mediaPlaceholder }
</div>
) : (
mediaPlaceholder
) }
{ mediaPlaceholder }
</Block.div>
</>
);
}

const classes = classnames( className, {
const classes = classnames( className, `align${ align }`, {
ellatrix marked this conversation as resolved.
Show resolved Hide resolved
'is-transient': isBlobURL( url ),
'is-resized': !! width || !! height,
'is-focused': isSelected,
[ `size-${ sizeSlug }` ]: sizeSlug,
[ `align${ align }` ]: align,
} );

const isResizable =
Expand Down Expand Up @@ -516,17 +503,13 @@ export class ImageEdit extends Component {
</>
);

const AlignmentWrapper = needsAlignmentWrapper ? Block.div : Fragment;
const BlockContentWrapper = needsAlignmentWrapper
? 'figure'
: Block.figure;
// Disable reason: Each block can be selected by clicking on it
/* eslint-disable jsx-a11y/click-events-have-key-events */
return (
<>
{ controls }
<AlignmentWrapper>
<BlockContentWrapper className={ classes }>
<div className="wp-align-wrapper">
<Block.figure className={ classes }>
<ImageSize src={ url } dirtynessTrigger={ align }>
{ ( sizes ) => {
const {
Expand Down Expand Up @@ -702,10 +685,9 @@ export class ImageEdit extends Component {
inlineToolbar
/>
) }

{ mediaPlaceholder }
</BlockContentWrapper>
</AlignmentWrapper>
</Block.figure>
</div>
</>
);
/* eslint-enable jsx-a11y/click-events-have-key-events */
Expand Down