From fad53c3a21b601085769ab30bd4d147151d5597b Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Tue, 8 May 2018 18:18:02 +0200 Subject: [PATCH 1/2] First porting of functionalities from 6245 into the Button component. --- components/button/README.md | 16 ++++++-- components/button/index.js | 40 ++++++++++++++++++- components/button/style.scss | 5 ++- .../audio/test/__snapshots__/index.js.snap | 10 +++++ .../test/__snapshots__/index.js.snap | 5 +++ .../embed/test/__snapshots__/index.js.snap | 5 +++ .../gallery/test/__snapshots__/index.js.snap | 5 +++ .../video/test/__snapshots__/index.js.snap | 10 +++++ editor/components/post-excerpt/index.js | 6 +-- 9 files changed, 93 insertions(+), 9 deletions(-) diff --git a/components/button/README.md b/components/button/README.md index 7f78cb981c7dc..346f6cdc70d2b 100644 --- a/components/button/README.md +++ b/components/button/README.md @@ -1,8 +1,18 @@ -This component is used to implement dang sweet buttons. +# Button -#### Props +This component is used to implement buttons and links. +It's also used to implement links that open in a new browser's tab. -The following props are used to control the display of the component. Any additional props will be passed to the rendered `` or `
Upload + + (opens in a new tab) + Upload + + (opens in a new tab) + Embed + + (opens in a new tab) +
diff --git a/core-blocks/gallery/test/__snapshots__/index.js.snap b/core-blocks/gallery/test/__snapshots__/index.js.snap index 28da151354f23..bf9729cb92d76 100644 --- a/core-blocks/gallery/test/__snapshots__/index.js.snap +++ b/core-blocks/gallery/test/__snapshots__/index.js.snap @@ -80,6 +80,11 @@ exports[`core/gallery block edit matches snapshot 1`] = ` /> Upload + + (opens in a new tab) + Use URL + + (opens in a new tab) +
Upload + + (opens in a new tab) + onUpdateExcerpt( value ) } value={ excerpt } /> - +
); } From 2f8b3e2df29d32d8b40cda34770166e777b8bb22 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Wed, 16 May 2018 18:56:57 +0200 Subject: [PATCH 2/2] Use on all linsk with target blank and remove ExternalLink. --- components/button/index.js | 36 ++++++++--------- components/button/style.scss | 9 +++++ components/external-link/index.js | 40 ------------------- components/external-link/style.scss | 8 ---- components/index.js | 1 - .../audio/test/__snapshots__/index.js.snap | 10 ----- core-blocks/categories/edit.js | 11 ++++- .../test/__snapshots__/index.js.snap | 5 --- .../embed/test/__snapshots__/index.js.snap | 5 --- .../gallery/test/__snapshots__/index.js.snap | 5 --- core-blocks/latest-posts/edit.js | 12 +++++- .../video/test/__snapshots__/index.js.snap | 10 ----- editor/components/block-list/style.scss | 5 +++ .../components/post-last-revision/style.scss | 1 + editor/components/post-permalink/index.js | 3 ++ .../components/post-preview-button/index.js | 1 + .../rich-text/format-toolbar/index.js | 6 ++- .../rich-text/format-toolbar/style.scss | 3 +- 18 files changed, 63 insertions(+), 108 deletions(-) delete mode 100644 components/external-link/index.js delete mode 100644 components/external-link/style.scss diff --git a/components/button/index.js b/components/button/index.js index 6726ae129043d..b0c632a6cfec6 100644 --- a/components/button/index.js +++ b/components/button/index.js @@ -2,7 +2,7 @@ * External dependencies */ import classnames from 'classnames'; -import { compact, uniq, includes } from 'lodash'; +import { compact, uniq, includes, omit } from 'lodash'; /** * WordPress dependencies @@ -33,9 +33,22 @@ export function Button( props, ref ) { ...additionalProps } = props; + const tag = href !== undefined && ! disabled ? 'a' : 'button'; + const tagProps = tag === 'a' ? { href, target, rel } : { type: 'button', disabled }; const { icon = true } = additionalProps; const isExternalLink = href && ( target && ! includes( [ '_self', '_parent', '_top' ], target ) ); + const classes = classnames( 'components-button', className, { + button: ( isPrimary || isLarge || isSmall ), + 'button-primary': isPrimary, + 'button-large': isLarge, + 'button-small': isSmall, + 'is-toggled': isToggled, + 'is-busy': isBusy, + 'external-link': isExternalLink, + 'components-icon-button': isExternalLink && icon && ( isPrimary || isLarge || isSmall ), + } ); + const getRel = () => { // Allow to omit the `rel` attribute passing a `null` value. return rel === null ? rel : uniq( compact( [ @@ -51,7 +64,7 @@ export function Button( props, ref ) { '(opens in a new tab)' ) } = additionalProps; - const OpensInNewTabText = ( + const OpensInNewTabScreenReaderText = isExternalLink && ( { // We need a space to separate this from previous text. @@ -60,29 +73,16 @@ export function Button( props, ref ) { ); - const classes = classnames( 'components-button', className, { - button: ( isPrimary || isLarge || isSmall ), - 'button-primary': isPrimary, - 'button-large': isLarge, - 'button-small': isSmall, - 'is-toggled': isToggled, - 'is-busy': isBusy, - 'components-external-link': isExternalLink, - 'components-icon-button': isExternalLink && icon && ( isPrimary || isLarge || isSmall ), - } ); - - const tag = href !== undefined && ! disabled ? 'a' : 'button'; - const tagProps = tag === 'a' ? { href, target, rel } : { type: 'button', disabled }; - const externalIcon = icon && isExternalLink && ; + const ExternalIcon = icon && isExternalLink && ; return createElement( tag, { ...tagProps, - ...additionalProps, + ...omit( additionalProps, [ 'icon', 'opensInNewTabText' ] ), className: classes, autoFocus: focus, rel: isExternalLink && getRel(), ref, - }, ...children, OpensInNewTabText, externalIcon ); + }, children, OpensInNewTabScreenReaderText, ExternalIcon ); } export default forwardRef( Button ); diff --git a/components/button/style.scss b/components/button/style.scss index 09b5567a3d29e..ff13e228fb47d 100644 --- a/components/button/style.scss +++ b/components/button/style.scss @@ -44,6 +44,15 @@ .wp-core-ui.gutenberg-editor-page & { font-size: $default-font-size; } + + &.external-link { + .dashicon { + width: 1.4em; + height: 1.4em; + margin: 0 .2em; + vertical-align: top; + } + } } @keyframes components-button__busy-animation { diff --git a/components/external-link/index.js b/components/external-link/index.js deleted file mode 100644 index 6a484111ff665..0000000000000 --- a/components/external-link/index.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; -import { compact, uniq } from 'lodash'; - -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; - -/** - * Internal dependencies - */ -import Dashicon from '../dashicon'; -import './style.scss'; - -function ExternalLink( { href, children, className, rel = '', ...additionalProps } ) { - rel = uniq( compact( [ - ...rel.split( ' ' ), - 'external', - 'noreferrer', - 'noopener', - ] ) ).join( ' ' ); - const classes = classnames( 'components-external-link', className ); - return ( -
- { children } - - { - /* translators: accessibility text */ - __( '(opens in a new window)' ) - } - - - - ); -} - -export default ExternalLink; diff --git a/components/external-link/style.scss b/components/external-link/style.scss deleted file mode 100644 index b20adc9ccccc9..0000000000000 --- a/components/external-link/style.scss +++ /dev/null @@ -1,8 +0,0 @@ -.components-external-link { - .dashicon { - width: 1.4em; - height: 1.4em; - margin: 0 .2em; - vertical-align: top; - } -} \ No newline at end of file diff --git a/components/index.js b/components/index.js index 3f76939bcfac2..e709cc51b3a05 100644 --- a/components/index.js +++ b/components/index.js @@ -16,7 +16,6 @@ export { default as DropZone } from './drop-zone'; export { default as DropZoneProvider } from './drop-zone/provider'; export { default as Dropdown } from './dropdown'; export { default as DropdownMenu } from './dropdown-menu'; -export { default as ExternalLink } from './external-link'; export { default as FocusableIframe } from './focusable-iframe'; export { default as FontSizePicker } from './font-size-picker'; export { default as FormFileUpload } from './form-file-upload'; diff --git a/core-blocks/audio/test/__snapshots__/index.js.snap b/core-blocks/audio/test/__snapshots__/index.js.snap index a61dc473aa1b0..c40fb0b476a8f 100644 --- a/core-blocks/audio/test/__snapshots__/index.js.snap +++ b/core-blocks/audio/test/__snapshots__/index.js.snap @@ -43,11 +43,6 @@ exports[`core/audio block edit matches snapshot 1`] = ` type="submit" > Use URL - - (opens in a new tab) -
Upload - - (opens in a new tab) - - { this.renderCategoryName( category ) } + { showPostCounts && { ' ' }({ category.count }) diff --git a/core-blocks/cover-image/test/__snapshots__/index.js.snap b/core-blocks/cover-image/test/__snapshots__/index.js.snap index 6fbfc5c4a297e..ee701c6e9620c 100644 --- a/core-blocks/cover-image/test/__snapshots__/index.js.snap +++ b/core-blocks/cover-image/test/__snapshots__/index.js.snap @@ -80,11 +80,6 @@ exports[`core/cover-image block edit matches snapshot 1`] = ` /> Upload - - (opens in a new tab) - Embed - - (opens in a new tab) -
diff --git a/core-blocks/gallery/test/__snapshots__/index.js.snap b/core-blocks/gallery/test/__snapshots__/index.js.snap index bf9729cb92d76..28da151354f23 100644 --- a/core-blocks/gallery/test/__snapshots__/index.js.snap +++ b/core-blocks/gallery/test/__snapshots__/index.js.snap @@ -80,11 +80,6 @@ exports[`core/gallery block edit matches snapshot 1`] = ` /> Upload - - (opens in a new tab) - { inspectorControls } @@ -144,7 +147,14 @@ class LatestPostsEdit extends Component { > { displayPosts.map( ( post, i ) =>
  • - { decodeEntities( post.title.rendered.trim() ) || __( '(Untitled)' ) } + { displayPostDate && post.date_gmt &&