|
1 | | -/** Applies a property to an md-button element for each of the supported palettes. */ |
2 | | -@mixin md-button-theme($property, $color: 'default', $opacity: 1) { |
| 1 | +@import '../core/theming/theming'; |
| 2 | + |
| 3 | + |
| 4 | +// Applies a focus style to an md-button element for each of the supported palettes. |
| 5 | +@mixin _md-button-focus-color($theme) { |
| 6 | + $primary: map-get($theme, primary); |
| 7 | + $accent: map-get($theme, accent); |
| 8 | + $warn: map-get($theme, warn); |
| 9 | + |
| 10 | + &.md-primary::after { |
| 11 | + background-color: md-color($primary, 0.12); |
| 12 | + } |
| 13 | + |
| 14 | + &.md-accent::after { |
| 15 | + background-color: md-color($accent, 0.12); |
| 16 | + } |
| 17 | + |
| 18 | + &.md-warn::after { |
| 19 | + background-color: md-color($warn, 0.12); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +// Applies a property to an md-button element for each of the supported palettes. |
| 24 | +@mixin _md-button-theme-color($theme, $property, $color: 'default') { |
| 25 | + $primary: map-get($theme, primary); |
| 26 | + $accent: map-get($theme, accent); |
| 27 | + $warn: map-get($theme, warn); |
| 28 | + $background: map-get($theme, background); |
| 29 | + $foreground: map-get($theme, foreground); |
| 30 | + |
3 | 31 | &.md-primary { |
4 | | - #{$property}: md-color($md-primary, $color, $opacity); |
| 32 | + #{$property}: md-color($primary, $color); |
5 | 33 | } |
6 | 34 | &.md-accent { |
7 | | - #{$property}: md-color($md-accent, $color, $opacity); |
| 35 | + #{$property}: md-color($accent, $color); |
8 | 36 | } |
9 | 37 | &.md-warn { |
10 | | - #{$property}: md-color($md-warn, $color, $opacity); |
| 38 | + #{$property}: md-color($warn, $color); |
11 | 39 | } |
12 | 40 |
|
13 | 41 | &.md-primary, &.md-accent, &.md-warn, &[disabled] { |
14 | 42 | &[disabled] { |
15 | | - $palette: if($property == 'color', $md-foreground, $md-background); |
| 43 | + $palette: if($property == 'color', $foreground, $background); |
16 | 44 | #{$property}: md-color($palette, disabled-button); |
17 | 45 | } |
18 | 46 | } |
19 | 47 | } |
20 | 48 |
|
21 | | -/** Applies a focus style to an md-button element for each of the supported palettes. */ |
22 | | -@mixin md-button-focus { |
23 | | - &::after { |
24 | | - // The button spec calls for focus on raised buttons (and FABs) to be indicated with a |
25 | | - // black, 12% opacity shade over the normal color (for both light and dark themes). |
26 | | - // We do this by placing an :after psuedo-element with the appropriate shade over the button. |
27 | | - position: absolute; |
28 | | - top: 0; |
29 | | - left: 0; |
30 | | - bottom: 0; |
31 | | - right: 0; |
32 | | - content: ''; |
33 | | - background-color: rgba(black, 0.12); |
34 | | - border-radius: inherit; |
35 | | - pointer-events: none; |
| 49 | +@mixin md-button-theme($theme) { |
| 50 | + $primary: map-get($theme, primary); |
| 51 | + $accent: map-get($theme, accent); |
| 52 | + $warn: map-get($theme, warn); |
| 53 | + $background: map-get($theme, background); |
| 54 | + $foreground: map-get($theme, foreground); |
| 55 | + |
| 56 | + [md-button], [md-icon-button], [md-raised-button], [md-fab], [md-mini-fab] { |
| 57 | + &.md-button-focus { |
| 58 | + @include _md-button-focus-color($theme); |
| 59 | + } |
36 | 60 | } |
37 | 61 |
|
38 | | - &.md-primary::after { |
39 | | - background-color: md-color($md-primary, 0.12); |
| 62 | + [md-button], [md-icon-button] { |
| 63 | + @include _md-button-theme-color($theme, 'color'); |
| 64 | + background: transparent; |
| 65 | + |
| 66 | + // Only flat buttons and icon buttons (not raised or fabs) have a hover style. |
| 67 | + // Use the same visual treatment for hover as for focus. |
| 68 | + &:hover { |
| 69 | + @include _md-button-focus-color($theme); |
| 70 | + } |
40 | 71 | } |
41 | 72 |
|
42 | | - &.md-accent::after { |
43 | | - background-color: md-color($md-accent, 0.12); |
| 73 | + [md-raised-button], [md-fab], [md-mini-fab] { |
| 74 | + @include _md-button-theme-color($theme, 'color', default-contrast); |
| 75 | + @include _md-button-theme-color($theme, 'background-color'); |
| 76 | + background-color: md-color($background, background); |
44 | 77 | } |
45 | 78 |
|
46 | | - &.md-warn::after { |
47 | | - background-color: md-color($md-warn, 0.12); |
| 79 | + [md-fab], [md-mini-fab] { |
| 80 | + background-color: md-color($accent); |
| 81 | + color: md-color($accent, default-contrast); |
48 | 82 | } |
49 | 83 | } |
| 84 | + |
| 85 | + |
0 commit comments