material icon indicating copy to clipboard operation
material copied to clipboard

Breaking SCSS Theme Templates

Open ericrini opened this issue 11 years ago • 25 comments

So I saw this commit in master today.

Commit: 47f0d09e9ebd87891703fa2b7e81355ce3952a86 [47f0d09]
Parents: c62b970536
Author: Andrew <[email protected]>
Date: December 5, 2014 at 5:34:19 PM EST
Commit Date: December 16, 2014 at 12:45:35 PM EST

feat(theming): use $mdThemingProvider

BREAKING CHANGE: Themes are no longer defined by linked CSS files.

Themes are now defined through Javascript only. A 'theme template' is
bundled into angular-material.js, and then Javascript is used to
generate theme css for every theme the user defines.

The `default` theme is still shipped with angular-material.

So FWIW, this is MAJOR bad news for us.

Instead of using your built CSS, we have been @importing and extending your SCSS structure and theme files directly (as one would do with Foundation or Bootstrap or other popular style frameworks) using a SMACSS based style architecture. We even have our own gulp task (a simplified version of your original theme build task) to build out lots of highly customized themes to white label our product.

Now that the theme .SCSS files are a frankenstein of SCSS and a proprietary template language, I'm not sure where to go with it. I guess I was mostly posting to let you guys know this was going to cause a lot of pain in our specific case.

I guess we'll have to figure out how to leave the old theme files intact somehow and manually keep them up to date. :(

ericrini avatar Dec 18 '14 02:12 ericrini

@ericrini what type of modifications are you doing?

ilanbiala avatar Dec 18 '14 03:12 ilanbiala

A lot of it revolves around adding to md-input-group and md-input so things like error states, integration with Angular core validation attribute directives and so forth. We added a select drop down widget in the material design style and a calendar is in progress.

We also have some first class application logic widgets\directives in our site that are D3 visualizations that use the $mdTheming service to extend your theme.

Basically we're trying to avoid independently writhing a theme engine, by extending yours.

ericrini avatar Dec 18 '14 03:12 ericrini

@rschmukler - can you respond with some details here?

ThomasBurleson avatar Dec 18 '14 03:12 ThomasBurleson

@ericrini If you want to add your own styles to theming, you can follow the structure we've defined in the theme files.

Does that work for you? I realize it's hard to do all of this right now because you're stuck inside our project folder. We do want to make this easier, but things have been changing so fast.

ajoslin avatar Dec 18 '14 16:12 ajoslin

@ajoslin I also have a very similar issue with needing to extend the theme - the mentioned set of commits broke the ability to include the raw SCSS into our build chain and get at the goodies upstream via SCSS.

Can you provide some clarification on the move from using CSS & SCSS for theming (both great tools doing just what they are designed for) to attempting an odd Javascript/CSS hybrid?

@ SCSS rules and directives are powerful allies when it comes to structuring an applications CSS.

I understand this is a fast moving project but at the same time does it make sense to use the right tool for the right problem and not try to reinvent the wheel?

tehnorm avatar Dec 18 '14 22:12 tehnorm

@ajoslin "If you want to add your own styles to theming, you can follow the structure we've defined in the theme files."

Well, that's what we were doing basically. We would @import your theme templates, then build on them. Then the template language was changed, such that the templates can no longer be built by the SASS compiler. Since the SASS compiler seemed to be solving problems well, the radical abandonment of SASS for a proprietary template language is surprising.

Maybe you could help us understand the benefits of the current design vs. the old.

ericrini avatar Dec 18 '14 23:12 ericrini

I'd like to extract the stylesheet logic to be able to build it from gulp if you like or from a grunt task or keep the mdThemingProvider... Then everybody could use or not the javascript stylesheet generator...

I just started to work on it #1002...

Sandreu avatar Dec 19 '14 19:12 Sandreu

@tehnorm @ericrini @Sandreu:

Why did we go for javascript-generated CSS instead of straight SASS?

People wanted more flexibility from the theming system. They wanted access to all of the colors in the material design color palette. They wanted to be able to mix different shades of these colors. #537 is one of the many issues.

There was no way for us to do this without making the download time of angular-material absolutely ridiculous, by adding in many thousands of selectors just for theming.

In #537, an idea was brought up: Why not generate the proper CSS classes using javascript, and inject them into the DOM?

We liked this idea because it lets us send only a tiny bit of CSS over-the-wire, and then generate all the classes we want to. It also allows the developer to customize his or her theme to any degree, and still use the same basic pattern in his HTML.

Our approach does definitely deviate from the norm. But the Material Design color palette and the ways it is used are definitely not the norm, either.

I encourage you to come up with a better way using only Sass to allow the developer to follow the spec, but switch between colors as easily as he wants to.

