Neutrino Storybook Emotion
STATUS: BROKEN / WIP
Configuration that tries to tie in Neutrino, Storybook, and Emotion while preserving the example files as much as possible.
Note: The <Button>
example from Storybook was used to test integration, and underwent the most change. See Steps to create this repo, below.
Emotion has been configured both to have global and local styles.
Note on esList: Linting was disabled because the out-of-box Storybook example stories did not conform to linting, resulting in build errors. You might want to consider re-enabling the linting in .neutrinorc.js
after clearing out the example files.
Development
Steps to create this repo
- Installed a new NeutrinoJS Project:
yarn create @neutrinojs/project neutrino-storybook-emotion
- Chose
Components
,Jest
,StandardJS rules
- Chose
- Install Storybook:
npx sb init
- Follow instructions on how to install Neutrino preset for Storybook with React
yarn add -D neutrino-preset-storybook-react
- Move
.storybook/main.js
configuration to.neutrinorc.js
, and addrequire(neutrino-preset-storybook-react)
- Run
yarn list --pattern "@storybook/react"
to make sure dependency versions match between current project andneutrino-preset-storybook-react
. Addedresolution
inpackage.json
. (Flushednode_modules
andyarn.lock
just in case.) - Run
yarn add @emotion/react @emotion/styled
as per the Emotion Docs.@emotion/styled
was added for flexibility in Emotion syntax. - Example adaptation focused on
<Button>
- In
src/components/Example
, refer to the Storybook example component<Button>
rather than plain<button>
- Update
<Button>
styling to come through emotion rather than css.- Put part of the style definition in
<Button></Button>
inline - Put the rest of the styling definition in
EmotionGlobal.jsx
. This is so that both Storybook and the app can have access to it. - Added
<EmotionGlobal>
as decorator in.storybook/preview.js
- Put part of the style definition in
- In
- Enable Emotion from within Storybook required doing manuall config (maybe in the future neutrino-preset-emotion will update).
yarn add --dev @emotion/babel-plugin
- Install Prettier according to their docs:
yarn add --dev --exact prettier
Unresolved
- Not sure why .storybook/preview.jsx doesn't compile to JSX. I thought storybook was working.
- do I use .babelrc? or should I be passing in something to the neutrino-storybook middleware?
Currently viewing https://duncanleung.com/emotion-css-prop-jsx-pragma-storybook/
Notes on Dependencies
Node v14
warning @storybook/react > webpack > watchpack > watchpack-chokidar2 > chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
warning @storybook/react > webpack > watchpack > watchpack-chokidar2 > chokidar > fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.