mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-05-26 15:16:14 +00:00
Fix opening links in a new tab
This commit is contained in:
23
src/sidepanel/details/linkify-new-tab.tsx
Normal file
23
src/sidepanel/details/linkify-new-tab.tsx
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import Linkify from 'react-linkify';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper component that uses react-linkify to convert any plain text URLs
|
||||||
|
* within its children into clickable links that open in a new tab.
|
||||||
|
*/
|
||||||
|
export function LinkifyNewTab({children}: Props) {
|
||||||
|
return (
|
||||||
|
<Linkify
|
||||||
|
componentDecorator={(decoratedHref: string, decoratedText: string, key: number) => (
|
||||||
|
<a href={decoratedHref} key={key} target="_blank" rel="noopener noreferrer">
|
||||||
|
{decoratedText}
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Linkify>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import Linkify from 'react-linkify';
|
import {LinkifyNewTab} from './linkify-new-tab';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
lines: (React.ReactNode | string)[];
|
lines: (React.ReactNode | string)[];
|
||||||
@@ -9,7 +9,7 @@ export function MultilineText(props: Props) {
|
|||||||
<>
|
<>
|
||||||
{props.lines.map((line, index) => (
|
{props.lines.map((line, index) => (
|
||||||
<div key={index}>
|
<div key={index}>
|
||||||
<Linkify properties={{target: '_blank'}}>{line}</Linkify>
|
<LinkifyNewTab>{line}</LinkifyNewTab>
|
||||||
<br />
|
<br />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import {useIntl} from 'react-intl';
|
import {useIntl} from 'react-intl';
|
||||||
import Linkify from 'react-linkify';
|
|
||||||
import {List} from 'semantic-ui-react';
|
import {List} from 'semantic-ui-react';
|
||||||
import {formatDateOrRange} from '../../util/date_util';
|
import {formatDateOrRange} from '../../util/date_util';
|
||||||
import {Source} from '../../util/gedcom_util';
|
import {Source} from '../../util/gedcom_util';
|
||||||
|
import {LinkifyNewTab} from './linkify-new-tab';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
sources?: Source[];
|
sources?: Source[];
|
||||||
@@ -20,14 +20,14 @@ export function Sources({sources}: Props) {
|
|||||||
<List.Icon verticalAlign="middle" name="circle" size="tiny" />
|
<List.Icon verticalAlign="middle" name="circle" size="tiny" />
|
||||||
<List.Content>
|
<List.Content>
|
||||||
<List.Header>
|
<List.Header>
|
||||||
<Linkify properties={{target: '_blank'}}>
|
<LinkifyNewTab>
|
||||||
{[source.author, source.title, source.publicationInfo]
|
{[source.author, source.title, source.publicationInfo]
|
||||||
.filter((sourceElement) => !!sourceElement)
|
.filter((sourceElement) => !!sourceElement)
|
||||||
.join(', ')}
|
.join(', ')}
|
||||||
</Linkify>
|
</LinkifyNewTab>
|
||||||
</List.Header>
|
</List.Header>
|
||||||
<List.Description>
|
<List.Description>
|
||||||
<Linkify properties={{target: '_blank'}}>{source.page}</Linkify>
|
<LinkifyNewTab>{source.page}</LinkifyNewTab>
|
||||||
{source.date && ` [${formatDateOrRange(source.date, intl)}]`}
|
{source.date && ` [${formatDateOrRange(source.date, intl)}]`}
|
||||||
</List.Description>
|
</List.Description>
|
||||||
</List.Content>
|
</List.Content>
|
||||||
|
|||||||
Reference in New Issue
Block a user