-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(checkbox): Added radiobutton support for reactive forms
Closes #168
- Loading branch information
Showing
8 changed files
with
103 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./message/message.module"; | ||
export * from "./pagination/pagination.module"; | ||
export * from "./message"; | ||
export * from "./pagination"; |
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 @@ | ||
export * from "./util/util.module"; | ||
export * from "./util"; |
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Directive, AfterContentInit, ContentChildren, QueryList, ElementRef } from "@angular/core"; | ||
import { SuiRadio } from "../components/radio"; | ||
import { Subscription } from "rxjs/Subscription"; | ||
import { Util } from "../../../misc/util"; | ||
|
||
@Directive({ | ||
selector: "form:not([ngForm]):not([[ngForm]]),ngForm,[ngForm]" | ||
}) | ||
export class SuiRadioManager<T> implements AfterContentInit { | ||
|
||
public isNested:boolean; | ||
|
||
@ContentChildren(SuiRadioManager, { descendants: true }) | ||
private _subManagers:QueryList<SuiRadioManager<T>>; | ||
|
||
@ContentChildren(SuiRadio, { descendants: true }) | ||
private _renderedRadios:QueryList<SuiRadio<T>>; | ||
|
||
private _radioSubs:Subscription[]; | ||
|
||
constructor(public element:ElementRef) { | ||
this.isNested = false; | ||
this._radioSubs = []; | ||
} | ||
|
||
public ngAfterContentInit():void { | ||
this.updateNesting(); | ||
this._subManagers.changes.subscribe(() => this.updateNesting()); | ||
|
||
this.updateRadios(); | ||
this._renderedRadios.changes.subscribe(() => this.updateRadios()); | ||
} | ||
|
||
private updateNesting():void { | ||
this._subManagers | ||
.filter(m => m !== this) | ||
.forEach(m => m.isNested = true); | ||
} | ||
|
||
private updateRadios():void { | ||
this._radioSubs.forEach(s => s.unsubscribe()); | ||
this._radioSubs = []; | ||
|
||
const groups = Util.Array.groupBy(this._renderedRadios.toArray(), "name"); | ||
Object | ||
.keys(groups) | ||
.map(k => groups[k]) | ||
.forEach(g => g | ||
.forEach(r => this._radioSubs | ||
.push(r.onCurrentValueChange | ||
.subscribe((v:T) => { | ||
if (!this.isNested) { | ||
g.forEach(radio => radio.writeValue(v)); | ||
} | ||
})))); | ||
} | ||
} |
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,4 +1,6 @@ | ||
export * from "./components/checkbox"; | ||
export * from "./components/radiobutton"; | ||
export * from "./components/radio"; | ||
|
||
export * from "./directives/radio-manager"; | ||
|
||
export * from "./checkbox.module"; |