diff --git a/.changeset/gorgeous-steaks-report.md b/.changeset/gorgeous-steaks-report.md new file mode 100644 index 0000000000..2df79ac6f6 --- /dev/null +++ b/.changeset/gorgeous-steaks-report.md @@ -0,0 +1,6 @@ +--- +'@emotion/cache': minor +'@emotion/sheet': minor +--- + +Accept new `prepend` option to allow for adding style tags at the beginning of the specified DOM container. diff --git a/packages/cache/README.md b/packages/cache/README.md index 0b94e1ffe2..be76d90ecb 100644 --- a/packages/cache/README.md +++ b/packages/cache/README.md @@ -56,3 +56,9 @@ The prefix before class names. It will also be set as the value of the `data-emo `HTMLElement` A DOM node that emotion will insert all of its style tags into. This is useful for inserting styles into iframes. + +### `prepend` + +`boolean` + +A string representing whether to prepend rather than append style tags into the specified container DOM node. diff --git a/packages/cache/src/index.js b/packages/cache/src/index.js index a8caad7a1b..f93998e60b 100644 --- a/packages/cache/src/index.js +++ b/packages/cache/src/index.js @@ -19,7 +19,8 @@ export type Options = { prefix?: PrefixOption, key?: string, container?: HTMLElement, - speedy?: boolean + speedy?: boolean, + prepend?: boolean } let rootServerStylisCache = {} @@ -240,7 +241,8 @@ let createCache = (options?: Options): EmotionCache => { key, container, nonce: options.nonce, - speedy: options.speedy + speedy: options.speedy, + prepend: options.prepend }), nonce: options.nonce, inserted, diff --git a/packages/cache/types/index.d.ts b/packages/cache/types/index.d.ts index a9a9ca8fd5..ef317ac573 100644 --- a/packages/cache/types/index.d.ts +++ b/packages/cache/types/index.d.ts @@ -12,6 +12,7 @@ export interface Options { key?: string container?: HTMLElement speedy?: boolean + prepend?: boolean } export default function createCache(options?: Options): EmotionCache diff --git a/packages/sheet/__tests__/__snapshots__/index.js.snap b/packages/sheet/__tests__/__snapshots__/index.js.snap index 322157e694..0a281a3b4f 100644 --- a/packages/sheet/__tests__/__snapshots__/index.js.snap +++ b/packages/sheet/__tests__/__snapshots__/index.js.snap @@ -1,5 +1,28 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`StyleSheet should accept prepend option 1`] = ` + + + + +