-
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
feat(checkbox): Add color attribute. #1463
Conversation
.md-checkbox-background { | ||
background-color: $checkbox-background-color-primary; | ||
} | ||
} |
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.
It would be a little more concise as
.md-checkbox-indeterminate, .md-checkbox-checked {
&.primary .md-checkbox-background {
background: md-color($primary, 500);
}
...
}
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.
Done if you meant &.md-primary
instead of &.primary
.
MdButton
also uses the CSS classes md-primary
, md-accent
and md-warn
.
$checkbox-background-color: md-color($accent, 500); | ||
$checkbox-background-color-primary: md-color($primary, 500); | ||
$checkbox-background-color-accent: md-color($accent, 500); | ||
$checkbox-background-color-warn: md-color($warn, 500); |
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 don't think these variables are necessary; you can use md-color
directly where its needed.
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.
Done.
.md-ink-ripple { | ||
background-color: md-color($primary, 0.26); | ||
} | ||
} |
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.
It would also be a little more concise as
.md-checkbox-focused {
&.primary .md-ink-ripple {
background: md-color($primary, 0.26);
}
...
}
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.
Done if you meant &.md-primary
instead of &.primary
.
MdButton
also uses the CSS classes md-primary
, md-accent
and md-warn
.
|
||
// Animation | ||
transition: background $swift-ease-out-duration $swift-ease-out-timing-function, | ||
md-elevation-transition-property-value(); |
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.
Why is md-elevation-transition-property-value
here? This was only meant to be used with elevation
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.
Here it's used in the same way. _button-base.scss
@@ -128,11 +128,15 @@ export class MdCheckbox implements ControlValueAccessor { | |||
|
|||
private _indeterminate: boolean = false; | |||
|
|||
private _color: string; |
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.
You can just say private _color: string = 'accent';
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.
Unfortunately that alone won't do the magic. The md-checkbox
DOM element has to get the class md-accent
. To achieve this you have the following options:
- Add one of these lines to the constructor (All are somehow weird calls):
this.color = 'accent';
this._updateColor(this._color)
this._setElementColor(this._color, true)
this._renderer.setElementClass(this._elementRef.nativeElement,
md-${this._color}, true);
- Alternative way: Modify the theme css like this (Introduce a "base" color):
.md-checkbox-indeterminate, .md-checkbox-checked {
.md-checkbox-background {
background-color: md-color($accent, 500);
}
&.md-primary .md-checkbox-background {
background-color: md-color($primary, 500);
}
...
}
Which option do you think is the best? Have a missed an option?
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 Any thoughts on this?
LGTM I'm not sure we'll keep all of the |
Now that this is merged, how do I actually change the color of the checkbox? I have tried doing this - <md-checkbox [checked]="(task.state == 'STATE_CLEARED')" color="red"></md-checkbox> All it does is to add the .mat-red .mat-checkbox-background {
background-color: red;
} But the selectors get converted to I don't want to define global styles for this. |
@jaibatrik your color options are |
Oh. But what if I want my checkbox to be colored red? Or any custom color? Is there any way to do it? Let's suppose none of primary, accent, and warn are red in my theme. |
In that case, global styles or the If you're still unable to get the override, make sure your selectors have a higher specificity than the original selector. |
Just so that others can know, I was able to achieve this by using the .mat-red.mat-checkbox-checked /deep/ .mat-checkbox-background {
background-color: red;
} According to the docs, Thanks! |
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. |
Fixes #947
Do you any suggestions how improve setting the default value?
(
src/lib/checkbox/checkbox.ts
line 138)