Skip to content

react-markdown renderer for people who using Chakra-UI's CSSReset component

License

Notifications You must be signed in to change notification settings

eli-s-r/chakra-ui-markdown-renderer

 
 

Repository files navigation

Chakra UI Markdown Renderer

This package is created for people who using Chakra-UI's and react-markdown together.

The Problem

CSSReset component is turning down every default style of elements that provided by browser. HTML elements like h1, h2, h3... aren't get default styles but Markdown need them for rendering purposes. This package is solving the problem by changing renderer defaults with chakra-ui's components.

For example, when you want to render level 2 heading component, it is rendering: <Heading as="h2" size="xl">Your Header Title</Heading>.

Install

Make @chakra-ui/react installation how they tell you on their Getting Started - Chakra UI page.

$ yarn add @chakra-ui/react @emotion/react @emotion/styled framer-motion chakra-ui-markdown-renderer

# or

$ npm i @chakra-ui/react @emotion/react @emotion/styled framer-motion chakra-ui-markdown-renderer

Usage

import ChakraUIRenderer from 'chakra-ui-markdown-renderer';

<ReactMarkdown
  components={ChakraUIRenderer()}
  children={markdown}
  escapeHtml={false}
/>;

Extending Defaults

chakra-ui-markdown-renderer is merging standart theme with your theme by default.

import ChakraUIRenderer from 'chakra-ui-markdown-renderer';

const newTheme = {
  p: props => {
    const { children } = props;
    return <Text mb={2} fontSize={'12px'}>{children}</Text>;
  },
}

<ReactMarkdown
  components={ChakraUIRenderer(newTheme)}
  children={decode(recipeDescription)}
  escapeHtml={false}
/>

About

react-markdown renderer for people who using Chakra-UI's CSSReset component

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 85.1%
  • JavaScript 14.9%