Theming your own component doc incorrectly references pre-built theme
See original GitHub issueBug, feature request, or proposal:
Bug/Incorrect Documentation
What is the expected behavior?
According to the theming your components documentation you should be able to use pre-built themes with your custom components
// Import a pre-built theme
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
// Import your custom input theme file so you can call the custom-input-theme function
@import 'app/candy-carousel/candy-carousel-theme.scss';
// Using the $theme variable from the pre-built theme you can call the theming function
@include candy-carousel-theme($theme);
What is the current behavior?
The Sass compiler throws an error : Undefined variable: "$theme"
What are the steps to reproduce?
Componet Theme scss:
@import '~@angular/material/theming';
@mixin my-component-theme($theme) {
$primary: map-get($theme, primary);
my-component{
background-color: mat-color($primary);
}
}
Styles.scss
@import '~@angular/material/prebuilt-themes/indigo-pink.css';
@import './path/to/my-component.theme';
@include my-component-theme($theme);
What is the use-case or motivation for changing an existing behavior?
While this isn’t as much of a problem with components that are defined in an application as you can define your own theme, it IS a major issue when creating component libraries that will be consumed by other applications that may choose to use a pre-built theme.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular: 4.1.3 Material: Beta 6
Is there anything else we should know?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:23 (8 by maintainers)
Top Results From Across the Web
Angular 13: Angular Material 13 custom theme throwing error
It seems that material needs at least hue: 100, hue 500 and hue 700 (probably for functions like lighter etc). I had the...
Read more >Theming your own components - Angular Material
Theme your own components with Angular Material's theming system. You can use Angular Material's Sass-based theming system for your own custom components.
Read more >Angular Material Theming System - Complete Guide
In this article, we will learn about custom themes, modifying typography and much more ... and we will apply custom theme to Angular...
Read more >Theme your angular application with angular material library
A theme is the set of colors that will be applied to the Angular Material components. In Angular Material, a theme is created...
Read more >How to make a custom theme in Angular Material
Every single color reference needs a separate .theme.scss file. · custom-theme.scss must know exactly which components provide custom themes.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you all to the contributions to this thread, after fighting with the docs this was a very useful resource. I would appreciate confirmation that my understanding of the approach is correct, and specifically does not import the mat-core and angular-material-theme multiple times.
theme_variables.scss
theme.scss
styles.scss
nav.component.scss
.angular-cli.json
I suppose my concern is that the nav component imports the theme_variables which imports angular/material/theming but I cannot see how to accomplish without.
I must agree that the docs behind theming custom components are pretty confusing.
I want to create a custom component (much like angular button etc.) which would work with the current theme’s
$primary
&$accent
colors. This component would be packaged and then consumed by target app (so the component should not have a theme, but use the theme of target app).So what is the correct way to do this?