-
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
Changes from 1 commit
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); | ||
|
||
|
||
|
@@ -15,7 +16,9 @@ | |
$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); | ||
$checkbox-background-color-primary: md-color($primary, 500); | ||
$checkbox-background-color-accent: md-color($accent, 500); | ||
$checkbox-background-color-warn: md-color($warn, 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 | ||
|
@@ -43,8 +46,22 @@ | |
} | ||
|
||
.md-checkbox-indeterminate, .md-checkbox-checked { | ||
.md-checkbox-background { | ||
background-color: $checkbox-background-color; | ||
&.md-primary { | ||
.md-checkbox-background { | ||
background-color: $checkbox-background-color-primary; | ||
} | ||
} | ||
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 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done if you meant |
||
|
||
&.md-accent { | ||
.md-checkbox-background { | ||
background-color: $checkbox-background-color-accent; | ||
} | ||
} | ||
|
||
&.md-warn { | ||
.md-checkbox-background { | ||
background-color: $checkbox-background-color-warn; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -63,7 +80,23 @@ | |
} | ||
|
||
// 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); | ||
} | ||
} | ||
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);
}
...
} 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(); | ||
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 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; | ||
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 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? 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.
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.