-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Docs about webpack + custom css #802
Comments
It is important to remember that all React is doing is rendering down to HTML. Imagine you had an HTML page with a Semantic-UI Button on it: <html>
<head>
<meta charset="UTF-8">
<title>Semantic UI</title>
</head>
<body>
<button class="ui button">Click Here</button>
</body>
</html> How would you go about adding style to this HTML page? You'd probably add a <html>
<head>
<meta charset="UTF-8">
<title>Semantic UI</title>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.6/semantic.css">
</head>
<body>
<button class="ui button">Click Here</button>
</body>
</html> This is exactly what is happening with React and Semantic-UI-React. When Semantic-UI-React components render, they are rendering normal Semantic-UI HTML. So, you style it just as you would normally style an HTML page with Semantic-UI HTML, using any Semantic-UI stylesheet. if you wanted a custom stylesheet, you should create a Semantic-UI theme and include the final built CSS for that instead. Hope that helps some for now. We get this question a lot and there have been plenty of others who are confused by this, so I'll leave this issue open. I'd like to add at least one minimal working example to the repo and a better explanation of what Semantic-UI-React is and how it fits into the development stack. Thanks for raising this issue. |
Hey, thanks for taking the time to answer! You are absolutely right, this shouldn't be the responsibility of the a package dedicated to react components, I'm just looking for a webpack friendly way to get customized css working, and was curious how you do it! Will check out the core semantic docs, maybe there are some news on the less/css front :) |
@bali182 - I found this blog post super helpful in setting up SemanticUI + webpack with a custom theme: https://www.artembutusov.com/webpack-semantic-ui/ If you're using My particular setup is basically:
If you're using CSS modules, you'll need to explicitly prevent it from running on Most of this is covered in that blog post I referenced. Hope this helps! |
Still running into a lot of issues. Tried following the instructions in the link as well as in the last comment. I think the part I'm having an issue with is:
When you say css modules, do you mean things like less-loader, css-loader, and the like? How do you prevent it from running on all of the files it's importing? |
Way to go without semantic-ui-less: $ npm install semantic-ui --save-dev You can add your theme like shown in this tutorial. http://g14n.info/2016/11/react-semantic-customized/ include "import '../semantic/dist/semantic.min.css';" to index.js to load that customized css. |
From reading your post, please correct me if my understanding is incorrect:
/semantic This basically allows you to build the style sheet which you would you would then import into your project. When you run gulp build-css and build-assets, it will generate /dist/components (styles for each component) You can also move the generate dist to any project you want that support semantic-ui with the customized theme. When you use react semantic ui, all you need to do is include the semantic.min.css in the index.js and it will pick up the changes? Also what is the difference between semantic.min.css and the styles in component/. I looks like semantic.min.css has everything that component/ has. Is there a reason for this? And if my webpack is configure to load both css and less files, then this should be sufficient? What is the purpose of semantic-ui-less? Thanks, |
Ran into a similar issue like this with GXT some years back. The setup script of semantic-ui hangs when i add it with yarn to my electron react (cra) application. I also dont use gulp for my build process, so im not really liking having to break/adjust that. Wouldn't a better way to do this is to create a new project to build your theme in, and roll it up into your own semantic-css-yourtheme npm package that you can include the min css into your parent project? It just seems so wasteful to having to all of the core source code to make the styles work to just adjust the theme. I also don't feel like a project would be modifying the theme much after your make it once. The end result is just adding the theme package to your project and import the min.css. Any specific customization i imagine you could override with inline or supplementary css link after you load the theme css. Also seems like by forking the semantic-css repo you will be ensured to get all of the latest and greatest, and merge according. |
Yes
Also agreed. The issue here is a missing theme customizer. The blocker to that is a willing and able team. I would love nothing more than to get the chance to build this, but I have no time nor funding for it. This is wildly popular enough, that I may put a bounty up for it. I have several ideas for how to do this short term and long term. The theme builder would be superb and would integrate into the doc site for previewing/testing. I would base it on my older work for a Bootstrap theme customizer: You would have high-level controls for setting theme values, they would update the preview live, and you would download the stylesheets. Long term, this would customize a theme JS object for a future CSS-in-JS solution. I will eventually get to this, but I have no idea when. |
@levithomason that's pretty snazzy. I have seen a couple other theme editors like this and love the idea of it. I think i might start working on this, since I could not find anyone else working on this. Ill dive into this more in the next week or two.. I have a good idea on how to integrate this nicely with semantic-ui and have made an editor like this for GWT, ExtJS, and GXT in the past. Accepting donations ;) |
Awesome, I'd love to collaborate. Also, @brianespinosa and I were just talking over in #1009 (comment) about a similar related venture. I'd like to get us all together and get a plan going. This way, we can collect our efforts and hopefully get some community support also. I will try to scaffold the repo tonight or this weekend. Can't wait to hash this out! 🎉 |
I've kickstarted the convo, see here: openmastery/semantic-ui-theme#1 |
okay great. |
I found the I found the blog post mentioned above to be very close to a good solution, but still found it unsatisfactory and a bit cumbersome. It did inspire me so I wrote this: https://gist.github.com/DesignByOnyx/c5d6bc8440479d7213ac157135544954 It allows users to decide where semantic-ui-less assets are stored, and all assets are stored inside a single directory (no other side effects on the project). I've tested this extensively on my current project, but I would love some feedback on how to make it better. |
@rachelslurs It has been a while, I think you might already figured this out:
I actually had this issue when I followed this link provided in #802 (comment)
you have to set "modules" to "false", or just commented it out. Otherwise, it will hash the semantic-ui-less' classname. In case you use https://github.com/bertho-zero/react-redux-universal-hot-example, I forked the repository to implement it with semantic-ui instead of bootstrap. The repo is here: https://github.com/dongcai/react-redux-semantic-ui Hope this helps. |
I never managed to make the original semantic UI work with webpack AND with a custom css theme (there are numerous guides about how you can "force" it to work by either creating the whole semantic structure or loading one of the less or css packages and fiddling with stuff inside
node_modules
, but I was looking for - and still am - a clean solution).What the docs says about CSS is not very helpful currently: http://react.semantic-ui.com/usage#semantic-ui-css-package which translates to either use the default themes or you have to modify stuff inside
node_modules
.I'm curious, are there any plans of a better way of dealing with styling? What is the recommended way currently if someone wants to change a few things preferably using less? Is it possible without putting the whole semantic folder structure inside user code and with this managing a duplicate of the dependency under version control?
The text was updated successfully, but these errors were encountered: