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

Theming specific components with React Toolbox #2920

Closed
adrianmcli opened this issue Sep 7, 2017 · 1 comment
Closed

Theming specific components with React Toolbox #2920

adrianmcli opened this issue Sep 7, 2017 · 1 comment

Comments

@adrianmcli
Copy link
Contributor

I found an example repo here that shows how to integrate React Toolbox with a global theme (by way of using react-toolbox-themr.

But unfortunately, it seems that it does not show how I can customize the theme (not style) of a specific component. It also does not seem to be a use-case supported by react-toolbox-themr, or at least I have not found a way to do it.

Lack of CSS Modules

Normally, this is done with CSS Modules, but since the example does not use CSS Modules, I am not sure how I can fulfill the required API.

So, although this works:

import Button from "react-toolbox/lib/button/Button"

const Component = () => <Button></Button>

This does not work:

import Button from "react-toolbox/lib/button/Button"
import btnTheme from "./btnTheme.css"

const Component = () => <Button theme={btnTheme}></Button>

Since we don't have CSS Modules, adding theme={btnTheme} with the import btnTheme from "./btnTheme.css" will Next.JS to not know how to import a CSS file. I should also note that the main README.md cautioned against using the custom Webpack configuration to add loaders (like a CSS loader in this instance), because only the client code gets bundled with Webpack.

Warning: Adding loaders to support new file types (css, less, svg, etc.) is not recommended because only the client code gets bundled via webpack and thus it won't work on the initial server rendering.

Source: https://github.com/zeit/next.js#customizing-webpack-config

What is the best course of action here?

@timneutkens
Copy link
Member

Since we support postcss in styled-jsx now using styled-jsx plugins. You could add postcss-import and <style jsx>{@import 'some-module/file.css'}</style>. Haven't tested it yet. cc @albinekb

@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants