Skip to content

Commit

Permalink
feat(@qiwi/pijma-desktop): add overrides prop
Browse files Browse the repository at this point in the history
  • Loading branch information
deshi committed Apr 5, 2021
1 parent 4f31018 commit 9f2e913
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions packages/desktop/src/markdown/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Children, FC} from 'react'
import MarkdownComponent from 'markdown-to-jsx'
import MarkdownComponent, {MarkdownOptions} from 'markdown-to-jsx'
import {Paragraph, Heading, Text} from '../typography'
import {Link} from '../link'
import {List} from '../list'
Expand All @@ -8,6 +8,7 @@ import {styled, Box, Image} from '@qiwi/pijma-core'
export interface MarkdownProps {
size?: 's' | 'm' | 'l'
children: string
overrides?: {[tag: string]: FC<any>}
}

const MarkdownBox = styled(Box)({
Expand Down Expand Up @@ -127,7 +128,7 @@ const ol: FC<NumericListProps> = ({size, start, children}) => (
</MarkdownBox>
)

const overrides: {[tag: string]: FC<any>} = {
const defaultOverrides: MarkdownProps['overrides'] = {
p,
h1,
h2,
Expand All @@ -143,21 +144,24 @@ const overrides: {[tag: string]: FC<any>} = {
img,
}

export const Markdown: FC<MarkdownProps> = ({size = 'm', children}) => (
<MarkdownComponent
children={children}
options={{
overrides: Object.keys(overrides).reduce((prev, tag) => ({
...prev,
...{
[tag]: {
component: overrides[tag],
props: {
size,
export const Markdown: FC<MarkdownProps> = ({size = 'm', children, overrides = {}}) => {
const allOverrides = {...defaultOverrides, ...overrides}
return (
<MarkdownComponent
children={children}
options={{
overrides: Object.keys(allOverrides).reduce<MarkdownOptions['overrides']>((prev, tag) => ({
...prev,
...{
[tag]: {
component: allOverrides[tag],
props: {
size,
},
},
},
},
}), {}),
}}
/>
)
}), {}),
}}
/>
)
}

0 comments on commit 9f2e913

Please sign in to comment.