-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
643 additions
and
48 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
statshouse-ui/src/components2/Plot/PlotView/MarkdownRender.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import ReactMarkdown, { Components } from 'react-markdown'; | ||
import remarkGfm from 'remark-gfm'; | ||
|
||
type IMarkdownRenderer = { | ||
children?: string; | ||
className?: string; | ||
allowedElements?: string[]; | ||
components?: Components; | ||
unwrapDisallowed?: boolean; | ||
}; | ||
|
||
const remarkPlugins = [remarkGfm]; | ||
|
||
const customLinkComponents: Components = { | ||
a: ({ node, ...props }) => ( | ||
<a {...props} target="_blank" rel="noopener noreferrer"> | ||
{props.children} | ||
</a> | ||
), | ||
}; | ||
|
||
const _MarkdownRender = ({ children = '', components, ...props }: IMarkdownRenderer) => ( | ||
<ReactMarkdown remarkPlugins={remarkPlugins} components={{ ...customLinkComponents, ...components }} {...props}> | ||
{children} | ||
</ReactMarkdown> | ||
); | ||
|
||
export const MarkdownRender = React.memo(_MarkdownRender); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
statshouse-ui/src/components2/Plot/PlotView/TooltipMarkdown.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2024 V Kontakte LLC | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
import React from 'react'; | ||
import markdownStyles from '../../style.module.css'; | ||
import { MarkdownRender } from './MarkdownRender'; | ||
import cn from 'classnames'; | ||
|
||
export type ITooltipMarkdownProps = { | ||
description?: string; | ||
}; | ||
|
||
const _TooltipMarkdown = ({ description }: ITooltipMarkdownProps) => ( | ||
<> | ||
<div style={{ maxWidth: '80vw', maxHeight: '80vh' }}> | ||
<MarkdownRender className={cn(markdownStyles.markdownMargin, markdownStyles.markdownSpace)}> | ||
{description} | ||
</MarkdownRender> | ||
</div> | ||
<div className="opacity-0 overflow-hidden h-0" style={{ maxWidth: '80vw', whiteSpace: 'pre' }}> | ||
<MarkdownRender className={markdownStyles.markdownMargin}>{description}</MarkdownRender> | ||
</div> | ||
</> | ||
); | ||
|
||
export const TooltipMarkdown = React.memo(_TooltipMarkdown); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* Copyright 2024 V Kontakte LLC | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
/* referring to tag <p> because <Markdown> returns content inside tag <p> */ | ||
.markdown { | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
margin: 0; | ||
} | ||
|
||
.markdownMargin * { | ||
margin: 0; | ||
} | ||
|
||
.markdownSpace p, | ||
.markdownSpace h1, | ||
.markdownSpace h2, | ||
.markdownSpace h3, | ||
.markdownSpace h4, | ||
.markdownSpace h5, | ||
.markdownSpace h6, | ||
.markdownSpace li { | ||
white-space: break-spaces; | ||
} |