Skip to content

Commit 1d2c577

Browse files
committed
added Link Component Factory
1 parent fa68531 commit 1d2c577

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

packages/ui/src/error-boundary/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ErrorBoundary as SentryErrorBoundary } from "@sentry/react";
22
import { FC, PropsWithChildren } from "react";
33

44
import { Grid } from "../grid";
5-
import { Link } from "../link";
5+
import { Link } from "../link-factory";
66
import { Typography } from "../typography";
77

88
type ErrorBoundaryProps = PropsWithChildren<{
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { FC, HTMLProps } from "react";
2+
import { Link as ReactRouterLink, LinkProps } from "react-router-dom";
3+
4+
export const linkFactory =
5+
(getLanguageCode: () => string, defaultLanguageCode: string): FC<HTMLProps<HTMLAnchorElement>> =>
6+
// eslint-disable-next-line react/display-name
7+
(props) => {
8+
const languageCode = getLanguageCode();
9+
10+
if (props.href && (props.href.startsWith("/") || props.href.startsWith(location.origin))) {
11+
return (
12+
<ReactRouterLink
13+
{...(props as LinkProps)}
14+
to={defaultLanguageCode === languageCode ? props.href : `/${languageCode}${props.href}`}
15+
/>
16+
);
17+
} else {
18+
return <a {...props} />;
19+
}
20+
};
21+
22+
export const Link = linkFactory(() => "en", "en");

packages/ui/src/link/index.tsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)