Skip to content

Commit c68ac25

Browse files
refactor: encapsulate and standardize on RTL within scss (google#4861)
* Create `mdl-rtl` helper package * Refactor all rtl-aware components to use mdl-rtl * Fix minor issues relating to RTL in some components * Reformat mdl-list mixins to use trailing underscore Resolves google#4749 [#130314041]
1 parent 4e72e9c commit c68ac25

File tree

16 files changed

+544
-133
lines changed

16 files changed

+544
-133
lines changed

packages/mdl-drawer/_functions.scss

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/mdl-drawer/_mixins.scss

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,10 @@
1818
@import "mdl-animation/variables";
1919
@import "mdl-theme/mixins";
2020
@import "mdl-typography/mixins";
21-
@import "./functions";
2221

2322
/* All variables are local, so disable pattern checking. */
2423
/* stylelint-disable scss/dollar-variable-pattern */
2524

26-
@mixin mdl-drawer-dir_($property, $value) {
27-
$directions: (
28-
ltr: (
29-
"start": "left",
30-
"end": "right"
31-
),
32-
rtl: (
33-
"start": "right",
34-
"end": "left"
35-
)
36-
);
37-
38-
#{mdl-drawer-replace($property, map-get($directions, ltr))}: $value;
39-
40-
[dir="rtl"] & {
41-
#{mdl-drawer-replace($property, map-get($directions, ltr))}: auto;
42-
#{mdl-drawer-replace($property, map-get($directions, rtl))}: $value;
43-
}
44-
}
45-
4625
@mixin mdl-drawer-toolbar-spacer_() {
4726
&__toolbar-spacer {
4827
display: flex;

packages/mdl-drawer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"mdl-animation": "^1.0.0",
88
"mdl-base": "^1.0.0",
99
"mdl-elevation": "^1.0.0",
10+
"mdl-rtl": "^1.0.0",
1011
"mdl-theme": "^1.0.0",
1112
"mdl-typography": "^1.0.0"
1213
}

packages/mdl-drawer/permanent/mdl-permanent-drawer.scss

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
@import "mdl-rtl/mixins";
1718
@import "mdl-theme/mixins";
1819
@import "../mixins";
1920

@@ -22,14 +23,14 @@ $mdl-permanent-drawer-width: 240px;
2223
.mdl-permanent-drawer {
2324
@include mdl-drawer-base_;
2425
@include mdl-theme-prop(background, background);
25-
@include mdl-drawer-dir_(border-end, 1px solid #e4e4e4);
26-
@include mdl-drawer-dir_(start, 0);
26+
@include mdl-rtl-reflexive-box(border, right, 1px solid #e4e4e4);
27+
@include mdl-rtl-reflexive-position(left, 0);
2728

2829
@include mdl-theme-dark {
2930
background: #212121;
3031

3132
@include mdl-theme-prop(color, text-primary-on-dark);
32-
@include mdl-drawer-dir_(border-end, 1px solid rgba(255, 255, 255, .12));
33+
@include mdl-rtl-reflexive-box(border, right, 1px solid rgba(white, .12));
3334
}
3435

3536
display: inline-flex;
@@ -42,12 +43,12 @@ $mdl-permanent-drawer-width: 240px;
4243
&--floating {
4344
background: none;
4445

45-
@include mdl-drawer-dir_(border-end, none);
46+
@include mdl-rtl-reflexive-box(border, right, none);
4647

4748
@include mdl-theme-dark {
4849
background: none;
4950

50-
@include mdl-drawer-dir_(border-end, none);
51+
@include mdl-rtl-reflexive-box(border, right, none);
5152
}
5253
}
5354
}

packages/mdl-drawer/temporary/mdl-temporary-drawer.scss

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
@import "mdl-animation/functions";
1818
@import "mdl-elevation/mixins";
19+
@import "mdl-rtl/mixins";
1920
@import "mdl-theme/mixins";
2021
@import "../mixins";
2122

@@ -51,6 +52,7 @@
5152
&__drawer {
5253
@include mdl-theme-prop(background, background);
5354
@include mdl-elevation(16);
55+
@include mdl-rtl-reflexive-position(left, 0);
5456

5557
@include mdl-theme-dark(".mdl-temporary-drawer") {
5658
background: #303030;
@@ -60,7 +62,6 @@
6062

6163
display: flex;
6264
position: absolute;
63-
left: 0;
6465
flex-direction: column;
6566
width: calc(100% - 56px);
6667
max-width: 280px;
@@ -70,9 +71,7 @@
7071
box-sizing: border-box;
7172
overflow: hidden;
7273

73-
[dir="rtl"] & {
74-
right: 0;
75-
left: auto;
74+
@include mdl-rtl(".mdl-temporary-drawer") {
7675
transform: translateX(calc(100% + 20px));
7776
}
7877

@@ -122,5 +121,12 @@
122121
.mdl-temporary-drawer__drawer {
123122
transform: none;
124123
}
124+
125+
// Specificity fix to ensure that mdl-drawer is not translated off-screen within an RTL context
126+
@include mdl-rtl {
127+
.mdl-temporary-drawer__drawer {
128+
transform: none;
129+
}
130+
}
125131
}
126132
}

packages/mdl-form-field/mdl-form-field.scss

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
@import "mdl-rtl/mixins";
1718
@import "mdl-theme/mixins";
1819
@import "mdl-typography/mixins";
1920

@@ -38,20 +39,26 @@ $mdl-form-field-item-spacing: 4px;
3839
margin-left: $mdl-form-field-item-spacing;
3940
}
4041

41-
&--align-end > label {
42-
order: -1;
43-
margin-right: $mdl-form-field-item-spacing;
44-
margin-left: auto;
42+
@include mdl-rtl {
43+
> label {
44+
margin-right: $mdl-form-field-item-spacing;
45+
margin-left: auto;
46+
}
4547
}
48+
}
4649

47-
[dir="rtl"] & > label,
48-
&[dir="rtl"] > label {
50+
.mdl-form-field--align-end {
51+
> label {
4952
order: -1;
53+
margin-right: $mdl-form-field-item-spacing;
54+
margin-left: auto;
5055
}
5156

52-
[dir="rtl"] &--align-end > label,
53-
&--align-end[dir="rtl"] > label {
54-
order: 0;
57+
@include mdl-rtl {
58+
> label {
59+
margin-right: auto;
60+
margin-left: $mdl-form-field-item-spacing;
61+
}
5562
}
5663
}
5764
/* stylelint-enable selector-no-type */

packages/mdl-form-field/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "1.0.0",
55
"license": "Apache-2.0",
66
"dependencies": {
7+
"mdl-rtl": "^1.0.0",
78
"mdl-theme": "^1.0.0",
89
"mdl-typography": "^1.0.0"
910
}

packages/mdl-list/mdl-list.scss

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17+
@import "mdl-rtl/mixins";
1718
@import "mdl-theme/mixins";
1819
@import "mdl-typography/mixins";
1920
@import "mdl-typography/variables";
2021

21-
/* stylelint-disable scss/dollar-variable-pattern, scss/at-mixin-pattern */
22-
@mixin _mdl-list-reflexive-margin($default-side, $value, $reset-opposite-margin: true) {
23-
@if (index((right, left), $default-side) == null) {
24-
@error "Invalid default margin side #{default-side}. Please specifiy either right or left";
25-
}
26-
27-
$rtl-side: left;
28-
29-
@if ($default-side == left) {
30-
$rtl-side: right;
31-
}
32-
33-
margin-#{$default-side}: $value;
34-
[dir="rtl"] & {
35-
margin-#{$rtl-side}: $value;
36-
37-
@if ($reset-opposite-margin) {
38-
margin-#{$default-side}: 0;
39-
}
40-
}
41-
}
42-
4322
/**
4423
* Sets the width and height of a detail element to the specified dimension.
4524
*/
46-
@mixin _mdl-list-detail-size($size) {
25+
@mixin mdl-list-detail-size_($size) {
4726
width: $size;
4827
height: $size;
4928
}
@@ -53,15 +32,18 @@
5332
* the start detail element such that the text is always offset by 72px, which is defined within
5433
* the spec.
5534
*/
56-
@mixin _mdl-list-start-detail-size($size) {
35+
@mixin mdl-list-start-detail-size_($size) {
36+
/* stylelint-disable scss/dollar-variable-pattern */
37+
5738
$text-offset: 72px;
5839
$side-padding: 16px;
5940
$margin-value: $text-offset - $side-padding - $size;
6041

61-
@include _mdl-list-detail-size($size);
62-
@include _mdl-list-reflexive-margin(right, $margin-value);
42+
@include mdl-list-detail-size_($size);
43+
@include mdl-rtl-reflexive-box(margin, right, $margin-value, ".mdl-list-item");
44+
45+
/* stylelint-enable scss/dollar-variable-pattern */
6346
}
64-
/* stylelint-enable scss/dollar-variable-pattern, scss/at-mixin-pattern */
6547

6648
/* postcss-bem-linter: define list */
6749

@@ -98,13 +80,12 @@
9880
height: 48px;
9981

10082
&__start-detail {
101-
@include _mdl-list-start-detail-size(24px);
83+
@include mdl-list-start-detail-size_(24px);
10284
}
10385

10486
&__end-detail {
105-
@include _mdl-list-detail-size(24px);
106-
@include _mdl-list-reflexive-margin(left, auto, false);
107-
@include _mdl-list-reflexive-margin(right, 16px, false);
87+
@include mdl-list-detail-size_(24px);
88+
@include mdl-rtl-reflexive-property(margin, auto, 16px, ".mdl-list-item");
10889
}
10990

11091
&__text {
@@ -133,19 +114,19 @@
133114
height: 40px;
134115

135116
&__start-detail {
136-
@include _mdl-list-start-detail-size(20px);
117+
@include mdl-list-start-detail-size_(20px);
137118
}
138119

139120
&__end-detail {
140-
@include _mdl-list-detail-size(20px);
121+
@include mdl-list-detail-size_(20px);
141122
}
142123
}
143124

144125
.mdl-list--avatar-list & {
145126
height: 56px;
146127

147128
&__start-detail {
148-
@include _mdl-list-start-detail-size(40px);
129+
@include mdl-list-start-detail-size_(40px);
149130
border-radius: 50%;
150131
}
151132
}
@@ -154,7 +135,7 @@
154135
height: 48px;
155136

156137
&__start-detail {
157-
@include _mdl-list-start-detail-size(36px);
138+
@include mdl-list-start-detail-size_(36px);
158139
}
159140
}
160141

@@ -186,7 +167,7 @@
186167
.mdl-list-divider--inset {
187168
$mdl-list-divider-inset-amt: /* text offset */ 72px - /* padding offset */ 16px;
188169

189-
@include _mdl-list-reflexive-margin(left, $mdl-list-divider-inset-amt);
170+
@include mdl-rtl-reflexive-box(margin, left, $mdl-list-divider-inset-amt, ".mdl-list-group");
190171
width: calc(100% - #{$mdl-list-divider-inset-amt});
191172
}
192173

packages/mdl-list/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "1.0.0",
55
"license": "Apache-2.0",
66
"dependencies": {
7+
"mdl-rtl": "^1.0.0",
78
"mdl-typography": "^1.0.0",
89
"mdl-theme": "^1.0.0"
910
}

0 commit comments

Comments
 (0)