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

Site Editor: add more menu and fullscreen toggle #21006

Merged
merged 4 commits into from
Mar 23, 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
1 change: 1 addition & 0 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ $z-layers: (
".components-popover.table-of-contents__popover": 99998,
".components-popover.block-editor-block-navigation__popover": 99998,
".components-popover.edit-post-more-menu__content": 99998,
".components-popover.edit-site-more-menu__content": 99998,
".components-popover.block-editor-rich-text__inline-format-toolbar": 99998,

".components-autocomplete__results": 1000000,
Expand Down
52 changes: 52 additions & 0 deletions packages/edit-site/src/components/header/feature-toggle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* External dependencies
*/
import { flow } from 'lodash';

/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { MenuItem, withSpokenMessages } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { check } from '@wordpress/icons';

function FeatureToggle( {
feature,
label,
info,
messageActivated,
messageDeactivated,
speak,
} ) {
const speakMessage = () => {
if ( isActive ) {
speak( messageDeactivated || __( 'Feature deactivated' ) );
} else {
speak( messageActivated || __( 'Feature activated' ) );
}
};

const isActive = useSelect( ( select ) => {
return select( 'core/edit-site' ).isFeatureActive( feature );
}, [] );

const { toggleFeature } = useDispatch( 'core/edit-site' );

return (
<MenuItem
icon={ isActive && check }
isSelected={ isActive }
onClick={ flow(
toggleFeature.bind( null, feature ),
speakMessage
) }
role="menuitemcheckbox"
info={ info }
>
{ label }
</MenuItem>
);
}

export default withSpokenMessages( FeatureToggle );
2 changes: 2 additions & 0 deletions packages/edit-site/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BlockNavigationDropdown, ToolSelector } from '@wordpress/block-editor';
* Internal dependencies
*/
import { useEditorContext } from '../editor';
import MoreMenu from './more-menu';
import TemplateSwitcher from '../template-switcher';
import SaveButton from '../save-button';

Expand Down Expand Up @@ -59,6 +60,7 @@ export default function Header() {
</div>
<div className="edit-site-header__actions">
<SaveButton />
<MoreMenu />
</div>
</div>
);
Expand Down
43 changes: 43 additions & 0 deletions packages/edit-site/src/components/header/more-menu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* WordPress dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { DropdownMenu, MenuGroup } from '@wordpress/components';

/**
* Internal dependencies
*/
import FeatureToggle from '../feature-toggle';
import { moreVertical } from '@wordpress/icons';

const POPOVER_PROPS = {
className: 'edit-site-more-menu__content',
position: 'bottom left',
};
const TOGGLE_PROPS = {
tooltipPosition: 'bottom',
};

const MoreMenu = () => (
<DropdownMenu
className="edit-site-more-menu"
icon={ moreVertical }
label={ __( 'More tools & options' ) }
popoverProps={ POPOVER_PROPS }
toggleProps={ TOGGLE_PROPS }
>
{ () => (
<MenuGroup label={ _x( 'View', 'noun' ) }>
<FeatureToggle
feature="fullscreenMode"
label={ __( 'Fullscreen mode' ) }
info={ __( 'Work without distraction' ) }
messageActivated={ __( 'Fullscreen mode activated' ) }
messageDeactivated={ __( 'Fullscreen mode deactivated' ) }
/>
</MenuGroup>
) }
</DropdownMenu>
);

export default MoreMenu;
29 changes: 29 additions & 0 deletions packages/edit-site/src/components/header/more-menu/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.edit-site-more-menu {
margin-left: -4px;

// the padding and margin of the more menu is intentionally non-standard
.components-button {
width: auto;
padding: 0 2px;
}

@include break-small() {
margin-left: 4px;

.components-button {
padding: 0 4px;
}
}
}

.edit-site-more-menu__content .components-popover__content {
min-width: 260px;

.components-dropdown-menu__menu {
padding: 0;
}
}

.components-popover.edit-site-more-menu__content {
z-index: z-index(".components-popover.edit-site-more-menu__content");
}
1 change: 1 addition & 0 deletions packages/edit-site/src/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "./components/block-editor/style.scss";
@import "./components/header/style.scss";
@import "./components/header/more-menu/style.scss";
@import "./components/notices/style.scss";
@import "./components/sidebar/style.scss";
@import "./components/template-switcher/style.scss";
Expand Down