![]() | Name | Last modified | Size | Description |
---|---|---|---|---|
![]() | Parent Directory | - | ||
![]() | types/ | 2 years ago | - | |
![]() | src/ | 2 years ago | - | |
![]() | dist/ | 2 years ago | - | |
![]() | package.json | 2 years ago | 1.5K | 7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك] |
![]() | README.md | 39 years ago | 2.5K | f12eb36 documentaiton updates [كارل مبارك] |
![]() | LICENSE | 39 years ago | 1.1K | 7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك] |
![]() | CHANGELOG.md | 39 years ago | 7.2K |
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
type Options = {
nonce?: string
key: string
container: HTMLElement
speedy?: boolean
prepend?: boolean
}
A nonce that will be set on each style tag that the sheet inserts for Content Security Policies.
A DOM Node that the sheet will insert all of it's style tags into, this is useful for inserting styles into iframes.
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.
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.
This defines where rules are inserted into the container
. By default they are appended but this can be changed by using prepend: true
option.
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.
This method will remove all style tags that were inserted into the document.
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.
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()
This StyleSheet is based on glamor's StyleSheet written by Sunil Pai. ❤️