@@ -7,11 +7,15 @@ import { css } from '@emotion/css';
7
7
* WordPress dependencies
8
8
*/
9
9
import { __ } from '@wordpress/i18n' ;
10
- import { CheckboxControl , ClipboardButton , ExternalLink , Path , SVG } from '@wordpress/components' ;
10
+ import { CheckboxControl , Button , ExternalLink , TextControl } from '@wordpress/components' ;
11
11
import { Component , createRef , createInterpolateElement } from '@wordpress/element' ;
12
- import { withSelect , withDispatch } from '@wordpress/data' ;
12
+ import { withSelect , withDispatch , useDispatch } from '@wordpress/data' ;
13
13
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' ;
15
19
16
20
const { ajaxurl, DSPublicPostPreviewData } = window ;
17
21
@@ -21,28 +25,31 @@ const pluginPostStatusInfoRow = css`
21
25
` ;
22
26
23
27
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 ;
31
29
width : 100% ;
32
- margin-right : 0.2em ;
33
30
` ;
34
31
35
32
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 ;
39
35
` ;
40
36
41
37
const pluginPostStatusInfoPreviewUrlInputWrapper = css `
38
+ position : relative;
42
39
display : flex;
43
40
justify-content : flex-start;
44
41
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
+ }
46
53
` ;
47
54
48
55
const pluginPostStatusInfoPreviewCheckbox = css `
@@ -51,14 +58,30 @@ const pluginPostStatusInfoPreviewCheckbox = css`
51
58
}
52
59
` ;
53
60
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"
59
82
/>
60
- </ SVG >
61
- ) ;
83
+ ) ;
84
+ }
62
85
63
86
class PreviewToggle extends Component {
64
87
constructor ( props ) {
@@ -67,7 +90,6 @@ class PreviewToggle extends Component {
67
90
this . state = {
68
91
previewEnabled : DSPublicPostPreviewData . previewEnabled ,
69
92
previewUrl : DSPublicPostPreviewData . previewUrl ,
70
- hasCopied : false ,
71
93
} ;
72
94
73
95
this . previewUrlInput = createRef ( ) ;
@@ -141,11 +163,7 @@ class PreviewToggle extends Component {
141
163
}
142
164
143
165
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 ;
149
167
150
168
return (
151
169
< >
@@ -155,34 +173,23 @@ class PreviewToggle extends Component {
155
173
checked = { previewEnabled }
156
174
onChange = { this . onChange }
157
175
className = { pluginPostStatusInfoPreviewCheckbox }
176
+ __nextHasNoMarginBottom
158
177
/>
159
178
{ previewEnabled && (
160
179
< 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
169
182
ref = { this . previewUrlInput }
170
- type = "text"
171
- id = "public-post-preview-url"
172
- className = { pluginPostStatusInfoPreviewUrlInput }
183
+ hideLabelFromVision
184
+ label = { __ ( 'Preview URL' , 'public-post-preview' ) }
173
185
value = { previewUrl }
174
186
readOnly
175
187
onFocus = { this . onPreviewUrlInputFocus }
188
+ className = { pluginPostStatusInfoPreviewUrlInput }
189
+ __next40pxDefaultSize
176
190
/>
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 >
186
193
< p className = { pluginPostStatusInfoPreviewDescription } >
187
194
{ createInterpolateElement (
188
195
__ (
@@ -204,8 +211,8 @@ class PreviewToggle extends Component {
204
211
205
212
export default compose ( [
206
213
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 ) ;
209
216
const postType = getPostType ( getEditedPostAttribute ( 'type' ) ) ;
210
217
211
218
return {
@@ -220,7 +227,7 @@ export default compose( [
220
227
} ) ,
221
228
withDispatch ( ( dispatch ) => {
222
229
return {
223
- createNotice : dispatch ( 'core/notices' ) . createNotice ,
230
+ createNotice : dispatch ( noticesStore ) . createNotice ,
224
231
} ;
225
232
} ) ,
226
233
] ) ( PreviewToggle ) ;
0 commit comments