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

feat(menu-surface): add feature targeting for styles #4279

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
130 changes: 124 additions & 6 deletions packages/mdc-menu-surface/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,135 @@
// THE SOFTWARE.
//

@import "@material/feature-targeting/functions";
@import "@material/feature-targeting/mixins";
@import "@material/theme/mixins";
@import "@material/shape/mixins";
@import "@material/animation/variables";
@import "@material/elevation/mixins";
@import "@material/rtl/mixins";
@import "./variables";

@mixin mdc-menu-surface-ink-color($color) {
@include mdc-theme-prop(color, $color);
//
// Public
//

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

// postcss-bem-linter: define menu-surface
.mdc-menu-surface {
@include mdc-menu-surface-base_($query);
@include mdc-elevation($z-value: 8, $query: $query);
@include mdc-menu-surface-fill-color(surface, $query);
@include mdc-menu-surface-ink-color(on-surface, $query);
@include mdc-menu-surface-shape-radius(medium, false, $query);

@include mdc-feature-targets($feat-structure) {
@include mdc-rtl-reflexive-property(transform-origin, top left, top right);
}
}

.mdc-menu-surface--anchor {
@include mdc-feature-targets($feat-structure) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you move this mdc-feature-targets up a level you can surround this rule and the one below

position: relative;
overflow: visible;
}
}

.mdc-menu-surface--fixed {
@include mdc-feature-targets($feat-structure) {
position: fixed;
}
}
// postcss-bem-linter: end
}

@mixin mdc-menu-surface-ink-color($color, $query: mdc-feature-all()) {
$feat-color: mdc-feature-create-target($query, color);

@include mdc-feature-targets($feat-color) {
@include mdc-theme-prop(color, $color);
}
}

@mixin mdc-menu-surface-fill-color($color, $query: mdc-feature-all()) {
$feat-color: mdc-feature-create-target($query, color);

@include mdc-feature-targets($feat-color) {
@include mdc-theme-prop(background-color, $color);
}
}

@mixin mdc-menu-surface-fill-color($color) {
@include mdc-theme-prop(background-color, $color);
@mixin mdc-menu-surface-shape-radius($radius, $rtl-reflexive: false, $query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);

@include mdc-feature-targets($feat-structure) {
@include mdc-shape-radius($radius, $rtl-reflexive);
}
}

@mixin mdc-menu-surface-shape-radius($radius, $rtl-reflexive: false) {
@include mdc-shape-radius($radius, $rtl-reflexive);
//
// Private
//

@mixin mdc-menu-surface-base_($query: mdc-feature-all()) {
$feat-structure: mdc-feature-create-target($query, structure);
$feat-animation: mdc-feature-create-target($query, animation);

@include mdc-feature-targets($feat-structure) {
display: none;
position: absolute;
box-sizing: border-box;
max-width: calc(100vw - #{$mdc-menu-surface-min-distance-from-edge});
max-height: calc(100vh - #{$mdc-menu-surface-min-distance-from-edge});
margin: 0;
padding: 0;
transform: scale(1);
transform-origin: top left;
opacity: 0;
overflow: auto;
will-change: transform, opacity;
z-index: $mdc-menu-surface-z-index;
}

&:focus {
@include mdc-feature-targets($feat-structure) {
outline: none;
}
}

// stylelint-disable-next-line selector-max-type
&--open {
@include mdc-feature-targets($feat-structure) {
display: inline-block;
transform: scale(1);
opacity: 1;
}
}

&--animating-open {
@include mdc-feature-targets($feat-structure) {
display: inline-block;
transform: scale(.8);
opacity: 0;
}

@include mdc-feature-targets($feat-animation) {
transition:
opacity $mdc-menu-surface-fade-in-duration linear,
transform $mdc-menu-surface-scale-duration $mdc-animation-deceleration-curve-timing-function;
}
}

&--animating-closed {
@include mdc-feature-targets($feat-structure) {
display: inline-block;
opacity: 0;
}

@include mdc-feature-targets($feat-animation) {
transition: opacity $mdc-menu-surface-fade-out-duration linear;
}
}
}
64 changes: 1 addition & 63 deletions packages/mdc-menu-surface/mdc-menu-surface.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,5 @@
// THE SOFTWARE.
//

@import "@material/animation/variables";
@import "@material/elevation/mixins";
@import "@material/theme/mixins";
@import "@material/rtl/mixins";
@import "./mixins";
@import "./variables";

// postcss-bem-linter: define menu-surface
.mdc-menu-surface {
@include mdc-elevation(8);
@include mdc-menu-surface-fill-color(surface);
@include mdc-menu-surface-ink-color(on-surface);
@include mdc-rtl-reflexive-property(transform-origin, top left, top right);
@include mdc-menu-surface-shape-radius(medium);

display: none;
position: absolute;
box-sizing: border-box;
max-width: calc(100vw - #{$mdc-menu-surface-min-distance-from-edge});
max-height: calc(100vh - #{$mdc-menu-surface-min-distance-from-edge});
margin: 0;
padding: 0;
transform: scale(1);
transform-origin: top left;
opacity: 0;
overflow: auto;
will-change: transform, opacity;
z-index: $mdc-menu-surface-z-index;

&:focus {
outline: none;
}

&--animating-open {
display: inline-block;
transform: scale(.8);
transition:
opacity $mdc-menu-surface-fade-in-duration linear,
transform $mdc-menu-surface-scale-duration $mdc-animation-deceleration-curve-timing-function;
opacity: 0;
}

&--open {
display: inline-block;
transform: scale(1);
opacity: 1;
}

&--animating-closed {
display: inline-block;
transition: opacity $mdc-menu-surface-fade-out-duration linear;
opacity: 0;
}
}

.mdc-menu-surface--anchor {
position: relative;
overflow: visible;
}

.mdc-menu-surface--fixed {
position: fixed;
}
// postcss-bem-linter: end
@include mdc-menu-surface;
7 changes: 7 additions & 0 deletions test/scss/feature-targeting.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "@material/button/mixins";
@import "@material/card/mixins";
@import "@material/menu-surface/mixins";
@import "@material/checkbox/mixins";
@import "@material/elevation/mixins";
@import "@material/feature-targeting/functions";
Expand Down Expand Up @@ -41,6 +42,12 @@
@include mdc-menu($query: mdc-feature-any());
@include mdc-menu-width(0, $query: mdc-feature-any());

// Menu surface
@include mdc-menu-surface($query: mdc-feature-any());
@include mdc-menu-surface-fill-color(surface, $query: mdc-feature-any());
@include mdc-menu-surface-ink-color(on-surface, $query: mdc-feature-any());
@include mdc-menu-surface-shape-radius(medium, $query: mdc-feature-any());

// Radio
@include mdc-radio($query: mdc-feature-any());
@include mdc-radio-unchecked-stroke-color(red, $query: mdc-feature-any());
Expand Down