-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(checkbox): Add color attribute. #1463
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| $is-dark-theme: map-get($theme, is-dark); | ||
| $primary: map-get($theme, primary); | ||
| $accent: map-get($theme, accent); | ||
| $warn: map-get($theme, warn); | ||
| $background: map-get($theme, background); | ||
|
|
||
|
|
||
|
|
@@ -14,9 +15,6 @@ | |
| // The color of the checkbox's checkmark / mixedmark. | ||
| $checkbox-mark-color: md-color($background, background); | ||
|
|
||
| // The color that is used as the checkbox background when it is checked. | ||
| $checkbox-background-color: md-color($accent, 500); | ||
|
|
||
| // NOTE(traviskaufman): While the spec calls for translucent blacks/whites for disabled colors, | ||
| // this does not work well with elements layered on top of one another. To get around this we | ||
| // blend the colors together based on the base color and the theme background. | ||
|
|
@@ -43,8 +41,16 @@ | |
| } | ||
|
|
||
| .md-checkbox-indeterminate, .md-checkbox-checked { | ||
| .md-checkbox-background { | ||
| background-color: $checkbox-background-color; | ||
| &.md-primary .md-checkbox-background { | ||
| background-color: md-color($primary, 500); | ||
| } | ||
|
|
||
| &.md-accent .md-checkbox-background { | ||
| background-color: md-color($accent, 500); | ||
| } | ||
|
|
||
| &.md-warn .md-checkbox-background { | ||
| background-color: md-color($warn, 500); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -63,7 +69,17 @@ | |
| } | ||
|
|
||
| // TODO(jelbourn): remove style for temporary ripple once the real ripple is applied. | ||
| .md-checkbox-focused .md-ink-ripple { | ||
| background-color: md-color($accent, 0.26); | ||
| .md-checkbox-focused { | ||
| &.md-primary .md-ink-ripple { | ||
| background-color: md-color($primary, 0.26); | ||
| } | ||
|
Member
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 also be a little more concise as .md-checkbox-focused {
&.primary .md-ink-ripple {
background: md-color($primary, 0.26);
}
...
}
Contributor
Author
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. Done if you meant |
||
|
|
||
| &.md-accent .md-ink-ripple { | ||
| background-color: md-color($accent, 0.26); | ||
| } | ||
|
|
||
| &.md-warn .md-ink-ripple { | ||
| background-color: md-color($warn, 0.26); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| @import '../core/theming/theming'; | ||
| @import '../core/style/elevation'; | ||
| @import '../core/style/variables'; | ||
| @import '../core/ripple/ripple'; | ||
|
|
||
|
|
@@ -189,6 +190,10 @@ $_md-checkbox-indeterminate-checked-easing-function: cubic-bezier(0.14, 0, 0, 1) | |
|
|
||
| md-checkbox { | ||
| cursor: pointer; | ||
|
|
||
| // Animation | ||
| transition: background $swift-ease-out-duration $swift-ease-out-timing-function, | ||
| md-elevation-transition-property-value(); | ||
|
Member
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. Why is
Contributor
Author
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. Here it's used in the same way. _button-base.scss |
||
| } | ||
|
|
||
| .md-checkbox-layout { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,11 +128,15 @@ export class MdCheckbox implements ControlValueAccessor { | |
|
|
||
| private _indeterminate: boolean = false; | ||
|
|
||
| private _color: string; | ||
|
Member
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 can just say
Contributor
Author
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. Unfortunately that alone won't do the magic. The
Which option do you think is the best? Have a missed an option?
Contributor
Author
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 Any thoughts on this? |
||
|
|
||
| private _controlValueAccessorChangeFn: (value: any) => void = (value) => {}; | ||
|
|
||
| hasFocus: boolean = false; | ||
|
|
||
| constructor(private _renderer: Renderer, private _elementRef: ElementRef) {} | ||
| constructor(private _renderer: Renderer, private _elementRef: ElementRef) { | ||
| this.color = 'accent'; | ||
| } | ||
|
|
||
| /** | ||
| * Whether the checkbox is checked. Note that setting `checked` will immediately set | ||
|
|
@@ -174,6 +178,28 @@ export class MdCheckbox implements ControlValueAccessor { | |
| } | ||
| } | ||
|
|
||
| /** Sets the color of the checkbox */ | ||
| @Input() | ||
| get color(): string { | ||
| return this._color; | ||
| } | ||
|
|
||
| set color(value: string) { | ||
| this._updateColor(value); | ||
| } | ||
|
|
||
| _updateColor(newColor: string) { | ||
| this._setElementColor(this._color, false); | ||
| this._setElementColor(newColor, true); | ||
| this._color = newColor; | ||
| } | ||
|
|
||
| _setElementColor(color: string, isAdd: boolean) { | ||
| if (color != null && color != '') { | ||
| this._renderer.setElementClass(this._elementRef.nativeElement, `md-${color}`, isAdd); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Implemented as part of ControlValueAccessor. | ||
| * TODO: internal | ||
|
|
||
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
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-primaryinstead of&.primary.MdButtonalso uses the CSS classesmd-primary,md-accentandmd-warn.