npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nikolovlazar/chakra-ui-prose

v1.2.1

Published

A custom Chakra UI component that adds ready-made styles for rendering remote HTML content.

Downloads

14,221

Readme

Chakra UI Prose

Prose is a Chakra UI component that adds a ready-made typography styles when rendering remote HTML.

Installation

yarn add @nikolovlazar/chakra-ui-prose

# or

npm i @nikolovlazar/chakra-ui-prose

Usage

To use the Prose component in your app, first you need to use the withProse theme extension:

import { withProse } from '@nikolovlazar/chakra-ui-prose';

const theme = extendTheme({}, withProse());

export default theme;

I know you've already did it, but I want to remind you to pass your theme in your ChakraProvider.

Then, to render the remote HTML content, you need to import the Prose component and add a div element with dangerouslySetInnerHTML inside of it:

import { Prose } from '@nikolovlazar/chakra-ui-prose';

const MyPage = (content) => {
  return <Prose dangerouslySetInnerHTML={{ _html: content }} />;
};

export default MyPage;

Content Sanitization

If you're rendering content that's not entered by you, it's a good idea to sanitize the content before rendering it. There are numerous packages for content sanitation, but for this example we'll use the DOMPurify package. First you need to install the package itself:

yarn add dompurify

# or

npm i dompurify

Then, you need to use the sanitize method before rendering your content:

import { Prose } from '@nikolovlazar/chakra-ui-prose';
import DOMPurify from 'dompurify';

const MyPage = (content) => {
  return (
    <Prose
      dangerouslySetInnerHTML={{
        __html: DOMPurify.sanitize(content),
      }}
    />
  );
};

export default MyPage;

This way you'll make sure that the user-submitted content will be safe and you won't be exposed to cross-site scripting (XSS) attacks.

Styling the Prose component

The Prose component receives Chakra UI's BoxProps, which means you can use Style Props like p, mx, maxW etc... to apply styling to the Prose component itself.

Overriding Style

The withProse theme extension has an optional argument that overrides its default style. To change the style of a certain element, supply a component style object in the theme extension, provide the baseStyle property and override the element, like so:

const theme = extendTheme(
  {},
  withProse({
    baseStyle: {
      h2: {
        fontWeight: 'light',
      },
    },
  }),
);

Refer to the default theme when overriding certain elements.

I've also created a CodeSandbox which you can use to try out the Prose component, and override its default style.

Making it official

The Prose package is not part of the official Chakra UI package for a reason. We decided to roll it out as a separate package is to avoid bloating the core library while we figure out how much people actually need it.

If you want this package to be part of the core library, let us know in this discussion thread: https://github.com/chakra-ui/chakra-ui-docs/discussions/469.