Skip to content

Commit

Permalink
Minor improvements for the permalink Copy to clipboard button (#6472)
Browse files Browse the repository at this point in the history
* Permalink copy button minor improvements.

* Reset focus/hover styles, use aria-disabled, and update the label when the permalink is copied.
  • Loading branch information
afercia authored Apr 30, 2018
1 parent eabcb9b commit 414d850
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions components/button/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
opacity: 0.3;
}

&:not( :disabled ) {
&:not( :disabled ):not( [aria-disabled="true"] ) {
cursor: pointer;
}

&:focus {
&:not( :disabled ):not( [aria-disabled="true"] ):focus {
@include button-style__focus-active;
}

Expand Down
6 changes: 3 additions & 3 deletions components/clipboard-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Component } from '@wordpress/element';
/**
* Internal dependencies
*/
import { Button } from '../';
import IconButton from '../icon-button';

class ClipboardButton extends Component {
constructor() {
Expand Down Expand Up @@ -82,9 +82,9 @@ class ClipboardButton extends Component {

return (
<span ref={ this.bindContainer }>
<Button { ...buttonProps } className={ classes }>
<IconButton { ...buttonProps } icon="admin-links" className={ classes }>
{ children }
</Button>
</IconButton>
</span>
);
}
Expand Down
29 changes: 16 additions & 13 deletions editor/components/post-permalink/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { withDispatch, withSelect } from '@wordpress/data';
import { Component, compose } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Dashicon, ClipboardButton, Button, Tooltip } from '@wordpress/components';
import { ClipboardButton, Button } from '@wordpress/components';

/**
* Internal Dependencies
Expand All @@ -21,7 +26,7 @@ class PostPermalink extends Component {
this.onVisibilityChange = this.onVisibilityChange.bind( this );

this.state = {
iconClass: '',
isCopied: false,
isEditingPermalink: false,
};
}
Expand Down Expand Up @@ -52,23 +57,22 @@ class PostPermalink extends Component {

render() {
const { isNew, previewLink, isEditable, samplePermalink, isPublished } = this.props;
const { iconClass, isEditingPermalink } = this.state;
const { isCopied, isEditingPermalink } = this.state;
const ariaLabel = isCopied ? __( 'Permalink copied' ) : __( 'Copy the permalink' );

if ( isNew || ! previewLink ) {
return null;
}

return (
<div className="editor-post-permalink">
<Tooltip text={ __( 'Copy the permalink to your clipboard' ) }>
<ClipboardButton
className="editor-post-permalink__copy"
text={ samplePermalink }
onCopy={ () => this.setState( { iconClass: 'is-copied' } ) }
>
<Dashicon icon="admin-links" className={ iconClass } />
</ClipboardButton>
</Tooltip>
<ClipboardButton
className={ classnames( 'editor-post-permalink__copy', { 'is-copied': isCopied } ) }
text={ samplePermalink }
label={ ariaLabel }
onCopy={ () => this.setState( { isCopied: true } ) }
aria-disabled={ isCopied }
/>

<span className="editor-post-permalink__label">{ __( 'Permalink:' ) }</span>

Expand Down Expand Up @@ -132,4 +136,3 @@ export default compose( [
return { refreshPost };
} ),
] )( PostPermalink );

7 changes: 4 additions & 3 deletions editor/components/post-permalink/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
}

.editor-post-permalink__copy {
margin-top: 4px;
border-radius: 4px;
padding: 6px;
}

.editor-post-permalink__copy .is-copied {
.editor-post-permalink__copy.is-copied {
opacity: 0.3;
}

.editor-post-permalink__label {
margin: 0 10px;
margin: 0 10px 0 5px;
}

.editor-post-permalink__link {
Expand Down

0 comments on commit 414d850

Please sign in to comment.