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

@emotion/sheet

v1.2.2

Published

emotion's stylesheet

Downloads

42,979,682

Readme

@emotion/sheet

A StyleSheet for css-in-js libraries

yarn add @emotion/sheet
import { StyleSheet } from '@emotion/sheet'

const sheet = new StyleSheet({ key: '', container: document.head })

sheet.insert('html { color: hotpink; }')

Note: This is not useful for server-side rendering, you should implement SSR seperately

StyleSheet

Options

type Options = {
  nonce?: string
  key: string
  container: Node
  speedy?: boolean
  prepend?: boolean
}

nonce

A nonce that will be set on each style tag that the sheet inserts for Content Security Policies.

container

A DOM Node that the sheet will insert all of it's style tags into, this is useful for inserting styles into iframes.

key

This will be set as the value of the data-emotion attribute on the style tags that get inserted. This is useful to identify different sheets.

speedy

This defines how rules are inserted. If it is true, rules will be inserted with insertRule which is very fast but doesn't allow rules to be edited in DevTools. If it is false, rules will be inserted by appending text nodes to style elements which is much slower than insertRule but allows rules to be edited in DevTools. By default, speedy is enabled in production and disabled in development.

prepend

Deprecated: Please use insertionPoint option instead.

This defines where rules are inserted into the container. By default they are appended but this can be changed by using prepend: true option.

insertionPoint

This defines specific dom node after which the rules are inserted into the container. You can use a meta tag to specify the specific location:

const head = document.querySelector('head')

// <meta name="emotion-insertion-point" content="">
const emotionInsertionPoint = document.createElement('meta')
emotionInsertionPoint.setAttribute('name', 'emotion-insertion-point')
emotionInsertionPoint.setAttribute('content', '')

head.appendChild(emotionInsertionPoint)

// the emotion sheets should be inserted right after the meta tag
const cache = createCache({
  key: 'my-app',
  insertionPoint: emotionInsertionPoint
})

function App() {
  return (
    <CacheProvider value={cache}>
      <Main />
    </CacheProvider>
  )
}

Methods

insert

This method inserts a single rule into the document. It must be a single rule otherwise an error will be thrown in speedy mode which is enabled by default in production.

flush

This method will remove all style tags that were inserted into the document.

hydrate

This method moves given style elements into sheet's container and put them into internal tags collection. It's can be used for SSRed styles.

Example with all options

import { StyleSheet } from '@emotion/sheet'

const container = document.createElement('div')

document.head.appendChild(container)

const sheet = new StyleSheet({
  nonce: 'some-nonce',
  key: 'some-key',
  container
})

sheet.insert('html { color: hotpink; }')

sheet.flush()

Thanks

This StyleSheet is based on glamor's StyleSheet written by Sunil Pai. ❤️