Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add disableLinks props for Markdown #604

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/desktop/src/main/ts/markdown/Markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,33 @@
</BlockContent>
</Block>
```

## Отключение ссылок

```jsx
<Block>
<BlockContent>
<Markdown>{`
####disableLinks = false

Киви кошелек: https://qiwi.com

Игровая витрина: <a href="https://games.qiwi.com">games.qiwi.com</a>
`}</Markdown>
</BlockContent>
</Block>
```

```jsx
<Block>
<BlockContent>
<Markdown disableLinks>{`
####disableLinks = true

Киви кошелек: https://qiwi.com

Игровая витрина: <a href="https://games.qiwi.com">games.qiwi.com</a>
`}</Markdown>
</BlockContent>
</Block>
```
22 changes: 18 additions & 4 deletions packages/desktop/src/main/ts/markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { List } from '../list'
import { Heading, Paragraph, Text } from '../typography'

export interface MarkdownProps {
disableLinks?: boolean
size?: 's' | 'm' | 'l'
children: string
}
Expand Down Expand Up @@ -49,13 +50,20 @@ const img: FC<ImageProps> = ({ src, alt }) => (
img.displayName = 'img'

interface LinkProps extends SizeProps {
disableLinks?: boolean
title?: string
href?: string
}

const a: FC<LinkProps> = ({ title, href, size, children }) => (
<Link title={title} href={href} size={size} children={children} />
)
const a: FC<LinkProps> = ({ disableLinks, title, href, size, children }) => {
if (disableLinks) {
return <Text size={size} children={children} />
}

return (
<Link title={title} href={href} size={size} children={children} />
)
}

a.displayName = 'a'

Expand Down Expand Up @@ -167,10 +175,15 @@ const overrides: { [tag: string]: FC<any> } = {
img,
}

export const Markdown: FC<MarkdownProps> = ({ size = 'm', children }) => (
export const Markdown: FC<MarkdownProps> = ({
size = 'm',
disableLinks = false,
children
}) => (
<MarkdownToJSX
children={children}
options={{
disableAutoLink: disableLinks,
overrides: Object.keys(overrides).reduce(
(prev, tag) => ({
...prev,
Expand All @@ -179,6 +192,7 @@ export const Markdown: FC<MarkdownProps> = ({ size = 'm', children }) => (
component: overrides[tag],
props: {
size,
disableLinks
},
},
},
Expand Down
30 changes: 30 additions & 0 deletions packages/mobile/src/main/ts/markdown/Markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,33 @@
</BlockContent>
</Block>
```

## Отключение ссылок

```jsx
<Block>
<BlockContent>
<Markdown>{`
####disableLinks = false

Киви кошелек: https://qiwi.com

Игровая витрина: <a href="https://games.qiwi.com">games.qiwi.com</a>
`}</Markdown>
</BlockContent>
</Block>
```

```jsx
<Block>
<BlockContent>
<Markdown disableLinks>{`
####disableLinks = true

Киви кошелек: https://qiwi.com

Игровая витрина: <a href="https://games.qiwi.com">games.qiwi.com</a>
`}</Markdown>
</BlockContent>
</Block>
```
22 changes: 18 additions & 4 deletions packages/mobile/src/main/ts/markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { List } from '../list'
import { Heading, Paragraph, Text } from '../typography'

export interface MarkdownProps {
disableLinks?: boolean
size?: 's' | 'm' | 'l'
children: string
}
Expand Down Expand Up @@ -49,13 +50,20 @@ const img: FC<ImageProps> = ({ src, alt }) => (
img.displayName = 'img'

interface LinkProps extends SizeProps {
disableLinks?: boolean
title?: string
href?: string
}

const a: FC<LinkProps> = ({ title, href, size, children }) => (
<Link title={title} href={href} size={size} children={children} />
)
const a: FC<LinkProps> = ({ disableLinks, title, href, size, children }) => {
if (disableLinks) {
return <Text size={size} children={children} />
}

return (
<Link title={title} href={href} size={size} children={children} />
)
}

a.displayName = 'a'

Expand Down Expand Up @@ -158,10 +166,15 @@ const overrides: { [tag: string]: FC<any> } = {
img,
}

export const Markdown: FC<MarkdownProps> = ({ size = 'm', children }) => (
export const Markdown: FC<MarkdownProps> = ({
size = 'm',
disableLinks = false,
children
}) => (
<MarkdownToJSX
children={children}
options={{
disableAutoLink: disableLinks,
overrides: Object.keys(overrides).reduce(
(prev, tag) => ({
...prev,
Expand All @@ -170,6 +183,7 @@ export const Markdown: FC<MarkdownProps> = ({ size = 'm', children }) => (
component: overrides[tag],
props: {
size,
disableLinks
},
},
},
Expand Down
Loading