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

Try: "Focus Mode". #8920

Closed
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions edit-post/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ function Layout( {
hasActiveMetaboxes,
isSaving,
isMobileViewport,
isFocusMode,
} ) {
const sidebarIsOpened = editorSidebarOpened || pluginSidebarOpened || publishSidebarOpened;

const className = classnames( 'edit-post-layout', {
'is-sidebar-opened': sidebarIsOpened,
'has-fixed-toolbar': hasFixedToolbar,
'is-focus-mode': isFocusMode,
} );

const publishLandmarkProps = {
Expand Down Expand Up @@ -143,6 +145,7 @@ export default compose(
metaBoxes: select( 'core/edit-post' ).getMetaBoxes(),
hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(),
isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(),
isFocusMode: select( 'core/edit-post' ).isFocusMode(),
} ) ),
withDispatch( ( dispatch ) => {
const { closePublishSidebar, togglePublishSidebar } = dispatch( 'core/edit-post' );
Expand Down
30 changes: 30 additions & 0 deletions edit-post/hooks/more-menu/focus-mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* WordPress dependencies
*/
import { MenuItem } from '@wordpress/components';
import { withDispatch, withSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { compose } from '@wordpress/compose';

function FocusModeMenuItem( { isFocusMode, toggleFocusMode } ) {
return (
<MenuItem
icon={ isFocusMode && 'yes' }
onClick={ toggleFocusMode }
>
{ __( 'Focus Mode' ) }
</MenuItem>
);
}

export default compose(
withSelect( ( select ) => ( {
isFocusMode: select( 'core/edit-post' ).isFocusMode(),
} ) ),
withDispatch( ( dispatch ) => {
const { toggleFocusMode } = dispatch( 'core/edit-post' );
return {
toggleFocusMode: toggleFocusMode,
};
} ),
)( FocusModeMenuItem );
16 changes: 14 additions & 2 deletions edit-post/hooks/more-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@ import { addFilter } from '@wordpress/hooks';
* Internal dependencies
*/
import CopyContentMenuItem from './copy-content-menu-item';
import FocusMode from './focus-mode';

const withCopyContentMenuItem = ( menuItems ) => [
const withCopyMenuItem = ( menuItems ) => [
...menuItems,
<CopyContentMenuItem key="copy-content-menu-item" />,
];

addFilter(
'editPost.MoreMenu.tools',
'core/edit-post/more-menu/withCopyContentMenuItem',
withCopyContentMenuItem
withCopyMenuItem
);

const withFocusMode = ( menuItems ) => [
...menuItems,
<FocusMode key="focus-mode" />,
];

addFilter(
'editPost.MoreMenu.tools',
'core/edit-post/more-menu/focusMode',
withFocusMode
);
11 changes: 11 additions & 0 deletions edit-post/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ export function toggleGeneralSidebarEditorPanel( panel ) {
};
}

/**
* Returns an action object used in signalling that the user toggles focus mode.
*
* @return {Object} Action object
*/
export function toggleFocusMode() {
return {
type: 'TOGGLE_FOCUS_MODE',
};
}

/**
* Returns an action object used to toggle a feature flag.
*
Expand Down
9 changes: 9 additions & 0 deletions edit-post/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ export function publishSidebarActive( state = false, action ) {
return state;
}

export function focusModeActive( state = false, action ) {
switch ( action.type ) {
case 'TOGGLE_FOCUS_MODE':
return ! state;
}
return state;
}

const locations = [
'normal',
'side',
Expand Down Expand Up @@ -195,6 +203,7 @@ export default combineReducers( {
panel,
activeModal,
publishSidebarActive,
focusModeActive,
metaBoxes,
isSavingMetaBoxes,
} );
11 changes: 11 additions & 0 deletions edit-post/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ export function isEditorSidebarPanelOpened( state, panel ) {
return panels ? !! panels[ panel ] : false;
}

/**
* Returns true if focus mode is enabled.
*
* @param {Object} state Global application state
*
* @return {boolean} Whether focus mode is enabled.
*/
export function isFocusMode( state ) {
return state.focusModeActive;
}

/**
* Returns true if a modal is active, or false otherwise.
*
Expand Down
44 changes: 43 additions & 1 deletion packages/editor/src/components/block-list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
cursor: grab;
}


// Allow Drag & Drop when clicking on the empty area of the mover and the settings menu
.editor-block-list__layout .editor-block-list__block .editor-block-mover,
.editor-block-list__layout .editor-block-list__block .editor-block-settings-menu {
Expand Down Expand Up @@ -1029,3 +1028,46 @@
}
}
}

// When focus mode is engaged, dim down visibility of non-selected blocks
.editor-block-list__layout .editor-block-list__block:not(.is-selected):not(.is-typing) {
.is-focus-mode & {
opacity: 0.2;
}
}

.editor-block-list__layout .editor-block-contextual-toolbar,
.editor-block-settings-menu,
.editor-block-mover,
.editor-block-list__block.is-hovered .editor-block-list__block-edit::before,
.editor-block-list__breadcrumb,
.editor-post-permalink {
.is-focus-mode & {
display: none !important;
outline: none !important;
}
}

.is-focus-mode .edit-post-header {
.edit-post-header-toolbar {
> * {
visibility: hidden !important;
}

.editor-inserter,
.editor-history__undo,
.editor-history__redo,
.edit-post-header-toolbar__block-toolbar {
visibility: visible !important;
}
}
.edit-post-header__settings {
> * {
visibility: hidden !important;
}

.edit-post-more-menu {
visibility: visible !important;
}
}
}