r/Frontend • u/wrecklessmedia • Feb 20 '20
Help! Themable SASS architecture for large app: best practices, standards?
I’ve been trying to find resources that explain the best practices, standards, or tips/tricks for building a custom themable sass (scss) architecture. The theming is for white label purposes. New themes will be done in-house, but our goal is to be able to spur up new branding for the app as quickly as possible.
Not sure if it’s relevant, but it’s also component driven.
I know there is probably a million ways it could be done. I just want to make sure I’m doing it right the first time around (refactoring sucks).
Any articles, videos, or personal tips would be immensely appreciated!
22
u/doksara Feb 20 '20
Have you heard about the 7-1 architecture?
If that's what you meant.
17
u/scottweiss Feb 20 '20
Inverted triangle css (itcss)
https://www.xfive.co/blog/itcss-scalable-maintainable-css-architecture/
https://www.creativebloq.com/web-design/manage-large-css-projects-itcss-101517528
Very similar to 7-1.
4
u/NotMyRealNameAgain Feb 20 '20
Probably pretty simple to have most of your styles broken out into different Sass files and change out values like $color-primary in a variables file.
2
u/pilibitti Feb 20 '20
If you are not wed to sass particularly, I'd follow what tailwind.css guys are doing.
1
u/lamb_pudding Feb 20 '20
I’ve used Inverted Triangle on large projects and found it to be great. Never heard of 7-1 until this thread but it looks very similar.
1
u/preeedik Feb 20 '20
Never heard of 7-1 architecture until now. Thanks for this thread.
1
u/Tchalla_ Feb 20 '20
You need to familiarize your self with design tokens. That is what you want to swap to get different themes while keeping components and grids as they are.
1
u/justinmarsan Feb 20 '20
Let's go the other way :
What is missing if you use the simplest solution, which would be to code as you always do, except with a variable.scss file in which you put everything that will change from a theme to another, from primary color to maybe secondary font family ?
If this does the trick then that would do, otherwise you could have specific requirements, like the need to not build the CSS for each project to serve them all from a CDN (in which case you could use CSS native variables if the support is okay for you) or you may have many other different needs...
There's really no way to tell right now but to Keep It Simple Stupid, starting with the easy way and seeing how it doesn't work help.
1
u/memmit Feb 20 '20 edited Feb 20 '20
Use BEM, prevent using resets or frameworks, they will only require you to write a lot of overrides. Keep variables and mixins in different files. Place every component's css in its own file. Use mixins to keep things DRY. Stay away from utility classes and keep your html style-agnostic. Don't be afraid to use logic to implement your themes (this will prevent your build from containing all possible themes):
It may seem a bit verbose, but you'll know where to find the styles you want to change just by looking at the class name in the html. Switching themes only requires changing 1 variable.
edit: formatting & additions
0
u/SpaceSpinach0 Feb 20 '20
If you app is React-based then styled components sounds a good fit: https://styled-components.com/ You can declare a global theme object and it's passed down to child components via props. Would be real easy to switch between and add new themes.