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 🙏

© 2025 – Pkg Stats / Ryan Hefner

emotion-mdx

v1.0.0-6

Published

A fine blend of Emotion, theming, MDX, and React components

Readme

emotion-mdx

A fine blend of Emotion, theming, MDX, and React components

WIP/Experimental

npm i emotion-mdx

You'll also need the following:

npm i @emotion/core emotion-theming @mdx-js/mdx@next @mdx-js/react@next

Emotion MDX is a context provider meant to be a complete replacement for both the MDXProvider and ThemeProvider. It creates styled MDX components that have access to the Emotion theme object and can be nested to created contextual styles.

// basic example
import React from 'react'
import { ComponentProvider } from 'emotion-mdx'
import theme from './theme'
import components from './components'
import Hello from './hello.mdx'

export default props =>
  <ComponentProvider
    theme={theme}
    components={components}>
    <Hello />
  </ComponentProvider>

Styles

The theme.styles object adds styles to child MDX elements.

<ComponentProvider
  theme={{
    styles: {
      h1: {
        fontSize: 48,
        color: 'tomato',
      },
    }
  }}
/>

Transforming Styles

A transform function can be provided to transform the style object based on the theme. This can be used with libraries like Styled System to quickly add theme-derived styles.

import React from 'react'
import { ComponentProvider } from 'emotion-mdx'
import css from '@styled-system/css'

export default props =>
  <ComponentProvider
    transform={css}
    theme={{
      colors: {
        primary: 'tomato',
      },
      styles: {
        h1: {
          color: 'primary'
        }
      }
    }}
  />

The transform function should accept styles as an argument and return a function that accepts theme as an argument.

transform(styles)(theme)

Nesting Providers

The ComponentProvider can be nested to make contextual changes to the theme, components, or theme.styles.

Props

  • components (object) React components to render MDX elements
  • theme (object) Emotion theming object
  • theme.styles (object) Nested style objects for each component, with access to the Emotion theme context
  • transform (function) Optional function to transform styles

useComponents

The useComponents hook will return an object of styled components that can be used outside of an MDX document.

import React from 'react'
import { useComponents } from 'emotion-mdx'

export default props => {
  const Styled = useComponents()
  return (
    <>
      <Styled.h1>Hello</Styled.h1>
      <Styled.p>I'm themed</Styled.p>
    </>
  )
}

Styled Components

The Styled component can be imported directly and works similarly to the useComponents hook.

import React from 'react'
import { Styled } from 'emotion-mdx'

export default props =>
  <Styled.div>
    <Styled.h1>Hello</Styled.h1>
  </Styled.div>

Theming

Emotion MDX can be used to create isolated "theme" layout components for MDX documents. These component can encapsulate typography styles that will only apply to MDX elements.

// example MDX theme
import React from 'react'
import { ComponentProvider } from 'emotion-mdx'

const theme = {
  styles: {
    wrapper: {
      fontFamily: 'Roboto, system-ui, sans-serif',
      lineHeight: 1.5,
    },
    h1: {
      fontSize: 48,
      fontWeight: 900,
      lineHeight: 1.25,
    },
    h2: {
      fontSize: 32,
      lineHeight: 1.25,
    }
  }
}

export default props =>
  <ComponentProvider
    {...props}
    theme={theme}
  />
// example mdx file
import Theme from './theme'
export default Theme

# Hello

## We're styled!

MIT License