Skip to content

Commit

Permalink
Make the editor canvas friendly towards colored backgrounds
Browse files Browse the repository at this point in the history
One long term vision for the editor, is to allow you to load the theme stylesheet into the editor canvas itself, so you have an almost if not completely WYSIWYG experience where the theme background and fonts apply to the editor.

In the interim, we should make it easier to load _editor styles_ into the canvas. This already works today, but the block UI is not really ready for it — white backgrounds are used here and there, and borders are colored light grays which quickly disappear on some colors.

This PR takes an initial stab at alleviating that, by moving to using various levels of opacities of the darkest gray we have, to emulate the range of opaque grays we have. As such, this PR includes a range of those opacities. For example, shown on a white background, $dark-opacity-500 should look the same as $dark-gray-500, but the latter should look good on colored backgrounds as well.

This is going to be a fair bit of work, and this is only the beginnings of it. It styles the borders, the outermost toolbar borders, the naked mover/settings/more icons, and the title field, as well as the appender. In doing this, it now means you can at least change the background color and still sort of use the editor.

Asking for thoughts now, before I do more work — what do you think of this approach?

If there's positive agreement on this direction, I will fix the drag and drop shadows/colors. Note that this PR makes the UI work on _light_ backgrounds. If you cross a certain threshold of luminosity into the dark background territory, we need to invert the colors. This PR already contains the opacities for that, but we'll need to detect the background color and apply a body class, something like `body.has-dark-background`, so that I can invert the UI for that. Would appreciate thoughts on this too.
  • Loading branch information
Joen Asmussen committed May 2, 2018
1 parent f3f59d2 commit 079f43e
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 31 deletions.
2 changes: 1 addition & 1 deletion components/placeholder/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
text-align: center;
font-family: $default-font;
font-size: $default-font-size;
background: $light-gray-100;
background: $dark-opacity-light-200; // use opacity to work in various editor styles
}

