question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Define stylis plugins through ThemeProvider (or similar)?

See original GitHub issue

Would it be possible to add a way to define stylis plugins through some context API rather than the create-emotion package?

I find the need to use a custom stylis plugin for some accessibility features and I don’t feel confident in asking my users to use a custom Emotion package just for my library needs.

Ideally it would look like this:

import { ConfigProvider } from 'emotion';

<ConfigProvider stylisPlugins={...} prefix="..." key="..." container="..." etc>
  <StyledComponentAffectedByConfigHere />
</ConfigProvider>

would this be something possible?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
srmaguracommented, Jul 25, 2022

You can probably write a custom Stylis plugin for that if there is not one already. Though, likely more trouble than it’s worth.

1reaction
tkh44commented, Jan 7, 2019

It is undocumented at the moment.

import React from 'react'
import { CacheProvider } from '@emotion/core'
import createCache from '@emotion/cache'

const myCache = createCache({
  key: 'my-prefix-key',
  stylisPlugins: [/* Your plugins here */],
  // only prefix the following style properties
  prefix: key => {
    switch (key) {
      case 'appearance':
      case 'user-select':
      case ':placeholder':
        return true
      default:
        return false
    }
  }
})

export default function EmotionProvider(props) {
  return <CacheProvider value={myCache} {...props} />
}

After this wrap your App at whatever level you need (top-level or only a portion)

Here’s the source if you are curious. https://github.com/emotion-js/emotion/blob/ab535a8c7a0dcbbb6af310634eb3cee4bc2f8e2c/packages/cache/src/index.js#L94

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Usage - styled-components
styled-components has full theming support by exporting a <ThemeProvider> wrapper component. ... Define what props.theme will look like. const theme = {.
Read more >
Advanced (LEGACY) - MUI System
Add a ThemeProvider to the top level of your app to pass a theme down the React component tree. Then, you can access...
Read more >
Theming in React with Styled Components | by Ross Bulat
As you may know, styled components utilise template literals as a means of defining styles directly into your component files:
Read more >
How To Use React Styled Components Efficiently - Copycat
What is styled-components? Why styled-components? How to use Styled Components in React; Installation; Syntax. SCSS-like Syntax: Stylis.
Read more >
JSS integration with React
Remember, since React-JSS uses the default preset, // most plugins are available ... Define the component using these styles and pass it the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found