diff --git a/ionic/components/segment/extensions/ios.scss b/ionic/components/segment/extensions/ios.scss index 2d113d64c0..bb3e46861d 100644 --- a/ionic/components/segment/extensions/ios.scss +++ b/ionic/components/segment/extensions/ios.scss @@ -1,6 +1,6 @@ .platform-ios { - ion-segment { + .ion-segment { > .button { border-width: 2px; @@ -16,10 +16,10 @@ border-style: solid; border-color: get-color(primary, base); - &:first-child { + &:first-of-type { border-right-width: 0px; } - &:last-child { + &:last-of-type { border-left-width: 0px; } } diff --git a/ionic/components/segment/segment.js b/ionic/components/segment/segment.js index 6f0259558a..5b4c8b6949 100644 --- a/ionic/components/segment/segment.js +++ b/ionic/components/segment/segment.js @@ -1,29 +1,100 @@ -import {NgElement, Component, View, Decorator} from 'angular2/angular2' +import {NgElement, Renderer, ElementRef, Component, DefaultValueAccessor, View, Ancestor, Optional, Decorator, Directive} from 'angular2/angular2' +import {dom} from 'ionic/util'; import {IonicComponent} from 'ionic/config/component' import {Button} from 'ionic/components/button/button' @Component({ - selector: 'ion-segment' + selector: 'ion-segment', + hostListeners: { + 'click': 'buttonClicked($event)' + } }) @View({ - template: `
+ template: `
`, - directives: [Button] + directives: [Button, SegmentButton] }) export class Segment { constructor( - @NgElement() ngElement:NgElement + @NgElement() ngElement:NgElement, + elementRef: ElementRef, + renderer: Renderer ) { this.domElement = ngElement.domElement - this.config = Button.config.invoke(this) + this.config = Segment.config.invoke(this) + this.elementRef = elementRef; + this.renderer = renderer; + + this.buttons = []; + } + + bindButton(segmentValue) { + this.buttons.push(segmentValue); + let index = this.buttons.length; + console.log('Bound button', index); + } + + register(segmentButton) { + this.buttons.push(segmentButton); + } + + selected(event, segmentButton) { + for(let button of this.buttons) { + button.setActive(false); + } + segmentButton.setActive(true); + } +} + +new IonicComponent(Segment, { +}); + +@Component({ + selector: 'ion-segment-button', + hostListeners: { + 'click': 'buttonClicked($event)' + }, + properties: { + value: 'value' + } +}) +@View({ + template: '' +}) +/* +@Directive({ + hostListeners: { + mouseover: 'buttonClicked' + } +}) +*/ +export class SegmentButton { + constructor( + @Ancestor() segment: Segment, + @NgElement() ngElement:NgElement, + elementRef: ElementRef, + renderer: Renderer + ) { + this.domElement = ngElement.domElement + this.segment = segment; + + segment.register(this); + } + + setActive(isActive) { + // TODO: No domElement + if(isActive) { + this.domElement.classList.add('active'); + } else { + this.domElement.classList.remove('active'); + } } buttonClicked(event) { - console.log('Button clicked', event); + this.segment.selected(event, this); } + } -new IonicComponent(Segment, { -}) diff --git a/ionic/components/segment/segment.scss b/ionic/components/segment/segment.scss index 71fa929d9e..ca7ef7582f 100644 --- a/ionic/components/segment/segment.scss +++ b/ionic/components/segment/segment.scss @@ -1,4 +1,6 @@ -ion-segment { +ion-segment { display: block; } + +.ion-segment { @include flex-display(); @include flex(1); width: 100%; @@ -27,10 +29,10 @@ ion-segment { color: white; } - &:first-child { + &:first-of-type { border-radius: $button-border-radius 0px 0px $button-border-radius; } - &:last-child { + &:last-of-type { border-right-width: 1px; border-radius: 0px $button-border-radius $button-border-radius 0px; } diff --git a/ionic/components/segment/test/basic/main.html b/ionic/components/segment/test/basic/main.html index b03c220265..c8d1618241 100644 --- a/ionic/components/segment/test/basic/main.html +++ b/ionic/components/segment/test/basic/main.html @@ -1,13 +1,29 @@ + -