-
Notifications
You must be signed in to change notification settings - Fork 6.8k
(docs) update theming.md #1385
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
(docs) update theming.md #1385
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0e5fc4d
(docs) update theming.md
2ac7813
Added theming-your-components.md
c85eeb0
Update theming.md
f9e30f4
Update theming-your-components.md
7da5872
Update theming-your-components.md
69f6654
Update hteming.md
cee6d39
Update theming-your-components.md
21e80d1
Update theming-your-components.md
2388c76
Update theming-your-components.md
5c1cc1b
Update theming.md
5d82484
Update theming-your-components.md
e3f5ff1
Update theming.md
bdc78ad
Cleaned up and changed as @jelbourn suggested
eb916d3
Update theming-your-components.md
0e1f1a7
Update theming-your-components.md
eda28bb
Update theming-your-components.md
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#Theming your custom components | ||
In order to style your own components with Angular Material's tooling, the component's styles must be defined with Sass. | ||
|
||
## Using `@mixin` to automatically apply a theme | ||
|
||
### Why using `@mixin` | ||
The advantage of using a `@mixin` function is that when you change your theme, every file that uses it will be updated automatically. | ||
Calling it with a different theme argument allow multiple themes within the app or component. | ||
|
||
### How to use `@mixin` | ||
We can better theming our custom components adding a `@mixin` function to its theme file and then calling this function to apply a theme. | ||
|
||
All you need is to create a `@mixin` function in the custom-component-theme.scss | ||
|
||
```sass | ||
// Import all the tools needed to customize the theme and extract parts of it | ||
@import '~@angular/material/core/theming/all-theme'; | ||
|
||
// Define a mixin that accepts a theme and outputs the color styles for the component. | ||
@mixin candy-carousel-theme($theme) { | ||
// Extract whichever individual palettes you need from the theme. | ||
$primary: map-get($theme, primary); | ||
$accent: map-get($theme, accent); | ||
|
||
// Use md-color to extract individual colors from a palette as necessary. | ||
.candy-carousel { | ||
background-color: md-color($primary); | ||
border-color: md-color($accent, A400); | ||
} | ||
} | ||
``` | ||
Now you just have have to call the `@mixin` function to apply the theme: | ||
|
||
```sass | ||
// Import a pre-built theme | ||
@import '~@angular/material/core/theming/prebuilt/deep-purple-amber'; | ||
// 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); | ||
``` | ||
|
||
For more details about the theming functions, see the comments in the | ||
[source](https://github.com/angular/material2/blob/master/src/lib/core/theming/_theming.scss). | ||
|
||
### Best practices using `@mixin` | ||
When using `@mixin`, the theme file should only contain the definitions that are affected by the passed-in theme. | ||
|
||
All styles that are not affected by the theme should be placed in a `candy-carousel.scss` file. This file should contain everything that is not affected by the theme like sizes, transitions... | ||
|
||
Styles that are affected by the theme should be placed in a separated theming file as `_candy-carousel-theme.scss` and the file should have a `_` before the name. This file should contain the `@mixin` function responsible for applying the theme to the component. | ||
|
||
|
||
## Using colors from a pallete | ||
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: | ||
|
||
```scss | ||
// Import theming functions | ||
@import '~@angular/material/core/theming/theming'; | ||
// Import your custom theme | ||
@import 'src/unicorn-app-theme.scss'; | ||
|
||
// Use md-color to extract individual colors from a palette as necessary. | ||
.candy-carousel { | ||
background-color: md-color($candy-app-primary); | ||
border-color: md-color($candy-app-accent, A400); | ||
} | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Rather than making this document much longer, I'd rather create another file
theming-your-components.md
that covers how to theme your own components with the material tools.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.
@jelbourn Ok, I'll do this! But should I use your tiny as possible example or can we provide the example with all that information to theming custom form components?
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 still want to use as small of an example as possible that illustrates the point. Right now, there's just way too much here that distracts from the theming bits.