react-toolbox: Error: composition is only allowed when selector is single :local class name not in ".raised", ".raised" is weird
Followed instructions from
Used “Create react app”
using
- “react-scripts”: “0.9.3”
Added
- “react-toolbox”: “^2.0.0-beta.6”
- “react-toolbox-themr”: “^1.0.2”
Added script
- “toolbox”: “react-toolbox-themr”,
npm run toolbox
confirmed created correctly
Edit App.js
Add ThemeProvider
Run
npm run start
Get Error
Failed to compile.
Error in ./~/react-toolbox/lib/button/theme.css
Module build failed: Error: composition is only allowed when selector is single :local class name not in ".raised", ".raised" is weird
at Array.map (native)
@ ./~/react-toolbox/lib/button/theme.css 4:14-116 13:2-17:4 14:20-122
See full repository that duplicates the problem https://github.com/mulyoved/toolbox-sample
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 11
- Comments: 19
Considering that theres some many people still having issues with this, maybe it would make sense to reopen it? 😃
I know this is an old issue, but I though I’d post my solution here as well.
Using the latest create-react-app and ejecting the app, I had to change my config that loads the css to include the
modules: true
option.Ok I got this to work. All that was necessary was to change my import to be:
The initial error as reported by @mulyoved was caused by importing per the docs:
This imports a bundled module and includes CSS modules that don’t play nice w/ create-react-app. Importing the default export directly from the module file includes the theme but not the CSS modules.
My issue was caused by following the Raw Component import instructions in the README:
https://github.com/react-toolbox/react-toolbox#raw-component
This imports the component minus any theme functionality. I think the docs could be clearer on this so I’ll create another issue.
I’m still having an issue here. With
import { Button } from 'react-toolbox/lib/button';
I just see the ripple affect only on the button.Using
import Button from 'react-toolbox/lib/button/Button';
I see no affect/theme on the button at all.I followed the instructions on setting up postcss/webpack. Any ideas?
Finally I found solution.
In my case webpack was configured to use css-modules only for
src
folder of my app. Since React Toolbox located insidenode_modules
directory, post-css loader was applied to source that doesn’t handled by css-modules. This is common approach because most of npm packages ships with compiled css so there is no reason to apply css-modules for them.So I just added react-toolbox into app styles pipeline and all stuff start working as expected in docs.
Also be noticed that latest css-loader depends on fresh
postcss-modules-scope
release that incompatible with postcss@5 (used by react-toolbox 2 beta). To be sure that your project uses compatible version you have to explicitly installpostcss-modules-scope@1.0.2
This helped me out: https://github.com/react-toolbox/react-toolbox/issues/1054#issuecomment-267741717
@mulyoved remove the brackets, those pull in the named export which doesn’t have theming.
Here’s the relevant source from the component:
You can see how only the default export from the component file has the theme functionality. If you use the {} you end up pulling that named Button export which is just the factory w/ ripple.
Tried all of the above methods. The one @alexlapinski proposed helped me get some of styles and animations, but it still doesn’t load all of them
I can get around the error by importing the raw component.
However the problem I have now is no styles are applied to the button. I have the ThemeProvider configured w/ the generated theme.js from
toolbox
, and it wraps the global App component.Then I have a simple component as a test:
The button renders w/ no styles, but if clicked the ripple effect shows. I’m guessing the
ThemeProvider
isn’t providing the theme.This may need to be another issue, but I’ve followed the same path as @mulyoved