ajoslin avatar Dec 19 '14 20:12 ajoslin

Limit your selection of colors by choosing three color hues from the primary palette and one accent color from the secondary palette. The accent color may or may not need fallback options.

http://www.google.com/design/spec/style/color.html#color-ui-color-application

We also added a warn color.

ajoslin avatar Dec 19 '14 20:12 ajoslin

I totally agree with the new $mdTheming !! I just think its better to extract the generation logic from angular dependency ! ...the idea is to have a standalone generation class/object that will be built with gulp as a constant in angular to use it from the $mdTemingProvider...

That allow to build theme stylesheets outside angular environment ! For example if another project would like to use the angular-material markup with another framework! As angular-bootstrap did with bootstrap stylesheets !!

Take a look on #1002...

Sandreu avatar Dec 19 '14 21:12 Sandreu

Closing this issue for now. Breaking out the theming logic is definitely something that we should look into. That being said, as @ajoslin said, this makes a radical number of themes possible with very little over-the-wire data transfer. It's much more powerful than what we were able to achieve with scss, and it doesn't impose a pre-processor (sass) on developer's build environments to modify themes.

rschmukler avatar Jan 07 '15 18:01 rschmukler

Styling via Javascript is a very novel concept for most front end developers who typically implement designs and palettes rather than designing themselves.

This will be a very large barrier to entry for most front end developers. The proposed build system seems worthwhile.

sime avatar Mar 24 '15 16:03 sime

I can understand the reasons behind that decision, but I got to say, that I think it is a bad one. I often work together with devs and even designers that don't know much about angular and sometimes even JavaScript. It's not good that they have to learn a new system for styling the components when they're used to doing things css-only. This also violates the principle of separation of concerns. Call me old-fashioned, but as a general rule of thumb I believe in 'styling should be done in stylesheets'.

johannesjo avatar Apr 05 '15 19:04 johannesjo

The javascript based system will only benefit a small percentage of projects that require large amounts of colour schemes and palettes, however, majority of projects don't need this and majority of development teams will be negatively affected by this for the following two reasons:

  • As @johannesjo says, you lose the separation of concerns.
  • The SASS build system will cannot be extended to your own custom components

...and probably a few more issues. This is a deal breaker for me

hofnarwillie avatar Jun 24 '15 16:06 hofnarwillie

Why not simply provide a default color set for the main css file and if people want to have different colors they could compile there own by using the sass files instead like with bootstrap-sass and ionics sass files. Shouldn't it be possible to replace all those variables by sass variables? If you really want to have multiple themes for the same website, this could also be handled via a sass loop for example and the theming relevant part of the sass files is not too big so the final css file wouldn't be too much bigger.

johannesjo avatar Jun 24 '15 20:06 johannesjo

For my project this was quite handy, but, is there a way to extend the css stylesheet that gets injected by Angular? I want to add some more classes that the theme shall be applied to... Documentation does not mention this.

AntonKL avatar Jun 24 '15 22:06 AntonKL

@AntonKL currently there isn't support for extending the stylesheets handled by the theming engine. Some day this might be possible.

@hofnarwillie The javascript theming engine does introduce some extra complexity, but it offers the following:

  • We don't dictate your build tool stack. Why should sass be a requirement for using ngMaterial / having themes? Should we also support stylus? What about Less, Rework, CSSNext, etc.? Ultimately we don't want to have any opinion on your build tools, nor be supporting 100 different ways of generating custom CSS.
  • Styles are transmitted exactly once no matter how many themes you have. This means less data over the wire, a big win for the end user that consume your applications. This is especially beneficial for applications with multiple themes

Ultimately, if your application is consistent with material design guidelines there are very few exceptions to the color rules that you configure in your theming config. If they aren't, then writing custom CSS (in your flavor of pre-processing tool of choice) doesn't seem like a huge problem, especially since there are other open-source plugins to help with color-palette related tasks:

rschmukler avatar Jun 25 '15 17:06 rschmukler

So if I want to change SCSS variables or make some sizing/layout tweaks to certain elements, I understand that I'll need to edit the SCSS files and make my own builds. That's fine.

But I want to be able to include Angular Material in a larger git project and do some customizations. I also want to be able to update Angular Material when needed (new releases). So, is the best solution right now to include the project as a git (remote) subtree in our repository? Then I can make the changes I need and create custom builds, commit those changes to our repo, and update the subtree periodically by pulling from the remote. Does that workflow make sense at this point?

breity avatar Jul 15 '15 23:07 breity

@breity Please post this in the Angular Material Forum

ThomasBurleson avatar Jul 15 '15 23:07 ThomasBurleson

@ThomasBurleson Okay, sure. Thanks.

breity avatar Jul 15 '15 23:07 breity