You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to style your own components with Angular Material's tooling, the component's styles must be defined with Sass.
2
3
3
-
In order to style your own components with our tooling, the component's styles must be defined with Sass.
4
+
## Using `@mixin`to automatically apply a theme
4
5
5
-
You can consume the theming functions from the `@angular/material/core/theming/all-theme` and theming variables from a pre-built theme or a custom one. You can use the `md-color` function to extract a specific color from a palette.
6
-
For example:
6
+
### Why using `@mixin`
7
+
The advantage of using a `@mixin` function is that when you change your theme, every file that uses it will be updated automatically.
8
+
Calling it with a different theme argument allow multiple themes within the app or component.
7
9
8
-
app/candy-carousel/candy-carousel-theme.scss
10
+
### How to use `@mixin`
11
+
We can better theming our custom components adding a `@mixin` function to its theme file and then calling this function to apply a theme.
When using `@mixin`, the theme file should only contain the definitions that are affected by the passed-in theme.
49
+
50
+
All styles that are not affected by the theme should be placed in a `component.scss` file. This file should contain sizes, transitions, positioning and everything that is not affected by the theme.
51
+
52
+
Styles that are affected by the theme should be placed in a separated theming file as `component-theme.scss`. This file should contain the `@mixin` function responsible for applying the theme to the component.
53
+
54
+
55
+
## Using colors from a pallete
56
+
You can consume the theming functions from the `@angular/material/core/theming/theming` and Material pallete vars from `@angular/material/core/theming/palette`. You can use the `md-color` function to extract a specific color from a palette. For example:
57
+
58
+
```scss
59
+
// Import theming functions
60
+
@import'~@angular/material/core/theming/theming';
61
+
// Import your custom theme
62
+
@import'src/unicorn-app-theme.scss';
63
+
64
+
// Use md-color to extract individual colors from a palette as necessary.
With this, any element inside of a parent with the `unicorn-dark-theme` class will use this
106
106
dark theme.
107
107
108
-
### Styling your own components
109
-
In order to style your own components with our tooling, the component's styles must be defined
110
-
with Sass.
111
-
112
-
You can consume the theming functions and variables from the @angular/material/core/theming. You can use the `md-color` function to extract a specific color from a palette. For example:
For more details about theming your own components, see [theming-your-components.md](https://github.com/angular/material2/blob/master/docs/theming-your-components.md)
130
110
131
111
### Future work
132
112
* Once CSS variables (custom properties) are available in all the browsers we support,
0 commit comments