-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(material-experimental/mdc-radio): add functionality and styling
- Loading branch information
1 parent
39dd216
commit fd0e995
Showing
13 changed files
with
1,317 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,63 @@ | ||
<h1>Basic Example</h1> | ||
<section class="demo-section"> | ||
<mat-radio-button name="group1">Option 1</mat-radio-button> | ||
<mat-radio-button name="group1" checked>Option 1</mat-radio-button> | ||
<mat-radio-button name="group1">Option 2</mat-radio-button> | ||
<mat-radio-button name="group1" disabled>Option 3 (Disabled)</mat-radio-button> | ||
<mat-radio-button name="group1" disabled="true">Option 3 (disabled)</mat-radio-button> | ||
</section> | ||
|
||
<h1>Color Example</h1> | ||
<section class="demo-section"> | ||
<mat-radio-button name="group2">Default (accent)</mat-radio-button> | ||
<mat-radio-button name="group2" color="primary">Primary</mat-radio-button> | ||
<mat-radio-button name="group2" color="accent">Accent</mat-radio-button> | ||
<mat-radio-button name="group2" color="warn">Warn</mat-radio-button> | ||
</section> | ||
|
||
<h1>Group Color Example</h1> | ||
<section class="demo-section"> | ||
<mat-radio-group color="warn"> | ||
<mat-radio-button name="group3" value="1">Option 1</mat-radio-button> | ||
<mat-radio-button name="group3" value="2">Option 2</mat-radio-button> | ||
<mat-radio-button name="group3" value="3">Option 3</mat-radio-button> | ||
<mat-radio-button name="group3" value="4" color="primary">Option with color override</mat-radio-button> | ||
</mat-radio-group> | ||
</section> | ||
|
||
<h1>Dynamic Example</h1> | ||
<section class="demo-section"> | ||
<div> | ||
<span>isDisabled: {{isDisabled}}</span> | ||
<button mat-raised-button (click)="isDisabled=!isDisabled" class="demo-button"> | ||
Disable buttons | ||
</button> | ||
</div> | ||
<div> | ||
<span>isRequired: {{isRequired}}</span> | ||
<button mat-raised-button (click)="isRequired=!isRequired" class="demo-button"> | ||
Require buttons | ||
</button> | ||
</div> | ||
<div> | ||
<span><mat-checkbox [(ngModel)]="isAlignEnd">Align end</mat-checkbox></span> | ||
</div> | ||
<mat-radio-group | ||
name="my_options" | ||
[disabled]="isDisabled" | ||
[required]="isRequired" | ||
[labelPosition]="isAlignEnd ? 'after' : 'before'"> | ||
<mat-radio-button value="option_1">Option 1</mat-radio-button> | ||
<mat-radio-button value="option_2">Option 2</mat-radio-button> | ||
<mat-radio-button value="option_3">Option 3</mat-radio-button> | ||
</mat-radio-group> | ||
</section> | ||
|
||
<h1>Favorite Season Example</h1> | ||
<h2>Dynamic Example with two-way data-binding</h2> | ||
<section class="demo-section"> | ||
<mat-radio-group name="more_options" [(ngModel)]="favoriteSeason"> | ||
<mat-radio-button *ngFor="let season of seasonOptions" name="more_options" [value]="season"> | ||
{{season}} | ||
</mat-radio-button> | ||
</mat-radio-group> | ||
<p>Your favorite season is: {{favoriteSeason}}</p> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
// TODO: copy in demo styles from existing mat-radio demo. | ||
.demo-button { | ||
margin: 8px; | ||
text-transform: uppercase; | ||
} | ||
|
||
.demo-section { | ||
margin: 8px; | ||
padding: 16px; | ||
|
||
.mat-radio-button { | ||
margin: 8px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,38 @@ | ||
@import '../mdc-helpers/mdc-helpers'; | ||
@import '@material/radio/mixins'; | ||
@import '@material/radio/variables'; | ||
|
||
@mixin mat-radio-theme-mdc($theme) { | ||
// Save original values of MDC global variables. We need to save these so we can restore the | ||
// variables to their original values and prevent unintended side effects from using this mixin. | ||
$orig-mdc-radio-baseline-theme-color: $mdc-radio-baseline-theme-color; | ||
|
||
@include mat-using-mdc-theme($theme) { | ||
// TODO: MDC theme styles here. | ||
$mdc-radio-baseline-theme-color: primary !global; | ||
|
||
.mat-mdc-radio-button { | ||
&.mat-primary { | ||
@include mdc-radio-without-ripple($query: $mat-theme-styles-query); | ||
} | ||
|
||
&.mat-accent { | ||
$mdc-radio-baseline-theme-color: secondary !global; | ||
@include mdc-radio-without-ripple($query: $mat-theme-styles-query); | ||
} | ||
|
||
&.mat-warn { | ||
$mdc-radio-baseline-theme-color: error !global; | ||
@include mdc-radio-without-ripple($query: $mat-theme-styles-query); | ||
} | ||
} | ||
} | ||
|
||
// Restore original values of MDC global variables. | ||
$mdc-radio-baseline-theme-color: $orig-mdc-radio-baseline-theme-color !global; | ||
} | ||
|
||
@mixin mat-radio-typography-mdc($config) { | ||
@include mat-using-mdc-typography($config) { | ||
// TODO: MDC typography styles here. | ||
@include mdc-radio-without-ripple($query: $mat-typography-styles-query); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,34 @@ | ||
<div class="mdc-form-field"> | ||
<div class="mdc-form-field" #formField | ||
[class.mdc-form-field--align-end]="labelPosition == 'before'"> | ||
<div class="mdc-radio" [ngClass]="_classes"> | ||
<input class="mdc-radio__native-control" type="radio" [id]="inputId" [disabled]="disabled"> | ||
<input #input class="mdc-radio__native-control" type="radio" | ||
[id]="inputId" | ||
[checked]="checked" | ||
[disabled]="disabled" | ||
[tabIndex]="tabIndex" | ||
[attr.name]="name" | ||
[attr.value]="value" | ||
[required]="required" | ||
[attr.aria-label]="ariaLabel" | ||
[attr.aria-labelledby]="ariaLabelledby" | ||
[attr.aria-describedby]="ariaDescribedby" | ||
(change)="_onInputChange($event)" | ||
(click)="_onInputClick($event)"> | ||
<div class="mdc-radio__background"> | ||
<div class="mdc-radio__outer-circle"></div> | ||
<div class="mdc-radio__inner-circle"></div> | ||
</div> | ||
<div class="mdc-radio__ripple"></div> | ||
<div mat-ripple class="mat-radio-ripple" | ||
[matRippleTrigger]="formField" | ||
[matRippleDisabled]="_isRippleDisabled()" | ||
[matRippleCentered]="true" | ||
[matRippleRadius]="20" | ||
[matRippleAnimation]="{enterDuration: 150}"> | ||
<div class="mat-ripple-element mat-radio-persistent-ripple"></div> | ||
</div> | ||
</div> | ||
<label [for]="inputId" #label> | ||
<label [for]="inputId"> | ||
<ng-content></ng-content> | ||
</label> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
@import '@material/radio/mixins.import'; | ||
@import '@material/radio/variables.import'; | ||
@import '@material/form-field/mixins.import'; | ||
@import '../mdc-helpers/mdc-helpers'; | ||
|
||
|
||
@include mdc-radio-without-ripple($query: $mat-base-styles-query); | ||
@include mdc-form-field-core-styles($query: $mat-base-styles-query); | ||
|
||
.mat-mdc-radio-button .mat-radio-ripple { | ||
position: absolute; | ||
left: calc(50% - #{$mdc-radio-icon-size}); | ||
top: calc(50% - #{$mdc-radio-icon-size}); | ||
height: $mdc-radio-icon-size * 2; | ||
width: $mdc-radio-icon-size * 2; | ||
z-index: 1; | ||
pointer-events: none; | ||
|
||
.mat-ripple-element:not(.mat-radio-persistent-ripple) { | ||
opacity: $mdc-radio-ripple-opacity; | ||
} | ||
} |
Oops, something went wrong.