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. * * @property [outline] - A transparent button with a border. * @property [clear] - A transparent button without a border. * @property [round] - A button with rounded corners. * @property [block] - A button that fills its parent container with a border-radius. * @property [full] - A button that fills its parent container without a border-radius or borders on the left/right. * @property [small] - A button with size small. * @property [large] - A button with size large. * @property [disabled] - A disabled button. * @property [fab] - A floating action button. * @property [fab-left] - Position a fab button to the left. * @property [fab-right] - Position a fab button to the right. * @property [fab-center] - Position a fab button towards the center. * @property [fab-top] - Position a fab button towards the top. * @property [fab-bottom] - Position a fab button towards the bottom. * @property [fab-fixed] - Makes a fab button have a fixed position. * @property [color] - Dynamically set which predefined color this button should use (e.g. primary, secondary, danger, etc). * * @usage * * ```html * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ``` * * @demo /docs/v2/demos/button/ * @see {@link /docs/v2/components#buttons Button Component Docs} */ @Component({ selector: '[ion-button]', template: '
', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, }) export class Button extends Ion { /** @private */ _role: string = 'button'; // bar-button /** @private */ _mt: boolean; // menutoggle /** @private */ _size: string; // large/small/default /** @private */ _style: string = 'default'; // outline/clear/solid /** @private */ _shape: string; // round/fab /** @private */ _display: string; // block/full /** @private */ _init: boolean; /** * @input {string} Large button. */ @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 floating action button. */ @Input() set fab(val: boolean) { this._attr('_shape', 'fab', 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); } /** * @input {string} A button that fills its parent container without a border-radius or borders on the left/right. */ @Input() set mode(val: string) { this._assignCss(false); this._mode = val; this._assignCss(true); } /** @private */ _attr(type: string, attrName: string, attrValue: boolean) { if (type === '_style') { this._updateColor(this._color, isTrueProperty(attrValue)); } this._setClass(( ' + '