Skip to content

Commit

Permalink
Pass component-button__icon class through to icon, and use it for scs…
Browse files Browse the repository at this point in the history
…s selectors
  • Loading branch information
talldan committed Jul 11, 2018
1 parent 98f0c5d commit e241a6a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
9 changes: 7 additions & 2 deletions components/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ export function Button( props, ref ) {
let tagProps;

if ( href !== undefined && ! disabled ) {
tag = !! isExternalLink ? ExternalLink : 'a';
tagProps = { href, target };
if ( isExternalLink ) {
tag = ExternalLink;
tagProps = { href, target, iconClassName: 'components-button__icon' };
} else {
tag = 'a';
tagProps = { href, target };
}
} else {
tag = 'button';
tagProps = { type: 'button', disabled };
Expand Down
4 changes: 2 additions & 2 deletions components/button/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@
font-size: 11px;
}

.components-external-link__icon {
&__icon {
margin: 2px 0 0 4px;
}

&.is-button .components-external-link__icon {
&.is-button &__icon {
align-self: center;
margin-top: 1px;
}
Expand Down
14 changes: 12 additions & 2 deletions components/external-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@ import { __ } from '@wordpress/i18n';
import Dashicon from '../dashicon';
import './style.scss';

function ExternalLink( { href, children, className, rel = '', ...additionalProps } ) {
function ExternalLink( {
href,
children,
className,
iconClassName,
rel = '',
...additionalProps
} ) {
rel = uniq( compact( [
...rel.split( ' ' ),
'external',
'noreferrer',
'noopener',
] ) ).join( ' ' );

const classes = classnames( 'components-external-link', className );
const iconClasses = classnames( 'components-external-link__icon', iconClassName );

return (
<a { ...additionalProps } className={ classes } href={ href } target="_blank" rel={ rel }>
{ children }
Expand All @@ -32,7 +42,7 @@ function ExternalLink( { href, children, className, rel = '', ...additionalProps
__( '(opens in a new window)' )
}
</span>
<Dashicon className="components-external-link__icon" icon="external" />
<Dashicon className={ iconClasses } icon="external" />
</a>
);
}
Expand Down

0 comments on commit e241a6a

Please sign in to comment.