From 9f2e91383d00f8453fc679ef40cfe9d013ec9192 Mon Sep 17 00:00:00 2001 From: deshi Date: Mon, 5 Apr 2021 19:20:02 +0300 Subject: [PATCH] feat(@qiwi/pijma-desktop): add overrides prop --- packages/desktop/src/markdown/Markdown.tsx | 40 ++++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/desktop/src/markdown/Markdown.tsx b/packages/desktop/src/markdown/Markdown.tsx index c0ebcb494..b65d8d415 100644 --- a/packages/desktop/src/markdown/Markdown.tsx +++ b/packages/desktop/src/markdown/Markdown.tsx @@ -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' @@ -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} } const MarkdownBox = styled(Box)({ @@ -127,7 +128,7 @@ const ol: FC = ({size, start, children}) => ( ) -const overrides: {[tag: string]: FC} = { +const defaultOverrides: MarkdownProps['overrides'] = { p, h1, h2, @@ -143,21 +144,24 @@ const overrides: {[tag: string]: FC} = { img, } -export const Markdown: FC = ({size = 'm', children}) => ( - ({ - ...prev, - ...{ - [tag]: { - component: overrides[tag], - props: { - size, +export const Markdown: FC = ({size = 'm', children, overrides = {}}) => { + const allOverrides = {...defaultOverrides, ...overrides} + return ( + ((prev, tag) => ({ + ...prev, + ...{ + [tag]: { + component: allOverrides[tag], + props: { + size, + }, }, }, - }, - }), {}), - }} - /> -) + }), {}), + }} + /> + ) +}