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

feat: Add feature targeting support and apply to mdc-button #4228

Merged
merged 23 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a726384
add feature targeting infrastructure
mmalerba Nov 19, 2018
130dd7d
npm pack the new package and add it as a dep
mmalerba Nov 20, 2018
0e22da5
refactor button sass so all styles can be emited by `@include` rather
mmalerba Nov 20, 2018
4dbb99e
annotate button and its deps w/ mdc-targets
mmalerba Nov 20, 2018
3fb6a48
add some example usages of the query API
mmalerba Dec 3, 2018
d673353
WIP Update deps for lerna
Dec 5, 2018
5ec05e3
WIP Rename mixins/functions to mdc-feature-*
Dec 19, 2018
4a1f432
WIP Fix sync with fa415797
Jan 2, 2019
c332fc3
WIP Add script to verify everything is feature-targeted
Jan 2, 2019
4db71f6
WIP Revert example in button.scss (which is emitting duplicate CSS)
Jan 4, 2019
ae0ee70
WIP Remove unnecessary defaults for private mixins
Jan 15, 2019
aa8cbff
WIP Remove redundant verify-feature-targets call
Jan 15, 2019
ed179b4
WIP Omit () for no-param mixin invocation
Jan 16, 2019
22d6e7d
Merge remote-tracking branch 'origin/master' into experimental/featur…
Jan 16, 2019
bff443f
WIP Add publishConfig to feature-targeting package.json
Jan 16, 2019
57c9374
WIP Metadata updates
Jan 16, 2019
9d7bf83
WIP Resolve review comments
Jan 18, 2019
52bc27c
WIP Add missing license comments
Jan 18, 2019
257112e
WIP Improve readability with a bit of reorganization
Jan 18, 2019
0e7c5c0
WIP Move will-change to animation
Jan 18, 2019
80382f1
WIP Revert "WIP Move will-change to animation"
Jan 18, 2019
dcf632d
WIP Make states opacity use color, not structure
Jan 18, 2019
9677b66
Merge branch 'master' into experimental/feature-targeting
kfranqueiro Jan 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ matrix:
env:
- TEST_SUITE=lint
script:
- if has_testable_files; then npm run lint; else log_untestable_files; fi
- if has_testable_files; then npm run lint && npm run test:feature-targeting; else log_untestable_files; fi

