-
Notifications
You must be signed in to change notification settings - Fork 4k
/
index.js
40 lines (36 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* External dependencies
*/
import classnames from 'classnames';
import { compact, uniq } from 'lodash';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import Dashicon from '../dashicon';
export function ExternalLink( { href, children, className, rel = '', ...additionalProps }, ref ) {
rel = uniq( compact( [
...rel.split( ' ' ),
'external',
'noreferrer',
'noopener',
] ) ).join( ' ' );
const classes = classnames( 'components-external-link', className );
return (
<a { ...additionalProps } className={ classes } href={ href } target="_blank" rel={ rel } ref={ ref }> { /* eslint-disable-line react/jsx-no-target-blank */ }
{ children }
<span className="screen-reader-text">
{
/* translators: accessibility text */
__( '(opens in a new tab)' )
}
</span>
<Dashicon icon="external" className="components-external-link__icon" />
</a>
);
}
export default forwardRef( ExternalLink );