Material-ui: Equivalent to Blueprint's RunningText

Created on 13 Mar 2019  路  4Comments  路  Source: mui-org/material-ui

A <RunningText> component would apply typography styles to basic html elements in it, so something like this:

<RunningText>
  <h2>Foo</h2>
</RunningText>

Would behave like this:

<Typography variant="h2">Foo</Typography>
  • [x] This is not a v0.x issue.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 馃

Within a <RunningText> all of the styles normally applied by <Typography> would be applied to the corresponding plain html elements.

Current Behavior 馃槸

If you want to render markdown in Material-UI, you have to use something like https://github.com/remarkjs/remark-react and its remarkReactComponents to make transformations like <h2> => <Typography variant="h2">. If you want to render arbitrary rich text from something like ProseMirror, you have to use something like https://github.com/remarkablemark/html-react-parser/ and its replace functionality to do the same. If you want to render rich text from a contenteditable with WYSIWYG, you're out of luck because there's no way to use <Typography> in the editing control of things like ProseMirror.

Examples 馃寛

Blueprint.js is React component library unrelated to Material Design. It has a feature like this, documented here as "RUNNING_TEXT": https://blueprintjs.com/docs/#core/components/html

Context 馃敠

I listed some specific use cases in Current Behavior, but basically any situation where you want to render basic document content that might be dynamically generated and where using lots of <Typography> elements would be difficult.

Benchmark

Typography enhancement waiting for 馃憤

Most helpful comment

A similar concept component for benchmark: https://elastic.github.io/eui/#/display/text.

All 4 comments

@nmain We don't have such a component. For the markdown problem. You have two options:

  1. markdown-to-jsx: You specify to a parser the React component to use for each type of element. You have a demo here:
    https://github.com/mui-org/material-ui/blob/2f6a982aa74ffa46680798089ad20ed67ed0c5ae/docs/src/pages/getting-started/page-layout-examples/blog/Markdown.js#L1-L35.
    This demo uses that strategy.
  2. markdown-to-html: You use a traditional html generator, then style the output. You have a demo here:
    https://github.com/mui-org/material-ui/blob/2f6a982aa74ffa46680798089ad20ed67ed0c5ae/docs/src/modules/components/MarkdownElement.js#L1-L309
    The documentation uses this strategy.

n掳1 has the advantage of being fully idiomatic with React. The drawback is that it's slower than n掳2.

So what I'm proposing is a component that implements style rules similar to line 105 here: https://github.com/mui-org/material-ui/blob/2f6a982aa74ffa46680798089ad20ed67ed0c5ae/docs/src/modules/components/MarkdownElement.js#L105-277 be added to Material-UI

A similar concept component for benchmark: https://elastic.github.io/eui/#/display/text.

I'm also looking for something like this.
Bulma's content an another similar thing.

Is there any reason not to just copy MarkdownElement pretty much as-is and rename it to RunningText?
I guess remove the renderedMarkdown prop, and it might be nice to have add a prop that works like the reverse of variantMapping to map semantic elements to variants.

Would you accept a PR for something like this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FranBran picture FranBran  路  3Comments

ericraffin picture ericraffin  路  3Comments

anthony-dandrea picture anthony-dandrea  路  3Comments

rbozan picture rbozan  路  3Comments

chris-hinds picture chris-hinds  路  3Comments