Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 64c1e78

Browse files
authored
fix(gui): external links in documentation (#871)
* fix(gui): external links in documentation * style: apply automatic fixes of linters Co-authored-by: lars-reimann <[email protected]>
1 parent 8a401d4 commit 64c1e78

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

api-editor/gui/src/features/packageData/selectionView/DocumentationText.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Code,
33
Flex,
44
HStack,
5+
Icon,
56
IconButton,
67
Link as ChakraLink,
78
Stack,
@@ -10,7 +11,7 @@ import {
1011
} from '@chakra-ui/react';
1112
import 'katex/dist/katex.min.css';
1213
import React, { ClassAttributes, FunctionComponent, HTMLAttributes, useState } from 'react';
13-
import { FaChevronDown, FaChevronRight } from 'react-icons/fa';
14+
import { FaChevronDown, FaChevronRight, FaExternalLinkAlt } from 'react-icons/fa';
1415
import ReactMarkdown from 'react-markdown';
1516
import {
1617
CodeComponent,
@@ -40,11 +41,20 @@ type ParagraphComponent = FunctionComponent<
4041
type LinkComponent = ComponentType<ComponentPropsWithoutRef<'a'> & ReactMarkdownProps>;
4142

4243
const CustomLink: LinkComponent = function ({ className, children, href }) {
43-
return (
44-
<ChakraLink as={RouterLink} to={href ?? '#'} className={className} textDecoration="underline">
45-
{children}
46-
</ChakraLink>
47-
);
44+
const to = href ?? '#';
45+
if (to.startsWith('http')) {
46+
return (
47+
<ChakraLink href={to} isExternal>
48+
{children} <Icon as={FaExternalLinkAlt} />
49+
</ChakraLink>
50+
);
51+
} else {
52+
return (
53+
<ChakraLink as={RouterLink} to={to} className={className} textDecoration="underline">
54+
{children}
55+
</ChakraLink>
56+
);
57+
}
4858
};
4959

5060
const CustomCode: CodeComponent = function ({ className, children }) {

0 commit comments

Comments
 (0)