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

Editor: Unify the preview dropdown between post and site editors #56921

Merged
merged 5 commits into from
Dec 11, 2023
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
94 changes: 0 additions & 94 deletions packages/block-editor/src/components/preview-options/README.md

This file was deleted.

93 changes: 6 additions & 87 deletions packages/block-editor/src/components/preview-options/index.js
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 packages/block-editor/src/components/preview-options/style.scss

This file was deleted.

1 change: 0 additions & 1 deletion packages/block-editor/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@

@import "./components/block-toolbar/style.scss";
@import "./components/inserter/style.scss";
@import "./components/preview-options/style.scss";
@import "./components/spacing-sizes-control/style.scss";

@include wordpress-admin-schemes();
4 changes: 1 addition & 3 deletions packages/e2e-test-utils-playwright/src/editor/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export async function openPreviewPage( this: Editor ): Promise< Page > {
const editorTopBar = this.page.locator(
'role=region[name="Editor top bar"i]'
);
const previewButton = editorTopBar.locator(
'role=button[name="Preview"i]'
);
const previewButton = editorTopBar.locator( 'role=button[name="View"i]' );

await previewButton.click();

Expand Down
8 changes: 4 additions & 4 deletions packages/e2e-test-utils/src/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export async function openPreviewPage( editorPage = page ) {
let openTabs = await browser.pages();
const expectedTabsCount = openTabs.length + 1;
await page.waitForSelector(
'.block-editor-post-preview__button-toggle:not([disabled])'
'.editor-preview-dropdown__toggle:not([disabled])'
);
await editorPage.click( '.block-editor-post-preview__button-toggle' );
await editorPage.click( '.editor-preview-dropdown__toggle' );
await editorPage.waitForSelector(
'.edit-post-header-preview__button-external'
'.editor-preview-dropdown__button-external'
);
await editorPage.click( '.edit-post-header-preview__button-external' );
await editorPage.click( '.editor-preview-dropdown__button-external' );

// Wait for the new tab to open.
while ( openTabs.length < expectedTabsCount ) {
Expand Down
71 changes: 0 additions & 71 deletions packages/edit-post/src/components/device-preview/index.js

This file was deleted.

Loading
Loading