-
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
Add support for color
attribute to radio
#4039
Changes from all commits
344aabd
eae54b1
ecdaa67
d166384
b08104a
0d39d54
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 |
---|---|---|
|
@@ -9,33 +9,57 @@ | |
$background: map-get($theme, background); | ||
$foreground: map-get($theme, foreground); | ||
|
||
.mat-radio-outer-circle { | ||
border-color: mat-color($foreground, secondary-text); | ||
} | ||
.mat-radio-button { | ||
//default color (accent) | ||
&:not(.mat-primary):not(.mat-accent):not(.mat-warn) { | ||
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 don't think this |
||
@include radio-theme-color($accent, $foreground); | ||
} | ||
|
||
.mat-radio-checked .mat-radio-outer-circle { | ||
border-color: mat-color($accent); | ||
} | ||
&.mat-primary { | ||
@include radio-theme-color($primary, $foreground); | ||
} | ||
|
||
.mat-radio-disabled .mat-radio-outer-circle { | ||
border-color: mat-color($foreground, disabled); | ||
} | ||
&.mat-accent { | ||
@include radio-theme-color($accent, $foreground); | ||
} | ||
|
||
.mat-radio-inner-circle { | ||
background-color: mat-color($accent); | ||
} | ||
&.mat-warn { | ||
@include radio-theme-color($warn, $foreground); | ||
} | ||
} | ||
} | ||
|
||
.mat-radio-ripple .mat-ripple-element { | ||
background-color: mat-color($accent, 0.26); | ||
} | ||
@mixin radio-theme-color($color, $foreground) { | ||
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. This mixin is going to generate a lot of css output; only styles that are directly affected by the palette swap should be defined within. |
||
|
||
.mat-radio-outer-circle { | ||
border-color: mat-color($foreground, secondary-text); | ||
} | ||
|
||
.mat-radio-disabled { | ||
.mat-radio-ripple .mat-ripple-element, .mat-radio-inner-circle { | ||
background-color: mat-color($foreground, disabled); | ||
.mat-radio-checked .mat-radio-outer-circle { | ||
border-color: mat-color($color); | ||
} | ||
|
||
.mat-radio-label-content { | ||
color: mat-color($foreground, disabled); | ||
.mat-radio-disabled .mat-radio-outer-circle { | ||
border-color: mat-color($foreground, disabled); | ||
} | ||
|
||
.mat-radio-inner-circle { | ||
background-color: mat-color($color); | ||
} | ||
|
||
.mat-radio-ripple .mat-ripple-element { | ||
background-color: mat-color($color, 0.26); | ||
} | ||
|
||
.mat-radio-disabled { | ||
.mat-radio-ripple .mat-ripple-element, .mat-radio-inner-circle { | ||
background-color: mat-color($foreground, disabled); | ||
} | ||
|
||
.mat-radio-label-content { | ||
color: mat-color($foreground, disabled); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -369,6 +369,16 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy { | |
this._disabled = coerceBooleanProperty(value); | ||
} | ||
|
||
/** The color of the button. Can be `primary`, `accent`, or `warn`. */ | ||
@Input() | ||
get color(): string { | ||
return this._color; | ||
} | ||
|
||
set color(value: string) { | ||
this._updateColor(value); | ||
} | ||
|
||
/** | ||
* Event emitted when the checked state of this radio button changes. | ||
* Change events are only emitted when the value changes due to user interaction with | ||
|
@@ -396,6 +406,9 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy { | |
/** Whether the ripple effect on click should be disabled. */ | ||
private _disableRipple: boolean; | ||
|
||
/** Current color. Can be `primary`, `accent`, or `warn`. */ | ||
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. The type should use the string literal values private _color: 'primary' | 'accent' | 'warn'; 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. Is there any way to use straight color values like for example |
||
|
||
/** The child ripple instance. */ | ||
@ViewChild(MdRipple) _ripple: MdRipple; | ||
|
||
|
@@ -492,6 +505,22 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy { | |
} | ||
} | ||
|
||
_updateColor(newColor: string) { | ||
this._setElementColor(this._color, false); | ||
this._setElementColor(newColor, true); | ||
this._color = newColor; | ||
} | ||
|
||
_setElementColor(color: string, isAdd: boolean) { | ||
if (color != null && color != '') { | ||
if (isAdd) { | ||
this._renderer.addClass(this._elementRef.nativeElement, `mat-${color}`); | ||
} else { | ||
this._renderer.removeClass(this._elementRef.nativeElement, `mat-${color}`); | ||
} | ||
} | ||
} | ||
|
||
/** Function is called whenever the focus changes for the input element. */ | ||
private _onInputFocusChange(focusOrigin: FocusOrigin) { | ||
if (!this._focusRipple && focusOrigin === 'keyboard') { | ||
|
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.
Our indentation is +2, not +4