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

Commit e8a9936

Browse files
crisbetoabhiomkar
authored andcommitted
feat(text-field): add feature targeting for styles (#5378)
1 parent 2b3ec56 commit e8a9936

File tree

10 files changed

+1003
-631
lines changed

10 files changed

+1003
-631
lines changed

packages/mdc-textfield/_mixins.scss

Lines changed: 788 additions & 257 deletions
Large diffs are not rendered by default.

packages/mdc-textfield/character-counter/_mixins.scss

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,45 +22,77 @@
2222

2323
@use "@material/theme/mixins" as theme-mixins;
2424
@use "@material/rtl/mixins" as rtl-mixins;
25+
@use "@material/feature-targeting/functions" as feature-targeting-functions;
26+
@use "@material/feature-targeting/mixins" as feature-targeting-mixins;
27+
@use "@material/typography/mixins" as typography-mixins;
2528

2629
// Public mixins
2730

31+
@mixin character-counter-core-styles($query: feature-targeting-functions.all()) {
32+
$feat-structure: feature-targeting-functions.create-target($query, structure);
33+
34+
// postcss-bem-linter: define text-field-character-counter
35+
36+
.mdc-text-field-character-counter {
37+
@include typography-mixins.typography(caption, $query: $query);
38+
@include typography-mixins.baseline-top(16px, $query: $query);
39+
40+
@include feature-targeting-mixins.targets($feat-structure) {
41+
// Keep flex item align to trailing side on absence of helper text.
42+
@include rtl-mixins.reflexive-box(margin, left, auto);
43+
@include rtl-mixins.reflexive-box(padding, left, 16px);
44+
45+
white-space: nowrap;
46+
}
47+
}
48+
49+
// postcss-bem-linter: end
50+
}
51+
2852
///
2953
/// Customizes the color of the character counter associated with an enabled text field.
3054
/// @param {Color} $color - The desired character counter color.
3155
///
32-
@mixin character-counter-color($color) {
56+
@mixin character-counter-color($color, $query: feature-targeting-functions.all()) {
3357
&:not(.mdc-text-field--disabled) {
34-
@include character-counter-color_($color);
58+
@include character-counter-color_($color, $query);
3559
}
3660
}
3761

3862
///
3963
/// Customizes the color of the character counter associated with a disabled text field.
4064
/// @param {Color} $color - The desired character counter color.
4165
///
42-
@mixin disabled-character-counter-color($color) {
66+
@mixin disabled-character-counter-color($color, $query: feature-targeting-functions.all()) {
4367
&.mdc-text-field--disabled {
44-
@include character-counter-color_($color);
68+
@include character-counter-color_($color, $query);
4569
}
4670
}
4771

48-
@mixin character-counter-position($xOffset, $yOffset) {
49-
.mdc-text-field-character-counter {
50-
@include rtl-mixins.reflexive-position(right, $xOffset);
72+
@mixin character-counter-position($xOffset, $yOffset, $query: feature-targeting-functions.all()) {
73+
$feat-structure: feature-targeting-functions.create-target($query, structure);
5174

52-
position: absolute;
53-
bottom: $yOffset;
75+
.mdc-text-field-character-counter {
76+
@include feature-targeting-mixins.targets($feat-structure) {
77+
@include rtl-mixins.reflexive-position(right, $xOffset);
78+
position: absolute;
79+
bottom: $yOffset;
80+
}
5481
}
5582
}
5683

84+
5785
// Private mixins
5886

59-
@mixin character-counter-color_($color) {
60-
// Character counter is placed inside mdc-textfield element (for textarea variant ) or
87+
@mixin character-counter-color_($color, $query: feature-targeting-functions.all()) {
88+
$feat-color: feature-targeting-functions.create-target($query, color);
89+
90+
// Character counter is placed inside mdc-textfield element (for textarea variant) or
6191
// inside helper line which is sibling to mdc-textfield.
6292
.mdc-text-field-character-counter,
6393
+ .mdc-text-field-helper-line .mdc-text-field-character-counter {
64-
@include theme-mixins.prop(color, $color);
94+
@include feature-targeting-mixins.targets($feat-color) {
95+
@include theme-mixins.prop(color, $color);
96+
}
6597
}
6698
}

packages/mdc-textfield/character-counter/mdc-text-field-character-counter.scss

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,5 @@
2020
// THE SOFTWARE.
2121
//
2222

23-
@use "../functions";
24-
@use "@material/rtl/mixins" as rtl-mixins;
25-
@use "@material/typography/mixins" as typography-mixins;
26-
27-
// postcss-bem-linter: define text-field-character-counter
28-
29-
.mdc-text-field-character-counter {
30-
@include typography-mixins.typography(caption);
31-
@include typography-mixins.baseline-top(16px);
32-
// Keep flex item align to trailing side on absence of helper text.
33-
@include rtl-mixins.reflexive-box(margin, left, auto);
34-
@include rtl-mixins.reflexive-box(padding, left, 16px);
35-
36-
white-space: nowrap;
37-
}
38-
39-
// postcss-bem-linter: end
23+
@use "./mixins";
24+
@include mixins.character-counter-core-styles;

packages/mdc-textfield/helper-text/_mixins.scss

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,92 @@
2020
// THE SOFTWARE.
2121
//
2222

23+
@use "../functions";
2324
@use "@material/theme/mixins";
25+
@use "@material/typography/mixins" as typography-mixins;
26+
@use "@material/feature-targeting/functions" as feature-targeting-functions;
27+
@use "@material/feature-targeting/mixins" as feature-targeting-mixins;
2428
// Public mixins
2529

30+
@mixin helper-text-core-styles($query: feature-targeting-functions.all()) {
31+
$feat-structure: feature-targeting-functions.create-target($query, structure);
32+
$feat-animation: feature-targeting-functions.create-target($query, animation);
33+
34+
// postcss-bem-linter: define text-field-helper-text
35+
36+
.mdc-text-field-helper-text {
37+
@include typography-mixins.typography(caption, $query: $query);
38+
@include typography-mixins.baseline-top(16px, $query: $query);
39+
40+
@include feature-targeting-mixins.targets($feat-structure) {
41+
margin: 0;
42+
opacity: 0;
43+
will-change: opacity;
44+
}
45+
46+
@include feature-targeting-mixins.targets($feat-animation) {
47+
transition: functions.transition(opacity);
48+
}
49+
}
50+
51+
.mdc-text-field-helper-text--persistent {
52+
@include feature-targeting-mixins.targets($feat-animation) {
53+
transition: none;
54+
}
55+
56+
@include feature-targeting-mixins.targets($feat-structure) {
57+
opacity: 1;
58+
will-change: initial;
59+
}
60+
}
61+
62+
// postcss-bem-linter: end
63+
}
64+
2665
///
2766
/// Customizes the color of the helper text following an enabled text-field.
2867
/// @param {Color} $color - The desired helper text color.
2968
///
30-
@mixin helper-text-color($color) {
69+
@mixin helper-text-color($color, $query: feature-targeting-functions.all()) {
3170
&:not(.mdc-text-field--disabled) {
32-
@include helper-text-color_($color);
71+
@include helper-text-color_($color, $query);
3372
}
3473
}
3574

3675
///
3776
/// Customizes the color of the helper text following a disabled text-field.
3877
/// @param {Color} $color - The desired helper text color.
3978
///
40-
@mixin disabled-helper-text-color($color) {
79+
@mixin disabled-helper-text-color($color, $query: feature-targeting-functions.all()) {
4180
&.mdc-text-field--disabled {
42-
@include helper-text-color_($color);
81+
@include helper-text-color_($color, $query);
4382
}
4483
}
4584

46-
@mixin helper-text-validation-color($color) {
85+
@mixin helper-text-validation-color($color, $query: feature-targeting-functions.all()) {
4786
&:not(.mdc-text-field--disabled) {
48-
@include helper-text-validation-color_($color);
87+
@include helper-text-validation-color_($color, $query);
4988
}
5089
}
5190

5291
// Private mixins
5392

54-
@mixin helper-text-color_($color) {
93+
@mixin helper-text-color_($color, $query: feature-targeting-functions.all()) {
94+
$feat-color: feature-targeting-functions.create-target($query, color);
95+
5596
+ .mdc-text-field-helper-line .mdc-text-field-helper-text {
56-
@include mixins.prop(color, $color);
97+
@include feature-targeting-mixins.targets($feat-color) {
98+
@include mixins.prop(color, $color);
99+
}
57100
}
58101
}
59102

60-
@mixin helper-text-validation-color_($color) {
103+
@mixin helper-text-validation-color_($color, $query: feature-targeting-functions.all()) {
104+
$feat-color: feature-targeting-functions.create-target($query, color);
105+
61106
&.mdc-text-field--invalid + .mdc-text-field-helper-line .mdc-text-field-helper-text--validation-msg {
62-
@include mixins.prop(color, $color);
107+
@include feature-targeting-mixins.targets($feat-color) {
108+
@include mixins.prop(color, $color);
109+
}
63110
}
64111
}

packages/mdc-textfield/helper-text/mdc-text-field-helper-text.scss

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,5 @@
2020
// THE SOFTWARE.
2121
//
2222

23-
@use "../functions";
24-
@use "@material/theme/mixins" as mixins2;
25-
@use "@material/typography/mixins";
26-
27-
// postcss-bem-linter: define text-field-helper-text
28-
29-
.mdc-text-field-helper-text {
30-
@include mixins.typography(caption);
31-
@include mixins.baseline-top(16px);
32-
33-
margin: 0;
34-
transition: functions.transition(opacity);
35-
opacity: 0;
36-
will-change: opacity;
37-
}
38-
39-
.mdc-text-field-helper-text--persistent {
40-
transition: none;
41-
opacity: 1;
42-
will-change: initial;
43-
}
44-
45-
// postcss-bem-linter: end
23+
@use "./mixins";
24+
@include mixins.helper-text-core-styles;

packages/mdc-textfield/icon/_mixins.scss

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,80 +23,112 @@
2323
@use "@material/rtl/mixins" as rtl-mixins;
2424
@use "@material/theme/variables";
2525
@use "@material/theme/mixins" as theme-mixins;
26+
@use "@material/feature-targeting/functions" as feature-targeting-functions;
27+
@use "@material/feature-targeting/mixins" as feature-targeting-mixins;
2628

2729
// Public mixins
2830

31+
@mixin icon-core-styles($query: feature-targeting-functions.all()) {
32+
.mdc-text-field__icon {
33+
@include icon_($query: $query);
34+
}
35+
}
36+
2937
///
3038
/// Customizes the color for the leading icon in an enabled text-field.
3139
/// @param {Color} $color - The desired icon color.
3240
///
33-
@mixin leading-icon-color($color) {
41+
@mixin leading-icon-color($color, $query: feature-targeting-functions.all()) {
3442
&:not(.mdc-text-field--disabled) {
35-
@include leading-icon-color_($color);
43+
@include leading-icon-color_($color, $query);
3644
}
3745
}
3846

3947
///
4048
/// Customizes the color for the trailing icon in an enabled text-field.
4149
/// @param {Color} $color - The desired icon color.
4250
///
43-
@mixin trailing-icon-color($color) {
51+
@mixin trailing-icon-color($color, $query: feature-targeting-functions.all()) {
4452
&:not(.mdc-text-field--disabled) {
45-
@include trailing-icon-color_($color);
53+
@include trailing-icon-color_($color, $query);
4654
}
4755
}
4856

4957
///
5058
/// Customizes the color for the leading/trailing icons in a disabled text-field.
5159
/// @param {Color} $color - The desired icon color.
5260
///
53-
@mixin disabled-icon-color($color) {
61+
@mixin disabled-icon-color($color, $query: feature-targeting-functions.all()) {
5462
&.mdc-text-field--disabled {
55-
@include leading-icon-color_($color);
56-
@include trailing-icon-color_($color);
63+
@include leading-icon-color_($color, $query);
64+
@include trailing-icon-color_($color, $query);
5765
}
5866
}
5967

6068
// Private mixins
6169

62-
@mixin leading-icon-horizontal-position_($position) {
70+
@mixin leading-icon-horizontal-position_($position, $query: feature-targeting-functions.all()) {
71+
$feat-structure: feature-targeting-functions.create-target($query, structure);
72+
6373
.mdc-text-field__icon--leading {
64-
@include rtl-mixins.reflexive-position(left, $position);
74+
@include feature-targeting-mixins.targets($feat-structure) {
75+
@include rtl-mixins.reflexive-position(left, $position);
76+
}
6577
}
6678
}
6779

68-
@mixin trailing-icon-horizontal-position_($position) {
80+
@mixin trailing-icon-horizontal-position_($position, $query: feature-targeting-functions.all()) {
81+
$feat-structure: feature-targeting-functions.create-target($query, structure);
82+
6983
.mdc-text-field__icon--trailing {
70-
@include rtl-mixins.reflexive-position(right, $position);
84+
@include feature-targeting-mixins.targets($feat-structure) {
85+
@include rtl-mixins.reflexive-position(right, $position);
86+
}
7187
}
7288
}
7389

74-
@mixin icon-horizontal-position-two-icons_($position-left, $position-right) {
75-
@include leading-icon-horizontal-position_($position-left);
76-
@include trailing-icon-horizontal-position_($position-right);
90+
@mixin icon-horizontal-position-two-icons_(
91+
$position-left, $position-right, $query: feature-targeting-functions.all()) {
92+
@include leading-icon-horizontal-position_($position-left, $query);
93+
@include trailing-icon-horizontal-position_($position-right, $query);
7794
}
7895

79-
@mixin icon_ {
80-
position: absolute;
81-
top: 50%;
82-
transform: translateY(-50%);
83-
cursor: pointer;
96+
@mixin icon_($query: feature-targeting-functions.all()) {
97+
$feat-structure: feature-targeting-functions.create-target($query, structure);
98+
$feat-color: feature-targeting-functions.create-target($query, color);
99+
100+
@include feature-targeting-mixins.targets($feat-structure) {
101+
position: absolute;
102+
top: 50%;
103+
transform: translateY(-50%);
104+
cursor: pointer;
105+
}
84106

85107
&:not([tabindex]),
86108
&[tabindex="-1"] {
87-
cursor: default;
88-
pointer-events: none;
109+
@include feature-targeting-mixins.targets($feat-color) {
110+
cursor: default;
111+
pointer-events: none;
112+
}
89113
}
90114
}
91115

92-
@mixin leading-icon-color_($color) {
116+
@mixin leading-icon-color_($color, $query: feature-targeting-functions.all()) {
117+
$feat-color: feature-targeting-functions.create-target($query, color);
118+
93119
.mdc-text-field__icon--leading {
94-
@include theme-mixins.prop(color, $color);
120+
@include feature-targeting-mixins.targets($feat-color) {
121+
@include theme-mixins.prop(color, $color);
122+
}
95123
}
96124
}
97125

98-
@mixin trailing-icon-color_($color) {
126+
@mixin trailing-icon-color_($color, $query: feature-targeting-functions.all()) {
127+
$feat-color: feature-targeting-functions.create-target($query, color);
128+
99129
.mdc-text-field__icon--trailing {
100-
@include theme-mixins.prop(color, $color);
130+
@include feature-targeting-mixins.targets($feat-color) {
131+
@include theme-mixins.prop(color, $color);
132+
}
101133
}
102134
}

packages/mdc-textfield/icon/mdc-text-field-icon.scss

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,4 @@
2121
//
2222

2323
@use "./mixins";
24-
25-
.mdc-text-field__icon {
26-
@include mixins.icon_;
27-
}
24+
@include mixins.icon-core-styles;

0 commit comments

Comments
 (0)