forked from material-components/material-components-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_mixins.scss
133 lines (126 loc) · 4.01 KB
/
_mixins.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
@import "./variables";
// Applies the correct theme color style to the specified property.
// $property is typically color or background-color, but can be any CSS property that accepts color values.
// $style should be one of the map keys in $mdc-theme-property-values (_variables.scss), or a literal color value.
// $edgeOptOut controls whether to feature-detect around Edge to avoid emitting CSS variables for it,
// intended for use in cases where interactions with pseudo-element styles cause problems due to Edge bugs.
@mixin mdc-theme-prop($property, $style, $important: false, $edgeOptOut: false) {
@if type-of($style) == "color" or $style == "currentColor" {
@if $important {
#{$property}: $style !important;
} @else {
#{$property}: $style;
}
} @else {
@if not map-has-key($mdc-theme-property-values, $style) {
@error "Invalid style: '#{$style}'. Choose one of: #{map-keys($mdc-theme-property-values)}";
}
$value: map-get($mdc-theme-property-values, $style);
@if $important {
/* @alternate */
#{$property}: $value !important;
@if $edgeOptOut {
// stylelint-disable max-nesting-depth
@at-root {
@supports not (-ms-ime-align:auto) {
// stylelint-disable scss/selector-no-redundant-nesting-selector
& {
#{$property}: var(--mdc-theme-#{$style}, $value) !important;
}
// stylelint-enable scss/selector-no-redundant-nesting-selector
}
}
// stylelint-enable max-nesting-depth
} @else {
#{$property}: var(--mdc-theme-#{$style}, $value) !important;
}
} @else {
/* @alternate */
#{$property}: $value;
@if $edgeOptOut {
// stylelint-disable max-nesting-depth
@at-root {
@supports not (-ms-ime-align:auto) {
// stylelint-disable scss/selector-no-redundant-nesting-selector
& {
#{$property}: var(--mdc-theme-#{$style}, $value);
}
// stylelint-enable scss/selector-no-redundant-nesting-selector
}
}
// stylelint-enable max-nesting-depth
} @else {
#{$property}: var(--mdc-theme-#{$style}, $value);
}
}
}
}
// Creates a rule to be used in MDC-Web components for dark theming, and applies the provided contents.
// Should provide the $root-selector option if applied to anything other than the root selector.
// When used with a modifier class, provide a second argument of `true` for the $compound parameter
// to specify that this should be attached as a compound class.
//
// Usage example:
//
// ```scss
// .mdc-foo {
// color: black;
//
// @include mdc-theme-dark {
// color: white;
// }
//
// &__bar {
// background: black;
//
// @include mdc-theme-dark(".mdc-foo") {
// background: white;
// }
// }
// }
//
// .mdc-foo--disabled {
// opacity: .38;
//
// @include mdc-theme-dark(".mdc-foo", true) {
// opacity: .5;
// }
// }
// ```
@mixin mdc-theme-dark($root-selector: null, $compound: false) {
@if ($root-selector) {
@at-root {
@if ($compound) {
#{$root-selector}--theme-dark#{&},
.mdc-theme--dark & {
@content;
}
} @else {
#{$root-selector}--theme-dark &,
.mdc-theme--dark & {
@content;
}
}
}
} @else {
&--theme-dark,
.mdc-theme--dark & {
@content;
}
}
}