-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Applying styles to DOM elements that aren't React components? #750
Comments
+1 to this. It is also problematic when using another component that comes with its styling. I wonder, what other CSS setups are folks using with this boilerplate besides the default? |
@oyeanuj I found a workaround, though it's ugly and definitely not a solution. You can import any sass/css files in import '!style!css!sass!components/aComponent/someStyles.scss'; And it will be included as an inline style in EDIT: Another potential workaround is to set css inline dangerously so at least you can subscribe to a "keep styles in components" mentality -- still not a great solution though. |
@FoxxMD try this: .aClass {
:global(.panel-body) {
padding: 15px 0px 0px 0px;
}
} I use regular css and it works |
I had this problem too, with styling for a datetime component, I've used this workaround: :global {
@import "../../theme/react-datetime.scss";
} Is this recommended? |
If we're talking about
Could you explain what problems exactly you have run into? |
In my case I didn't see that occurring. As I said in my OP the element
I feel like this should be the case, but when dealing with packages/components that aren't highly polished being able to style dom elements that don't map 1:1 with a react component is essential functionality, at least for me. Plus I'd prefer being able to apply inline styles without having to be required to attach specific selectors to specific react components -- it's just seems like a very limited method to force users of this boilerplate to use. Am I missing some key functionality here or this really the way it works?
As mentioned above, in order to get inline styles, I had to require my files directly inside import '!style!css!sass!components/aComponent/someStyles.scss';
import '!style!css!react-select/dist/react-select.css'; This works fine for development, but when trying to build production I kept running into the error return /msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase());
^
ReferenceError: window is not defined Finally figured out I needed to use However after that I discovered that, though So I had to end up converting all my scss files to css in order to use them in production. My require('./components/Meta/MetaFilter.css');
require('./containers/App/App.css');
require('../node_modules/react-bootstrap-table/css/react-bootstrap-table.min.css');
require('../node_modules/react-select/dist/react-select.css');
require('../node_modules/ladda/dist/ladda-themeless.min.css');
const client = new ApiClient();
... and loaders: [
{ test: /\.js$/, exclude: /node_modules/, loaders: [strip.loader('debug'), 'babel']},
{ test: /\.css$/, loader: ExtractTextPlugin.extract('style-loader', 'css-loader')},
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.less$/, loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=2&sourceMap!autoprefixer?browsers=last 2 version!less?outputStyle=expanded&sourceMap=true&sourceMapContents=true') },
{ test: /\.scss$/, loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=2&sourceMap!autoprefixer?browsers=last 2 version!sass?outputStyle=expanded&sourceMap=true&sourceMapContents=true') },
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" },
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" },
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" },
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" },
{ test: webpackIsomorphicToolsPlugin.regular_expression('images'), loader: 'url-loader?limit=10240' }
] I really hope that either a) I'm missing something critical pertaining to how requiring scss in react components is supposed to work or b) there is a less convoluted way to go about applying inline styles and requiring third-party css. Sorry for the wall of text! This was what I spent most of my day yesterday trying to figure out... |
I haven't encountered these problems, yet. There are few things I have in mind you could try. Firstly, I think render() {
require('medium-editor/dist/css/medium-editor.css');
require('medium-editor/dist/css/themes/bootstrap.css'); This code is from my |
@Dattaya that did the trick! 👍 I guess this was one of those "down the rabbit hole" problems where it hadn't even occurred to me to try requiring and not assigning to a variable. I also solved the obfuscated selectors problem by removing Thanks for your help! @OkuraSt @oyeanuj You'll find the above advice very useful I hope :) |
@Dattaya Thanks for this 👍 |
I like the idea that I should have
but in practice this isn't helpful when I want to apply styles to DOM elements that aren't react components.
In my scenario I am using
react-bootstrap
and want to style the DOM tag<div class="body-panel">
, but only have access to a<Panel>
react component where the className only applies to the parent DOM element of thebody-panel
div.When I try to do something like this:
No style is applied. How can I make this work? Thanks
The text was updated successfully, but these errors were encountered: