How to use the @emotion/serialize.serializeStyles function in @emotion/serialize

To help you get started, we’ve selected a few @emotion/serialize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github emotion-js / emotion / packages / core / __tests__ / css-cache-hash.js View on Github external
test('does not rehash if value is css call return value', () => {
  const val = css`
    color: hotpink;
  `
  const tree = renderer.create(
    <div>
      <div>
    </div>
  )
  expect(serializeStyles([val])).toBe(val)

  expect(spy.mock.calls[0][1]).toBe(val)
  expect(tree.toJSON()).toMatchSnapshot()
})
</div>
github emotion-js / emotion / packages / core / src / class-names.js View on Github external
let css = (...args: Array) =&gt; {
          if (hasRendered &amp;&amp; process.env.NODE_ENV !== 'production') {
            throw new Error('css can only be used during render')
          }
          let serialized = serializeStyles(args, context.registered)
          if (isBrowser) {
            insertStyles(context, serialized, false)
          } else {
            let res = insertStyles(context, serialized, false)
            if (res !== undefined) {
              rules += res
            }
          }
          if (!isBrowser) {
            serializedHashes += ` ${serialized.name}`
          }
          return `${context.key}-${serialized.name}`
        }
        let cx = (...args: Array) =&gt; {
github egoist / vue-emotion / src / styled.js View on Github external
const mergedProps = {
          ...data.attrs,
          theme: injections.theme,
          ...parent.$evergarden
        }
        const domProps = { value }

        if (data.class) {
          className += getRegisteredStyles(
            cache.registered,
            classInterpolations,
            clsx(data.class)
          )
        }

        const serialized = serializeStyles(
          styles.concat(classInterpolations),
          cache.registered,
          mergedProps
        )

        insertStyles(
          cache,
          serialized,
          typeof finalTag === 'string'
        )

        className += `${cache.key}-${serialized.name}`
        if (targetClassName !== undefined) {
          className += ` ${targetClassName}`
        }
github emotion-js / next / packages / dynamic / src / index.js View on Github external
renderChild = (context: CSSContextType) =&gt; {
    const { css } = this.props
    const serialized = serializeStyles([css])
    const rules = context.stylis(`.css-${serialized.name}`, serialized.styles)
    if (this.sheet === undefined &amp;&amp; isBrowser) {
      this.sheet = new DynamicStyleSheet(StyleSheetOptions)
      this.sheet.inject()
    }
    if (isBrowser) {
      this.sheet.insertRules(rules)
    }

    const child = this.props.render(serialized.cls)
    if (shouldSerializeToReactTree &amp;&amp; rules.length !== 0) {
      return (
github emotion-js / emotion / packages / css / src / index.js View on Github external
function css(...args: Array): SerializedStyles {
  return serializeStyles(args)
}
github evergarden-ui / evergarden / packages / emotion / src / styled.js View on Github external
render(h, { children, data, parent }) {
      const cache = parent.$emotionCache

      const { value, as, ...restAttrs } = data.attrs || {}
      const mergedProps = { ...data.attrs, ...parent.$evergarden }
      const finalTag = as || tag

      const serialized = serializeStyles(
        styles,
        cache.registered,
        mergedProps
      )
      insertStyles(cache, serialized, typeof finalTag === 'string')
      
      const className = `${cache.key}-${serialized.name}`

      return h(
        finalTag,
        {
          ...data,
          class: className,
          attrs: getAttrs ? getAttrs(restAttrs) : restAttrs,
          domProps: {
            ...(value && { value })
github emotion-js / emotion / packages / core / src / global.js View on Github external
warnedAboutCssPropForGlobal = true
  }
  let styles = props.styles

  if (typeof styles === 'function') {
    return (
      
        {theme =&gt; {
          let serialized = serializeStyles([styles(theme)])

          return 
        }}
      
    )
  }
  let serialized = serializeStyles([styles])

  return 
})
github emotion-js / emotion / packages / create-emotion / src / index.js View on Github external
let css = function(...args) {
    let serialized = serializeStyles(
      args,
      cache.registered,
      this !== undefined ? this.mergedProps : undefined
    )
    insertStyles(cache, serialized, false)
    return `${cache.key}-${serialized.name}`
  }
github emotion-js / emotion / packages / core / src / jsx.js View on Github external
let render = (cache, props, theme: null | Object, ref) => {
  let type = props[typePropName]
  let registeredStyles = []

  let className = ''
  if (props.className !== undefined) {
    className = getRegisteredStyles(
      cache.registered,
      registeredStyles,
      props.className
    )
  }
  registeredStyles.push(theme === null ? props.css : props.css(theme))
  const serialized = serializeStyles(cache.registered, registeredStyles)
  const rules = insertStyles(cache, serialized, typeof type === 'string')
  className += `${cache.key}-${serialized.name}`

  const newProps = {}
  for (let key in props) {
    if (
      hasOwnProperty.call(props, key) &&
      key !== 'css' &&
      key !== typePropName
    ) {
      newProps[key] = props[key]
    }
  }
  newProps.ref = ref
  newProps.className = className
github emotion-js / emotion / packages / core / src / global.js View on Github external
{theme =&gt; {
          let serialized = serializeStyles(cache.registered, [styles(theme)])

          return 
        }}

@emotion/serialize

serialization utils for emotion

MIT
Latest version published 2 days ago

Package Health Score

84 / 100
Full package analysis

Similar packages