123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. import { ChangeDetectionStrategy, Component, ElementRef, Input, Renderer, ViewEncapsulation } from '@angular/core';
  12. import { Config } from '../../config/config';
  13. import { Ion } from '../ion';
  14. import { isTrueProperty } from '../../util/util';
  15. /**
  16. * @name Spinner
  17. * @description
  18. * The `ion-spinner` component provides a variety of animated SVG spinners.
  19. * Spinners enables you to give users feedback that the app is actively
  20. * processing/thinking/waiting/chillin’ out, or whatever you’d like it to indicate.
  21. * By default, the `ion-refresher` feature uses this spinner component while it's
  22. * the refresher is in the `refreshing` state.
  23. *
  24. * Ionic offers a handful of spinners out of the box, and by default, it will use
  25. * the appropriate spinner for the platform on which it’s running.
  26. *
  27. * <table class="table spinner-table">
  28. * <tr>
  29. * <th>
  30. * <code>ios</code>
  31. * </th>
  32. * <td>
  33. * <ion-spinner name="ios"></ion-spinner>
  34. * </td>
  35. * </tr>
  36. * <tr>
  37. * <th>
  38. * <code>ios-small</code>
  39. * </th>
  40. * <td>
  41. * <ion-spinner name="ios-small"></ion-spinner>
  42. * </td>
  43. * </tr>
  44. * <tr>
  45. * <th>
  46. * <code>bubbles</code>
  47. * </th>
  48. * <td>
  49. * <ion-spinner name="bubbles"></ion-spinner>
  50. * </td>
  51. * </tr>
  52. * <tr>
  53. * <th>
  54. * <code>circles</code>
  55. * </th>
  56. * <td>
  57. * <ion-spinner name="circles"></ion-spinner>
  58. * </td>
  59. * </tr>
  60. * <tr>
  61. * <th>
  62. * <code>crescent</code>
  63. * </th>
  64. * <td>
  65. * <ion-spinner name="crescent"></ion-spinner>
  66. * </td>
  67. * </tr>
  68. * <tr>
  69. * <th>
  70. * <code>dots</code>
  71. * </th>
  72. * <td>
  73. * <ion-spinner name="dots"></ion-spinner>
  74. * </td>
  75. * </tr>
  76. * </table>
  77. *
  78. * @usage
  79. * The following code would use the default spinner for the platform it's
  80. * running from. If it's neither iOS or Android, it'll default to use `ios`.
  81. *
  82. * ```html
  83. * <ion-spinner></ion-spinner>
  84. * ```
  85. *
  86. * By setting the `name` property, you can specify which predefined spinner to
  87. * use, no matter what the platform is.
  88. *
  89. * ```html
  90. * <ion-spinner name="bubbles"></ion-spinner>
  91. * ```
  92. *
  93. * ## Styling SVG with CSS
  94. * One cool thing about SVG is its ability to be styled with CSS! One thing to note
  95. * is that some of the CSS properties on an SVG element have different names. For
  96. * example, SVG uses the term `stroke` instead of `border`, and `fill` instead
  97. * of `background-color`.
  98. *
  99. * ```css
  100. * ion-spinner * {
  101. * width: 28px;
  102. * height: 28px;
  103. * stroke: #444;
  104. * fill: #222;
  105. * }
  106. * ```
  107. */
  108. var Spinner = (function (_super) {
  109. __extends(Spinner, _super);
  110. function Spinner(config, elementRef, renderer) {
  111. var _this = _super.call(this, config, elementRef, renderer, 'spinner') || this;
  112. _this._dur = null;
  113. _this._paused = false;
  114. return _this;
  115. }
  116. Object.defineProperty(Spinner.prototype, "name", {
  117. /**
  118. * @input {string} SVG spinner name.
  119. */
  120. get: function () {
  121. return this._name;
  122. },
  123. set: function (val) {
  124. this._name = val;
  125. this.load();
  126. },
  127. enumerable: true,
  128. configurable: true
  129. });
  130. Object.defineProperty(Spinner.prototype, "duration", {
  131. /**
  132. * @input {string} How long it takes it to do one loop.
  133. */
  134. get: function () {
  135. return this._dur;
  136. },
  137. set: function (val) {
  138. this._dur = val;
  139. this.load();
  140. },
  141. enumerable: true,
  142. configurable: true
  143. });
  144. Object.defineProperty(Spinner.prototype, "paused", {
  145. /**
  146. * @input {boolean} If true, pause the animation.
  147. */
  148. get: function () {
  149. return this._paused;
  150. },
  151. set: function (val) {
  152. this._paused = isTrueProperty(val);
  153. },
  154. enumerable: true,
  155. configurable: true
  156. });
  157. /**
  158. * @hidden
  159. */
  160. Spinner.prototype.ngOnInit = function () {
  161. this._init = true;
  162. this.load();
  163. };
  164. /**
  165. * @hidden
  166. */
  167. Spinner.prototype.load = function () {
  168. if (this._init) {
  169. this._l = [];
  170. this._c = [];
  171. var name = this._name || this._config.get('spinner', 'ios');
  172. var spinner = SPINNERS[name];
  173. if (spinner) {
  174. if (spinner.lines) {
  175. for (var i = 0, l = spinner.lines; i < l; i++) {
  176. this._l.push(this._loadEle(spinner, i, l));
  177. }
  178. }
  179. else if (spinner.circles) {
  180. for (var i = 0, l = spinner.circles; i < l; i++) {
  181. this._c.push(this._loadEle(spinner, i, l));
  182. }
  183. }
  184. this.setElementClass("spinner-" + name, true);
  185. this.setElementClass("spinner-" + this._mode + "-" + name, true);
  186. }
  187. }
  188. };
  189. Spinner.prototype._loadEle = function (spinner, index, total) {
  190. var duration = this._dur || spinner.dur;
  191. var data = spinner.fn(duration, index, total);
  192. data.style.animationDuration = duration + 'ms';
  193. return data;
  194. };
  195. Spinner.decorators = [
  196. { type: Component, args: [{
  197. selector: 'ion-spinner',
  198. template: '<svg viewBox="0 0 64 64" *ngFor="let i of _c" [ngStyle]="i.style">' +
  199. '<circle [attr.r]="i.r" transform="translate(32,32)"></circle>' +
  200. '</svg>' +
  201. '<svg viewBox="0 0 64 64" *ngFor="let i of _l" [ngStyle]="i.style">' +
  202. '<line [attr.y1]="i.y1" [attr.y2]="i.y2" transform="translate(32,32)"></line>' +
  203. '</svg>',
  204. host: {
  205. '[class.spinner-paused]': '_paused'
  206. },
  207. changeDetection: ChangeDetectionStrategy.OnPush,
  208. encapsulation: ViewEncapsulation.None,
  209. },] },
  210. ];
  211. /** @nocollapse */
  212. Spinner.ctorParameters = function () { return [
  213. { type: Config, },
  214. { type: ElementRef, },
  215. { type: Renderer, },
  216. ]; };
  217. Spinner.propDecorators = {
  218. 'name': [{ type: Input },],
  219. 'duration': [{ type: Input },],
  220. 'paused': [{ type: Input },],
  221. };
  222. return Spinner;
  223. }(Ion));
  224. export { Spinner };
  225. var SPINNERS = {
  226. ios: {
  227. dur: 1000,
  228. lines: 12,
  229. fn: function (dur, index, total) {
  230. var transform = 'rotate(' + (30 * index + (index < 6 ? 180 : -180)) + 'deg)';
  231. var animationDelay = -(dur - ((dur / total) * index)) + 'ms';
  232. return {
  233. y1: 17,
  234. y2: 29,
  235. style: {
  236. transform: transform,
  237. webkitTransform: transform,
  238. animationDelay: animationDelay,
  239. webkitAnimationDelay: animationDelay
  240. }
  241. };
  242. }
  243. },
  244. 'ios-small': {
  245. dur: 1000,
  246. lines: 12,
  247. fn: function (dur, index, total) {
  248. var transform = 'rotate(' + (30 * index + (index < 6 ? 180 : -180)) + 'deg)';
  249. var animationDelay = -(dur - ((dur / total) * index)) + 'ms';
  250. return {
  251. y1: 12,
  252. y2: 20,
  253. style: {
  254. transform: transform,
  255. webkitTransform: transform,
  256. animationDelay: animationDelay,
  257. webkitAnimationDelay: animationDelay
  258. }
  259. };
  260. }
  261. },
  262. bubbles: {
  263. dur: 1000,
  264. circles: 9,
  265. fn: function (dur, index, total) {
  266. var animationDelay = -(dur - ((dur / total) * index)) + 'ms';
  267. return {
  268. r: 5,
  269. style: {
  270. top: (9 * Math.sin(2 * Math.PI * index / total)) + 'px',
  271. left: (9 * Math.cos(2 * Math.PI * index / total)) + 'px',
  272. animationDelay: animationDelay,
  273. webkitAnimationDelay: animationDelay
  274. }
  275. };
  276. }
  277. },
  278. circles: {
  279. dur: 1000,
  280. circles: 8,
  281. fn: function (dur, index, total) {
  282. var animationDelay = -(dur - ((dur / total) * index)) + 'ms';
  283. return {
  284. r: 5,
  285. style: {
  286. top: (9 * Math.sin(2 * Math.PI * index / total)) + 'px',
  287. left: (9 * Math.cos(2 * Math.PI * index / total)) + 'px',
  288. animationDelay: animationDelay,
  289. webkitAnimationDelay: animationDelay
  290. }
  291. };
  292. }
  293. },
  294. crescent: {
  295. dur: 750,
  296. circles: 1,
  297. fn: function () {
  298. return {
  299. r: 26,
  300. style: {}
  301. };
  302. }
  303. },
  304. dots: {
  305. dur: 750,
  306. circles: 3,
  307. fn: function (_dur, index) {
  308. var animationDelay = -(110 * index) + 'ms';
  309. return {
  310. r: 6,
  311. style: {
  312. left: (9 - (9 * index)) + 'px',
  313. animationDelay: animationDelay,
  314. webkitAnimationDelay: animationDelay
  315. }
  316. };
  317. }
  318. }
  319. };
  320. //# sourceMappingURL=spinner.js.map