@@ -3,30 +3,21 @@ import { styled } from 'styled-components';
3
3
import remarkGFM from 'remark-gfm' ;
4
4
import { Button } from '../Button' ;
5
5
import { truncateMarkdown } from '../../helpers/markdown' ;
6
- import { useState } from 'react' ;
6
+ import { FC , useState } from 'react' ;
7
7
8
8
type Props = {
9
9
text : string ;
10
- /**
11
- * By default, all bottom Markdown elements have some margin (e.g. the last
12
- * paragraph). If you set noMargin, this is corrected.
13
- */
14
- noMargin ?: boolean ;
15
10
renderGFM ?: boolean ;
16
11
/**
17
12
* If this is set, and the markdown is more characters than this number, the
18
13
* text will be truncated and a button will be shown
19
14
*/
20
15
maxLength ?: number ;
16
+ className ?: string ;
21
17
} ;
22
18
23
19
/** Renders a markdown value */
24
- function Markdown ( {
25
- text,
26
- noMargin,
27
- renderGFM,
28
- maxLength,
29
- } : Props ) : JSX . Element | null {
20
+ const Markdown : FC < Props > = ( { text, renderGFM, maxLength, className } ) => {
30
21
const [ collapsed , setCollapsed ] = useState ( true ) ;
31
22
32
23
maxLength = maxLength || 5000 ;
@@ -36,7 +27,7 @@ function Markdown({
36
27
}
37
28
38
29
return (
39
- < MarkdownWrapper noMargin = { noMargin } >
30
+ < MarkdownWrapper className = { className } >
40
31
< ReactMarkdown remarkPlugins = { renderGFM ? [ remarkGFM ] : [ ] } >
41
32
{ collapsed ? truncateMarkdown ( text , maxLength ) : text }
42
33
</ ReactMarkdown >
@@ -47,19 +38,14 @@ function Markdown({
47
38
) }
48
39
</ MarkdownWrapper >
49
40
) ;
50
- }
41
+ } ;
51
42
52
43
Markdown . defaultProps = {
53
44
renderGFM : true ,
54
45
} ;
55
46
56
- interface MarkdownWrapperProps {
57
- noMargin ?: boolean ;
58
- }
59
-
60
- const MarkdownWrapper = styled . div < MarkdownWrapperProps > `
47
+ const MarkdownWrapper = styled . div `
61
48
/* Corrects the margin added by <p> and other HTML elements */
62
- margin-bottom: -${ p => ( p . noMargin ? p . theme . margin : 0 ) } rem;
63
49
64
50
width: 100%;
65
51
overflow-x: hidden;
0 commit comments