source: trip-planner-front/node_modules/@angular/material/button/_button-theme.scss@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 6.5 KB
Line 
1@use 'sass:map';
2@use 'sass:meta';
3@use '../core/theming/theming';
4@use '../core/style/private';
5@use '../core/typography/typography';
6@use '../core/typography/typography-utils';
7
8$_ripple-opacity: 0.1;
9
10// Applies a focus style to an mat-button element for each of the supported palettes.
11@mixin _focus-overlay-color($config-or-theme) {
12 $config: theming.get-color-config($config-or-theme);
13 $primary: map.get($config, primary);
14 $accent: map.get($config, accent);
15 $warn: map.get($config, warn);
16
17 &.mat-primary .mat-button-focus-overlay {
18 background-color: theming.get-color-from-palette($primary);
19 }
20
21 &.mat-accent .mat-button-focus-overlay {
22 background-color: theming.get-color-from-palette($accent);
23 }
24
25 &.mat-warn .mat-button-focus-overlay {
26 background-color: theming.get-color-from-palette($warn);
27 }
28
29 &.mat-button-disabled .mat-button-focus-overlay {
30 background-color: transparent;
31 }
32}
33
34// Applies the background color for a ripple. If the value provided is not a Sass color,
35// we assume that we've been given a CSS variable. Since we can't perform alpha-blending
36// on a CSS variable, we instead add the opacity directly to the ripple element.
37@mixin _ripple-background($palette, $hue, $opacity) {
38 $background-color: theming.get-color-from-palette($palette, $hue, $opacity);
39 background-color: $background-color;
40 @if (meta.type-of($background-color) != color) {
41 opacity: $opacity;
42 }
43}
44
45@mixin _ripple-color($theme, $hue, $opacity: $_ripple-opacity) {
46 $primary: map.get($theme, primary);
47 $accent: map.get($theme, accent);
48 $warn: map.get($theme, warn);
49
50 &.mat-primary .mat-ripple-element {
51 @include _ripple-background($primary, $hue, $opacity);
52 }
53
54 &.mat-accent .mat-ripple-element {
55 @include _ripple-background($accent, $hue, $opacity);
56 }
57
58 &.mat-warn .mat-ripple-element {
59 @include _ripple-background($warn, $hue, $opacity);
60 }
61}
62
63// Applies a property to an mat-button element for each of the supported palettes.
64@mixin _theme-property($theme, $property, $hue) {
65 $primary: map.get($theme, primary);
66 $accent: map.get($theme, accent);
67 $warn: map.get($theme, warn);
68 $background: map.get($theme, background);
69 $foreground: map.get($theme, foreground);
70
71 &.mat-primary {
72 #{$property}: theming.get-color-from-palette($primary, $hue);
73 }
74 &.mat-accent {
75 #{$property}: theming.get-color-from-palette($accent, $hue);
76 }
77 &.mat-warn {
78 #{$property}: theming.get-color-from-palette($warn, $hue);
79 }
80
81 &.mat-primary, &.mat-accent, &.mat-warn, &.mat-button-disabled {
82 &.mat-button-disabled {
83 $palette: if($property == 'color', $foreground, $background);
84 #{$property}: theming.get-color-from-palette($palette, disabled-button);
85 }
86 }
87}
88
89@mixin color($config-or-theme) {
90 $config: theming.get-color-config($config-or-theme);
91 $primary: map.get($config, primary);
92 $accent: map.get($config, accent);
93 $warn: map.get($config, warn);
94 $background: map.get($config, background);
95 $foreground: map.get($config, foreground);
96
97 .mat-button, .mat-icon-button, .mat-stroked-button {
98 // Buttons without a background color should inherit the font color. This is necessary to
99 // ensure that the button is readable on custom background colors. It's wrong to always assume
100 // that those buttons are always placed inside of containers with the default background
101 // color of the theme (e.g. themed toolbars).
102 color: inherit;
103 background: transparent;
104
105 @include _theme-property($config, 'color', text);
106 @include _focus-overlay-color($config);
107
108 // Setup the ripple color to be based on the text color. This ensures that the ripples
109 // are matching with the current theme palette and are in contrast to the background color
110 // (e.g in themed toolbars).
111 .mat-ripple-element {
112 opacity: $_ripple-opacity;
113 background-color: currentColor;
114 }
115 }
116
117 .mat-button-focus-overlay {
118 background: map.get($foreground, base);
119 }
120
121 // Note: this needs a bit extra specificity, because we're not guaranteed the inclusion
122 // order of the theme styles and the button reset may end up resetting this as well.
123 .mat-stroked-button:not(.mat-button-disabled) {
124 border-color: theming.get-color-from-palette($foreground, divider);
125 }
126
127 .mat-flat-button, .mat-raised-button, .mat-fab, .mat-mini-fab {
128 // Default font and background color when not using any color palette.
129 color: theming.get-color-from-palette($foreground, text);
130 background-color: theming.get-color-from-palette($background, raised-button);
131
132 @include _theme-property($config, 'color', default-contrast);
133 @include _theme-property($config, 'background-color', default);
134 @include _ripple-color($config, default-contrast);
135 }
136
137 .mat-stroked-button, .mat-flat-button {
138 @include private.private-theme-overridable-elevation(0, $config);
139 }
140
141 .mat-raised-button {
142 @include private.private-theme-overridable-elevation(2, $config);
143
144 &:not(.mat-button-disabled):active {
145 @include private.private-theme-overridable-elevation(8, $config);
146 }
147
148 &.mat-button-disabled {
149 @include private.private-theme-overridable-elevation(0, $config);
150 }
151 }
152
153 .mat-fab, .mat-mini-fab {
154 @include private.private-theme-overridable-elevation(6, $config);
155
156 &:not(.mat-button-disabled):active {
157 @include private.private-theme-overridable-elevation(12, $config);
158 }
159
160 &.mat-button-disabled {
161 @include private.private-theme-overridable-elevation(0, $config);
162 }
163 }
164}
165
166@mixin typography($config-or-theme) {
167 $config: typography.private-typography-to-2014-config(
168 theming.get-typography-config($config-or-theme));
169 .mat-button, .mat-raised-button, .mat-icon-button, .mat-stroked-button,
170 .mat-flat-button, .mat-fab, .mat-mini-fab {
171 font: {
172 family: typography-utils.font-family($config, button);
173 size: typography-utils.font-size($config, button);
174 weight: typography-utils.font-weight($config, button);
175 }
176 }
177}
178
179@mixin _density($config-or-theme) {}
180
181@mixin theme($theme-or-color-config) {
182 $theme: theming.private-legacy-get-theme($theme-or-color-config);
183 @include theming.private-check-duplicate-theme-styles($theme, 'mat-button') {
184 $color: theming.get-color-config($theme);
185 $density: theming.get-density-config($theme);
186 $typography: theming.get-typography-config($theme);
187
188 @if $color != null {
189 @include color($color);
190 }
191 @if $density != null {
192 @include _density($density);
193 }
194 @if $typography != null {
195 @include typography($typography);
196 }
197 }
198}
Note: See TracBrowser for help on using the repository browser.