forked from material-components/material-components-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_mixins.scss
270 lines (257 loc) · 6.81 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
//
// Copyright 2017 Google Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// Creates a rule that will be applied when an MDC Web component is within the context of an RTL layout.
//
// Usage Example:
//
// ```scss
// .mdc-foo {
// position: absolute;
// left: 0;
//
// @include mdc-rtl {
// left: auto;
// right: 0;
// }
//
// &__bar {
// margin-left: 4px;
// @include mdc-rtl(".mdc-foo") {
// margin-left: auto;
// margin-right: 4px;
// }
// }
// }
//
// .mdc-foo--mod {
// padding-left: 4px;
//
// @include mdc-rtl {
// padding-left: auto;
// padding-right: 4px;
// }
// }
// ```
//
// Note that this mixin works by checking for an ancestor element with `[dir="rtl"]`.
// As a result, nested `dir` values are not supported:
//
// ```html
// <html dir="rtl">
// <!-- ... -->
// <div dir="ltr">
// <div class="mdc-foo">Styled incorrectly as RTL!</div>
// </div>
// </html>
// ```
//
// In the future, selectors such as the `:dir` pseudo-class (http://mdn.io/css/:dir) will help us mitigate this.
@mixin mdc-rtl($root-selector: null) {
@if ($root-selector) {
@at-root {
#{$root-selector}[dir="rtl"] &,
[dir="rtl"] #{$root-selector} & {
@content;
}
}
} @else {
[dir="rtl"] &,
&[dir="rtl"] {
@content;
}
}
}
// Takes a base box-model property name (`margin`, `border`, `padding`, etc.) along with a
// default direction (`left` or `right`) and value, and emits rules which apply the given value to the
// specified direction by default and the opposite direction in RTL.
//
// For example:
//
// ```scss
// .mdc-foo {
// @include mdc-rtl-reflexive-box(margin, left, 8px);
// }
// ```
//
// is equivalent to:
//
// ```scss
// .mdc-foo {
// margin-left: 8px;
// margin-right: 0;
//
// @include mdc-rtl {
// margin-left: 0;
// margin-right: 8px;
// }
// }
// ```
//
// whereas:
//
// ```scss
// .mdc-foo {
// @include mdc-rtl-reflexive-box(margin, right, 8px);
// }
// ```
//
// is equivalent to:
//
// ```scss
// .mdc-foo {
// margin-left: 0;
// margin-right: 8px;
//
// @include mdc-rtl {
// margin-left: 8px;
// margin-right: 0;
// }
// }
// ```
//
// You can also pass an optional 4th `$root-selector` argument which will be forwarded to `mdc-rtl`,
// e.g. `@include mdc-rtl-reflexive-box(margin, left, 8px, ".mdc-component")`.
//
// Note that this function will always zero out the original value in an RTL context.
// If you're trying to flip the values, use `mdc-rtl-reflexive-property()` instead.
@mixin mdc-rtl-reflexive-box($base-property, $default-direction, $value, $root-selector: null) {
@if (index((right, left), $default-direction) == null) {
@error "Invalid default direction: '#{$default-direction}'. Please specifiy either 'right' or 'left'.";
}
$left-value: $value;
$right-value: 0;
@if ($default-direction == right) {
$left-value: 0;
$right-value: $value;
}
@include mdc-rtl-reflexive-property($base-property, $left-value, $right-value, $root-selector);
}
// Takes a base property and emits rules that assign <base-property>-left to <left-value> and
// <base-property>-right to <right-value> in a LTR context, and vice versa in a RTL context.
// For example:
//
// ```scss
// .mdc-foo {
// @include mdc-rtl-reflexive-property(margin, auto, 12px);
// }
// ```
//
// is equivalent to:
//
// ```scss
// .mdc-foo {
// margin-left: auto;
// margin-right: 12px;
//
// @include mdc-rtl {
// margin-left: 12px;
// margin-right: auto;
// }
// }
// ```
//
// An optional 4th `$root-selector` argument can be given, which will be passed to `mdc-rtl`.
@mixin mdc-rtl-reflexive-property($base-property, $left-value, $right-value, $root-selector: null) {
$prop-left: #{$base-property}-left;
$prop-right: #{$base-property}-right;
@include mdc-rtl-reflexive($prop-left, $left-value, $prop-right, $right-value, $root-selector);
}
// Takes an argument specifying a horizontal position property (either "left" or "right") as well
// as a value, and applies that value to the specified position in a LTR context, and flips it in a
// RTL context. For example:
//
// ```scss
// .mdc-foo {
// @include mdc-rtl-reflexive-position(left, 0);
// }
// ```
//
// is equivalent to:
//
// ```scss
// .mdc-foo {
// left: 0;
// right: initial;
//
// @include mdc-rtl {
// left: initial;
// right: 0;
// }
// }
// ```
//
// An optional third $root-selector argument may also be given, which is passed to `mdc-rtl`.
@mixin mdc-rtl-reflexive-position($position-property, $value, $root-selector: null) {
@if (index((right, left), $position-property) == null) {
@error "Invalid position #{position-property}. Please specifiy either right or left";
}
// TODO: "initial" is not supported in IE 11. https://caniuse.com/#feat=css-initial-value
$left-value: $value;
$right-value: initial;
@if ($position-property == right) {
$right-value: $value;
$left-value: initial;
}
@include mdc-rtl-reflexive(left, $left-value, right, $right-value, $root-selector);
}
// Takes pair of properties with values as arguments and flips it in RTL context.
// For example:
//
// ```scss
// .mdc-foo {
// @include mdc-rtl-reflexive(left, 2px, right, 5px);
// }
// ```
//
// is equivalent to:
//
// ```scss
// .mdc-foo {
// left: 2px;
// right: 5px;
//
// @include mdc-rtl {
// right: 2px;
// left: 5px;
// }
// }
// ```
//
// An optional fifth `$root-selector` argument may also be given, which is passed to `mdc-rtl`.
@mixin mdc-rtl-reflexive(
$left-property,
$left-value,
$right-property,
$right-value,
$root-selector: null
) {
/* @noflip */
#{$left-property}: $left-value;
/* @noflip */
#{$right-property}: $right-value;
@include mdc-rtl($root-selector) {
/* @noflip */
#{$left-property}: $right-value;
/* @noflip */
#{$right-property}: $left-value;
}
}