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

Address "wide" alignment programatically #812

Merged
merged 15 commits into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 2 additions & 0 deletions blocks/library/embed/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.blocks-embed,
.blocks-embed-video {
margin: 0;
clear: both; // necessary because we use responsive trickery to set width/height, and therefore the video doesn't intrinsically clear floats like an img does

&.is-loading {
display: flex;
flex-direction: column;
Expand Down
10 changes: 8 additions & 2 deletions blocks/library/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,22 @@ registerBlockType( 'core/image', {
onClick: toggleAlignment( 'right' ),
},
{
icon: 'align-full-width',
icon: 'align-wide',
title: wp.i18n.__( 'Wide width' ),
isActive: ( { align } ) => 'wide' === align,
onClick: toggleAlignment( 'wide' ),
},
{
icon: 'align-full-width',
title: wp.i18n.__( 'Full width' ),
isActive: ( { align } ) => 'full' === align,
onClick: toggleAlignment( 'full' ),
},
],

getEditWrapperProps( attributes ) {
const { align } = attributes;
if ( 'left' === align || 'right' === align || 'wide' === align ) {
if ( 'left' === align || 'right' === align || 'wide' === align || 'full' === align ) {
return { 'data-align': align };
}
},
Expand Down
47 changes: 42 additions & 5 deletions blocks/library/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,28 @@
&[data-align="left"] {
float: left;
margin-right: $block-padding;
@include break-medium() {
margin-left: calc( 50% - #{ $visual-editor-max-width / 2 } );
}
}

&[data-align="right"] {
float: right;
margin-left: $block-padding;
@include break-medium() {
margin-right: calc( 50% - #{ $visual-editor-max-width / 2 } );
}
}

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

&[data-align="full"] {
max-width: 100%;
padding-left: 0;
padding-right: 0;
margin-right: -#{ $block-padding + $block-mover-margin }; /* Compensate for .editor-visual-editor centering padding */
box-sizing: border-box;
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

👍


&:before {
left: 0;
Expand All @@ -30,13 +41,39 @@
.editor-block-mover {
display: none;
}
}

&[data-align="full"],
&[data-align="wide"] {
.editor-visual-editor__block-controls {
max-width: #{ $visual-editor-max-width - $block-padding - ( $block-padding * 2 + $block-mover-margin ) };
margin-left: auto;
margin-right: auto;
}
max-width: $visual-editor-max-width - ( ( $block-padding + $block-padding + $block-mover-margin ) * 2 );;
Copy link
Member

Choose a reason for hiding this comment

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

Double semi-colon ending.

Copy link
Member

Choose a reason for hiding this comment

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

Should we move following comments before the max-width line?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

I think the max-width was removed just now.

// a block is 600px wide inside a 700px container
// with block mover margin, border widths and paddings, toolbars are indented 46px
// that's 2px border plus 10px padding plus 18px mover margin
// these 46px are accounted for on both sides, to make sure the block is centered

width: auto;
margin-left: $block-mover-padding-hidden + $block-padding;
margin-right: $block-mover-padding-hidden + $block-padding;

@include break-small() {
width: 100%;
Copy link
Member

Choose a reason for hiding this comment

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

The position of the controls isn't quite right when at wide or full alignments. You can see it move left and right when toggling between an image "Align left" and "Align wide".

I think we need to assign width: $visual-editor-max-width; max-width: none;

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

margin-left: auto;
margin-right: auto;

.is-sidebar-opened & {
padding-left: $block-mover-padding-visible + $block-padding;
padding-right: $block-mover-padding-visible + $block-padding;
}
}

@include break-large() {
.is-sidebar-opened & {
padding-left: 0;
padding-right: 0;
}
}
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions editor/assets/stylesheets/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ $icon-button-size: 36px;
/* Blocks */
$block-padding: 14px;
$block-mover-margin: 18px;
$block-mover-padding-hidden: 10px;
$block-mover-padding-visible: 32px;

/* Media Queries */

Expand Down
2 changes: 1 addition & 1 deletion editor/block-mover/style.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.editor-block-mover {
position: absolute;
top: 10px;
left: 0;
left: -$block-mover-padding-visible;
}

.editor-block-mover__control {
Expand Down
33 changes: 14 additions & 19 deletions editor/modes/visual-editor/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.editor-visual-editor {
margin: 0 auto;
padding: 50px 10px; /* Floating up/down arrows invisible */
padding: 50px 0; // Floating up/down arrows invisible

&,
& p {
Expand All @@ -10,26 +10,25 @@
}

@include break-small() {
padding: 50px 0 50px #{ $block-padding + $block-mover-margin }; /* Floating up/down appear, also compensate for mover */
padding: 50px 0;
}

@include break-large() {
padding: 60px 0 60px #{ $block-padding + $block-mover-margin }; /* Compensate for mover on the left side */
padding: 60px 0;
}
}

/* "Hassle-free full bleed" from CSS Tricks */
.editor-visual-editor > *:not( [data-align="wide"] ) {
max-width: $visual-editor-max-width;
.editor-visual-editor {
margin-left: auto;
margin-right: auto;
}

.editor-visual-editor__block {
margin-left: auto;
margin-right: auto;
max-width: $visual-editor-max-width;
position: relative;
left: -#{ $block-padding + $block-mover-margin }; /* Make room for the mover */
padding: $block-padding $block-padding $block-padding #{ $block-padding * 2 + $block-mover-margin }; /* Compensate for mover */
margin-right: #{ $block-padding + $block-mover-margin };
padding: $block-padding;
transition: 0.2s border-color;

&:before {
Expand All @@ -38,7 +37,7 @@
position: absolute;
top: 0;
bottom: 0;
left: #{ $block-padding + $block-mover-margin }; /* Compensate for mover */
left: 0;
right: 0;
border: 2px solid transparent;
transition: 0.2s border-color;
Expand Down Expand Up @@ -105,16 +104,12 @@
}
}

$sticky-bottom-offset: 20px;
.editor-visual-editor__block-controls + div {
margin-top: -20px;

// prevent collapsing margins between the block and the toolbar
&:before {
content: "";
display: table;
clear: both;
}
}
// prevent collapsing margins between block and toolbar, matches the 20px bottom offset
margin-top: -$sticky-bottom-offset - 1px;
padding-top: 1px;
}

.editor-visual-editor__block-controls .components-toolbar {
display: inline-flex;
Expand Down
3 changes: 3 additions & 0 deletions editor/post-title/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.editor-visual-editor > .editor-post-title:not( [ data-align="wide" ] ),
.editor-post-title {
margin-left: auto;
margin-right: auto;
max-width: $visual-editor-max-width;
position: relative;
padding-right: 2 * ( $block-mover-margin + $block-padding );
margin-bottom: 10px;
Expand Down