-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
feat(theming): support font-family css variable #13142
feat(theming): support font-family css variable #13142
Conversation
Before, the material font-family could only be set at application build-time. Now, developers can modify the material font-family at runtime by setting the --mat-font-family css variable. This will greatly improve the application's ability to be themed dynamically at runtime and with WYSIWYG material theme editors. This commit partially addresses this feature request: angular#4352
@return map-merge($config, ( | ||
font-family: $font-family, | ||
use-css-variables: $use-css-variables | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example usage in Angular:
// styles.scss
@import '~@angular/material/theming';
$typography-config: map-merge(
mat-typography-config(),
(use-css-variables: true)
);
@include mat-core($typography-config);
// app.component.ts
@Component({
selector: 'app-root',
template: `
<h1>Font Family CSS Variable Demo</h1>
`
})
export class AppComponent {
constructor(private element: ElementRef) {
this.element.nativeElement.style.setProperty('--mat-font-family', 'Comic Sans MS');
}
}
closing to simplify developer setup using suggested |
Before, the material font-family could only be set at application build-time. Now, developers can modify the material font-family at runtime by setting the --mat-font-family css variable. This will greatly improve the application's ability to be themed dynamically at runtime and with WYSIWYG material theme editors. This commit partially addresses this feature request: angular#4352
// or not supported by the browser | ||
@function css-var($variable, $fallback) { | ||
@return var(--mat-#{$variable}, $fallback); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods can be reused when expanding css variable support to colors
// Creates a CSS rule for font-family using the --mat-font-family css variable | ||
@mixin mat-font-family-css-var($config) { | ||
@include mat-css-var(font-family, font-family, mat-font-family($config)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convenience method to wrap mat-font-family calls and provide the necessary css-variable css rules
Before, the material font-family could only be set at application build-time. Now, developers can modify the material font-family at runtime by setting the --mat-font-family css variable. This will greatly improve the application's ability to be themed dynamically at runtime and with WYSIWYG material theme editors. This commit partially addresses this feature request: angular#4352
Before, the material font-family could only be set at application build-time. Now, developers can modify the material font-family at runtime by setting the --mat-font-family css variable. This will greatly improve the application's ability to be themed dynamically at runtime and with WYSIWYG material theme editors. This commit partially addresses this feature request: angular#4352
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can do this only for font-family
, without getting requests to do it for literally everything else that's using Sass variables at the moment, which we probably can't do, because the fallback approach will balloon the bundle size. The reason we haven't started using CSS variables in the first place is that we have to support IE11 for the foreseeable future.
Thanks for the PR! We unfortunately cannot use CSS variables until we end support for IE11. Once that happens, we will most likely change the entire theming system to use them. See #7374 |
Thank you for the quick feedback! This will be bad news for my client however. I understand this would not be fun to maintain as it would likely necessitate parallel scss partials for all existing component stylesheets. However, I'm still curious if a PR of that nature would be welcome since i will likely be developing the code regardless of whether or not the main angular/material2 repo adopts it : / |
We unfortunately don't have the resources to maintain two parallel sets of theming approaches. If there were tooling that automatically did this, perhaps, but that would be a pretty significant undertaking. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Before, the material font-family could only be set at application build-time. Now, developers can modify the material font-family at runtime by setting the --mat-font-family css variable. This will greatly improve the application's ability to be themed dynamically at runtime and with WYSIWYG material theme editors.
This commit partially addresses this feature request: #4352