Skip to content

feat(material-experimental/mdc-core): add missing color, density, typography mixins #24063

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

Merged
merged 1 commit into from
Dec 9, 2021
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
3 changes: 2 additions & 1 deletion src/material-experimental/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
popover-edit-typography, popover-edit-density, popover-edit-theme;

// MDC-related themes
@forward './mdc-core/core-theme' as mdc-core-* show mdc-core-theme;
@forward './mdc-core/core-theme' as mdc-core-* show mdc-core-theme, mdc-core-color,
mdc-core-density, mdc-core-typography;
@forward './mdc-helpers/focus-indicators-theme' as mdc-strong-focus-indicators-* show
mdc-strong-focus-indicators-color, mdc-strong-focus-indicators-theme;
@forward './mdc-core/option/option-theme' as mdc-option-* show mdc-option-color,
Expand Down
61 changes: 47 additions & 14 deletions src/material-experimental/mdc-core/_core-theme.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,46 @@
@use '../../material/core/theming/theming';
@use '../../material/core/typography/typography';
@use './option/option-theme';
@use './option/optgroup-theme';
@use './elevation';


@mixin color($config-or-theme) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to be the equivalent of the non-MDC core theme? If yes, it needs some more styles like the ripple and pseudo checkbox.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently we don't have an MDC-based ripple or pseudo checkbox. I think this should be everything for now

Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we include the non-MDC ripple here and use this mixin instead of the non-MDC one? Currently we include a bunch of unnecessary styles in the prebuilt themes, because we go through the non-MDC core mixin which contains the typographies of all non-MDC components. If you're blocked on this, it could be done in a follow-up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that would be a good idea, usually people include both the old mixins and new mixins while they're migrating, so if we did that we'd wind up with double the bytes

Copy link
Member

Choose a reason for hiding this comment

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

That's basically what we've been doing with the TS code though.

$config: theming.get-color-config($config-or-theme);

@include option-theme.color($config);
@include optgroup-theme.color($config);

@if $config != null {
// Provides external CSS classes for each elevation value. Each CSS class is formatted as
// `mat-mdc-elevation-z$zValue` where `$zValue` corresponds to the z-space to which the
// element is elevated.
@for $zValue from 0 through 24 {
$selector: elevation.$prefix + $zValue;
// We need the `mat-mdc-elevation-specific`, because some MDC mixins
// come with elevation baked in and we don't have a way of removing it.
.#{$selector}, .mat-mdc-elevation-specific.#{$selector} {
@include elevation.private-theme-elevation($zValue, $config);
}
}
}
}

@mixin typography($config-or-theme) {
$config: typography.private-typography-to-2018-config(
theming.get-typography-config($config-or-theme));

@include option-theme.typography($config-or-theme);
@include optgroup-theme.typography($config-or-theme);
}

@mixin density($config-or-theme) {
$density-scale: theming.get-density-config($config-or-theme);

@include option-theme.density($density-scale);
@include optgroup-theme.density($density-scale);
}

// Mixin that renders all of the core styles that depend on the theme.
@mixin theme($theme-or-color-config) {
$theme: theming.private-legacy-get-theme($theme-or-color-config);
Expand All @@ -12,22 +50,17 @@
// the imported themes (such as `mat-ripple-theme`) should not report again.
@include theming.private-check-duplicate-theme-styles($theme, 'mat-mdc-core') {
$color: theming.get-color-config($theme);

@include option-theme.theme($theme);
@include optgroup-theme.theme($theme);
$density: theming.get-density-config($theme);
$typography: theming.get-typography-config($theme);

@if $color != null {
// Provides external CSS classes for each elevation value. Each CSS class is formatted as
// `mat-mdc-elevation-z$zValue` where `$zValue` corresponds to the z-space to which the
// element is elevated.
@for $zValue from 0 through 24 {
$selector: elevation.$prefix + $zValue;
// We need the `mat-mdc-elevation-specific`, because some MDC mixins
// come with elevation baked in and we don't have a way of removing it.
.#{$selector}, .mat-mdc-elevation-specific.#{$selector} {
@include elevation.private-theme-elevation($zValue, $color);
}
}
@include color($color);
}
@if $density != null {
@include density($density);
}
@if $typography != null {
@include typography($typography);
}
}
}