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

Add a new page/post button on publish panel #33276

Merged
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
52 changes: 34 additions & 18 deletions packages/editor/src/components/post-publish-panel/postpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PanelBody, Button, TextControl } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { Component, createRef } from '@wordpress/element';
import { withSelect } from '@wordpress/data';
import { safeDecodeURIComponent } from '@wordpress/url';
import { addQueryArgs, safeDecodeURIComponent } from '@wordpress/url';
import { decodeEntities } from '@wordpress/html-entities';
import { useCopyToClipboard } from '@wordpress/compose';
import { store as coreStore } from '@wordpress/core-data';
Expand Down Expand Up @@ -92,8 +92,12 @@ class PostPublishPanelPostpublish extends Component {
const { children, isScheduled, post, postType } = this.props;
const postLabel = get( postType, [ 'labels', 'singular_name' ] );
const viewPostLabel = get( postType, [ 'labels', 'view_item' ] );
const addNewPostLabel = get( postType, [ 'labels', 'add_new_item' ] );
const link =
post.status === 'future' ? getFuturePostUrl( post ) : post.link;
const addLink = addQueryArgs( 'post-new.php', {
post_type: post.type,
} );

const postPublishNonLinkHeader = isScheduled ? (
<>
Expand All @@ -116,28 +120,40 @@ class PostPublishPanelPostpublish extends Component {
<p className="post-publish-panel__postpublish-subheader">
<strong>{ __( 'What’s next?' ) }</strong>
</p>
<TextControl
className="post-publish-panel__postpublish-post-address"
readOnly
label={ sprintf(
/* translators: %s: post type singular name */
__( '%s address' ),
postLabel
) }
value={ safeDecodeURIComponent( link ) }
onFocus={ this.onSelectInput }
/>
<div className="post-publish-panel__postpublish-post-address-container">
<TextControl
className="post-publish-panel__postpublish-post-address"
readOnly
label={ sprintf(
/* translators: %s: post type singular name */
__( '%s address' ),
postLabel
) }
thisissandip marked this conversation as resolved.
Show resolved Hide resolved
value={ safeDecodeURIComponent( link ) }
onFocus={ this.onSelectInput }
/>

<div className="post-publish-panel__postpublish-post-address__copy-button-wrap">
<CopyButton text={ link } onCopy={ this.onCopy }>
{ this.state.showCopyConfirmation
? __( 'Copied!' )
: __( 'Copy' ) }
</CopyButton>
</div>
</div>

<div className="post-publish-panel__postpublish-buttons">
{ ! isScheduled && (
<Button variant="secondary" href={ link }>
<Button variant="primary" href={ link }>
{ viewPostLabel }
</Button>
) }
<CopyButton text={ link } onCopy={ this.onCopy }>
{ this.state.showCopyConfirmation
? __( 'Copied!' )
: __( 'Copy Link' ) }
</CopyButton>
<Button
variant={ isScheduled ? 'primary' : 'secondary' }
href={ addLink }
>
{ addNewPostLabel }
</Button>
</div>
</PanelBody>
{ children }
Expand Down
32 changes: 31 additions & 1 deletion packages/editor/src/components/post-publish-panel/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
height: auto;
justify-content: center;
padding: 3px 10px 4px;
flex: 1;
line-height: 1.6;
text-align: center;
white-space: normal;
Expand All @@ -151,9 +152,19 @@
}
}

.post-publish-panel__postpublish-post-address {
.post-publish-panel__postpublish-post-address-container {
display: flex;
align-items: flex-end;
margin-bottom: $grid-unit-20;

.components-base-control__field {
margin-bottom: 0;
}

.post-publish-panel__postpublish-post-address {
flex: 1;
}

input[readonly] {
padding: 10px;
background: $gray-300;
Expand All @@ -162,6 +173,16 @@
}
}

.post-publish-panel__postpublish-post-address__copy-button-wrap {
flex-shrink: 0;
margin-left: 8px; // margin left for copy button

// match copy button height to the address field height
.components-button {
height: 38px;
}
}

.post-publish-panel__postpublish-header {
font-weight: 500;
}
Expand All @@ -173,3 +194,12 @@
.post-publish-panel__tip {
color: $alert-yellow;
}

@media screen and (max-width: 782px) {
.post-publish-panel__postpublish-post-address__button-wrap {
// match copy button height to the address field height in smaller screens
.components-button {
height: 40px;
}
}
}