- node_js: 8
env:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"test:unit": "karma start --single-run",
"test:closure": "./scripts/closure-test.sh",
"test:dependency": "./scripts/dependency-test.sh",
"test:feature-targeting": "node test/scss/verify-feature-targeting.js",
"test:site": "npm run clean:site && ./scripts/site-generator-test.sh"
},
"devDependencies": {
Expand Down Expand Up @@ -173,6 +174,7 @@
"drawer",
"elevation",
"fab",
"feature-targeting",
"floating-label",
"form-field",
"grid-list",
Expand Down
1 change: 1 addition & 0 deletions packages/material-components-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@material/drawer": "^0.43.0",
"@material/elevation": "^0.43.0",
"@material/fab": "^0.43.0",
"@material/feature-targeting": "0.0.0",
"@material/floating-label": "^0.43.0",
"@material/form-field": "^0.43.0",
"@material/grid-list": "^0.43.0",
Expand Down
241 changes: 185 additions & 56 deletions packages/mdc-button/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
//

@import "@material/elevation/mixins";
@import "@material/feature-targeting/functions";
@import "@material/feature-targeting/mixins";
@import "@material/ripple/mixins";
@import "@material/rtl/mixins";
@import "@material/theme/functions";
Expand All @@ -30,6 +32,97 @@
@import "@material/shape/functions";
@import "./variables";

@mixin mdc-button($query: mdc-feature-all()) {
$feat-color: mdc-feature-create-target($query, color);
$feat-structure: mdc-feature-create-target($query, structure);

@include mdc-ripple-common($query);

// postcss-bem-linter: define button
.mdc-button {
@include mdc-button-base_($query);

@include mdc-feature-targets($feat-structure) {
@include mdc-button-shape-radius(small);
// This fits under structure because it doesn't depend on the theme.
@include mdc-button-container-fill-color(transparent);

// The icon CSS class overrides styles defined in the .material-icons CSS
// class, which is loaded separately so the order of CSS definitions is not
// guaranteed. Therefore, increase specifity by nesting this class to ensure
// overrides apply.
.mdc-button__icon {
@include mdc-button__icon_;
}
}

@include mdc-feature-targets($feat-color) {
@include mdc-button-ink-color(primary);
}

@include mdc-states(primary, false, $query);
}

@include mdc-feature-targets($feat-structure) {
.mdc-button__label + .mdc-button__icon {
@include mdc-button__icon-trailing_;
}

// stylelint-disable-next-line selector-no-qualifying-type
svg.mdc-button__icon {
@include mdc-button__icon-svg_;
}

.mdc-button--raised,
.mdc-button--unelevated,
.mdc-button--outlined {
.mdc-button__icon {
// Icons inside contained buttons have different styles due to increased button padding
@include mdc-button__icon-contained_;
}

.mdc-button__label + .mdc-button__icon {
@include mdc-button__icon-contained-trailing_;
}
}
}

.mdc-button--raised,
.mdc-button--unelevated {
@include mdc-button--filled_($query);

@include mdc-feature-targets($feat-color) {
@include mdc-button-container-fill-color(primary);
@include mdc-button-ink-color(on-primary);
}

@include mdc-states(on-primary, false, $query);
kfranqueiro marked this conversation as resolved.
Show resolved Hide resolved
}

.mdc-button--raised {
@include mdc-button--raised_($query);
}

.mdc-button--outlined {
@include mdc-button--outlined_($query);

@include mdc-feature-targets($feat-structure) {
kfranqueiro marked this conversation as resolved.
Show resolved Hide resolved
@include mdc-button-outline-width(2px);
}

@include mdc-feature-targets($feat-color) {
@include mdc-button-outline-color(primary);
}
}

.mdc-button--dense {
@include mdc-feature-targets($feat-structure) {
@include mdc-button--dense_;
}
}
// postcss-bem-linter: end
}

@mixin mdc-button-filled-accessible($container-fill-color) {
$fill-tone: mdc-theme-tone($container-fill-color);

Expand Down Expand Up @@ -92,48 +185,63 @@
border-width: $outline-width;
}

@mixin mdc-button-base_() {
@include mdc-typography(button);
@include mdc-ripple-surface;
@include mdc-ripple-radius-bounded;
@include mdc-button-horizontal-padding($mdc-button-horizontal-padding);

display: inline-flex;
position: relative;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-width: 64px;
height: $mdc-button-height;
border: none;
outline: none;
/* @alternate */
line-height: inherit;
user-select: none;
-webkit-appearance: none;
overflow: hidden;
vertical-align: middle;

&::-moz-focus-inner {
padding: 0;
border: 0;
}

// postcss-bem-linter: ignore
&:active {
outline: none;
@mixin mdc-button-base_($query) {
$feat-color: mdc-feature-create-target($query, color);
$feat-structure: mdc-feature-create-target($query, structure);
$feat-typography: mdc-feature-create-target($query, typography);

@include mdc-feature-targets($feat-typography) {
@include mdc-typography(button);
}

&:hover {
cursor: pointer;
@include mdc-ripple-surface($query);

@include mdc-feature-targets($feat-structure) {
@include mdc-ripple-radius-bounded;
@include mdc-button-horizontal-padding($mdc-button-horizontal-padding);

display: inline-flex;
position: relative;
align-items: center;
justify-content: center;
box-sizing: border-box;
min-width: 64px;
height: $mdc-button-height;
border: none;
outline: none;
/* @alternate */
line-height: inherit;
user-select: none;
-webkit-appearance: none;
overflow: hidden;
vertical-align: middle;

&::-moz-focus-inner {
padding: 0;
border: 0;
}

// postcss-bem-linter: ignore
&:active {
outline: none;
}

&:hover {
cursor: pointer;
}
}

&:disabled {
kfranqueiro marked this conversation as resolved.
Show resolved Hide resolved
@include mdc-theme-prop(background-color, transparent);
@include mdc-feature-targets($feat-color) {
@include mdc-theme-prop(background-color, transparent);

color: $mdc-button-disabled-ink-color;
}

color: $mdc-button-disabled-ink-color;
cursor: default;
pointer-events: none;
@include mdc-feature-targets($feat-structure) {
cursor: default;
pointer-events: none;
}
}
}

Expand Down Expand Up @@ -163,39 +271,60 @@
@include mdc-rtl-reflexive-property(margin, 8px, -4px);
}

@mixin mdc-button--outlined_() {
border-style: solid;
@mixin mdc-button--outlined_($query) {
$feat-color: mdc-feature-create-target($query, color);
$feat-structure: mdc-feature-create-target($query, structure);

&:disabled {
border-color: $mdc-button-disabled-ink-color;
@include mdc-feature-targets($feat-structure) {
border-style: solid;
}

@include mdc-feature-targets($feat-color) {
&:disabled {
border-color: $mdc-button-disabled-ink-color;
}
}
}

@mixin mdc-button--filled_() {
@include mdc-button-horizontal-padding($mdc-button-contained-horizontal-padding);
@mixin mdc-button--filled_($query) {
$feat-color: mdc-feature-create-target($query, color);
$feat-structure: mdc-feature-create-target($query, structure);

&:disabled {
background-color: rgba(mdc-theme-prop-value(on-surface), .12);
color: $mdc-button-disabled-ink-color;
@include mdc-feature-targets($feat-structure) {
@include mdc-button-horizontal-padding($mdc-button-contained-horizontal-padding);
}

@include mdc-feature-targets($feat-color) {
&:disabled {
background-color: rgba(mdc-theme-prop-value(on-surface), .12);
color: $mdc-button-disabled-ink-color;
}
}
}

@mixin mdc-button--raised_() {
@include mdc-elevation(2);
@mixin mdc-button--raised_($query) {
$feat-animation: mdc-feature-create-target($query, animation);
$feat-color: mdc-feature-create-target($query, color);

transition: mdc-elevation-transition-value();
@include mdc-feature-targets($feat-color) {
@include mdc-elevation(2);

&:hover,
&:focus {
@include mdc-elevation(4);
}
&:hover,
&:focus {
@include mdc-elevation(4);
}

&:active {
@include mdc-elevation(8);
&:active {
@include mdc-elevation(8);
}

&:disabled {
@include mdc-elevation(0);
}
}

&:disabled {
@include mdc-elevation(0);
@include mdc-feature-targets($feat-animation) {
transition: mdc-elevation-transition-value();
}
}

Expand Down
66 changes: 1 addition & 65 deletions packages/mdc-button/mdc-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,69 +20,5 @@
// THE SOFTWARE.
//

@import "@material/ripple/common";
@import "@material/ripple/mixins";
@import "./mixins";
@import "./variables";

// postcss-bem-linter: define button
.mdc-button {
@include mdc-button-base_;
@include mdc-button-shape-radius(small);
@include mdc-button-container-fill-color(transparent);
@include mdc-button-ink-color(primary);
@include mdc-states(primary);

// The icon CSS class overrides styles defined in the .material-icons CSS
// class, which is loaded separately so the order of CSS definitions is not
// guaranteed. Therefore, increase specifity by nesting this class to ensure
// overrides apply.
.mdc-button__icon {
@include mdc-button__icon_;
}
}

.mdc-button__label + .mdc-button__icon {
@include mdc-button__icon-trailing_;
}

// stylelint-disable-next-line selector-no-qualifying-type
svg.mdc-button__icon {
@include mdc-button__icon-svg_;
}

.mdc-button--raised,
.mdc-button--unelevated,
.mdc-button--outlined {
.mdc-button__icon {
// Icons inside contained buttons have different styles due to increased button padding
@include mdc-button__icon-contained_;
}

.mdc-button__label + .mdc-button__icon {
@include mdc-button__icon-contained-trailing_;
}
}

.mdc-button--raised,
.mdc-button--unelevated {
@include mdc-button--filled_;
@include mdc-button-container-fill-color(primary);
@include mdc-button-ink-color(on-primary);
@include mdc-states(on-primary);
}

.mdc-button--raised {
@include mdc-button--raised_;
}

.mdc-button--outlined {
@include mdc-button--outlined_;
@include mdc-button-outline-width(2px);
@include mdc-button-outline-color(primary);
}

.mdc-button--dense {
@include mdc-button--dense_;
}
// postcss-bem-linter: end
@include mdc-button;
1 change: 1 addition & 0 deletions packages/mdc-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@material/elevation": "^0.43.0",
"@material/feature-targeting": "0.0.0",
"@material/ripple": "^0.43.0",
"@material/rtl": "^0.42.0",
"@material/shape": "^0.43.0",
Expand Down
Loading