Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(material/core): simplify structural styles #29269

Merged
merged 1 commit into from
Jun 17, 2024
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
25 changes: 9 additions & 16 deletions src/material/core/option/optgroup.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
@use 'sass:map';
@use '@material/list/evolution-mixins' as mdc-list-mixins;
@use '@material/list/evolution-variables' as mdc-list-variables;
@use '../tokens/m2/mat/optgroup' as tokens-mat-optgroup;
@use '../tokens/token-utils';
@use '../mdc-helpers/mdc-helpers';

.mat-mdc-optgroup {
// These tokens are set on the root option group to make them easier to override.
Expand All @@ -19,20 +15,17 @@
}

.mat-mdc-optgroup-label {
@include mdc-list-mixins.item-base;
@include mdc-list-mixins.item-spacing(
mdc-list-variables.$side-padding, $query: mdc-helpers.$mdc-base-styles-query);

// Set the `min-height` here ourselves, instead of going through
// the `mdc-list-one-line-item-density` mixin, because it sets a `height`
// which doesn't work well with multi-line options.
$height-config: map.get(mdc-list-variables.$one-line-item-density-config, height);
min-height: map.get($height-config, default);
display: flex;
position: relative;
align-items: center;
justify-content: flex-start;
overflow: hidden;
min-height: 48px;
padding: 0 16px;
outline: none;

&.mdc-list-item--disabled {
// This is the same as `mdc-list-mixins.list-disabled-opacity` which
// we can't use directly, because it comes with some selectors.
opacity: mdc-list-variables.$content-disabled-opacity;
opacity: 0.38;
}

// Needs to be overwritten explicitly, because the style can
Expand Down
45 changes: 20 additions & 25 deletions src/material/core/option/option.scss
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
@use 'sass:map';
@use '@angular/cdk';
@use '@material/list/evolution-mixins' as mdc-list-mixins;
@use '@material/list/evolution-variables' as mdc-list-variables;
@use '@material/typography/typography' as mdc-typography;

@use '../tokens/m2/mat/option' as tokens-mat-option;
@use '../tokens/m2/mdc/list' as tokens-mdc-list;
@use '../tokens/token-utils';
@use '../mdc-helpers/mdc-helpers';
@use '../style/vendor-prefixes';
@use '../style/layout-common';

$_side-padding: 16px;

.mat-mdc-option {
@include mdc-list-mixins.item-base;
@include mdc-list-mixins.item-spacing(
mdc-list-variables.$side-padding, $query: mdc-helpers.$mdc-base-styles-query);
@include vendor-prefixes.user-select(none);
@include mdc-typography.smooth-font();
@include vendor-prefixes.smooth-font();
display: flex;
position: relative;
align-items: center;
justify-content: flex-start;
overflow: hidden;
min-height: 48px;
padding: 0 16px;
cursor: pointer;
-webkit-tap-highlight-color: transparent;

Expand All @@ -38,6 +38,7 @@
&:focus.mdc-list-item,
&.mat-mdc-option-active.mdc-list-item {
@include token-utils.create-token-slot(background-color, focus-state-layer-color);
outline: 0;
}

&.mdc-list-item--selected:not(.mdc-list-item--disabled) {
Expand Down Expand Up @@ -65,12 +66,6 @@
background: transparent;
}

// Set the `min-height` here ourselves, instead of going through
// the `mdc-list-one-line-item-density` mixin, because it sets a `height`
// which doesn't work well with multi-line options.
$height-config: map.get(mdc-list-variables.$one-line-item-density-config, height);
min-height: map.get($height-config, default);

&.mdc-list-item--disabled {
// This is the same as `mdc-list-mixins.list-disabled-opacity` which
// we can't use directly, because it comes with some selectors.
Expand All @@ -84,7 +79,7 @@
// MatOption uses a child `<div>` element for its focus state to align with how ListItem does
// its focus state.
.mat-mdc-option-pseudo-checkbox, .mdc-list-item__primary-text, > mat-icon {
opacity: mdc-list-variables.$content-disabled-opacity;
opacity: 0.38;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like maybe it should come from a token

Copy link
Member Author

Choose a reason for hiding this comment

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

For now I'm focusing on forking off the styles, but once it's done, it should be easy to tokenize it.


// Prevent clicking on disabled options with mouse. Support focusing on disabled option using
Expand All @@ -96,31 +91,31 @@
// Note that we bump the padding here, rather than padding inside the
// group so that ripples still reach to the edges of the panel.
.mat-mdc-optgroup &:not(.mat-mdc-option-multiple) {
padding-left: mdc-list-variables.$side-padding * 2;
padding-left: $_side-padding * 2;

[dir='rtl'] & {
padding-left: mdc-list-variables.$side-padding;
padding-right: mdc-list-variables.$side-padding * 2;
padding-left: $_side-padding;
padding-right: $_side-padding * 2;
}
}

.mat-icon,
.mat-pseudo-checkbox-full {
margin-right: mdc-list-variables.$side-padding;
margin-right: $_side-padding;
flex-shrink: 0;

[dir='rtl'] & {
margin-right: 0;
margin-left: mdc-list-variables.$side-padding;
margin-left: $_side-padding;
}
}

.mat-pseudo-checkbox-minimal {
margin-left: mdc-list-variables.$side-padding;
margin-left: $_side-padding;
flex-shrink: 0;

[dir='rtl'] & {
margin-right: mdc-list-variables.$side-padding;
margin-right: $_side-padding;
margin-left: 0;
}
}
Expand Down Expand Up @@ -169,7 +164,7 @@
content: '';
position: absolute;
top: 50%;
right: mdc-list-variables.$side-padding;
right: $_side-padding;
transform: translateY(-50%);
width: $size;
height: 0;
Expand All @@ -179,7 +174,7 @@

[dir='rtl'] &.mdc-list-item--selected:not(.mat-mdc-option-multiple)::after {
right: auto;
left: mdc-list-variables.$side-padding;
left: $_side-padding;
}
}
}
Expand Down
Loading