Skip to content

Commit

Permalink
DOP-4562: new LinkNewTab role (#1307)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs authored Nov 12, 2024
1 parent 2e9ea83 commit 26d2690
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/components/ComponentFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import RoleGUILabel from './Roles/GUILabel';
import RoleHighlight from './Roles/Highlight';
import RoleIcon from './Roles/Icon';
import RoleKbd from './Roles/Kbd';
import RoleLinkNewTab from './Roles/LinkNewTab';
import RoleRed from './Roles/Red';
import RoleGold from './Roles/Gold';
import RoleRequired from './Roles/Required';
Expand Down Expand Up @@ -122,6 +123,7 @@ const roleMap = {
subscript: Subscript,
sup: Superscript,
superscript: Superscript,
'link-new-tab': RoleLinkNewTab,
};

const componentMap = {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const Link = ({
showLinkArrow,
hideExternalIcon: hideExternalIconProp,
showExternalIcon,
openInNewTab,
...other
}) => {
if (!to) to = '';
Expand Down Expand Up @@ -142,7 +143,7 @@ const Link = ({
className={joinClassNames(lgLinkStyling, className)}
href={to}
hideExternalIcon={!showExtIcon}
target={target}
target={openInNewTab ? '_blank' : target}
{...anchorProps}
>
{children}
Expand Down
21 changes: 21 additions & 0 deletions src/components/Roles/LinkNewTab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import PropTypes from 'prop-types';
import ComponentFactory from '../ComponentFactory';
import Link from '../Link';

const LinkNewTab = ({ nodeData: { children, target } }) => (
<Link to={target} openInNewTab={true}>
{children.map((node, i) => (
<ComponentFactory key={i} nodeData={node} />
))}
</Link>
);

LinkNewTab.propTypes = {
nodeData: PropTypes.shape({
children: PropTypes.arrayOf(PropTypes.object).isRequired,
target: PropTypes.string.isRequired,
}).isRequired,
};

export default LinkNewTab;

0 comments on commit 26d2690

Please sign in to comment.