Skip to content

Commit

Permalink
Add external preview button in edit-post context
Browse files Browse the repository at this point in the history
  • Loading branch information
vindl committed Apr 15, 2020
1 parent 47c3c22 commit 4921851
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const downArrow = (
</SVG>
);

export default function PreviewOptions( { isSaveable = true } ) {
export default function PreviewOptions( { children, isSaveable = true } ) {
const {
__experimentalSetPreviewDeviceType: setPreviewDeviceType,
} = useDispatch( 'core/block-editor' );
Expand Down Expand Up @@ -76,6 +76,7 @@ export default function PreviewOptions( { isSaveable = true } ) {
{ __( 'Mobile' ) }
</MenuItem>
</MenuGroup>
{ children }
</>
) }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
}

@include break-small() {
.editor-post-preview {
display: none;
}

.block-editor-post-preview__dropdown {
display: flex;
}
Expand Down
28 changes: 24 additions & 4 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { PostSavedState } from '@wordpress/editor';
import { Button, Icon, MenuGroup } from '@wordpress/components';
import { PostSavedState, PostPreviewButton } from '@wordpress/editor';
import { useSelect, useDispatch } from '@wordpress/data';
import { cog } from '@wordpress/icons';
import { cog, external } from '@wordpress/icons';
import { PinnedItems } from '@wordpress/interface';

/**
Expand All @@ -22,6 +22,7 @@ function Header() {
shortcut,
hasActiveMetaboxes,
isEditorSidebarOpened,
isPostSaveable,
isPublishSidebarOpened,
isSaving,
getBlockSelectionStart,
Expand All @@ -40,6 +41,7 @@ function Header() {
isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(),
getBlockSelectionStart: select( 'core/block-editor' )
.getBlockSelectionStart,
isPostSaveable: select( 'core/editor' ).isEditedPostSaveable(),
} ),
[]
);
Expand Down Expand Up @@ -74,7 +76,25 @@ function Header() {
forceIsSaving={ isSaving }
/>
) }
<PreviewOptions />
<PreviewOptions isSaveable={ isPostSaveable }>
<MenuGroup>
<div className="edit-post-header-preview__grouping-external">
<PostPreviewButton
className={
'edit-post-header-preview__button-external'
}
forceIsAutosaveable={ hasActiveMetaboxes }
forcePreviewLink={ isSaving ? null : undefined }
textContent={
<>
<Icon icon={ external } />
{ __( 'Preview in new tab' ) }
</>
}
/>
</div>
</MenuGroup>
</PreviewOptions>
<PostPublishButtonOrToggle
forceIsDirty={ hasActiveMetaboxes }
forceIsSaving={ isSaving }
Expand Down
19 changes: 19 additions & 0 deletions packages/edit-post/src/components/header/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,22 @@
}
}
}

.edit-post-header-preview__grouping-external {
display: flex;
position: relative;
padding-bottom: 0;
}

.edit-post-header-preview__button-external {
padding-left: $grid-unit-10;

margin-right: auto;
width: 100%;
display: flex;
justify-content: flex-start;

svg {
margin-right: $grid-unit-10;
}
}

0 comments on commit 4921851

Please sign in to comment.