material icon indicating copy to clipboard operation
material copied to clipboard

colors and hues should be available everywhere.

Open SanderElias opened this issue 11 years ago • 77 comments

I created this sample on plunker to demonstrate a few issues I'm having with forms.

If you look at like 24 of index.html in my sample, you see there is a heading there. This heading is not visible in the page, because I don't know how to set the background color according to the current selected theme/colorpallete. I added an md-hue-1 to the class-list as well as an attribute, but it is not giving the result I need.

This is also mentioned in #537, but I still could not find a solution to it.

SanderElias avatar Jan 23 '15 06:01 SanderElias

I took my solution from #537. and rewrote it a bit so it will work with the new $mdThemingProvider. For anybody that need something similar, have a look at my mdColors module. It's available in this plunker

This will serve my needs for now, but it still feels awkward that I have to go trough those lengths just to be able to get my hands on the selected color palette. I still feel like I somehow miss the obvious!

SanderElias avatar Jan 26 '15 14:01 SanderElias

Sander, I share your feelings, your concerns... and your solution !

Thanks a lot

iRouge avatar Jan 27 '15 16:01 iRouge

@iRouge I began to believe I was to only one ;)

SanderElias avatar Jan 29 '15 13:01 SanderElias

@SanderElias - I think we should include a version of your colors.js and publish a service $mdColors service for easy color lookups. @rschmukler - thoughts ?

ThomasBurleson avatar Feb 17 '15 12:02 ThomasBurleson

@ThomasBurleson I would like that! Should I add support for md-hue-x and so on too?

SanderElias avatar Feb 17 '15 13:02 SanderElias

@SanderElias - let's start with a simple, clean API for the initial work. Can you create the $mdColors service and submit a PR ? Thx is advance.

ThomasBurleson avatar Feb 17 '15 18:02 ThomasBurleson

I believe I have a pretty solution for color lookups: checkout my plunkr: http://plnkr.co/edit/gBDV2ABghTMqqs5YaElB?p=preview

jonnysamps avatar Feb 17 '15 19:02 jonnysamps

@marcysutton I'm preparing an PR, as it looks now, I will be done by the end of the day.

SanderElias avatar Feb 19 '15 10:02 SanderElias

@marcysutton I created a new branch, its in PR #1599. Somehow it would not let me update my other PR

SanderElias avatar Feb 21 '15 08:02 SanderElias

This is awesome! +1

Although, even with this in place, there is still no way to alter the color swatch assignments of a directive and it's generated elements (in the CSS). For instance, the mdToast background is set to {{foreground-1}}. Haven't found a particular way to change that without using a custom template or overridden CSS.

Definitely a step in the right direction to be able to use theme colors anywhere!

mtraynham avatar Mar 08 '15 03:03 mtraynham

@SanderElias finally got to reviewing the PR. I want to move it back a bit as I want to extend the API to make the following possible:

  • ability to lookup a color for a theme. eg. $mdColors.getTheme('default').primary.['hue-1']. This might get moved into $mdColors.getColor('default', 'primary', 'hue-1'). This would return an object with properties expressing the color and the contrast in rgba, {value: 'rgba(...)', contrast: 'rgba(...)'}. Specifically this will help with #2118
  • ability to dynamically generate stylesheets for more than one palette, and follow the .md-THEME_NAME-theme .md-primary-default-fg for selectors. This feels more consistent with how the framework on the whole works, and ideally we would allow for loading multiple themes at the same time. eg. $mdColors.generateColorCssForTheme('myOtherTheme').
  • Consider moving it all into $mdTheming as otherwise the distinction might be confusing / lots of shared logic.
  • Add proper tests for everything mentioned above

I apologize on the massive delay on this. I don't think I will have time to do all of this until after 0.10.0 ships.

rschmukler avatar Apr 01 '15 21:04 rschmukler

@rschmukler. I agree that solving #2118 will make color handling a lot easier. It is the sole reason for the whole copying and parsing that I do in the config function.

If you like, I can switch the whole thing over to keep/utilize rgba color/colorcontrast pairs. Also, the possibility to generate more then 1 palette is something I can create easily. It isn't in because @ThomasBurleson asked me to keep it simple.

I agree that this service should merge with $mdTheming, I kept it separate so I could work on it without messing up existing stuff ;) We can merge it into $mdTheming as soon as we have an complete solution.

SanderElias avatar Apr 02 '15 06:04 SanderElias

@rschmukler Have been thinking about the css. I assume you only want the colors of the active theme generated? (otherwise it might be a lot of css to generate!) To keep the usage simple I would generate the colors like (sass-like nested sample)

