From 3437c1d496fea58d6241e401fe7dd055df210d28 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Thu, 23 Jul 2015 16:12:22 -0500 Subject: [PATCH] button icons --- ionic/components/button/button.scss | 13 ---- ionic/components/button/button.ts | 16 ++++- .../button/extensions/material.scss | 1 - ionic/components/button/test/icons/main.html | 62 ++++++++++++------- ionic/components/icon/icon.ts | 53 ++++++++++++++-- ionic/components/modal/test/basic/index.ts | 4 +- 6 files changed, 101 insertions(+), 48 deletions(-) diff --git a/ionic/components/button/button.scss b/ionic/components/button/button.scss index 567ad04326..2ce3b1d45f 100644 --- a/ionic/components/button/button.scss +++ b/ionic/components/button/button.scss @@ -203,19 +203,6 @@ button, margin-top: 0; } -.icon-left:before { - font-size: 1.5em; - margin-top: -0.1em; - margin-right: 0.25em; -} - -.icon-right:before { - order: 2; - font-size: 1.5em; - margin-top: -0.1em; - margin-left: 0.25em; -} - // Button Misc // -------------------------------------------------- diff --git a/ionic/components/button/button.ts b/ionic/components/button/button.ts index 7c023df53a..7d351a169e 100644 --- a/ionic/components/button/button.ts +++ b/ionic/components/button/button.ts @@ -1,14 +1,24 @@ -import {Directive, ElementRef, Optional, Ancestor, onDestroy, NgZone} from 'angular2/angular2'; +import {Directive, ElementRef, Optional, Ancestor, onDestroy, NgZone, Query, QueryList} from 'angular2/angular2'; +import {Icon} from '../icon/icon'; import {IonicConfig} from '../../config/config'; import {Activator} from '../../util/activator'; import * as dom from '../../util/dom'; @Directive({ - selector: 'button,[button]' + selector: 'button,[button]', + host: { + '[class.icon-left]': 'icon.iconLeft', + '[class.icon-right]': 'icon.iconRight', + '[class.icon-only]': 'icon.iconOnly' + } }) -export class Button {} +export class Button { + registerIcon(icon) { + this.icon = icon; + } +} @Directive({ diff --git a/ionic/components/button/extensions/material.scss b/ionic/components/button/extensions/material.scss index aa0eddfe0c..96c9eef2b0 100644 --- a/ionic/components/button/extensions/material.scss +++ b/ionic/components/button/extensions/material.scss @@ -90,7 +90,6 @@ $button-material-border-radius: 3px !default; &.activated { opacity: 1; - background: transparent; } } diff --git a/ionic/components/button/test/icons/main.html b/ionic/components/button/test/icons/main.html index 1a73b0bd3d..385d93110a 100644 --- a/ionic/components/button/test/icons/main.html +++ b/ionic/components/button/test/icons/main.html @@ -2,77 +2,95 @@
- - + + Left Icon
- - + Right Icon +
- - + +
- - + + Left, Large
- - + Right, Large +
- - + +
- - - Left Icon, Small + + + Left, Small
- - - Right Icon, Small + + Right, Small +
- - + +
diff --git a/ionic/components/icon/icon.ts b/ionic/components/icon/icon.ts index b351707df8..9e4b323643 100644 --- a/ionic/components/icon/icon.ts +++ b/ionic/components/icon/icon.ts @@ -1,9 +1,10 @@ -import {Directive, View, CSSClass, ElementRef} from 'angular2/angular2'; +import {Directive, View, CSSClass, ElementRef, Optional, Parent} from 'angular2/angular2'; import {IonicConfig} from '../../config/config'; import {IonicComponent} from '../../config/annotations'; import {Ion} from '../ion'; import {Platform} from '../../platform/platform'; +import {Button} from '../button/button'; /* @@ -58,19 +59,59 @@ Custom Font Icon ], host: { '[attr.aria-label]': 'label', - 'role': 'img' + '[attr.role]': 'role', + '[attr.aria-hidden]': 'hidden' } }) export class IconDirective { - constructor(elementRef: ElementRef) { - this.ele = elementRef.nativeElement; + constructor(elementRef: ElementRef, @Optional() @Parent() parentButton: Button) { + var ele = this.ele = elementRef.nativeElement; + + this.previousText = (ele.previousSibling && ele.previousSibling.textContent || '').trim(); + this.nextText = (ele.nextSibling && ele.nextSibling.textContent || '').trim(); + + if (parentButton) { + this.withinButton = true; + this.iconLeft = !!this.nextText; + this.iconRight = !!this.previousText; + this.iconOnly = !this.iconLeft && !this.iconRight; + + parentButton.registerIcon(this); + } } onInit() { - if (this.name) { - this.ele.classList.add(this.name); + if (!this.name) return; + + // add the css class + this.ele.classList.add(this.name); + + + if (this.withinButton && !this.iconOnly) { + // icon's within a button that has text + this.hidden = true; + + } else { + // either not within a button, or it's not a icon only button + this.role = 'img'; + this.hidden = false; this.label = this.name.replace('ion-', '').replace('ios-', '').replace('md-', '').replace('-', ''); } + + + if (this.iconOnly) { + // this is an icon within a button that has not text label + + } else { + + } + + + + } + + onDestroy() { + this.ele = null; } } diff --git a/ionic/components/modal/test/basic/index.ts b/ionic/components/modal/test/basic/index.ts index 0c490ee4e5..22dc0817fc 100644 --- a/ionic/components/modal/test/basic/index.ts +++ b/ionic/components/modal/test/basic/index.ts @@ -53,9 +53,8 @@ export class ContactModal { @IonicView({ template: ` - First Page Header: {{ val }} + First Page Header -

First Page: {{ val }}

@@ -77,7 +76,6 @@ export class ModalFirstPage { actionMenu: ActionMenu ) { this.nav = nav; - this.val = Math.round(Math.random() * 8999) + 1000; this.modal = modal; this.actionMenu = actionMenu; }