-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
update theming docs to be more clear about how to structure your theme file to be usable across custom components #1786
Comments
This is fixed here: https://material.angular.io/guide/theming. This guide is really easy and I got started in 60 seconds. Happy holidays! |
why builder say 'No mixin named md-core'? |
You need to update to the latest version, and put a scss file in your src dir, not @angular/material. Make sure to add the sass file to angularcli.json
…On Feb 8, 2017, 11:04 PM -0500, 김동욱 ***@***.***>, wrote:
why builder say 'No mixin named md-core'?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub (#1786 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AEPIEnGoXQ_3-SoSKl-2x1ty8V-8P-mKks5rapA-gaJpZM4KthhC).
|
i am on latest of master branch, and it seemes that the prefix of names are changed from 'md' to 'mat'. |
/* angular material theming */
@import '~@angular/material/core/theming/all-theme';
@include mat-core();
$app-primary: mat-palette($mat-blue, A400, A100, A700);
$app-accent: mat-palette($mat-pink, A200, A100, A400);
$app-warn: mat-palette($mat-red);
$app-theme: mat-light-theme($app-primary, $app-accent, $app-warn);
@include angular-material-theme($app-theme); now it works! |
Interchangeable
…On Feb 8, 2017, 11:08 PM -0500, 김동욱 ***@***.***>, wrote:
i am on latest of master branch, and it seemes that the prefiex of names are changed from 'md' to 'mat'
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub (#1786 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AEPIElAWzShhC4MUA2JgP5z3URtTQC3Nks5rapEvgaJpZM4KthhC).
|
really? thank you for your help! |
Whatever works.
Wilson Hobbs
CEO/Founder/Developer at Canal
11th Grade at The Lovett School
Personal Information
E-mail: [email protected]
Cell: (404) 719-3252
Website: www.wilsonhobbs.com (https://www.wilsonhobbs.com)
Twitter/Instagram/Facebook: @wbhob
Canal Information
E-mail: [email protected]
Web: www.getcanal.com (https://www.getcanal.com/)
Twitter/Instagram/Facebook: @getcanal
…On Feb 8, 2017, 11:08 PM -0500, 김동욱 ***@***.***>, wrote:
/* angular material theming */ @import ***@***.***/material/core/theming/all-theme'; @include mat-core(); $app-primary: mat-palette($mat-blue, A400, A100, A700); $app-accent: mat-palette($mat-pink, A200, A100, A400); $app-warn: mat-palette($mat-red); $app-theme: mat-light-theme($app-primary, $app-accent, $app-warn); @include angular-material-theme($app-theme);
now it works!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub (#1786 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AEPIEitWt2Qnr8p5hFC-75v7-YenFtaBks5rapFZgaJpZM4KthhC).
|
For me mat-* does not work, but md-* does |
That's because beta.1 still uses |
Also @wbhob no, it's not "fixed", still if you took the code from https://material.angular.io/guide/theming and put it in |
Trust me, the situation is amazing compared to what it was couple of months ago. Also now you have the |
I updated to beta-2 and |
That is correct and by design. |
I feel like I'm really missing something here and I can't figure it out. Can someone please help me?
None of the styling is changing on any of the input fields though. What am I missing? |
The tilde ~ represents the path and doesn't actually work. You'll have to build in the absolute path (./node_modules/@angular/...). Also, I don't think remote origins are supported, so just include them in index.htnl. Finally, this is not the place for support requests, please post on stack overflow or elsewhere @sumnercreations |
Closing this as it's drifted a bit off-topic. AFAIK the two guides on theming on the docs site should provide decent guidance on custom theming and for theming your own components. Feel free to open a new issue if there are any specific problems. |
@jelbourn I still think it's misleading, wrong, and unnecessarily increasing people's bundle sizes, the specific problem I initially described still stands if I follow the directions of https://material.angular.io/guide/theming, that is:
@import '~@angular/material/theming';
// Plus imports for other components in your app.
// Include the base styles for Angular Material core. We include this here so that you only
// have to load a single css file for Angular Material in your app.
@include mat-core();
// Define the palettes for your theme using the Material Design palettes available in palette.scss
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
// hue.
$candy-app-primary: mat-palette($mat-indigo);
$candy-app-accent: mat-palette($mat-pink, A200, A100, A400);
// The warn palette is optional (defaults to red).
$candy-app-warn: mat-palette($mat-red);
// Create the theme object (a Sass map containing all of the palettes).
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn);
// Include theme styles for core and each component used in your app.
// Alternatively, you can import and @include the theme mixins for each component
// that you are using.
@include angular-material-theme($candy-app-theme);
// or whatever is the path to my theme
@import '../../assets/theme'; I do not need to do literally anything else, just this single line is gonna generate all the general m2 styles (elevation, ripple, cdk stuff) and this is gonna happen for every single component you import your that's why it's important to separate @import '~@angular/material/theming';
@include mat-core();
$candy-app-primary: mat-palette($mat-indigo);
$candy-app-accent: mat-palette($mat-pink, A200, A100, A400);
$candy-app-warn: mat-palette($mat-red);
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn); which is what you can safely import in any component, because it itself doesn't generate anything, from @include angular-material-theme($candy-app-theme); which is what you want to include only once in your root component |
Youll notice that the elevations classes are all actually different, and this is generated to create the elevation effect. It is not applied to every component, just available as a class when you need it.
Wilson Hobbs
CEO/Founder/Developer at Canal
11th Grade at The Lovett School
Personal Information
E-mail: [email protected]
Cell: (404) 719-3252
Website: www.wilsonhobbs.com (https://www.wilsonhobbs.com)
Twitter/Instagram/Facebook: @wbhob
Canal Information
E-mail: [email protected]
Web: www.getcanal.com (https://www.getcanal.com/)
Twitter/Instagram/Facebook: @getcanal
…On Apr 10, 2017, 4:34 AM -0400, Aleš ***@***.***>, wrote:
@jelbourn (https://github.com/jelbourn) I still think it's misleading and wrong, and unnecessarily increasing people's bundle sizes, the specific problem I initially described still stands
if I follow the directions of https://material.angular.io/guide/theming, that is:
create my theme.scss, with this content
@import ***@***.***/material/theming'; // Plus imports for other components in your app. // Include the base styles for Angular Material core. We include this here so that you only // have to load a single css file for Angular Material in your app. @include mat-core(); // Define the palettes for your theme using the Material Design palettes available in palette.scss // (imported above). For each palette, you can optionally specify a default, lighter, and darker // hue. $candy-app-primary: mat-palette($mat-indigo); $candy-app-accent: mat-palette($mat-pink, A200, A100, A400); // The warn palette is optional (defaults to red). $candy-app-warn: mat-palette($mat-red); // Create the theme object (a Sass map containing all of the palettes). $candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn); // Include theme styles for core and each component used in your app. // Alternatively, you can import and @include the theme mixins for each component // that you are using. @include angular-material-theme($candy-app-theme);
import it in my component's scss file with @import
// or whatever is the path to my theme @import '../../assets/theme';
now I do not need to do literally anything else, just this single line is gonna generate all the general m2 styles (elevation, ripple, cdk stuff)
and this is gonna happen for every single component you import your theme in!!
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub (#1786 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AEPIEjp-b9Muuq1mu8qEdCK8N8ikmw9iks5ruemJgaJpZM4KthhC).
|
No, that is not true. I have two empty components generated with ng-cli, import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-foo', // bar-foo
templateUrl: './foo.component.html', // bar.component.html
styleUrls: ['./foo.component.scss'] // bar.component.scss
})
export class FooComponent implements OnInit { // BarComponent
constructor() { }
ngOnInit() {
}
}
@import '~@angular/material/theming';
// Plus imports for other components in your app.
// Include the base styles for Angular Material core. We include this here so that you only
// have to load a single css file for Angular Material in your app.
@include mat-core();
// Define the palettes for your theme using the Material Design palettes available in palette.scss
// (imported above). For each palette, you can optionally specify a default, lighter, and darker
// hue.
$candy-app-primary: mat-palette($mat-indigo);
$candy-app-accent: mat-palette($mat-pink, A200, A100, A400);
// The warn palette is optional (defaults to red).
$candy-app-warn: mat-palette($mat-red);
// Create the theme object (a Sass map containing all of the palettes).
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn);
// Include theme styles for core and each component used in your app.
// Alternatively, you can import and @include the theme mixins for each component
// that you are using.
@include angular-material-theme($candy-app-theme); both are printed in the root component since I've removed all other ng-cli styles (the default app.component.css and styles.css), there are only two <style> tags appended to head, for |
You shouldn't have to import he style sheet into every component... it's just globally applied when you put it into your style sheet included in angular-cli.json
Wilson Hobbs
CEO/Founder/Developer at Canal
11th Grade at The Lovett School
Personal Information
E-mail: [email protected]
Cell: (404) 719-3252
Website: www.wilsonhobbs.com (https://www.wilsonhobbs.com)
Twitter/Instagram/Facebook: @wbhob
Canal Information
E-mail: [email protected]
Web: www.getcanal.com (https://www.getcanal.com/)
Twitter/Instagram/Facebook: @getcanal
…On Apr 10, 2017, 6:54 AM -0400, Aleš ***@***.***>, wrote:
No, that is not true.
I have two empty components generated with ng-cli, FooComponent, BarComponent,
import { Component, OnInit } from ***@***.***/core'; @component({ selector: 'app-foo', // bar-foo templateUrl: './foo.component.html', // bar.component.html styleUrls: ['./foo.component.scss'] // bar.component.scss }) export class FooComponent implements OnInit { // BarComponent constructor() { } ngOnInit() { } }
*.component.scss only includes this line @import '../../assets/theme';
theme.scss is c&p from themeing guide
@import ***@***.***/material/theming'; // Plus imports for other components in your app. // Include the base styles for Angular Material core. We include this here so that you only // have to load a single css file for Angular Material in your app. @include mat-core(); // Define the palettes for your theme using the Material Design palettes available in palette.scss // (imported above). For each palette, you can optionally specify a default, lighter, and darker // hue. $candy-app-primary: mat-palette($mat-indigo); $candy-app-accent: mat-palette($mat-pink, A200, A100, A400); // The warn palette is optional (defaults to red). $candy-app-warn: mat-palette($mat-red); // Create the theme object (a Sass map containing all of the palettes). $candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent, $candy-app-warn); // Include theme styles for core and each component used in your app. // Alternatively, you can import and @include the theme mixins for each component // that you are using. @include angular-material-theme($candy-app-theme);
both are printed in the root component
since I've removed all other ng-cli styles (the default app.component.css and styles.css), there are only two <style> tags appended to head, for app-foo and for app-bar
this is content of the first one
this is content of the second one
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (#1786 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AEPIErCFfDUzBsiwnLnca1_DSbPoti9zks5rugpigaJpZM4KthhC).
|
........... that's the whole point, you need to import your https://material.angular.io/guide/theming-your-components if you do this, where you are gonna 28kb of unnecessary styles (after minification) included in your component |
the guide should say that you should define your theme in |
I don't understand why you need it in each component, it's all already globally available
Wilson Hobbs
CEO/Founder/Developer at Canal
11th Grade at The Lovett School
Personal Information
E-mail: [email protected]
Cell: (404) 719-3252
Website: www.wilsonhobbs.com (https://www.wilsonhobbs.com)
Twitter/Instagram/Facebook: @wbhob
Canal Information
E-mail: [email protected]
Web: www.getcanal.com (https://www.getcanal.com/)
Twitter/Instagram/Facebook: @getcanal
…On Apr 10, 2017, 7:06 AM -0400, Aleš ***@***.***>, wrote:
........... that's the whole point, you need to import your theme.scss, if you want to utilise ANY material2 sass helper functions, color palettes
https://material.angular.io/guide/theming-your-components
if you do this, where @import 'src/unicorn-app-theme.scss' is this
you are gonna 28kb of unnecessary styles (after minification) included in your component
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (#1786 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AEPIEpk3dZjraR6u6G3mNhWpHb0ATG1Bks5rug0lgaJpZM4KthhC).
|
Oh that makes sense, still don't see why you need to use functions in individual components, just perform them globally.
Wilson Hobbs
CEO/Founder/Developer at Canal
11th Grade at The Lovett School
Personal Information
E-mail: [email protected]
Cell: (404) 719-3252
Website: www.wilsonhobbs.com (https://www.wilsonhobbs.com)
Twitter/Instagram/Facebook: @wbhob
Canal Information
E-mail: [email protected]
Web: www.getcanal.com (https://www.getcanal.com/)
Twitter/Instagram/Facebook: @getcanal
…On Apr 10, 2017, 7:08 AM -0400, Aleš ***@***.***>, wrote:
the guide should say that you should define your theme in theme.scss, but instead doing @include angular-material-theme($candy-app-theme); in the same file, your should import this theme.scss in your main/global style and call the angular-material-theme function there, only then you can safely import your theme.scss in any component without it generating duplicated files
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (#1786 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AEPIEvL5UIFBfrOwsPioiUkFB1XKT0IOks5rug3LgaJpZM4KthhC).
|
I don't understand why are you commenting if you don't understand. :) If you use webpack (or ng-cli), there's no such thing as globally available sass functions and/or variables, you HAVE to webpack-contrib/sass-loader#218 ..and million other issues. The only thing you can use, are the already generated css classes (ie. elevation), if they are either in your head tag, or in your root component with disabled encapsulation. But that still only allows you to do: <div class="mat-elevation-z1"></div> and not: <div class="foo"></div> .foo {
@include mat-elevation(1);
} |
@fxck thank you so much!!! Same functionality |
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. |
If I took this code https://github.com/angular/material2/blob/master/docs/theming.md#defining-a-custom-theme and put it into
_custom-theme.scss
and included it in my main styles file and then imported it into my components like as shown here https://github.com/angular/material2/blob/master/docs/theming-your-components.md#using-colors-from-a-palleteit would generate unnecessary(since they are already in the main file) classes, like elevation, inside my components's encapsulated css.. which is bad.
The way I see it, your
_custom-theme.scss
should import and contain something along these linesthe main style file should have
thanks to this, you'd be able to import
_custom-theme.scss
anywhere and be able to use palette functions as well as your variables without it generating any duplicated material classesThe text was updated successfully, but these errors were encountered: