mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
icon directive wip for Ionicons 3.0
This commit is contained in:
@ -1,9 +0,0 @@
|
|||||||
import {App, NavController, IonicView} from 'ionic/ionic';
|
|
||||||
|
|
||||||
@App({
|
|
||||||
templateUrl: 'main.html'
|
|
||||||
})
|
|
||||||
class IonicApp {
|
|
||||||
constructor() {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
<ion-row>
|
|
||||||
<ion-col class="col-33">
|
|
||||||
Hello
|
|
||||||
</ion-col>
|
|
||||||
<ion-col class="col-33">
|
|
||||||
Hello
|
|
||||||
</ion-col>
|
|
||||||
<ion-col class="col-33">
|
|
||||||
Hello
|
|
||||||
</ion-col>
|
|
||||||
</ion-row>
|
|
@ -3,59 +3,15 @@ import {Directive, View, NgClass, ElementRef, Optional, Host, Attribute, Rendere
|
|||||||
import {IonicConfig} from '../../config/config';
|
import {IonicConfig} from '../../config/config';
|
||||||
import {IonicComponent} from '../../config/annotations';
|
import {IonicComponent} from '../../config/annotations';
|
||||||
import {Ion} from '../ion';
|
import {Ion} from '../ion';
|
||||||
import {Platform} from '../../platform/platform';
|
|
||||||
import {Button} from '../button/button';
|
import {Button} from '../button/button';
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
'home': {
|
|
||||||
ios: ['ion-ios-home', 'ion-ios-home-outline'],
|
|
||||||
md: 'ion-md-home'
|
|
||||||
}
|
|
||||||
|
|
||||||
1-for-1 swap
|
|
||||||
Map of stuff that's 1-for-1
|
|
||||||
<icon name="home"></icon>
|
|
||||||
<icon class="ion-ios-home"></icon>
|
|
||||||
<icon class="ion-md-home"></icon>
|
|
||||||
|
|
||||||
|
|
||||||
Always use the same no matter what
|
|
||||||
Cuz it's not in the map of 1-for-1's
|
|
||||||
<icon name="alert"></icon>
|
|
||||||
<icon class="ion-alert"></icon>
|
|
||||||
|
|
||||||
|
|
||||||
Different between modes
|
|
||||||
Used different attributes
|
|
||||||
<icon ios-name="search3" md-name="search2"></icon>
|
|
||||||
<icon class="ion-ios-search3"></icon>
|
|
||||||
<icon class="ion-md-search2"></icon>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Ionicons SVG
|
|
||||||
<icon svg="home"></icon>
|
|
||||||
<icon><svg>...ios...</svg></icon>
|
|
||||||
<icon><svg>...md...</svg></icon>
|
|
||||||
|
|
||||||
|
|
||||||
Custom SVG File
|
|
||||||
<icon svg-src="home.svg"></icon>
|
|
||||||
|
|
||||||
|
|
||||||
Custom Font Icon
|
|
||||||
<icon class="fa-home"></icon>
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: 'icon',
|
selector: 'icon',
|
||||||
properties: [
|
properties: [
|
||||||
'name',
|
'name',
|
||||||
'iconName'
|
'ios',
|
||||||
|
'md'
|
||||||
],
|
],
|
||||||
host: {
|
host: {
|
||||||
'[attr.aria-label]': 'label',
|
'[attr.aria-label]': 'label',
|
||||||
@ -63,21 +19,24 @@ Custom Font Icon
|
|||||||
'role': 'img'
|
'role': 'img'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export class IconDirective {
|
export class Icon {
|
||||||
constructor(
|
constructor(
|
||||||
private _elementRef: ElementRef,
|
private elementRef: ElementRef,
|
||||||
@Optional() @Host() hostButton: Button,
|
@Optional() @Host() hostButton: Button,
|
||||||
@Attribute('forward') forward: string,
|
|
||||||
config: IonicConfig,
|
config: IonicConfig,
|
||||||
private renderer: Renderer
|
private renderer: Renderer
|
||||||
) {
|
) {
|
||||||
let ele = this.ele = _elementRef.nativeElement;
|
let ele = elementRef.nativeElement;
|
||||||
|
|
||||||
|
this.mode = config.setting('mode');
|
||||||
this.iconLeft = this.iconRight = this.iconOnly = false;
|
this.iconLeft = this.iconRight = this.iconOnly = false;
|
||||||
this.ariaHidden = true;
|
this.ariaHidden = true;
|
||||||
|
|
||||||
if (forward !== null) {
|
this.iconAttr = null;
|
||||||
this.iconFwd = config.setting('iconForward');
|
for (let i = 0, l = ele.attributes.length; i < l; i++) {
|
||||||
|
if (ele.attributes[i].value === '') {
|
||||||
|
this.iconAttr = ele.attributes[i].name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostButton) {
|
if (hostButton) {
|
||||||
@ -103,13 +62,20 @@ export class IconDirective {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onInit() {
|
onInit() {
|
||||||
if (this.iconFwd) {
|
if (this.mode == 'ios' && this.ios) {
|
||||||
this.name = this.iconFwd;
|
this.name = this.ios;
|
||||||
|
|
||||||
|
} else if (this.mode == 'md' && this.md) {
|
||||||
|
this.name = this.md;
|
||||||
|
|
||||||
|
} else if (!this.name && this.iconAttr) {
|
||||||
|
this.name = this.iconAttr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.name) return;
|
if (!this.name) return;
|
||||||
|
|
||||||
// add the css class to show the icon font
|
// add the css class to show the icon font
|
||||||
this.renderer.setElementClass(this._elementRef, this.name, true);
|
this.renderer.setElementClass(this.elementRef, this.name, true);
|
||||||
|
|
||||||
// hide the icon when it's within a button
|
// hide the icon when it's within a button
|
||||||
// and the button isn't an icon only button
|
// and the button isn't an icon only button
|
||||||
@ -123,36 +89,4 @@ export class IconDirective {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onDestroy() {
|
|
||||||
this.ele = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@IonicComponent({
|
|
||||||
selector: 'ion-icon',
|
|
||||||
properties: [
|
|
||||||
'md',
|
|
||||||
'ios'
|
|
||||||
],
|
|
||||||
host: {
|
|
||||||
'mode': 'mode'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@View({
|
|
||||||
template: '<i class="icon" [ng-class]="iconClass">',
|
|
||||||
directives: [NgClass]
|
|
||||||
})
|
|
||||||
export class Icon extends Ion {
|
|
||||||
constructor(elementRef: ElementRef, ionicConfig: IonicConfig) {
|
|
||||||
super(elementRef, ionicConfig);
|
|
||||||
}
|
|
||||||
onIonInit() {
|
|
||||||
this.iconClass = this.ios;
|
|
||||||
console.log('ICON', this.mode);
|
|
||||||
setTimeout(() => {
|
|
||||||
console.log('MODE', this.mode);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
11
ionic/components/icon/test/basic/index.ts
Normal file
11
ionic/components/icon/test/basic/index.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import {App} from 'ionic/ionic';
|
||||||
|
|
||||||
|
|
||||||
|
@App({
|
||||||
|
templateUrl: 'main.html'
|
||||||
|
})
|
||||||
|
class E2EApp {
|
||||||
|
constructor() {
|
||||||
|
this.homeIcon = 'ion-home';
|
||||||
|
}
|
||||||
|
}
|
28
ionic/components/icon/test/basic/main.html
Normal file
28
ionic/components/icon/test/basic/main.html
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
<ion-row>
|
||||||
|
<ion-col>
|
||||||
|
|
||||||
|
<icon ion-home></icon>
|
||||||
|
|
||||||
|
</ion-col>
|
||||||
|
<ion-col>
|
||||||
|
|
||||||
|
<icon name="ion-home"></icon>
|
||||||
|
|
||||||
|
</ion-col>
|
||||||
|
<ion-col>
|
||||||
|
|
||||||
|
<icon [name]="homeIcon"></icon>
|
||||||
|
|
||||||
|
</ion-col>
|
||||||
|
<ion-col>
|
||||||
|
|
||||||
|
<icon ios="ion-social-apple" md="ion-social-android"></icon>
|
||||||
|
|
||||||
|
</ion-col>
|
||||||
|
<ion-col>
|
||||||
|
|
||||||
|
<icon ion-social-twitter></icon>
|
||||||
|
|
||||||
|
</ion-col>
|
||||||
|
</ion-row>
|
@ -10,7 +10,6 @@ import {
|
|||||||
Card, List, ListHeader, Item, ItemGroup, ItemGroupTitle,
|
Card, List, ListHeader, Item, ItemGroup, ItemGroupTitle,
|
||||||
Toolbar,
|
Toolbar,
|
||||||
Icon,
|
Icon,
|
||||||
IconDirective,
|
|
||||||
Checkbox, Switch,
|
Checkbox, Switch,
|
||||||
TextInput, TextInputElement, Label,
|
TextInput, TextInputElement, Label,
|
||||||
Segment, SegmentButton, SegmentControlValueAccessor,
|
Segment, SegmentButton, SegmentControlValueAccessor,
|
||||||
@ -59,7 +58,6 @@ export const IonicDirectives = [
|
|||||||
|
|
||||||
// Media
|
// Media
|
||||||
forwardRef(() => Icon),
|
forwardRef(() => Icon),
|
||||||
forwardRef(() => IconDirective),
|
|
||||||
|
|
||||||
// Forms
|
// Forms
|
||||||
forwardRef(() => Segment),
|
forwardRef(() => Segment),
|
||||||
|
Reference in New Issue
Block a user