|
| 1 | +# Theming components with SCSS |
| 2 | +ng-material comes packaged with the [color palettes in the Material Design spec](https://www.google.com/design/spec/style/color.html#color-color-palette). |
| 3 | +The palettes are in `_palette.scss`. |
| 4 | +Each will be a SCSS map: |
| 5 | +$md-indigo: ( |
| 6 | + 50: #e8eaf6, |
| 7 | + 100: #c5cae9, |
| 8 | + 200: #9fa8da, |
| 9 | + ... |
| 10 | +); |
| 11 | + |
| 12 | +A theme, then, is a _set_ of palettes defined in terms of these (or custom) color palettes: |
| 13 | + |
| 14 | +```scss |
| 15 | +/** A typical theme definition file. */ |
| 16 | + |
| 17 | +$md-is-dark-theme: false; |
| 18 | + |
| 19 | +$md-primary: md-palette($md-indigo, 500, 100, 700, $md-contrast-palettes); |
| 20 | +$md-accent: md-palette($md-red, A200, A100, A400, $md-contrast-palettes); |
| 21 | +$md-warn: md-palette($md-red, 500, 300, 800, $md-contrast-palettes); |
| 22 | +$md-foreground: if($md-is-dark-theme, $md-dark-theme-foreground, $md-light-theme-foreground); |
| 23 | +$md-background: if($md-is-dark-theme, $md-dark-theme-background, $md-light-theme-background); |
| 24 | +``` |
| 25 | + |
| 26 | +The md-palette function creates a theme palette that contains all the colors of the original color |
| 27 | +palette plus contrast colors and semantic shortcuts for the specified hues. |
| 28 | + |
| 29 | + |
| 30 | +Once that is defined, an individual component is styled in terms of the theme palettes: |
| 31 | +my-comp { |
| 32 | + color: md-color($md-foreground, text); |
| 33 | + background-color: md-color($md-background, lighter); // Use one of the configured hue by semantic name. |
| 34 | + &.md-primary { |
| 35 | + color: md-color($md-primary, 300-contrast); |
| 36 | + background-color: md-color($md-primary, 300, 0.7); // Use a specific hue and opacity |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +The md-color function lets the user reference a specific color from the theme palette, |
| 41 | +either by a semantic name (e.g., "primary, lighter"), or directly by numbered hue |
| 42 | +(e.g., "accent, A700"). For each hue, a "-contrast" version is also present in the theme palette. |
| 43 | +The function also allows the user to specify an opacity. |
0 commit comments