import { Attribute, ChangeDetectionStrategy, Component, ElementRef, Input, Renderer, ViewEncapsulation } from '@angular/core'; import { Config } from '../../config/config'; import { Ion } from '../ion'; import { isTrueProperty } from '../../util/util'; /** * @name Button * @module ionic * @description * Buttons are simple components in Ionic. They can consist of text and icons * and be enhanced by a wide range of attributes. * * @usage * * ```html * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ``` * * @advanced * * ```html * * * * * * * * * * * * * * * * ``` * * ```ts * @Component({ * templateUrl: 'main.html' * }) * class E2EPage { * isDanger: boolean = true; * isSecondary: boolean = false; * isRound: boolean = true; * isOutline: boolean = false; * isClear: boolean = true; * myColor: string = 'secondary'; * myColor2: string = 'dark'; * * logEvent(event) { * console.log(event) * } * } * * ``` * * @demo /docs/demos/src/button/ * @see {@link /docs/components#buttons Button Component Docs} * @see {@link /docs/components#fabs FabButton Docs} * @see {@link ../../fab/FabButton FabButton API Docs} * @see {@link ../../fab/FabContainer FabContainer API Docs} */ @Component({ selector: '[ion-button]', template: '
', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, }) export class Button extends Ion { /** @hidden */ _role: string = 'button'; // bar-button /** @hidden */ _size: string; // large/small/default /** @hidden */ _style: string = 'default'; // outline/clear/solid /** @hidden */ _shape: string; // round/fab /** @hidden */ _display: string; // block/full /** @hidden */ _decorator: string; // strong /** @hidden */ _init: boolean; /** * @input {boolean} If true, activates the large button size. */ @Input() set large(val: boolean) { this._attr('_size', 'large', val); } /** * @input {boolean} If true, activates the small button size. */ @Input() set small(val: boolean) { this._attr('_size', 'small', val); } /** * @input {boolean} If true, activates the default button size. Normally the default, useful for buttons in an item. */ @Input() set default(val: boolean) { this._attr('_size', 'default', val); } /** * @input {boolean} If true, activates a transparent button style with a border. */ @Input() set outline(val: boolean) { this._attr('_style', 'outline', val); } /** * @input {boolean} If true, activates a transparent button style without a border. */ @Input() set clear(val: boolean) { this._attr('_style', 'clear', val); } /** * @input {boolean} If true, activates a solid button style. Normally the default, useful for buttons in a toolbar. */ @Input() set solid(val: boolean) { this._attr('_style', 'solid', val); } /** * @input {boolean} If true, activates a button with rounded corners. */ @Input() set round(val: boolean) { this._attr('_shape', 'round', val); } /** * @input {boolean} If true, activates a button style that fills the available width. */ @Input() set block(val: boolean) { this._attr('_display', 'block', val); } /** * @input {boolean} If true, activates a button style that fills the available width without * a left and right border. */ @Input() set full(val: boolean) { this._attr('_display', 'full', val); } /** * @input {boolean} If true, activates a button with a heavier font weight. */ @Input() set strong(val: boolean) { this._attr('_decorator', 'strong', val); } /** * @input {string} The mode determines which platform styles to use. * Possible values are: `"ios"`, `"md"`, or `"wp"`. * For more information, see [Platform Styles](/docs/theming/platform-specific-styles). */ @Input() set mode(val: string) { this._assignCss(false); this._mode = val; this._assignCss(true); } /** @hidden */ _attr(type: string, attrName: string, attrValue: boolean) { if (type === '_style') { this._updateColor(this._color, false); } this._setClass(( ' + '