Skip to content

Commit d52e653

Browse files
committed
feat: 텍스트의 링크를 링크 컴포넌트로 바꿔주는 기능 추가 및 적용
1 parent f8c39f2 commit d52e653

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from "react";
2+
3+
import { LinkHandler } from "./link_handler";
4+
5+
const urlRegex = /(mailto:[\w.-]+@[\w.-]+\.[a-zA-Z]{2,})|(https?:\/\/[^\s]+)/gi;
6+
7+
export const AutoTextLinking: React.FC<{ children: string }> = ({ children }) => {
8+
const convertedChildren = children
9+
.split(urlRegex)
10+
.filter((text) => text !== undefined)
11+
.map((text) => (text.match(urlRegex) ? <LinkHandler href={text} children={text} /> : text));
12+
return <span children={convertedChildren} />;
13+
};

packages/common/src/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AutoTextLinking as AutoTextLinkingComponent } from "./auto_text_linking";
12
import { CenteredPage as CenteredPageComponent } from "./centered_page";
23
import { CommonContextProvider as CommonContextProviderComponent } from "./common_context";
34
import { DndFileInput as DndFileInputComponent } from "./dnd_file_input";
@@ -44,6 +45,7 @@ namespace Components {
4445
export const ErrorFallback = ErrorFallbackComponent;
4546
export const FallbackImage = FallbackImageComponent;
4647
export const LinkHandler = LinkHandlerComponent;
48+
export const AutoTextLinking = AutoTextLinkingComponent;
4749
export const DndFileInput = DndFileInputComponent;
4850
export const Fieldset = FieldsetComponent;
4951

packages/shop/src/components/features/patron_list.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as Common from "@frontend/common";
12
import { CircularProgress, Stack, Typography } from "@mui/material";
23
import { ErrorBoundary, Suspense } from "@suspensive/react";
34
import * as React from "react";
@@ -12,7 +13,9 @@ const InnerPatronList: React.FC<{ year: number }> = ErrorBoundary.with(
1213
return data.map((patron) => (
1314
<Stack key={patron.name} spacing={1} sx={{ my: 2 }}>
1415
<Typography variant="h5" sx={(theme) => ({ fontWeight: 400, color: theme.palette.primary.dark })} children={patron.name} />
15-
<Typography variant="subtitle1" children={patron.contribution_message || "Weave with Python!"} />
16+
<Typography variant="subtitle1" sx={(theme) => ({ a: { color: theme.palette.primary.main }, whiteSpace: "pre-wrap" })}>
17+
<Common.Components.AutoTextLinking children={patron.contribution_message.replace("\\n", "\n") || "Weave with Python!"} />
18+
</Typography>
1619
</Stack>
1720
));
1821
})

0 commit comments

Comments
 (0)