Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7d47273
Add initial colorization code
glendaviesnz Nov 1, 2022
9204830
Tidy up the setting of colors in the list view
glendaviesnz Nov 1, 2022
c26150b
Tidy up doc block types
glendaviesnz Nov 1, 2022
27e1cf5
Add color to block toolbar
glendaviesnz Nov 1, 2022
1ab8214
Add color to template block toolbar
glendaviesnz Nov 1, 2022
93bf9ba
Add selection box color
glendaviesnz Nov 2, 2022
2a3deca
Fix scope of styles
glendaviesnz Nov 2, 2022
22c5977
Add colors to block selector
glendaviesnz Nov 2, 2022
be58817
fix issue with outline styles
glendaviesnz Nov 2, 2022
0d1dbb9
Switch to using the existing isTemplatePart and isReusable methods
glendaviesnz Nov 2, 2022
3fbf88d
another switch to use existing methods
glendaviesnz Nov 2, 2022
3e0d7f0
Combine the template part and reusable block colors under an `isSynce…
glendaviesnz Nov 3, 2022
bc38da3
Remove color from block name and just color icon
glendaviesnz Nov 3, 2022
e0f5905
Apply selected outline color to reusable blocks in the post editor
glendaviesnz Nov 3, 2022
6931586
change colour of focus outline
glendaviesnz Nov 3, 2022
e5d1f96
Add synced color to block icon in inspector panel header
glendaviesnz Nov 22, 2022
00abab3
Add synced color to block hover overlay
glendaviesnz Nov 3, 2022
a28dd85
Colorise name in header
glendaviesnz Nov 4, 2022
878ae16
Add icon to site editor template part dropdown
glendaviesnz Nov 16, 2022
a9d1848
Add brightness to background color
glendaviesnz Nov 17, 2022
31a7b11
Add extra class to denote synced branches
glendaviesnz Nov 17, 2022
d4e1e7d
Add synced color to list view branch items
glendaviesnz Nov 17, 2022
00846fb
Make sure child leaves are colored correctly
glendaviesnz Nov 17, 2022
e93470d
Standardise opacity as 0.04
glendaviesnz Nov 17, 2022
d50750c
Revert "Make sure child leaves are colored correctly"
glendaviesnz Nov 22, 2022
8fb97dd
Standardise format in classnames
glendaviesnz Nov 22, 2022
2333a27
Fix icon color
glendaviesnz Nov 22, 2022
0ea11cb
Fix failing e2e tests
glendaviesnz Nov 23, 2022
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
7 changes: 7 additions & 0 deletions packages/base-styles/_colors.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import "./functions";

/**
* Colors
*/
Expand All @@ -24,3 +26,8 @@ $light-gray-placeholder: rgba($white, 0.65);
$alert-yellow: #f0b849;
$alert-red: #cc1818;
$alert-green: #4ab866;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure if this is the best place to put these - went with CSS vars instead of SCSS vars so themes can potentially override these.

Copy link
Contributor

Choose a reason for hiding this comment

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

The choice of CSS vars over SCSS makes sense to me 👍

:root {
--wp-block-synced-color: #7a00df;
--wp-block-synced-color--rgb: #{hex-to-rgb(#7a00df)};
}
12 changes: 11 additions & 1 deletion packages/block-editor/src/components/block-card/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand All @@ -17,6 +22,7 @@ function BlockCard( {
blockType,
parentBlockClientId,
handleBackButton,
isSynced,
Copy link
Contributor

@ntsekouras ntsekouras Nov 23, 2022

Choose a reason for hiding this comment

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

I think it would make better to add className here instead of this specific prop. It would save us possible deprecations and we could also accommodate more use case for styles in the future. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea - I will take a look at that tomorrow.

} ) {
if ( blockType ) {
deprecated( '`blockType` property in `BlockCard component`', {
Expand All @@ -30,7 +36,11 @@ function BlockCard( {
window?.__experimentalEnableOffCanvasNavigationEditor === true;

return (
<div className="block-editor-block-card">
<div
className={ classnames( 'block-editor-block-card', {
'is-synced': isSynced,
} ) }
>
{ isOffCanvasNavigationEditorEnabled && parentBlockClientId && (
<Button
onClick={ handleBackButton }
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/components/block-card/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@
width: $button-size-small;
height: $button-size-small;
}

.block-editor-block-card.is-synced .block-editor-block-icon {
color: var(--wp-block-synced-color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@
}

&:hover:not(.is-dragging-blocks)::before {
background: rgba(var(--wp-admin-theme-color--rgb), 0.3);
background: rgba(var(--wp-admin-theme-color--rgb), 0.04);
box-shadow: 0 0 0 $border-width var(--wp-admin-theme-color) inset;
}

&.is-reusable:hover:not(.is-dragging-blocks)::before,
&.wp-block-template-part:hover:not(.is-dragging-blocks)::before {
background: rgba(var(--wp-block-synced-color--rgb), 0.04);
box-shadow: 0 0 0 $border-width var(--wp-block-synced-color) inset;
}

&.is-selected:not(.is-dragging-blocks)::before {
box-shadow: 0 0 0 $border-width var(--wp-admin-theme-color) inset;
}
Expand Down
17 changes: 12 additions & 5 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import classnames from 'classnames';
import { useSelect, useDispatch } from '@wordpress/data';
import { useRef } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';
import { getBlockType, hasBlockSupport } from '@wordpress/blocks';
import {
getBlockType,
hasBlockSupport,
isReusableBlock,
isTemplatePart,
} from '@wordpress/blocks';
import { ToolbarGroup } from '@wordpress/components';

/**
Expand Down Expand Up @@ -109,11 +114,13 @@ const BlockToolbar = ( { hideDragHandle } ) => {

const shouldShowVisualToolbar = isValid && isVisual;
const isMultiToolbar = blockClientIds.length > 1;
const isSynced =
isReusableBlock( blockType ) || isTemplatePart( blockType );

const classes = classnames(
'block-editor-block-toolbar',
shouldShowMovers && 'is-showing-movers'
);
const classes = classnames( 'block-editor-block-toolbar', {
'is-showing-movers': shouldShowMovers,
'is-synced': isSynced,
} );

return (
<div className={ classes }>
Expand Down
10 changes: 10 additions & 0 deletions packages/block-editor/src/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
border-right: $border-width solid $gray-300;
}

&.is-synced .block-editor-block-switcher .components-button .block-editor-block-icon {
color: var(--wp-block-synced-color);
}

&.is-synced .components-toolbar-button.block-editor-block-switcher__no-switcher-icon {
&:disabled .block-editor-block-icon.has-colors {
color: var(--wp-block-synced-color);
}
}

> :last-child,
> :last-child .components-toolbar-group,
> :last-child .components-toolbar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { useMemo, useRef, memo } from '@wordpress/element';
import {
createBlock,
createBlocksFromInnerBlocksTemplate,
isReusableBlock,
isTemplatePart,
} from '@wordpress/blocks';
import { __experimentalTruncate as Truncate } from '@wordpress/components';
import { ENTER, isAppleOS } from '@wordpress/keycodes';
Expand Down Expand Up @@ -47,6 +49,8 @@ function InserterListItem( {
];
}, [ item.name, item.initialAttributes, item.initialAttributes ] );

const isSynced = isReusableBlock( item ) || isTemplatePart( item );

return (
<InserterDraggableBlocks
isEnabled={ isDraggable && ! item.disabled }
Expand All @@ -55,7 +59,13 @@ function InserterListItem( {
>
{ ( { draggable, onDragStart, onDragEnd } ) => (
<div
className="block-editor-block-types-list__list-item"
className={ classnames(
'block-editor-block-types-list__list-item',

{
'is-synced': isSynced,
}
) }
draggable={ draggable }
onDragStart={ ( event ) => {
isDragging.current = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
width: 33.33%;
padding: 0;
margin: 0;
&.is-synced {
.block-editor-block-icon.has-colors {
color: var(--wp-block-synced-color);
}
}
}

.components-button.block-editor-block-types-list__item {
Expand Down
3 changes: 3 additions & 0 deletions packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function ListViewBlock( {
isExpanded,
selectedClientIds,
preventAnnouncement,
isSyncedBranch,
} ) {
const cellRef = useRef( null );
const [ isHovered, setIsHovered ] = useState( false );
Expand Down Expand Up @@ -205,8 +206,10 @@ function ListViewBlock( {
'is-first-selected': isFirstSelectedBlock,
'is-last-selected': isLastSelectedBlock,
'is-branch-selected': isBranchSelected,
'is-synced-branch': isSyncedBranch,
'is-dragging': isDragged,
'has-single-cell': ! showBlockActions,
'is-synced': blockInformation.isSynced,
} );

// Only include all selected blocks if the currently clicked on block
Expand Down
7 changes: 7 additions & 0 deletions packages/block-editor/src/components/list-view/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ListViewBlock from './block';
import { useListViewContext } from './context';
import { isClientIdSelected } from './utils';
import { store as blockEditorStore } from '../../store';
import useBlockDisplayInformation from '../use-block-display-information';

/**
* Given a block, returns the total number of blocks in that subtree. This is used to help determine
Expand Down Expand Up @@ -92,8 +93,12 @@ function ListViewBranch( props ) {
isExpanded,
parentId,
shouldShowInnerBlocks = true,
isSyncedBranch = false,
} = props;

const parentBlockInformation = useBlockDisplayInformation( parentId );
const syncedBranch = isSyncedBranch || !! parentBlockInformation?.isSynced;

const canParentExpand = useSelect(
( select ) => {
if ( ! parentId ) {
Expand Down Expand Up @@ -179,6 +184,7 @@ function ListViewBranch( props ) {
isExpanded={ shouldExpand }
listPosition={ nextPosition }
selectedClientIds={ selectedClientIds }
isSyncedBranch={ syncedBranch }
/>
) }
{ ! showBlock && (
Expand All @@ -199,6 +205,7 @@ function ListViewBranch( props ) {
isBranchSelected={ isSelectedBranch }
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
isSyncedBranch={ syncedBranch }
/>
) }
</AsyncModeProvider>
Expand Down
24 changes: 19 additions & 5 deletions packages/block-editor/src/components/list-view/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
&.is-selected td {
background: var(--wp-admin-theme-color);
}
&.is-selected.is-synced td {
background: var(--wp-block-synced-color);
}
&.is-synced:not(.is-selected) .block-editor-list-view-block-contents .block-editor-block-icon {
color: var(--wp-block-synced-color);
}
&.is-selected .block-editor-list-view-block-contents,
&.is-selected .components-button.has-icon {
color: $white;
Expand All @@ -37,6 +43,13 @@
0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
}
}
&.is-selected.is-synced .block-editor-list-view-block-contents:focus {
&::after {
box-shadow:
inset 0 0 0 1px $white,
0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-synced-color);
}
}
&.is-selected .block-editor-list-view-block__menu:focus {
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) $white;
}
Expand All @@ -58,11 +71,11 @@
&.is-last-selected td:last-child {
border-bottom-right-radius: $radius-block-ui;
}
&.is-branch-selected:not(.is-selected) {
// Lighten a CSS variable without introducing a new SASS variable
background:
linear-gradient(transparentize($white, 0.1), transparentize($white, 0.1)),
linear-gradient(var(--wp-admin-theme-color), var(--wp-admin-theme-color));
&.is-branch-selected:not(.is-selected):not(.is-synced-branch) {
background: rgba(var(--wp-admin-theme-color--rgb), 0.04);
}
&.is-synced-branch:not(.is-selected) {
background: rgba(var(--wp-block-synced-color--rgb), 0.04);
}
&.is-branch-selected.is-first-selected td:first-child {
border-top-left-radius: $radius-block-ui;
Expand Down Expand Up @@ -142,6 +155,7 @@
}
}
}

// Fix focus styling width when one row has fewer cells.
&.has-single-cell .block-editor-list-view-block-contents:focus::after {
right: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';
import {
store as blocksStore,
isReusableBlock,
isTemplatePart,
} from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -16,10 +20,11 @@ import { store as blockEditorStore } from '../../store';
*
* @typedef {Object} WPBlockDisplayInformation
*
* @property {string} title Human-readable block type label.
* @property {WPIcon} icon Block type icon.
* @property {string} description A detailed block type description.
* @property {string} anchor HTML anchor.
* @property {boolean} isSynced True if is a reusable block or template part
* @property {string} title Human-readable block type label.
* @property {WPIcon} icon Block type icon.
* @property {string} description A detailed block type description.
* @property {string} anchor HTML anchor.
*/

/**
Expand Down Expand Up @@ -50,7 +55,10 @@ export default function useBlockDisplayInformation( clientId ) {
if ( ! blockType ) return null;
const attributes = getBlockAttributes( clientId );
const match = getActiveBlockVariation( blockName, attributes );
const isSynced =
isReusableBlock( blockType ) || isTemplatePart( blockType );
const blockTypeInfo = {
isSynced,
title: blockType.title,
icon: blockType.icon,
description: blockType.description,
Expand All @@ -59,6 +67,7 @@ export default function useBlockDisplayInformation( clientId ) {
if ( ! match ) return blockTypeInfo;

return {
isSynced,
title: match.title || blockType.title,
icon: match.icon || blockType.icon,
description: match.description || blockType.description,
Expand Down
17 changes: 17 additions & 0 deletions packages/block-library/src/block/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@
display: none;
}
}

.edit-post-visual-editor .block-editor-block-list__block:not(.remove-outline).is-reusable {
&.is-highlighted,
&.is-selected {
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-synced-color);
}

&.block-editor-block-list__block:not([contenteditable]):focus {
&::after {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-synced-color);
// Show a light color for dark themes.
.is-dark-theme & {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $dark-theme-focus;
}
}
}
}
22 changes: 20 additions & 2 deletions packages/block-library/src/template-part/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// and height are used instead of max-(width/height).
.components-modal__frame {
@include break-small() {
width: calc(100% - #{ $grid-unit-20 * 2 });
height: calc(100% - #{ $header-height * 2 });
width: calc(100% - #{$grid-unit-20 * 2});
height: calc(100% - #{$header-height * 2});
}
@include break-medium() {
width: $break-medium - $grid-unit-20 * 2;
Expand All @@ -24,3 +24,21 @@
padding: $grid-unit-20 0;
z-index: z-index(".block-library-template-part__selection-search");
}

.is-outline-mode .block-editor-block-list__block:not(.remove-outline).wp-block-template-part,
.is-outline-mode .block-editor-block-list__block:not(.remove-outline).is-reusable {
&.is-highlighted,
&.is-selected {
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-synced-color);
}

&.block-editor-block-list__block:not([contenteditable]):focus {
&::after {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-block-synced-color);
// Show a light color for dark themes.
.is-dark-theme & {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $dark-theme-focus;
}
}
}
}
2 changes: 1 addition & 1 deletion packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ export function isReusableBlock( blockOrType ) {
* @return {boolean} Whether the given block is a template part.
*/
export function isTemplatePart( blockOrType ) {
return blockOrType.name === 'core/template-part';
return blockOrType?.name === 'core/template-part';
}

/**
Expand Down
Loading