Skip to content

Commit

Permalink
Components: Refactor ExternalLink away from Lodash (#42341)
Browse files Browse the repository at this point in the history
* Components: Refactor ExternalLink away from Lodash

* Add changelog
  • Loading branch information
tyxla authored Jul 12, 2022
1 parent 0f54e49 commit 7d5e47d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- `MenuItem`: Refactor away from `_.isString()` ([#42268](https://github.com/WordPress/gutenberg/pull/42268/)).
- `Shortcut`: Refactor away from `_.isString()` ([#42268](https://github.com/WordPress/gutenberg/pull/42268/)).
- `RangeControl`: Convert to TypeScript ([#40535](https://github.com/WordPress/gutenberg/pull/40535)).
- `ExternalLink`: Refactor away from Lodash ([#42341](https://github.com/WordPress/gutenberg/pull/42341/)).

## 19.14.0 (2022-06-29)

Expand Down
14 changes: 10 additions & 4 deletions packages/components/src/external-link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { compact, uniq } from 'lodash';
import type { ForwardedRef } from 'react';

/**
Expand All @@ -28,9 +27,16 @@ function UnforwardedExternalLink(
ref: ForwardedRef< HTMLAnchorElement >
) {
const { href, children, className, rel = '', ...additionalProps } = props;
const optimizedRel = uniq(
compact( [ ...rel.split( ' ' ), 'external', 'noreferrer', 'noopener' ] )
).join( ' ' );
const optimizedRel = [
...new Set(
[
...rel.split( ' ' ),
'external',
'noreferrer',
'noopener',
].filter( Boolean )
),
].join( ' ' );
const classes = classnames( 'components-external-link', className );
return (
/* eslint-disable react/jsx-no-target-blank */
Expand Down

0 comments on commit 7d5e47d

Please sign in to comment.