.components-placeholder__label {
Expand Down
40 changes: 40 additions & 0 deletions edit-post/assets/stylesheets/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,46 @@ $light-gray-200: #f3f4f5;
$light-gray-100: #f8f9f9;
$white: #fff;

// Dark opacities, for use with light themes
$dark-opacity-900: rgba( $dark-gray-900, .8 );
$dark-opacity-800: rgba( $dark-gray-900, .75 );
$dark-opacity-700: rgba( $dark-gray-900, .7 );
$dark-opacity-600: rgba( $dark-gray-900, .65 );
$dark-opacity-500: rgba( $dark-gray-900, .6 );
$dark-opacity-400: rgba( $dark-gray-900, .55 );
$dark-opacity-300: rgba( $dark-gray-900, .5 );
$dark-opacity-200: rgba( $dark-gray-900, .45 );
$dark-opacity-100: rgba( $dark-gray-900, .4 );
$dark-opacity-light-900: rgba( $dark-gray-900, .35 );
$dark-opacity-light-800: rgba( $dark-gray-900, .3 );
$dark-opacity-light-700: rgba( $dark-gray-900, .25 );
$dark-opacity-light-600: rgba( $dark-gray-900, .2 );
$dark-opacity-light-500: rgba( $dark-gray-900, .15 );
$dark-opacity-light-400: rgba( $dark-gray-900, .1 );
$dark-opacity-light-300: rgba( $dark-gray-900, .075 );
$dark-opacity-light-200: rgba( $dark-gray-900, .05 );
$dark-opacity-light-100: rgba( $dark-gray-900, .025 );

// Light opacities, for use with dark themes
$light-opacity-900: rgba( $white, 1 );
$light-opacity-800: rgba( $white, .9 );
$light-opacity-700: rgba( $white, .85 );
$light-opacity-600: rgba( $white, .8 );
$light-opacity-500: rgba( $white, .75 );
$light-opacity-400: rgba( $white, .7 );
$light-opacity-300: rgba( $white, .65 );
$light-opacity-200: rgba( $white, .6 );
$light-opacity-100: rgba( $white, .55 );
$light-opacity-light-900: rgba( $white, .5 );
$light-opacity-light-800: rgba( $white, .45 );
$light-opacity-light-700: rgba( $white, .4 );
$light-opacity-light-600: rgba( $white, .35 );
$light-opacity-light-500: rgba( $white, .3 );
$light-opacity-light-400: rgba( $white, .25 );
$light-opacity-light-300: rgba( $white, .2 );
$light-opacity-light-200: rgba( $white, .15 );
$light-opacity-light-100: rgba( $white, .1 );

// Additional colors
// some from https://make.wordpress.org/design/handbook/foundations/colors/
$blue-wordpress: #0073aa;
Expand Down
3 changes: 3 additions & 0 deletions edit-post/assets/stylesheets/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,20 @@ $float-margin: calc( 50% - #{ $content-width-padding / 2 } );
}

@mixin button-style__hover {
background-color: $white;
color: $dark-gray-900;
box-shadow: inset 0 0 0 1px $light-gray-500, inset 0 0 0 2px $white, 0 1px 1px rgba( $dark-gray-900, .2 );
}

@mixin button-style__active() {
outline: none;
background-color: $white;
color: $dark-gray-900;
box-shadow: inset 0 0 0 1px $light-gray-700, inset 0 0 0 2px $white;
}

@mixin button-style__focus-active() {
background-color: $white;
color: $dark-gray-900;
box-shadow: inset 0 0 0 1px $dark-gray-300, inset 0 0 0 2px $white;

Expand Down
2 changes: 1 addition & 1 deletion edit-post/assets/stylesheets/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// value is designed to work with).

$z-layers: (
'.editor-block-list__block-edit:before': 0,
'.editor-block-switcher__arrow': 1,
'.editor-block-list__block-edit:before': -1,
'.editor-block-list__block .wp-block-more:before': -1,
'.editor-block-list__block {core/image aligned left or right}': 20,
'.editor-block-list__block {core/image aligned wide or fullwide}': 20,
Expand Down
14 changes: 10 additions & 4 deletions edit-post/assets/stylesheets/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
}
}

// in order to use mix-blend-mode, this element needs to have an explicitly set background-color
html {
background: $white;
}

body.gutenberg-editor-page {
background: $white;

Expand Down Expand Up @@ -174,17 +179,18 @@ body.gutenberg-editor-page {
.editor-block-list__block {
input,
textarea {
// use opacity to work in various editor styles
&::-webkit-input-placeholder {
color: $dark-gray-300;
color: $dark-opacity-300;
}
&::-moz-placeholder {
color: $dark-gray-300;
color: $dark-opacity-300;
}
&:-ms-input-placeholder {
color: $dark-gray-300;
color: $dark-opacity-300;
}
&:-moz-placeholder {
color: $dark-gray-300;
color: $dark-opacity-300;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion edit-post/components/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

// This is a focus style shown for blocks that need an indicator even when in an isEditing state
// like for example an image block that receives arrowkey focus.
.edit-post-visual-editor .editor-block-list__block:not( .is-selected ) {
.edit-post-visual-editor .editor-block-list__block:not( .is-selected ):not( [data-type="core/paragraph"] ) {
.editor-block-list__block-edit {
box-shadow: 0 0 0 0 $white, 0 0 0 0 $dark-gray-900;
transition: .1s box-shadow .05s;
Expand Down
30 changes: 16 additions & 14 deletions editor/components/block-list/style.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.components-draggable__clone {
& > .editor-block-list__block > .editor-block-list__block-draggable {
background: $white;
background: $white; // @todo: ensure this works with themes that invert the color
box-shadow: $shadow-popover;

@include break-small {
Expand Down Expand Up @@ -33,7 +33,7 @@
right: 0;
bottom: 0;
left: 0;
background-color: $light-gray-200;
background-color: $dark-opacity-light-200;
visibility: hidden;

@include break-small {
Expand All @@ -57,7 +57,7 @@
}


cursor: move;/* Fallback for IE/Edge < 14 */
cursor: move; // Fallback for IE/Edge < 14
cursor: grab;
}

Expand Down Expand Up @@ -168,15 +168,13 @@
top: 10px;
}

&.is-selected > .editor-block-mover:before,
&.is-hovered > .editor-block-mover:before {
border-right: 1px solid $light-gray-500;
border-right: 1px solid $dark-opacity-light-500; // use opacity to work in various editor styles
right: 0;
}

&.is-selected > .editor-block-settings-menu:before,
&.is-hovered > .editor-block-settings-menu:before {
border-left: 1px solid $light-gray-500;
border-left: 1px solid $dark-opacity-light-500; // use opacity to work in various editor styles
left: 0;
}

Expand Down Expand Up @@ -213,7 +211,7 @@

// focused block-style
&.is-selected > .editor-block-list__block-edit:before {
outline: 1px solid $light-gray-500;
outline: 1px solid $dark-opacity-light-500; // use opacity to work in various editor styles
}

/**
Expand All @@ -235,6 +233,7 @@

&.is-multi-selected .editor-block-list__block-edit:before {
background: $blue-medium-highlight;
mix-blend-mode: multiply;
}

/**
Expand Down Expand Up @@ -652,10 +651,14 @@

.editor-block-contextual-toolbar .editor-block-toolbar,
.editor-block-list__breadcrumb .components-toolbar {
border: 1px solid $light-gray-500;
width: 100%;
background: $white;

// use opacity to work in various editor styles
border: 1px solid $dark-opacity-light-500;
background-clip: padding-box;
box-sizing: padding-box;

// this prevents floats from messing up the position
position: absolute;
left: 0;
Expand All @@ -665,16 +668,15 @@
right: 0;
}

// remove stacked borders in inline toolbar
> div:first-child {
margin-left: -1px;
}

@include break-small() {
width: auto;
}
}

.editor-block-contextual-toolbar .editor-block-toolbar {
border-bottom: none;
}

.editor-block-list__breadcrumb .components-toolbar {
padding: 0px 12px;
line-height: $block-toolbar-height - 1px;
Expand Down
4 changes: 2 additions & 2 deletions editor/components/block-mover/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
border: none;
outline: none;
background: none;
color: $dark-gray-300;
color: $dark-opacity-300; // use opacity to work in various editor styles
cursor: pointer;
padding: 0;
width: $block-side-ui-width;
Expand All @@ -23,7 +23,7 @@

&[aria-disabled="true"] {
cursor: default;
color: $light-gray-300;
color: $dark-opacity-light-300; // use opacity to work in various editor styles
pointer-events: none;
}

Expand Down
2 changes: 1 addition & 1 deletion editor/components/block-settings-menu/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
background: none;
outline: none;
border-radius: 0;
color: $dark-gray-500;
color: $dark-opacity-500; // use opacity to work in various editor styles
text-align: left;
cursor: pointer;
@include menu-style__neutral;
Expand Down
7 changes: 5 additions & 2 deletions editor/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@

.editor-block-toolbar .editor-block-switcher {
display: inline-flex;
border-left: 1px solid $light-gray-500;
}

.edit-post-header-toolbar__block-toolbar & {
border-left: 1px solid $light-gray-500;
}
}
4 changes: 2 additions & 2 deletions editor/components/default-block-appender/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $empty-paragraph-height: $text-editor-font-size * 4;
font-family: $editor-font;
cursor: text;
width: 100%;
color: $dark-gray-300;
color: $dark-opacity-300; // use opacity to work in various editor styles
font-family: $editor-font;
outline: 1px solid transparent;
transition: 0.2s outline;
Expand All @@ -23,7 +23,7 @@ $empty-paragraph-height: $text-editor-font-size * 4;
// Show quick insertion icons faded until hover
.editor-inserter-with-shortcuts {
.components-icon-button {
color: $light-gray-700;
color: $dark-opacity-light-700; // use opacity to work in various editor styles
transition: color 0.2s;
}
}
Expand Down
7 changes: 6 additions & 1 deletion editor/components/post-permalink/style.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
.editor-post-permalink {
display: inline-flex;
align-items: center;
border: 1px solid $light-gray-500;
background: $white;
padding: 5px;
font-family: $default-font;
font-size: $default-font-size;
height: 40px;
white-space: nowrap;

// use opacity to work in various editor styles
border: 1px solid $dark-opacity-light-500;
border-bottom: none;
background-clip: padding-box;
box-sizing: padding-box;

// put toolbar snugly to edge on mobile
margin-left: -$block-padding - 1px; // stack borders
margin-right: -$block-padding - 1px;
Expand Down
5 changes: 3 additions & 2 deletions editor/components/post-title/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
margin: 0;
box-shadow: none;
border: 1px solid transparent;
background: transparent;
font-family: $editor-font;
line-height: $default-line-height;

Expand All @@ -19,14 +20,14 @@

&.is-selected .editor-post-title__input,
.editor-post-title__input:hover {
border: 1px solid $light-gray-500;
border: 1px solid $dark-opacity-light-500; // use opacity to work in various editor styles
}
}

.editor-post-title .editor-post-permalink {
font-size: $default-font-size;
position: absolute;
top: -34px;
top: -35px;
left: 0;
right: 0;
}

0 comments on commit 079f43e

Please sign in to comment.