-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: Unify the preview dropdown between post and site editors
- Loading branch information
1 parent
1783a4e
commit 8e52e2d
Showing
12 changed files
with
168 additions
and
363 deletions.
There are no files selected for viewing
94 changes: 0 additions & 94 deletions
94
packages/block-editor/src/components/preview-options/README.md
This file was deleted.
Oops, something went wrong.
93 changes: 6 additions & 87 deletions
93
packages/block-editor/src/components/preview-options/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 |
---|---|---|
@@ -1,92 +1,11 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { check, desktop, mobile, tablet } from '@wordpress/icons'; | ||
|
||
export default function PreviewOptions( { | ||
children, | ||
viewLabel, | ||
className, | ||
isEnabled = true, | ||
deviceType, | ||
setDeviceType, | ||
label, | ||
showIconLabels, | ||
} ) { | ||
const isMobile = useViewportMatch( 'medium', '<' ); | ||
if ( isMobile ) return null; | ||
|
||
const popoverProps = { | ||
className: classnames( | ||
className, | ||
'block-editor-post-preview__dropdown-content' | ||
), | ||
placement: 'bottom-end', | ||
}; | ||
const toggleProps = { | ||
className: 'block-editor-post-preview__button-toggle', | ||
disabled: ! isEnabled, | ||
__experimentalIsFocusable: ! isEnabled, | ||
children: viewLabel, | ||
size: 'compact', | ||
showTooltip: ! showIconLabels, | ||
}; | ||
const menuProps = { | ||
'aria-label': __( 'View options' ), | ||
}; | ||
|
||
const deviceIcons = { | ||
mobile, | ||
tablet, | ||
desktop, | ||
}; | ||
import deprecated from '@wordpress/deprecated'; | ||
|
||
return ( | ||
<DropdownMenu | ||
className="block-editor-post-preview__dropdown" | ||
popoverProps={ popoverProps } | ||
toggleProps={ toggleProps } | ||
menuProps={ menuProps } | ||
icon={ deviceIcons[ deviceType.toLowerCase() ] } | ||
label={ label || __( 'Preview' ) } | ||
disableOpenOnArrowDown={ ! isEnabled } | ||
> | ||
{ ( renderProps ) => ( | ||
<> | ||
<MenuGroup> | ||
<MenuItem | ||
className="block-editor-post-preview__button-resize" | ||
onClick={ () => setDeviceType( 'Desktop' ) } | ||
icon={ deviceType === 'Desktop' && check } | ||
> | ||
{ __( 'Desktop' ) } | ||
</MenuItem> | ||
<MenuItem | ||
className="block-editor-post-preview__button-resize" | ||
onClick={ () => setDeviceType( 'Tablet' ) } | ||
icon={ deviceType === 'Tablet' && check } | ||
> | ||
{ __( 'Tablet' ) } | ||
</MenuItem> | ||
<MenuItem | ||
className="block-editor-post-preview__button-resize" | ||
onClick={ () => setDeviceType( 'Mobile' ) } | ||
icon={ deviceType === 'Mobile' && check } | ||
> | ||
{ __( 'Mobile' ) } | ||
</MenuItem> | ||
</MenuGroup> | ||
{ children?.( renderProps ) } | ||
</> | ||
) } | ||
</DropdownMenu> | ||
); | ||
export default function PreviewOptions() { | ||
deprecated( 'wp.blockEditor.PreviewOptions', { | ||
version: '6.5', | ||
} ); | ||
return null; | ||
} |
64 changes: 0 additions & 64 deletions
64
packages/block-editor/src/components/preview-options/style.scss
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.