md-primary {
   md-color-fg-400: rgba(1,2,3,.8)
   md-color-bg-400: rgba(1,2,3,.8)
   ...
}
md-accent {
   md-color-fg-400: rgba(1,2,3,.8)
   md-color-bg-400: rgba(1,2,3,.8)
   ...
}

that way it's easy to use every available color, and keep the length of the classnames a bit more in control. But I'm open for suggestions.

SanderElias avatar Apr 02 '15 06:04 SanderElias

Keep in mind that multiple themes can be "active" at a time.

gkalpak avatar Apr 02 '15 10:04 gkalpak

@galpak, Are you sure? As far as I see it, the $mdTheming provider can provide just 1 theme. A theme consists out of 4 color palettes (primary,accent,warn and background). It support for loading your own colors into the palettes, and you can even provide your own palettes, ~~but there is only 1 theme active at a time. All this can only be done during config, so there isn't much change that it's changing during runtime. It can be that I missed something, would you then be so kind to point me to it?~~ Nevermind, You are right. there is a possibility to activate multiple themes.

SanderElias avatar Apr 02 '15 11:04 SanderElias

As @gkalpak pointed out, there can be multiple themes active at 1 time. I can add support for this, and generate the needed CSS. However, I would suggest that if you want multiple themes, you kick off generating the css for each extra theme by hand. Each theme will add quite some CSS rules, and changes are, you won't need those for the added themes. So it will be lighter for memory and runtime if we only generate this stuff on request. Awaiting your comments..

SanderElias avatar Apr 02 '15 11:04 SanderElias

@SanderElias agreed that kicking off CSS generation should be done on a per-theme basis. I would even consider making that the case for the default theme since, ideally, $mdColor could also be used to just get colors.

Regarding the SCSS syntax, I'm not sure I follow your example.

Something like:

<p class="md-primary md-color-fg-50">Hello world</p>

The p would presumably be nested in a themable element, or have a theme set on it directly, making the selector as follows:

.md-default-theme .md-primary, .md-primary.md-default-theme {
  .md-color-fg-50 { color: #123456l }
  .md-color-bg-50 { background-color: #123456; }
}

Let me know if this makes sense / is what you were saying. If not, I'm definitely open to discussion... Just going off of what I'd intuit it to be.

rschmukler avatar Apr 02 '15 15:04 rschmukler

@rschmukler I think we are (mostly) on the same page. I think the 'default' theme can do without nesting. That would make more sense to me. Most users will go for 1 default theme, so why add the requirement of a nesting element just to set a default? Same goes for the primary color, that can be implied too. I'll write out a small part of the actual css, to make sure we are talking the same language. (this is what needs to be generated anyway!)

/* default theme is implied*/
/* Primary is implied */
.md-color-fg-100 {color: #574EF5; }
.md-color-bg-100 {background-color: #574EF5; }

.md-warn .md-color-fg-100 ,.md-warn.md-color-fg-100 {color: #FC0366; }
.md-warn .md-color-bg-100 ,.md-warn.md-color-bg-100{background-color: #FC0366; }

/*for secondary themes */
.md-someName-theme .md-color-fg-100 {color: #03FC6B; }
.md-someName-theme .md-color-bg-100 {background-color: #03FC6B; }

.md-someName-theme .md-warn .md-color-fg-100,.md-someName-theme .md-warn.md-color-fg-100  {color: #ff0; }
.md-someName-theme .md-warn .md-color-bg-100,.md-someName-theme .md-warn.md-color-bg-100  {background-color: #ff0; }

In action in this plunk

Is that in line on how you where thinking? It also becomes clear why I don't want to generate the alternate theme's css by default. Those extra style-sheets will add quite some load.

While thinking about this, it seems to make sense to generate the default-primary palette css-rules on init, and the rest on request, or do you think that's confusing?

SanderElias avatar Apr 03 '15 06:04 SanderElias

@SanderElias exactly! Your css look great to me.

Regarding the rules on init, I could argue either way. I think default on init seems fair. We'll just have to document that people will need to explicitly load the non-default themes. Thanks again for all of your contributions!

rschmukler avatar Apr 05 '15 22:04 rschmukler

@rschmukler I think we a re both in a wait state now, is there any progress? I'm waiting to see what happens with #2118, if that clears, I can code this right away. If not, I can solve #2118 with an update of mdColors. But I can't decide what needs to be done there alone!

SanderElias avatar Apr 08 '15 14:04 SanderElias