-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Site Editor: add more menu and fullscreen toggle (#21006)
Add necessary UI elements that will allow us to toggle the fullscreen mode in Site Editor.
- Loading branch information
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/edit-site/src/components/header/feature-toggle/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/edit-site/src/components/header/more-menu/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
29
packages/edit-site/src/components/header/more-menu/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters