babel-preset-css-prop does not work with Storybook
See original GitHub issueemotion
version: 10.0.9react
version: 16.8.3storybook
version 5.0.6
Relevant code:
// babel.config.js
module.exports = {
presets: [
'react-app',
'@emotion/babel-preset-css-prop',
],
plugins: [
'emotion',
],
};
// Button.jsx
import React from 'react';
import { css } from '@emotion/core';
const Button = props => (
<button
css={css`
background-color: blue;
&:hover {
background-color: lightblue;
}
`}
>
{'Hello'}
</button>
);
export default Button;
What you did:
Bootstrap a new Storybook instance:
npx -p @storybook/cli sb init --type react
What happened:
Output is <button css="[object Object]">Hello</button>
Problem description:
The css
prop is not transformed. It does, however, work when using /** @jsx jsx */
pragma.
Per https://storybook.js.org/docs/configurations/custom-babel-config/ Storybook uses the app’s babel config so the note about custom configs should not apply.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:9
Top Results From Across the Web
Can't get emotion's css prop working inside storybook #7540
Describe the bug I can't seem to get emotion's css prop to work inside of Storybook. Seems like emotion is now the dominant...
Read more >Use Emotion CSS Prop in Storybook - Duncan Leung
I was running into an issue where my Storybook webpack.config.js was not correctly parsing and evaluating Emotion styles passed via the css prop...
Read more >emotion/babel-preset-css-prop
A Babel preset to automatically enable Emotion's css prop when using the classic ... is not compatible with @babel/plugin-transform-react-inline-elements .
Read more >@emotion/babel-preset-css-prop examples - CodeSandbox
Learn how to use @emotion/babel-preset-css-prop by viewing and forking example apps that make use of @emotion/babel-preset-css-prop on CodeSandbox.
Read more >Configure Storybook
The main.js configuration file is a preset and, as such, has a powerful interface, ... babelModeV7, Enables the new Babel configuration mode for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Played around a bit with these solutions and realized that Storybook only supports loading
.storybook/.babelrc
and notbabel.config.js
.It only loads from
.storybook
(not root, where most babel configs are located), and only supports.babelrc
.If you drop a
.babelrc
file in.storybook/
then it works.🤦♂️
.storybook/main.js
https://storybook.js.org/docs/react/configure/babel#gatsby-focus-wrapper