a zip code crypto-currency system good for red ONLY

button.js 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. import { Attribute, ChangeDetectionStrategy, Component, ElementRef, Input, Renderer, ViewEncapsulation } from '@angular/core';
  2. import { Config } from '../../config/config';
  3. import { Ion } from '../ion';
  4. import { isTrueProperty } from '../../util/util';
  5. /**
  6. * @name Button
  7. * @module ionic
  8. * @description
  9. * Buttons are simple components in Ionic. They can consist of text and icons
  10. * and be enhanced by a wide range of attributes.
  11. *
  12. * @usage
  13. *
  14. * ```html
  15. *
  16. * <!-- Colors -->
  17. * <button ion-button>Default</button>
  18. *
  19. * <button ion-button color="secondary">Secondary</button>
  20. *
  21. * <button ion-button color="danger">Danger</button>
  22. *
  23. * <button ion-button color="light">Light</button>
  24. *
  25. * <button ion-button color="dark">Dark</button>
  26. *
  27. * <!-- Shapes -->
  28. * <button ion-button full>Full Button</button>
  29. *
  30. * <button ion-button block>Block Button</button>
  31. *
  32. * <button ion-button round>Round Button</button>
  33. *
  34. * <!-- Outline -->
  35. * <button ion-button full outline>Outline + Full</button>
  36. *
  37. * <button ion-button block outline>Outline + Block</button>
  38. *
  39. * <button ion-button round outline>Outline + Round</button>
  40. *
  41. * <!-- Icons -->
  42. * <button ion-button icon-start>
  43. * <ion-icon name="star"></ion-icon>
  44. * Left Icon
  45. * </button>
  46. *
  47. * <button ion-button icon-end>
  48. * Right Icon
  49. * <ion-icon name="star"></ion-icon>
  50. * </button>
  51. *
  52. * <button ion-button icon-only>
  53. * <ion-icon name="star"></ion-icon>
  54. * </button>
  55. *
  56. * <!-- Sizes -->
  57. * <button ion-button large>Large</button>
  58. *
  59. * <button ion-button>Default</button>
  60. *
  61. * <button ion-button small>Small</button>
  62. * ```
  63. *
  64. * @advanced
  65. *
  66. * ```html
  67. *
  68. * <!-- Bind the color and outline inputs to an expression -->
  69. * <button ion-button [color]="isDanger ? 'danger' : 'primary'" [outline]="isOutline">
  70. * Danger (Solid)
  71. * </button>
  72. *
  73. * <!-- Bind the color and round inputs to an expression -->
  74. * <button ion-button [color]="myColor" [round]="isRound">
  75. * Secondary (Round)
  76. * </button>
  77. *
  78. * <!-- Bind the color and clear inputs to an expression -->
  79. * <button ion-button [color]="isSecondary ? 'secondary' : 'primary'" [clear]="isClear">
  80. * Primary (Clear)
  81. * </button>
  82. *
  83. * <!-- Bind the color, outline and round inputs to an expression -->
  84. * <button ion-button [color]="myColor2" [outline]="isOutline" [round]="isRound">
  85. * Dark (Solid + Round)
  86. * </button>
  87. *
  88. * <!-- Bind the click event to a method -->
  89. * <button ion-button (click)="logEvent($event)">
  90. * Click me!
  91. * </button>
  92. * ```
  93. *
  94. * ```ts
  95. * @Component({
  96. * templateUrl: 'main.html'
  97. * })
  98. * class E2EPage {
  99. * isDanger: boolean = true;
  100. * isSecondary: boolean = false;
  101. * isRound: boolean = true;
  102. * isOutline: boolean = false;
  103. * isClear: boolean = true;
  104. * myColor: string = 'secondary';
  105. * myColor2: string = 'dark';
  106. *
  107. * logEvent(event) {
  108. * console.log(event)
  109. * }
  110. * }
  111. *
  112. * ```
  113. *
  114. * @demo /docs/demos/src/button/
  115. * @see {@link /docs/components#buttons Button Component Docs}
  116. * @see {@link /docs/components#fabs FabButton Docs}
  117. * @see {@link ../../fab/FabButton FabButton API Docs}
  118. * @see {@link ../../fab/FabContainer FabContainer API Docs}
  119. */
  120. export class Button extends Ion {
  121. constructor(ionButton, config, elementRef, renderer) {
  122. super(config, elementRef, renderer);
  123. /** @hidden */
  124. this._role = 'button'; // bar-button
  125. /** @hidden */
  126. this._style = 'default'; // outline/clear/solid
  127. this._mode = config.get('mode');
  128. if (config.get('hoverCSS') === false) {
  129. this.setElementClass('disable-hover', true);
  130. }
  131. if (ionButton.trim().length > 0) {
  132. this.setRole(ionButton);
  133. }
  134. }
  135. /**
  136. * @input {boolean} If true, activates the large button size.
  137. */
  138. set large(val) {
  139. this._attr('_size', 'large', val);
  140. }
  141. /**
  142. * @input {boolean} If true, activates the small button size.
  143. */
  144. set small(val) {
  145. this._attr('_size', 'small', val);
  146. }
  147. /**
  148. * @input {boolean} If true, activates the default button size. Normally the default, useful for buttons in an item.
  149. */
  150. set default(val) {
  151. this._attr('_size', 'default', val);
  152. }
  153. /**
  154. * @input {boolean} If true, activates a transparent button style with a border.
  155. */
  156. set outline(val) {
  157. this._attr('_style', 'outline', val);
  158. }
  159. /**
  160. * @input {boolean} If true, activates a transparent button style without a border.
  161. */
  162. set clear(val) {
  163. this._attr('_style', 'clear', val);
  164. }
  165. /**
  166. * @input {boolean} If true, activates a solid button style. Normally the default, useful for buttons in a toolbar.
  167. */
  168. set solid(val) {
  169. this._attr('_style', 'solid', val);
  170. }
  171. /**
  172. * @input {boolean} If true, activates a button with rounded corners.
  173. */
  174. set round(val) {
  175. this._attr('_shape', 'round', val);
  176. }
  177. /**
  178. * @input {boolean} If true, activates a button style that fills the available width.
  179. */
  180. set block(val) {
  181. this._attr('_display', 'block', val);
  182. }
  183. /**
  184. * @input {boolean} If true, activates a button style that fills the available width without
  185. * a left and right border.
  186. */
  187. set full(val) {
  188. this._attr('_display', 'full', val);
  189. }
  190. /**
  191. * @input {boolean} If true, activates a button with a heavier font weight.
  192. */
  193. set strong(val) {
  194. this._attr('_decorator', 'strong', val);
  195. }
  196. /**
  197. * @input {string} The mode determines which platform styles to use.
  198. * Possible values are: `"ios"`, `"md"`, or `"wp"`.
  199. * For more information, see [Platform Styles](/docs/theming/platform-specific-styles).
  200. */
  201. set mode(val) {
  202. this._assignCss(false);
  203. this._mode = val;
  204. this._assignCss(true);
  205. }
  206. /** @hidden */
  207. _attr(type, attrName, attrValue) {
  208. if (type === '_style') {
  209. this._updateColor(this._color, false);
  210. }
  211. this._setClass(this[type], false);
  212. if (isTrueProperty(attrValue)) {
  213. this[type] = attrName;
  214. this._setClass(attrName, true);
  215. }
  216. else {
  217. // Special handling for '_style' which defaults to 'default'.
  218. this[type] = (type === '_style' ? 'default' : null);
  219. this._setClass(this[type], true);
  220. }
  221. if (type === '_style') {
  222. this._updateColor(this._color, true);
  223. }
  224. }
  225. /**
  226. * @input {string} The color to use from your Sass `$colors` map.
  227. * Default options are: `"primary"`, `"secondary"`, `"danger"`, `"light"`, and `"dark"`.
  228. * For more information, see [Theming your App](/docs/theming/theming-your-app).
  229. */
  230. set color(val) {
  231. this._updateColor(this._color, false);
  232. this._updateColor(val, true);
  233. this._color = val;
  234. }
  235. /** @hidden */
  236. ngAfterContentInit() {
  237. this._init = true;
  238. this._assignCss(true);
  239. }
  240. /**
  241. * @hidden
  242. */
  243. setRole(val) {
  244. this._assignCss(false);
  245. this._role = val;
  246. this._assignCss(true);
  247. }
  248. /**
  249. * @hidden
  250. */
  251. _assignCss(assignCssClass) {
  252. let role = this._role;
  253. if (role) {
  254. this.setElementClass(role, assignCssClass); // button
  255. this.setElementClass(`${role}-${this._mode}`, assignCssClass); // button
  256. this._setClass(this._style, assignCssClass); // button-clear
  257. this._setClass(this._shape, assignCssClass); // button-round
  258. this._setClass(this._display, assignCssClass); // button-full
  259. this._setClass(this._size, assignCssClass); // button-small
  260. this._setClass(this._decorator, assignCssClass); // button-strong
  261. this._updateColor(this._color, assignCssClass); // button-secondary, bar-button-secondary
  262. }
  263. }
  264. /**
  265. * @hidden
  266. */
  267. _setClass(type, assignCssClass) {
  268. if (type && this._init) {
  269. type = type.toLocaleLowerCase();
  270. this.setElementClass(`${this._role}-${type}`, assignCssClass);
  271. this.setElementClass(`${this._role}-${type}-${this._mode}`, assignCssClass);
  272. }
  273. }
  274. /**
  275. * @hidden
  276. */
  277. _updateColor(color, isAdd) {
  278. if (color && this._init) {
  279. // The class should begin with the button role
  280. // button, bar-button
  281. let className = this._role;
  282. // If the role is not a bar-button, don't apply the solid style
  283. let style = this._style;
  284. style = (this._role !== 'bar-button' && style === 'solid' ? 'default' : style);
  285. className += (style !== null && style !== '' && style !== 'default' ? '-' + style.toLowerCase() : '');
  286. if (color !== null && color !== '') {
  287. this.setElementClass(`${className}-${this._mode}-${color}`, isAdd);
  288. }
  289. }
  290. }
  291. }
  292. Button.decorators = [
  293. { type: Component, args: [{
  294. selector: '[ion-button]',
  295. template: '<span class="button-inner">' +
  296. '<ng-content></ng-content>' +
  297. '</span>' +
  298. '<div class="button-effect"></div>',
  299. changeDetection: ChangeDetectionStrategy.OnPush,
  300. encapsulation: ViewEncapsulation.None,
  301. },] },
  302. ];
  303. /** @nocollapse */
  304. Button.ctorParameters = () => [
  305. { type: undefined, decorators: [{ type: Attribute, args: ['ion-button',] },] },
  306. { type: Config, },
  307. { type: ElementRef, },
  308. { type: Renderer, },
  309. ];
  310. Button.propDecorators = {
  311. 'large': [{ type: Input },],
  312. 'small': [{ type: Input },],
  313. 'default': [{ type: Input },],
  314. 'outline': [{ type: Input },],
  315. 'clear': [{ type: Input },],
  316. 'solid': [{ type: Input },],
  317. 'round': [{ type: Input },],
  318. 'block': [{ type: Input },],
  319. 'full': [{ type: Input },],
  320. 'strong': [{ type: Input },],
  321. 'mode': [{ type: Input },],
  322. 'color': [{ type: Input },],
  323. };
  324. //# sourceMappingURL=button.js.map