mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 04:53:58 +08:00
@ -2,6 +2,7 @@ import {Component, ElementRef, Renderer, Attribute, Optional, Input} from 'angul
|
|||||||
|
|
||||||
import {Config} from '../../config/config';
|
import {Config} from '../../config/config';
|
||||||
import {Toolbar} from '../toolbar/toolbar';
|
import {Toolbar} from '../toolbar/toolbar';
|
||||||
|
import {isTrueProperty} from '../../util/util';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,10 +46,10 @@ export class Button {
|
|||||||
private _style: string = 'default'; // outline/clear/solid
|
private _style: string = 'default'; // outline/clear/solid
|
||||||
private _shape: string = null; // round/fab
|
private _shape: string = null; // round/fab
|
||||||
private _display: string = null; // block/full
|
private _display: string = null; // block/full
|
||||||
private _lastColor: string = null;
|
|
||||||
private _colors: Array<string> = []; // primary/secondary
|
private _colors: Array<string> = []; // primary/secondary
|
||||||
private _icon: string = null; // left/right/only
|
private _icon: string = null; // left/right/only
|
||||||
private _disabled: boolean = false; // disabled
|
private _disabled: boolean = false; // disabled
|
||||||
|
private _init: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@ -56,9 +57,97 @@ export class Button {
|
|||||||
isItem: boolean;
|
isItem: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @input {string} Large button.
|
||||||
*/
|
*/
|
||||||
@Input() color: string;
|
@Input()
|
||||||
|
set large(val: boolean) {
|
||||||
|
this._attr('_size', 'large', val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @input {string} Small button.
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
set small(val: boolean) {
|
||||||
|
this._attr('_size', 'small', val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @input {string} Default button.
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
set default(val: boolean) {
|
||||||
|
this._attr('_size', 'default', val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @input {string} A transparent button with a border.
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
set outline(val: boolean) {
|
||||||
|
this._attr('_style', 'outline', val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @input {string} A transparent button without a border.
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
set clear(val: boolean) {
|
||||||
|
this._attr('_style', 'clear', val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @input {string} Force a solid button. Useful for buttons within an item.
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
set solid(val: boolean) {
|
||||||
|
this._attr('_style', 'solid', val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @input {string} A button with rounded corners.
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
set round(val: boolean) {
|
||||||
|
this._attr('_shape', 'round', val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @input {string} A button that fills its parent container with a border-radius.
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
set block(val: boolean) {
|
||||||
|
this._attr('_display', 'block', val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @input {string} A button that fills its parent container without a border-radius or borders on the left/right.
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
set full(val: boolean) {
|
||||||
|
this._attr('_display', 'full', val);
|
||||||
|
}
|
||||||
|
|
||||||
|
_attr(type: string, attrName: string, attrValue: boolean) {
|
||||||
|
this._setClass(this[type], false);
|
||||||
|
if (isTrueProperty(attrValue)) {
|
||||||
|
this[type] = attrName;
|
||||||
|
this._setClass(attrName, true);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this[type] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @input {string} Dynamically set which color attribute this button should use.
|
||||||
|
*/
|
||||||
|
@Input()
|
||||||
|
set color(val: string) {
|
||||||
|
this._assignCss(false);
|
||||||
|
this._colors = [val];
|
||||||
|
this._assignCss(true);
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
config: Config,
|
config: Config,
|
||||||
@ -92,26 +181,11 @@ export class Button {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ngAfterContentInit() {
|
ngAfterContentInit() {
|
||||||
this._lastColor = this.color;
|
this._init = true;
|
||||||
if (this.color) {
|
|
||||||
this._colors = [this.color];
|
|
||||||
}
|
|
||||||
this._readIcon(this._elementRef.nativeElement);
|
this._readIcon(this._elementRef.nativeElement);
|
||||||
this._assignCss(true);
|
this._assignCss(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
ngAfterContentChecked() {
|
|
||||||
if (this._lastColor !== this.color) {
|
|
||||||
this._assignCss(false);
|
|
||||||
this._lastColor = this.color;
|
|
||||||
this._colors = [this.color];
|
|
||||||
this._assignCss(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
@ -225,7 +299,7 @@ export class Button {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
private _setClass(type: string, assignCssClass: boolean) {
|
private _setClass(type: string, assignCssClass: boolean) {
|
||||||
if (type) {
|
if (type && this._init) {
|
||||||
this._renderer.setElementClass(this._elementRef.nativeElement, this._role + '-' + type, assignCssClass);
|
this._renderer.setElementClass(this._elementRef.nativeElement, this._role + '-' + type, assignCssClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,10 @@ import {App} from 'ionic-angular';
|
|||||||
@App({
|
@App({
|
||||||
templateUrl: 'main.html'
|
templateUrl: 'main.html'
|
||||||
})
|
})
|
||||||
class E2EApp {}
|
class E2EApp {
|
||||||
|
blockButton = true;
|
||||||
|
|
||||||
|
toggleBlock() {
|
||||||
|
this.blockButton = !this.blockButton;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -35,4 +35,8 @@
|
|||||||
<button block round outline>button[block][round][outline]</button>
|
<button block round outline>button[block][round][outline]</button>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<button [block]="blockButton" (click)="toggleBlock()">Toggle Block</button>
|
||||||
|
</p>
|
||||||
|
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
@ -179,7 +179,7 @@ export function run() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function mockButton(attrs, config) {
|
function mockButton(attrs?, config?) {
|
||||||
config = config || new Config();
|
config = config || new Config();
|
||||||
let elementRef = {
|
let elementRef = {
|
||||||
nativeElement: document.createElement('button')
|
nativeElement: document.createElement('button')
|
||||||
@ -189,12 +189,14 @@ export function run() {
|
|||||||
elementRef.nativeElement.setAttribute(attrs[i], '');
|
elementRef.nativeElement.setAttribute(attrs[i], '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let renderer = {
|
let renderer: any = {
|
||||||
setElementClass: function(nativeElement, className, shouldAdd) {
|
setElementClass: function(nativeElement, className, shouldAdd) {
|
||||||
nativeElement.classList[shouldAdd ? 'add' : 'remove'](className);
|
nativeElement.classList[shouldAdd ? 'add' : 'remove'](className);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return new Button(config, elementRef, renderer, null);
|
let b = new Button(config, elementRef, renderer, null);
|
||||||
|
b._init = true;
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasClass(button, className) {
|
function hasClass(button, className) {
|
||||||
|
@ -4,4 +4,10 @@ import {App} from 'ionic-angular';
|
|||||||
@App({
|
@App({
|
||||||
templateUrl: 'main.html'
|
templateUrl: 'main.html'
|
||||||
})
|
})
|
||||||
class E2EApp {}
|
class E2EApp {
|
||||||
|
clearButton = true;
|
||||||
|
|
||||||
|
toggleClear() {
|
||||||
|
this.clearButton = !this.clearButton;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -35,4 +35,8 @@
|
|||||||
<button clear dark class="activated">Dark.activated</button>
|
<button clear dark class="activated">Dark.activated</button>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<button [clear]="clearButton" (click)="toggleClear()">Toggle Clear</button>
|
||||||
|
</p>
|
||||||
|
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
@ -4,4 +4,10 @@ import {App} from 'ionic-angular';
|
|||||||
@App({
|
@App({
|
||||||
templateUrl: 'main.html'
|
templateUrl: 'main.html'
|
||||||
})
|
})
|
||||||
class E2EApp {}
|
class E2EApp {
|
||||||
|
outlineButton = true;
|
||||||
|
|
||||||
|
toggleOutline() {
|
||||||
|
this.outlineButton = !this.outlineButton;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -51,4 +51,8 @@
|
|||||||
<button outline block secondary class="activated">[outline][block][secondary].activated</button>
|
<button outline block secondary class="activated">[outline][block][secondary].activated</button>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<button [outline]="outlineButton" (click)="toggleOutline()">Toggle Outline</button>
|
||||||
|
</p>
|
||||||
|
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
Reference in New Issue
Block a user