-
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
(docs) update theming.md #1385
Changes from 12 commits
0e5fc4d
2ac7813
c85eeb0
f9e30f4
7da5872
69f6654
cee6d39
21e80d1
2388c76
5c1cc1b
5d82484
e3f5ff1
bdc78ad
eb916d3
0e1f1a7
eda28bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#Theming your custom components | ||
|
||
In order to style your own components with our tooling, the component's styles must be defined with Sass. | ||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap lines at 100 columns. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The imports for theming should be I'd like to also link to the 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). |
||
For example: | ||
|
||
app/candy-carousel/candy-carousel-theme.scss | ||
|
||
```scss | ||
// Import theming functions and variables | ||
@import '~@angular/material/core/theming/all-theme'; | ||
// Import a pre-built theme | ||
@import '~@angular/material/core/theming/prebuilt/deep-purple-amber'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't ever import a pre-built theme; those are meant to be leaf nodes in the sass build. Instead you could mention importing the theme variables from your own app's theme definition with something like |
||
|
||
// 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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move the mixin approach above this example. I want to encourage people to use the mixin approach in order to make it easier to switch between themes in their app. |
||
``` | ||
|
||
## Using @mixin to automatically apply a theme | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to explain somewhere in this doc the advantage of using a mixin (calling it with a different theme argument to allow multiple themes within the app). We should also mention that, when doing this, the theme file should only contain the definitions that are affected by the passed-in 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space between |
||
@include candy-carousel-theme($theme); | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ secondary dark theme: | |
|
||
$dark-theme: md-dark-theme($dark-primary, $dark-accent, $dark-warn); | ||
|
||
@include angular-material-theme($dark-theme); | ||
@include angular-material-theme($dark-theme); | ||
} | ||
``` | ||
|
||
|
@@ -109,15 +109,25 @@ dark theme. | |
In order to style your own components with our tooling, the component's styles must be defined | ||
with Sass. | ||
|
||
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: | ||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just remove all of the content in this section now and point to the new doc. |
||
|
||
```scss | ||
.unicorn-carousel { | ||
// Import theming functions and variables | ||
@import '~@angular/material/core/theming/all-theme'; | ||
// Import a pre-built theme | ||
@import '~@angular/material/core/theming/prebuilt/deep-purple-amber'; | ||
|
||
// Use md-color to extract individual colors from a palette as necessary. | ||
.candy-carousel { | ||
background-color: md-color($primary); | ||
color: md-color($primary, default-contrast); | ||
border-color: md-color($accent, A400); | ||
} | ||
``` | ||
|
||
You can see a more complete example in [theming-your-components.md][2] | ||
|
||
[2]: https://github.com/angular/material2/blob/master/docs/theming-your-components.md | ||
|
||
### Future work | ||
* Once CSS variables (custom properties) are available in all the browsers we support, | ||
we will explore how to take advantage of them to make theming even simpler. |
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.
Let's change "our tooling" to "Angular Material's tooling"