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

Add an outline mode and use it both Site Editor and Template mode #27499

Merged
merged 3 commits into from
Dec 4, 2020
Merged
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
4 changes: 3 additions & 1 deletion packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function BlockListBlock( {
// In addition to withSelect, we should favor using useSelect in this
// component going forward to avoid leaking new props to the public API
// (editor.BlockListBlock filter)
const { isDragging, isHighlighted, isFocusMode } = useSelect(
const { isDragging, isHighlighted, isFocusMode, isOutlineMode } = useSelect(
( select ) => {
const {
isBlockBeingDragged,
Expand All @@ -122,6 +122,7 @@ function BlockListBlock( {
isDragging: isBlockBeingDragged( clientId ),
isHighlighted: isBlockHighlighted( clientId ),
isFocusMode: getSettings().focusMode,
isOutlineMode: getSettings().outlineMode,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick - call getSettings once and extract props?

};
},
[ clientId ]
Expand Down Expand Up @@ -175,6 +176,7 @@ function BlockListBlock( {
isLargeViewport &&
( isSelected || isAncestorOfSelectedBlock ),
'is-focus-mode': isFocusMode && isLargeViewport,
'is-outline-mode': isOutlineMode,
'has-child-selected': isAncestorOfSelectedBlock && ! isDragging,
'is-active-entity': activeEntityBlockId === clientId,
},
Expand Down
28 changes: 28 additions & 0 deletions packages/block-editor/src/components/block-list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,34 @@
}
}

&.is-outline-mode.is-selected:not(.is-typing) {
&::after {
box-shadow: 0 0 0 $border-width $gray-900; // Selected not focussed
top: $border-width;
left: $border-width;
right: $border-width;
bottom: $border-width;
}

&:focus {
&::after {
box-shadow: 0 0 0 $border-width-focus var(--wp-admin-theme-color);
}
}
}

&.is-outline-mode.is-hovered:not(.is-typing) {
cursor: default;

&::after {
top: $border-width;
left: $border-width;
right: $border-width;
bottom: $border-width;
box-shadow: 0 0 0 $border-width var(--wp-admin-theme-color);
}
}

// Spotlight mode.
&.is-focus-mode:not(.is-multi-selected) {
opacity: 0.5;
Expand Down
47 changes: 0 additions & 47 deletions packages/edit-site/src/components/block-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,3 @@
padding: 6px;
}
}

.block-editor-block-list__layout {
&.edit-site-block-editor__block-list {
.block-editor-block-list__block {
&::after {
outline: 2px solid transparent;
}

&.is-selected {
&::after {
box-shadow: 0 0 0 $border-width $gray-900; // Selected not focussed
top: $border-width;
left: $border-width;
right: $border-width;
bottom: $border-width;
}

&:focus {
&::after {
box-shadow: 0 0 0 $border-width-focus var(--wp-admin-theme-color);
}
}
}

&.is-hovered:not(.is-selected) {
cursor: default;

&::after {
top: $border-width;
left: $border-width;
right: $border-width;
bottom: $border-width;
box-shadow: 0 0 0 $border-width var(--wp-admin-theme-color);
}
}
}

// Do not display a border on rich text blocks when hovered and selected
.block-editor-rich-text__editable {
&.is-selected.is-hovered.is-typing {
&::after {
box-shadow: none;
}
}
}
}
}
1 change: 1 addition & 0 deletions packages/edit-site/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const getSettings = createSelector(
( state, setIsInserterOpen ) => {
const settings = {
...state.settings,
outlineMode: true,
focusMode: isFeatureActive( state, 'focusMode' ),
hasFixedToolbar: isFeatureActive( state, 'fixedToolbar' ),
__experimentalSetIsInserterOpened: setIsInserterOpen,
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-site/src/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe( 'selectors', () => {
const state = { settings: {}, preferences: {} };
const setInserterOpened = () => {};
expect( getSettings( state, setInserterOpened ) ).toEqual( {
outlineMode: true,
focusMode: false,
hasFixedToolbar: false,
__experimentalSetIsInserterOpened: setInserterOpened,
Expand All @@ -101,6 +102,7 @@ describe( 'selectors', () => {
};
const setInserterOpened = () => {};
expect( getSettings( state, setInserterOpened ) ).toEqual( {
outlineMode: true,
key: 'value',
focusMode: true,
hasFixedToolbar: true,
Expand Down
9 changes: 7 additions & 2 deletions packages/editor/src/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ class EditorProvider extends Component {
hasUploadPermissions,
canUserUseUnfilteredHTML,
undo,
shouldInsertAtTheTop
shouldInsertAtTheTop,
hasTemplate
) {
return {
...pick( settings, [
Expand Down Expand Up @@ -211,6 +212,7 @@ class EditorProvider extends Component {
__experimentalCanUserUseUnfilteredHTML: canUserUseUnfilteredHTML,
__experimentalUndo: undo,
__experimentalShouldInsertAtTheTop: shouldInsertAtTheTop,
outlineMode: hasTemplate,
};
}

Expand Down Expand Up @@ -259,6 +261,7 @@ class EditorProvider extends Component {
hasUploadPermissions,
isPostTitleSelected,
undo,
hasTemplate,
} = this.props;

if ( ! isReady ) {
Expand All @@ -271,7 +274,8 @@ class EditorProvider extends Component {
hasUploadPermissions,
canUserUseUnfilteredHTML,
undo,
isPostTitleSelected
isPostTitleSelected,
hasTemplate
);

const defaultBlockContext = this.getDefaultBlockContext(
Expand Down Expand Up @@ -321,6 +325,7 @@ export default compose( [

const { id, type } = __unstableTemplate ?? post;
return {
hasTemplate: !! __unstableTemplate,
canUserUseUnfilteredHTML: canUserUseUnfilteredHTML(),
isReady: isEditorReady(),
blocks: getEditedEntityRecord( 'postType', type, id ).blocks,
Expand Down