Skip to content

Commit

Permalink
refactor(comp): replace renderMarkDownToolTip with renderMarkDown
Browse files Browse the repository at this point in the history
Signed-off-by: Senthil Athiban <[email protected]>
  • Loading branch information
senthil-athiban committed Aug 12, 2024
1 parent a55d958 commit 8e3c12f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 43 deletions.
56 changes: 15 additions & 41 deletions src/custom/Markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,33 @@ import {
} from './style';
export interface RenderMarkdownProps {
content: string;
isTooltip?: boolean;
}

export const RenderMarkdown: React.FC<RenderMarkdownProps> = ({ content }) => {
export const RenderMarkdown: React.FC<RenderMarkdownProps> = ({ content, isTooltip = false }) => {
return (
<ReactMarkdown
remarkPlugins={[remarkGfm]}
rehypePlugins={[rehypeRaw]}
components={{
p: ({ ...props }) => <StyledMarkdownP>{props.children}</StyledMarkdownP>,
p: ({ ...props }) =>
isTooltip ? (
<StyledMarkdownTooltipP>{props.children}</StyledMarkdownTooltipP>
) : (
<StyledMarkdownP>{props.children}</StyledMarkdownP>
),
a: ({ ...props }) => (
<StyledMarkdown
onClick={(e) => {
e.preventDefault();
window.open(props.href, '_blank');
if (props.href) {
window.open(props.href, '_blank');
}
if (isTooltip) {
e.stopPropagation();
}
}}
href={props.href}
as={isTooltip ? 'a' : undefined}
>
{props.children}
</StyledMarkdown>
Expand All @@ -60,40 +71,3 @@ export const RenderMarkdown: React.FC<RenderMarkdownProps> = ({ content }) => {
</ReactMarkdown>
);
};

export const RenderMarkdownTooltip: React.FC<RenderMarkdownProps> = ({ content }) => {
return (
<ReactMarkdown
remarkPlugins={[remarkGfm]}
components={{
p: ({ ...props }) => <StyledMarkdownTooltipP>{props.children}</StyledMarkdownTooltipP>,
a: ({ ...props }) => (
<StyledMarkdown
onClick={(e) => {
window.open(props.href, '_blank');
e.stopPropagation();
}}
as="a"
>
{props.children}
</StyledMarkdown>
),
h1: ({ ...props }) => <StyledMarkdownH1>{props.children}</StyledMarkdownH1>,
h2: ({ ...props }) => <StyledMarkdownH2>{props.children}</StyledMarkdownH2>,
h3: ({ ...props }) => <StyledMarkdownH3>{props.children}</StyledMarkdownH3>,
h4: ({ ...props }) => <StyledMarkdownH4>{props.children}</StyledMarkdownH4>,
h5: ({ ...props }) => <StyledMarkdownH5>{props.children}</StyledMarkdownH5>,
h6: ({ ...props }) => <StyledMarkdownH6>{props.children}</StyledMarkdownH6>,
blockquote: ({ ...props }) => (
<StyledMarkdownBlockquote>{props.children}</StyledMarkdownBlockquote>
),
ul: ({ ...props }) => <StyledMarkdownUl>{props.children}</StyledMarkdownUl>,
li: ({ ...props }) => <StyledMarkdownLi>{props.children}</StyledMarkdownLi>,
th: ({ ...props }) => <StyledMarkdownTh>{props.children}</StyledMarkdownTh>,
td: ({ ...props }) => <StyledMarkdownTd>{props.children}</StyledMarkdownTd>
}}
>
{content}
</ReactMarkdown>
);
};
4 changes: 2 additions & 2 deletions src/custom/Note/Note.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { styled } from '@mui/material';
import { FC } from 'react';
import { RenderMarkdownTooltip } from '../Markdown';
import { RenderMarkdown } from '../Markdown';

interface AlertProps {
type?: 'success' | 'warning' | 'note';
Expand Down Expand Up @@ -42,7 +42,7 @@ const Note: FC<AlertProps> = ({ type = 'note', title, content }) => {
<NoteWrapper type={type}>
<NoteHeading type={type}>{title}</NoteHeading>
<NoteContent>
<RenderMarkdownTooltip content={content} />
<RenderMarkdown content={content} isTooltip={true} />
</NoteContent>
</NoteWrapper>
);
Expand Down

0 comments on commit 8e3c12f

Please sign in to comment.