Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 8691cf8

Browse files
mmalerbakfranqueiro
authored andcommitted
feat(typography): add feature targeting for styles (#4305)
1 parent bf956fa commit 8691cf8

File tree

3 files changed

+73
-28
lines changed

3 files changed

+73
-28
lines changed

packages/mdc-button/_mixins.scss

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,7 @@
190190
$feat-structure: mdc-feature-create-target($query, structure);
191191
$feat-typography: mdc-feature-create-target($query, typography);
192192

193-
@include mdc-feature-targets($feat-typography) {
194-
@include mdc-typography(button);
195-
}
196-
193+
@include mdc-typography(button, $query);
197194
@include mdc-ripple-surface($query);
198195

199196
@include mdc-feature-targets($feat-structure) {

packages/mdc-typography/_mixins.scss

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,78 @@
2020
// THE SOFTWARE.
2121
//
2222

23+
@import "@material/feature-targeting/functions";
24+
@import "@material/feature-targeting/mixins";
2325
@import "./variables";
2426

25-
@mixin mdc-typography-base {
26-
@each $key, $value in $mdc-typography-base {
27-
#{$key}: $value;
27+
@mixin mdc-typography-base($query: mdc-feature-all()) {
28+
$feat-typography: mdc-feature-create-target($query, typography);
29+
30+
@include mdc-feature-targets($feat-typography) {
31+
@each $key, $value in $mdc-typography-base {
32+
#{$key}: $value;
33+
}
2834
}
2935
}
3036

31-
@mixin mdc-typography($style) {
37+
@mixin mdc-typography($style, $query: mdc-feature-all()) {
38+
$feat-typography: mdc-feature-create-target($query, typography);
3239
$style-props: map-get($mdc-typography-styles, $style);
3340

3441
@if not map-has-key($mdc-typography-styles, $style) {
3542
@error "Invalid style specified! #{$style} doesn't exist. Choose one of #{map-keys($mdc-typography-styles)}";
3643
}
3744

38-
@each $key, $value in $style-props {
39-
#{$key}: $value;
45+
@include mdc-feature-targets($feat-typography) {
46+
@each $key, $value in $style-props {
47+
#{$key}: $value;
48+
}
4049
}
4150
}
4251

4352
// Element must be `display: block` or `display: inline-block` for this to work.
44-
@mixin mdc-typography-overflow-ellipsis {
45-
text-overflow: ellipsis;
46-
white-space: nowrap;
47-
overflow: hidden;
53+
@mixin mdc-typography-overflow-ellipsis($query: mdc-feature-all()) {
54+
$feat-structure: mdc-feature-create-target($query, structure);
55+
56+
@include mdc-feature-targets($feat-structure) {
57+
text-overflow: ellipsis;
58+
white-space: nowrap;
59+
overflow: hidden;
60+
}
4861
}
4962

50-
@mixin mdc-typography-baseline-top($distance) {
51-
display: block;
52-
margin-top: 0;
53-
/* @alternate */
54-
line-height: normal;
63+
@mixin mdc-typography-baseline-top($distance, $query: mdc-feature-all()) {
64+
$feat-structure: mdc-feature-create-target($query, structure);
65+
66+
@include mdc-feature-targets($feat-structure) {
67+
display: block;
68+
margin-top: 0;
69+
/* @alternate */
70+
line-height: normal;
71+
}
5572

5673
&::before {
57-
@include mdc-typography-baseline-strut_($distance);
74+
@include mdc-feature-targets($feat-structure) {
75+
@include mdc-typography-baseline-strut_($distance);
5876

59-
vertical-align: 0;
77+
vertical-align: 0;
78+
}
6079
}
6180
}
6281

63-
@mixin mdc-typography-baseline-bottom($distance) {
64-
margin-bottom: -1 * $distance;
82+
@mixin mdc-typography-baseline-bottom($distance, $query: mdc-feature-all()) {
83+
$feat-structure: mdc-feature-create-target($query, structure);
84+
85+
@include mdc-feature-targets($feat-structure) {
86+
margin-bottom: -1 * $distance;
87+
}
6588

6689
&::after {
67-
@include mdc-typography-baseline-strut_($distance);
90+
@include mdc-feature-targets($feat-structure) {
91+
@include mdc-typography-baseline-strut_($distance);
6892

69-
vertical-align: -1 * $distance;
93+
vertical-align: -1 * $distance;
94+
}
7095
}
7196
}
7297

test/scss/feature-targeting.scss

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
1-
@import "@material/feature-targeting/functions";
21
@import "@material/button/mixins";
32
@import "@material/checkbox/mixins";
4-
@import "@material/radio/mixins";
3+
@import "@material/feature-targeting/functions";
54
@import "@material/menu/mixins";
5+
@import "@material/radio/mixins";
6+
@import "@material/typography/mixins";
7+
8+
// Button
69

710
@include mdc-button($query: mdc-feature-any());
11+
12+
// Checkbox
13+
814
@include mdc-checkbox($query: mdc-feature-any());
9-
@include mdc-radio($query: mdc-feature-any());
15+
16+
// Menu
17+
1018
@include mdc-menu($query: mdc-feature-any());
19+
20+
// Radio
21+
22+
@include mdc-radio($query: mdc-feature-any());
23+
24+
// Typography
25+
26+
@include mdc-typography-base($query: mdc-feature-any());
27+
@include mdc-typography(button, $query: mdc-feature-any());
28+
@include mdc-typography-overflow-ellipsis($query: mdc-feature-any());
29+
30+
div {
31+
@include mdc-typography-baseline-top(0, $query: mdc-feature-any());
32+
@include mdc-typography-baseline-bottom(0, $query: mdc-feature-any());
33+
}

0 commit comments

Comments
 (0)