Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emotion not compatible with styled.box #286

Open
ivanbanov opened this issue Jun 28, 2021 · 1 comment
Open

Emotion not compatible with styled.box #286

ivanbanov opened this issue Jun 28, 2021 · 1 comment
Labels

Comments

@ivanbanov
Copy link
Contributor

ivanbanov commented Jun 28, 2021

I will just cross-post it here to set it as a known-issue.

To properly use Emotion11 with xstyled we have to use importMap and create a canonical reference to notify emotion that some internals are being re-exported. Something like this

//babel.config.js
module.exports = () => ({
  plugins: [
    [
      '@emotion/babel-plugin',
      {
        importMap: {
          '@xstyled/emotion': {
            default: {
              canonicalImport: ['@emotion/styled', 'default'],
              styledBaseImport: ['@xstyled/emotion', 'default'],
            },
          },
        },
      },
    ],
  ],
})

In xstyled it is not only re-exporting but also adding some new functionalities such as styled.box, the problem is that Emotion does not move the extras ahead, it only sticks to what the original Emotion instance would be able to do. I opened an issue in the emotions repo with an example of this problem.

emotion-js/emotion#2412

@ivanbanov
Copy link
Contributor Author

As a workaround for that Im now using the following

import styled, { x } from '@xstyled/emotion'

const MyComponent = styled(x.div)({
  color: 'red',
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants