Skip to content

Commit 2844fcc

Browse files
author
Sérgio Gomes
committed
feat(theme): Add !important option to mdl-theme-prop.
Also use the new option for the `mdl-theme--*` classes.
1 parent f1c3db7 commit 2844fcc

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

packages/mdl-theme/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ The correct text colors will automatically be calculated based on the provided t
5151
#### mdl-theme-prop mixin
5252

5353
MDL Theme exports an `mdl-theme-prop` mixin, which can be used to apply a theme color to a property. The mixin takes the
54-
property name as the first parameter, and the desired color as the second one.
54+
property name as the first parameter, and the desired color as the second one. It also has an optional boolean parameter
55+
for whether `!important` should be applied to the value.
5556

5657
For example, if you wanted to set the background of `.foo` to the primary color, and the text color to suit primary text
5758
on top of it:
@@ -258,6 +259,9 @@ Determines whether to use light or dark text on top of a given color.
258259
</span>
259260
```
260261

262+
> Note: These classes use `!important` on the values, since they're user-specified and are applied to ensure that a
263+
particular color gets used.
264+
261265
There are a number of CSS classes available for taking advantage of theming.
262266

263267
#### Theme color classes
@@ -338,15 +342,15 @@ calculate the correct text colors to use, based on the chosen theme colors. Thes
338342

339343
#### Theme colors
340344

341-
| Class | Description |
345+
| Custom property | Description |
342346
| ------------------------ | --------------------------- |
343347
| `--mdl-theme-primary` | The theme primary color. |
344348
| `--mdl-theme-accent` | The theme accent color. |
345349
| `--mdl-theme-background` | The theme background color. |
346350

347351
#### Text on a theme primary color background
348352

349-
| Class | Description |
353+
| Custom property | Description |
350354
| ------------------------------------------ | ---------------------------------------------------------- |
351355
| `--mdl-theme-text-primary-on-primary` | Primary text on top of a theme primary color background. |
352356
| `--mdl-theme-text-secondary-on-primary` | Secondary text on top of a theme primary color background. |
@@ -356,7 +360,7 @@ calculate the correct text colors to use, based on the chosen theme colors. Thes
356360

357361
#### Text on a theme accent color background
358362

359-
| Class | Description |
363+
| Custom property | Description |
360364
| ------------------------------------------ | ---------------------------------------------------------- |
361365
| `--mdl-theme-text-primary-on-accent` | Primary text on top of a theme accent color background. |
362366
| `--mdl-theme-text-secondary-on-accent` | Secondary text on top of a theme accent color background. |
@@ -366,7 +370,7 @@ calculate the correct text colors to use, based on the chosen theme colors. Thes
366370

367371
#### Text on the theme background
368372

369-
| Class | Description |
373+
| Custom property | Description |
370374
| ------------------------------------------ | ---------------------------------------------------------- |
371375
| `--mdl-theme-text-primary-on-background` | Primary text on top of the theme background. |
372376
| `--mdl-theme-text-secondary-on-background` | Secondary text on top of the theme background. |
@@ -376,7 +380,7 @@ calculate the correct text colors to use, based on the chosen theme colors. Thes
376380

377381
#### Text on a light-colored background (useful for custom backgrounds)
378382

379-
| Class | Description |
383+
| Custom property | Description |
380384
| ------------------------------------------ | ---------------------------------------------------------- |
381385
| `--mdl-theme-text-primary-on-light` | Primary text on top of a light-colored background. |
382386
| `--mdl-theme-text-secondary-on-light` | Secondary text on top of a light-colored background. |
@@ -386,7 +390,7 @@ calculate the correct text colors to use, based on the chosen theme colors. Thes
386390

387391
#### Text on a dark-colored background (useful for custom backgrounds)
388392

389-
| Class | Description |
393+
| Custom property | Description |
390394
| ------------------------------------------ | ---------------------------------------------------------- |
391395
| `--mdl-theme-text-primary-on-dark` | Primary text on top of a dark-colored background. |
392396
| `--mdl-theme-text-secondary-on-dark` | Secondary text on top of a dark-colored background. |

packages/mdl-theme/_mixins.scss

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@
2424
* $property is typically color or background-color, but can be any CSS property that accepts color values.
2525
* $style should be one of the map keys in $mdl-theme-property-values (_variables.scss).
2626
*/
27-
@mixin mdl-theme-prop($property, $style) {
27+
@mixin mdl-theme-prop($property, $style, $important: false) {
2828
@if not map-has-key($mdl-theme-property-values, $style) {
2929
@error "Invalid style specified! Choose one of #{map-keys($mdl-theme-property-values)}";
3030
}
3131

32-
#{$property}: map-get($mdl-theme-property-values, $style);
33-
#{$property}: var(--mdl-theme-#{$style}, map-get($mdl-theme-property-values, $style));
32+
@if $important {
33+
#{$property}: map-get($mdl-theme-property-values, $style) !important;
34+
#{$property}: var(--mdl-theme-#{$style}, map-get($mdl-theme-property-values, $style)) !important;
35+
}
36+
37+
@else {
38+
#{$property}: map-get($mdl-theme-property-values, $style);
39+
#{$property}: var(--mdl-theme-#{$style}, map-get($mdl-theme-property-values, $style));
40+
}
3441
}
3542

3643
/**

packages/mdl-theme/mdl-theme.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
@each $style in map-keys($mdl-theme-property-values) {
3131
@if $style != "background" {
3232
.mdl-theme--#{$style} {
33-
@include mdl-theme-prop(color, $style);
33+
@include mdl-theme-prop(color, $style, true);
3434
}
3535
}
3636
}
3737

3838
/* CSS rules for using primary and accent as background colors. */
3939
@each $style in ("primary", "accent") {
4040
.mdl-theme--#{$style}-bg {
41-
@include mdl-theme-prop(background-color, $style);
41+
@include mdl-theme-prop(background-color, $style, true);
4242
}
4343
}

0 commit comments

Comments
 (0)