-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change RadioSelectorComponent to not use input radio elements.
- Loading branch information
1 parent
34cbcda
commit 0c88e82
Showing
3 changed files
with
12 additions
and
63 deletions.
There are no files selected for viewing
33 changes: 7 additions & 26 deletions
33
AzureFunctions.AngularClient/src/app/radio-selector/radio-selector.component.html
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,27 +1,8 @@ | ||
<div class="switch" *ngIf="_options && _options.length === 2"> | ||
<input type="radio" | ||
class="switch-input" | ||
name="view" | ||
[attr.id]="_options[0].id" | ||
[checked]="_options[0].value === defaultValue" | ||
(click)="select(_options[0])" | ||
[attr.disabled]="disabled ? true : null"> | ||
|
||
<label [attr.for]="_options[0].id" class="switch-label switch-label-off"> | ||
{{_options[0].displayLabel}} | ||
</label> | ||
|
||
<input type="radio" | ||
class="switch-input" | ||
name="view" | ||
[attr.id]="_options[1].id" | ||
[checked]="_options[1].value === defaultValue" | ||
(click)="select(_options[1])" | ||
[attr.disabled]="disabled ? true : null"> | ||
|
||
<label [attr.for]="_options[1].id" class="switch-label switch-label-on"> | ||
{{_options[1].displayLabel}} | ||
</label> | ||
|
||
<span class="switch-selection"></span> | ||
<div class="switch" *ngIf="options"> | ||
<div *ngFor="let option of options" | ||
class="switch-label" | ||
[class.selected]="option.value === defaultValue" | ||
(click)="select(option)"> | ||
{{option.displayLabel}} | ||
</div> | ||
</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
24 changes: 4 additions & 20 deletions
24
AzureFunctions.AngularClient/src/app/radio-selector/radio-selector.component.ts
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,42 +1,26 @@ | ||
import { Subject } from 'rxjs/Rx'; | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import {SelectOption} from '../shared/models/select-option'; | ||
import { Subject } from 'rxjs/Subject'; | ||
import { SelectOption } from '../shared/models/select-option'; | ||
|
||
@Component({ | ||
selector: 'radio-selector', | ||
templateUrl: './radio-selector.component.html', | ||
styleUrls: ['./radio-selector.component.scss'], | ||
}) | ||
export class RadioSelectorComponent<T> { | ||
@Input() options: SelectOption<T>[]; | ||
@Input() disabled: boolean; | ||
@Input() public defaultValue: T; | ||
@Output() public value: Subject<T>; | ||
public _options: SelectOption<T>[]; | ||
|
||
constructor() { | ||
this.value = new EventEmitter<T>(); | ||
} | ||
|
||
@Input('options') set options(value: SelectOption<T>[]) { | ||
this._options = []; | ||
for (let i = 0; i < value.length; i++) { | ||
this._options.push({ | ||
id: this.getRandomInt(), | ||
displayLabel: value[i].displayLabel, | ||
value: value[i].value | ||
}); | ||
} | ||
} | ||
|
||
select(option: SelectOption<T>) { | ||
if (!this.disabled) { | ||
this.defaultValue = option.value; | ||
this.value.next(option.value); | ||
} | ||
} | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random | ||
getRandomInt() { | ||
let min = 1, max = 10000; | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
} | ||
} |