-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(text): remove margin from wrapping elements (#293)
- Loading branch information
Showing
1 changed file
with
6 additions
and
16 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,21 +1,11 @@ | ||
import React from 'react'; | ||
import attach from './attach'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import useComponent from './use-component'; | ||
import ReactMarkdown from 'react-markdown'; | ||
|
||
class Text extends React.PureComponent { | ||
render() { | ||
const { text } = this.props; | ||
export default function Text(props) { | ||
const { text } = useComponent(props.component, ['text']); | ||
|
||
// We use component=div to force usage of a div, instead of a p, as properly formatted HTML | ||
// cannot nest tags like h1 under a <p>. | ||
return ( | ||
<Typography component="div"> | ||
<ReactMarkdown source={text} /> | ||
</Typography> | ||
); | ||
} | ||
// As per https://github.com/remarkjs/react-markdown/issues/42, `renderers={{paragraph: 'span'}}` | ||
// substitutes the p tag with a span so that there is no margin | ||
return <ReactMarkdown renderers={{ paragraph: 'span' }} source={text} />; | ||
} | ||
|
||
Text = attach(['text'])(Text); | ||
export default Text; |