Skip to content

Commit 9258a7d

Browse files
committed
Update interface in block editor
1 parent 2ec1559 commit 9258a7d

File tree

5 files changed

+215
-83
lines changed

5 files changed

+215
-83
lines changed

js/dist/gutenberg-integration.asset.php

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/dist/gutenberg-integration.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/src/components/preview-toggle/index.js

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import { css } from '@emotion/css';
77
* WordPress dependencies
88
*/
99
import { __ } from '@wordpress/i18n';
10-
import { CheckboxControl, ClipboardButton, ExternalLink, Path, SVG } from '@wordpress/components';
10+
import { CheckboxControl, Button, ExternalLink, TextControl } from '@wordpress/components';
1111
import { Component, createRef, createInterpolateElement } from '@wordpress/element';
12-
import { withSelect, withDispatch } from '@wordpress/data';
12+
import { withSelect, withDispatch, useDispatch } from '@wordpress/data';
1313
import { PluginPostStatusInfo } from '@wordpress/edit-post';
14-
import { ifCondition, compose } from '@wordpress/compose';
14+
import { ifCondition, compose, useCopyToClipboard } from '@wordpress/compose';
15+
import { store as noticesStore } from '@wordpress/notices';
16+
import { store as editorStore } from '@wordpress/editor';
17+
import { copySmall } from '@wordpress/icons';
18+
import { store as coreStore } from '@wordpress/core-data';
1519

1620
const { ajaxurl, DSPublicPostPreviewData } = window;
1721

@@ -21,28 +25,31 @@ const pluginPostStatusInfoRow = css`
2125
`;
2226

2327
const pluginPostStatusInfoPreviewUrl = css`
24-
flex-direction: column;
25-
align-items: stretch;
26-
margin-top: 10px;
27-
width: 100%;
28-
`;
29-
30-
const pluginPostStatusInfoPreviewUrlInput = css`
28+
margin-top: 8px;
3129
width: 100%;
32-
margin-right: 0.2em;
3330
`;
3431

3532
const pluginPostStatusInfoPreviewDescription = css`
36-
font-style: italic;
37-
color: #666;
38-
margin: 0.2em 0 0 !important;
33+
color: #757575;
34+
margin: 8px 0 0 !important;
3935
`;
4036

4137
const pluginPostStatusInfoPreviewUrlInputWrapper = css`
38+
position: relative;
4239
display: flex;
4340
justify-content: flex-start;
4441
align-items: center;
45-
margin: 0;
42+
43+
.components-base-control {
44+
width: 100%;
45+
}
46+
`;
47+
48+
const pluginPostStatusInfoPreviewUrlInput = css`
49+
.components-text-control__input {
50+
background-color: #fff;
51+
padding-right: 30px !important;
52+
}
4653
`;
4754

4855
const pluginPostStatusInfoPreviewCheckbox = css`
@@ -51,14 +58,30 @@ const pluginPostStatusInfoPreviewCheckbox = css`
5158
}
5259
`;
5360

54-
const ClipboardIcon = (
55-
<SVG width="20" height="20" viewBox="0 0 14 16" xmlns="http://www.w3.org/2000/svg">
56-
<Path
57-
fillRule="evenodd"
58-
d="M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"
61+
const copyButton = css`
62+
position: absolute;
63+
right: 5px;
64+
top; 0;
65+
`;
66+
67+
function CopyButton( { text } ) {
68+
const { createNotice } = useDispatch( noticesStore );
69+
const ref = useCopyToClipboard( text, () => {
70+
createNotice( 'info', __( 'Preview link copied to clipboard.', 'public-post-preview' ), {
71+
isDismissible: true,
72+
type: 'snackbar',
73+
} );
74+
} );
75+
return (
76+
<Button
77+
icon={ copySmall }
78+
ref={ ref }
79+
label={ __( 'Copy the preview URL', 'public-post-preview' ) }
80+
className={ copyButton }
81+
size="small"
5982
/>
60-
</SVG>
61-
);
83+
);
84+
}
6285

6386
class PreviewToggle extends Component {
6487
constructor( props ) {
@@ -67,7 +90,6 @@ class PreviewToggle extends Component {
6790
this.state = {
6891
previewEnabled: DSPublicPostPreviewData.previewEnabled,
6992
previewUrl: DSPublicPostPreviewData.previewUrl,
70-
hasCopied: false,
7193
};
7294

7395
this.previewUrlInput = createRef();
@@ -141,11 +163,7 @@ class PreviewToggle extends Component {
141163
}
142164

143165
render() {
144-
const { previewEnabled, previewUrl, hasCopied } = this.state;
145-
146-
const ariaCopyLabel = hasCopied
147-
? __( 'Preview URL copied', 'public-post-preview' )
148-
: __( 'Copy the preview URL', 'public-post-preview' );
166+
const { previewEnabled, previewUrl } = this.state;
149167

150168
return (
151169
<>
@@ -155,34 +173,23 @@ class PreviewToggle extends Component {
155173
checked={ previewEnabled }
156174
onChange={ this.onChange }
157175
className={ pluginPostStatusInfoPreviewCheckbox }
176+
__nextHasNoMarginBottom
158177
/>
159178
{ previewEnabled && (
160179
<div className={ pluginPostStatusInfoPreviewUrl }>
161-
<p className={ pluginPostStatusInfoPreviewUrlInputWrapper }>
162-
<label
163-
htmlFor="public-post-preview-url"
164-
className="screen-reader-text"
165-
>
166-
{ __( 'Preview URL', 'public-post-preview' ) }
167-
</label>
168-
<input
180+
<div className={ pluginPostStatusInfoPreviewUrlInputWrapper }>
181+
<TextControl
169182
ref={ this.previewUrlInput }
170-
type="text"
171-
id="public-post-preview-url"
172-
className={ pluginPostStatusInfoPreviewUrlInput }
183+
hideLabelFromVision
184+
label={ __( 'Preview URL', 'public-post-preview' ) }
173185
value={ previewUrl }
174186
readOnly
175187
onFocus={ this.onPreviewUrlInputFocus }
188+
className={ pluginPostStatusInfoPreviewUrlInput }
189+
__next40pxDefaultSize
176190
/>
177-
<ClipboardButton
178-
text={ previewUrl }
179-
label={ ariaCopyLabel }
180-
onCopy={ () => this.setState( { hasCopied: true } ) }
181-
onFinishCopy={ () => this.setState( { hasCopied: false } ) }
182-
aria-disabled={ hasCopied }
183-
icon={ ClipboardIcon }
184-
/>
185-
</p>
191+
<CopyButton text={ previewUrl } />
192+
</div>
186193
<p className={ pluginPostStatusInfoPreviewDescription }>
187194
{ createInterpolateElement(
188195
__(
@@ -204,8 +211,8 @@ class PreviewToggle extends Component {
204211

205212
export default compose( [
206213
withSelect( ( select ) => {
207-
const { getPostType } = select( 'core' );
208-
const { getCurrentPostId, getEditedPostAttribute } = select( 'core/editor' );
214+
const { getPostType } = select( coreStore );
215+
const { getCurrentPostId, getEditedPostAttribute } = select( editorStore );
209216
const postType = getPostType( getEditedPostAttribute( 'type' ) );
210217

211218
return {
@@ -220,7 +227,7 @@ export default compose( [
220227
} ),
221228
withDispatch( ( dispatch ) => {
222229
return {
223-
createNotice: dispatch( 'core/notices' ).createNotice,
230+
createNotice: dispatch( noticesStore ).createNotice,
224231
};
225232
} ),
226233
] )( PreviewToggle );

0 commit comments

Comments
 (0)