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
Show file tree
Hide file tree
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
13 changes: 2 additions & 11 deletions packages/block-editor/src/components/block-list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,6 @@
cursor: default;
}

.alignleft,
.alignright {
// Without z-index, won't be clickable as "above" adjacent content.
z-index: z-index(".block-editor-block-list__block {core/image aligned left or right}");
}

// Alignments.
&[data-align="left"],
&[data-align="right"] {
Expand Down Expand Up @@ -288,15 +282,12 @@

// Wide and full-wide.
&[data-align="full"],
&[data-align="wide"],
&.alignfull,
&.alignwide {
&[data-align="wide"] {
clear: both;
}

// Full-wide.
&[data-align="full"],
&.alignfull {
&[data-align="full"] {
margin-left: -$block-padding;
margin-right: -$block-padding;

Expand Down
38 changes: 10 additions & 28 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 @@ -429,20 +426,11 @@ export class ImageEdit extends Component {
return (
<>
{ controls }
<Block.div
className={ classnames( className, {
[ `align${ align }` ]:
! needsAlignmentWrapper && align,
} ) }
>
{ needsAlignmentWrapper ? (
<div className={ `align${ align }` }>
{ mediaPlaceholder }
</div>
) : (
mediaPlaceholder
) }
</Block.div>
<div className={ `wp-align-wrapper wp-align-${ align }` }>
<Block.div className={ className }>
{ mediaPlaceholder }
</Block.div>
</div>
</>
);
}
Expand All @@ -452,7 +440,6 @@ export class ImageEdit extends Component {
'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 wp-align-${ align }` }>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're having wp-align-undefined sometimes

<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
51 changes: 47 additions & 4 deletions packages/edit-post/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,56 @@ body.block-editor-page {
.wp-block {
max-width: $content-width;

&[data-align="wide"],
&.alignwide {
&[data-align="wide"] {
max-width: 1100px;
}

&[data-align="full"],
&.alignfull {
&[data-align="full"] {
max-width: none;
}
}

.wp-align-wrapper {
max-width: $content-width;
margin-left: auto;
margin-right: auto;

> .wp-block,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the max-width should apply to the align wrapper, but not the nested block

&.wp-align-full {
max-width: none;
}

&.wp-align-full {
margin-left: -$block-padding;
margin-right: -$block-padding;

@include break-small() {
margin-left: -$block-padding - $block-padding - $block-side-ui-width - $border-width - $border-width;
margin-right: -$block-padding - $block-padding - $block-side-ui-width - $border-width - $border-width;
}
}

&.wp-align-wide {
max-width: 1100px;
}

&.wp-align-left > * {
float: left;
margin-right: 2em;
}

&.wp-align-right > * {
float: right;
margin-left: 2em;
}

&.wp-align-left > *,
&.wp-align-right > * {
// Without z-index, won't be clickable as "above" adjacent content.
z-index: z-index(".block-editor-block-list__block {core/image aligned left or right}");
}

&.wp-align-center {
// Same as no alignment?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs display: flex and justify-content center for me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be able to see the difference between "center" and "no" when you resize an image smaller than the $content-width

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

display: flex has the unfortunate side effect of not collapsing margins. :) I'll figure it out though.

}
}