ngx-bootstrap-buttons.umd.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms')) :
  3. typeof define === 'function' && define.amd ? define('ngx-bootstrap/buttons', ['exports', '@angular/core', '@angular/forms'], factory) :
  4. (global = global || self, factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].buttons = {}), global.ng.core, global.ng.forms));
  5. }(this, function (exports, core, forms) { 'use strict';
  6. /**
  7. * @fileoverview added by tsickle
  8. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  9. */
  10. // TODO: config: activeClass - Class to apply to the checked buttons
  11. /** @type {?} */
  12. var CHECKBOX_CONTROL_VALUE_ACCESSOR = {
  13. provide: forms.NG_VALUE_ACCESSOR,
  14. /* tslint:disable-next-line: no-use-before-declare */
  15. useExisting: core.forwardRef((/**
  16. * @return {?}
  17. */
  18. function () { return ButtonCheckboxDirective; })),
  19. multi: true
  20. };
  21. /**
  22. * Add checkbox functionality to any element
  23. */
  24. var ButtonCheckboxDirective = /** @class */ (function () {
  25. function ButtonCheckboxDirective() {
  26. /**
  27. * Truthy value, will be set to ngModel
  28. */
  29. this.btnCheckboxTrue = true;
  30. /**
  31. * Falsy value, will be set to ngModel
  32. */
  33. this.btnCheckboxFalse = false;
  34. this.state = false;
  35. this.onChange = Function.prototype;
  36. this.onTouched = Function.prototype;
  37. }
  38. // view -> model
  39. // view -> model
  40. /**
  41. * @return {?}
  42. */
  43. ButtonCheckboxDirective.prototype.onClick =
  44. // view -> model
  45. /**
  46. * @return {?}
  47. */
  48. function () {
  49. if (this.isDisabled) {
  50. return;
  51. }
  52. this.toggle(!this.state);
  53. this.onChange(this.value);
  54. };
  55. /**
  56. * @return {?}
  57. */
  58. ButtonCheckboxDirective.prototype.ngOnInit = /**
  59. * @return {?}
  60. */
  61. function () {
  62. this.toggle(this.trueValue === this.value);
  63. };
  64. Object.defineProperty(ButtonCheckboxDirective.prototype, "trueValue", {
  65. get: /**
  66. * @protected
  67. * @return {?}
  68. */
  69. function () {
  70. return typeof this.btnCheckboxTrue !== 'undefined'
  71. ? this.btnCheckboxTrue
  72. : true;
  73. },
  74. enumerable: true,
  75. configurable: true
  76. });
  77. Object.defineProperty(ButtonCheckboxDirective.prototype, "falseValue", {
  78. get: /**
  79. * @protected
  80. * @return {?}
  81. */
  82. function () {
  83. return typeof this.btnCheckboxFalse !== 'undefined'
  84. ? this.btnCheckboxFalse
  85. : false;
  86. },
  87. enumerable: true,
  88. configurable: true
  89. });
  90. /**
  91. * @param {?} state
  92. * @return {?}
  93. */
  94. ButtonCheckboxDirective.prototype.toggle = /**
  95. * @param {?} state
  96. * @return {?}
  97. */
  98. function (state) {
  99. this.state = state;
  100. this.value = this.state ? this.trueValue : this.falseValue;
  101. };
  102. // ControlValueAccessor
  103. // model -> view
  104. // ControlValueAccessor
  105. // model -> view
  106. /**
  107. * @param {?} value
  108. * @return {?}
  109. */
  110. ButtonCheckboxDirective.prototype.writeValue =
  111. // ControlValueAccessor
  112. // model -> view
  113. /**
  114. * @param {?} value
  115. * @return {?}
  116. */
  117. function (value) {
  118. this.state = this.trueValue === value;
  119. this.value = value ? this.trueValue : this.falseValue;
  120. };
  121. /**
  122. * @param {?} isDisabled
  123. * @return {?}
  124. */
  125. ButtonCheckboxDirective.prototype.setDisabledState = /**
  126. * @param {?} isDisabled
  127. * @return {?}
  128. */
  129. function (isDisabled) {
  130. this.isDisabled = isDisabled;
  131. };
  132. /**
  133. * @param {?} fn
  134. * @return {?}
  135. */
  136. ButtonCheckboxDirective.prototype.registerOnChange = /**
  137. * @param {?} fn
  138. * @return {?}
  139. */
  140. function (fn) {
  141. this.onChange = fn;
  142. };
  143. /**
  144. * @param {?} fn
  145. * @return {?}
  146. */
  147. ButtonCheckboxDirective.prototype.registerOnTouched = /**
  148. * @param {?} fn
  149. * @return {?}
  150. */
  151. function (fn) {
  152. this.onTouched = fn;
  153. };
  154. ButtonCheckboxDirective.decorators = [
  155. { type: core.Directive, args: [{
  156. selector: '[btnCheckbox]',
  157. providers: [CHECKBOX_CONTROL_VALUE_ACCESSOR]
  158. },] }
  159. ];
  160. ButtonCheckboxDirective.propDecorators = {
  161. btnCheckboxTrue: [{ type: core.Input }],
  162. btnCheckboxFalse: [{ type: core.Input }],
  163. state: [{ type: core.HostBinding, args: ['class.active',] }, { type: core.HostBinding, args: ['attr.aria-pressed',] }],
  164. onClick: [{ type: core.HostListener, args: ['click',] }]
  165. };
  166. return ButtonCheckboxDirective;
  167. }());
  168. /**
  169. * @fileoverview added by tsickle
  170. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  171. */
  172. /** @type {?} */
  173. var RADIO_CONTROL_VALUE_ACCESSOR = {
  174. provide: forms.NG_VALUE_ACCESSOR,
  175. /* tslint:disable-next-line: no-use-before-declare */
  176. useExisting: core.forwardRef((/**
  177. * @return {?}
  178. */
  179. function () { return ButtonRadioGroupDirective; })),
  180. multi: true
  181. };
  182. /**
  183. * A group of radio buttons.
  184. * A value of a selected button is bound to a variable specified via ngModel.
  185. */
  186. var ButtonRadioGroupDirective = /** @class */ (function () {
  187. function ButtonRadioGroupDirective(cdr) {
  188. this.cdr = cdr;
  189. this.onChange = Function.prototype;
  190. this.onTouched = Function.prototype;
  191. }
  192. Object.defineProperty(ButtonRadioGroupDirective.prototype, "value", {
  193. get: /**
  194. * @return {?}
  195. */
  196. function () {
  197. return this._value;
  198. },
  199. set: /**
  200. * @param {?} value
  201. * @return {?}
  202. */
  203. function (value) {
  204. this._value = value;
  205. },
  206. enumerable: true,
  207. configurable: true
  208. });
  209. /**
  210. * @param {?} value
  211. * @return {?}
  212. */
  213. ButtonRadioGroupDirective.prototype.writeValue = /**
  214. * @param {?} value
  215. * @return {?}
  216. */
  217. function (value) {
  218. this._value = value;
  219. this.cdr.markForCheck();
  220. };
  221. /**
  222. * @param {?} fn
  223. * @return {?}
  224. */
  225. ButtonRadioGroupDirective.prototype.registerOnChange = /**
  226. * @param {?} fn
  227. * @return {?}
  228. */
  229. function (fn) {
  230. this.onChange = fn;
  231. };
  232. /**
  233. * @param {?} fn
  234. * @return {?}
  235. */
  236. ButtonRadioGroupDirective.prototype.registerOnTouched = /**
  237. * @param {?} fn
  238. * @return {?}
  239. */
  240. function (fn) {
  241. this.onTouched = fn;
  242. };
  243. ButtonRadioGroupDirective.decorators = [
  244. { type: core.Directive, args: [{
  245. selector: '[btnRadioGroup]',
  246. providers: [RADIO_CONTROL_VALUE_ACCESSOR]
  247. },] }
  248. ];
  249. /** @nocollapse */
  250. ButtonRadioGroupDirective.ctorParameters = function () { return [
  251. { type: core.ChangeDetectorRef }
  252. ]; };
  253. return ButtonRadioGroupDirective;
  254. }());
  255. /**
  256. * @fileoverview added by tsickle
  257. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  258. */
  259. /** @type {?} */
  260. var RADIO_CONTROL_VALUE_ACCESSOR$1 = {
  261. provide: forms.NG_VALUE_ACCESSOR,
  262. /* tslint:disable-next-line: no-use-before-declare */
  263. useExisting: core.forwardRef((/**
  264. * @return {?}
  265. */
  266. function () { return ButtonRadioDirective; })),
  267. multi: true
  268. };
  269. /**
  270. * Create radio buttons or groups of buttons.
  271. * A value of a selected button is bound to a variable specified via ngModel.
  272. */
  273. var ButtonRadioDirective = /** @class */ (function () {
  274. function ButtonRadioDirective(el, cdr, group, renderer) {
  275. this.el = el;
  276. this.cdr = cdr;
  277. this.group = group;
  278. this.renderer = renderer;
  279. this.onChange = Function.prototype;
  280. this.onTouched = Function.prototype;
  281. }
  282. Object.defineProperty(ButtonRadioDirective.prototype, "value", {
  283. /** Current value of radio component or group */
  284. get: /**
  285. * Current value of radio component or group
  286. * @return {?}
  287. */
  288. function () {
  289. return this.group ? this.group.value : this._value;
  290. },
  291. set: /**
  292. * @param {?} value
  293. * @return {?}
  294. */
  295. function (value) {
  296. if (this.group) {
  297. this.group.value = value;
  298. return;
  299. }
  300. this._value = value;
  301. },
  302. enumerable: true,
  303. configurable: true
  304. });
  305. Object.defineProperty(ButtonRadioDirective.prototype, "disabled", {
  306. /** If `true` — radio button is disabled */
  307. get: /**
  308. * If `true` — radio button is disabled
  309. * @return {?}
  310. */
  311. function () {
  312. return this._disabled;
  313. },
  314. set: /**
  315. * @param {?} disabled
  316. * @return {?}
  317. */
  318. function (disabled) {
  319. this._disabled = disabled;
  320. this.setDisabledState(disabled);
  321. },
  322. enumerable: true,
  323. configurable: true
  324. });
  325. Object.defineProperty(ButtonRadioDirective.prototype, "isActive", {
  326. get: /**
  327. * @return {?}
  328. */
  329. function () {
  330. return this.btnRadio === this.value;
  331. },
  332. enumerable: true,
  333. configurable: true
  334. });
  335. /**
  336. * @return {?}
  337. */
  338. ButtonRadioDirective.prototype.onClick = /**
  339. * @return {?}
  340. */
  341. function () {
  342. if (this.el.nativeElement.attributes.disabled || !this.uncheckable && this.btnRadio === this.value) {
  343. return;
  344. }
  345. this.value = this.uncheckable && this.btnRadio === this.value ? undefined : this.btnRadio;
  346. this._onChange(this.value);
  347. };
  348. /**
  349. * @return {?}
  350. */
  351. ButtonRadioDirective.prototype.ngOnInit = /**
  352. * @return {?}
  353. */
  354. function () {
  355. this.uncheckable = typeof this.uncheckable !== 'undefined';
  356. };
  357. /**
  358. * @return {?}
  359. */
  360. ButtonRadioDirective.prototype.onBlur = /**
  361. * @return {?}
  362. */
  363. function () {
  364. this.onTouched();
  365. };
  366. /**
  367. * @param {?} value
  368. * @return {?}
  369. */
  370. ButtonRadioDirective.prototype._onChange = /**
  371. * @param {?} value
  372. * @return {?}
  373. */
  374. function (value) {
  375. if (this.group) {
  376. this.group.onTouched();
  377. this.group.onChange(value);
  378. return;
  379. }
  380. this.onTouched();
  381. this.onChange(value);
  382. };
  383. // ControlValueAccessor
  384. // model -> view
  385. // ControlValueAccessor
  386. // model -> view
  387. /**
  388. * @param {?} value
  389. * @return {?}
  390. */
  391. ButtonRadioDirective.prototype.writeValue =
  392. // ControlValueAccessor
  393. // model -> view
  394. /**
  395. * @param {?} value
  396. * @return {?}
  397. */
  398. function (value) {
  399. this.value = value;
  400. this.cdr.markForCheck();
  401. };
  402. /**
  403. * @param {?} fn
  404. * @return {?}
  405. */
  406. ButtonRadioDirective.prototype.registerOnChange = /**
  407. * @param {?} fn
  408. * @return {?}
  409. */
  410. function (fn) {
  411. this.onChange = fn;
  412. };
  413. /**
  414. * @param {?} fn
  415. * @return {?}
  416. */
  417. ButtonRadioDirective.prototype.registerOnTouched = /**
  418. * @param {?} fn
  419. * @return {?}
  420. */
  421. function (fn) {
  422. this.onTouched = fn;
  423. };
  424. /**
  425. * @param {?} disabled
  426. * @return {?}
  427. */
  428. ButtonRadioDirective.prototype.setDisabledState = /**
  429. * @param {?} disabled
  430. * @return {?}
  431. */
  432. function (disabled) {
  433. if (disabled) {
  434. this.renderer.setAttribute(this.el.nativeElement, 'disabled', 'disabled');
  435. return;
  436. }
  437. this.renderer.removeAttribute(this.el.nativeElement, 'disabled');
  438. };
  439. ButtonRadioDirective.decorators = [
  440. { type: core.Directive, args: [{
  441. selector: '[btnRadio]',
  442. providers: [RADIO_CONTROL_VALUE_ACCESSOR$1]
  443. },] }
  444. ];
  445. /** @nocollapse */
  446. ButtonRadioDirective.ctorParameters = function () { return [
  447. { type: core.ElementRef },
  448. { type: core.ChangeDetectorRef },
  449. { type: ButtonRadioGroupDirective, decorators: [{ type: core.Optional }] },
  450. { type: core.Renderer2 }
  451. ]; };
  452. ButtonRadioDirective.propDecorators = {
  453. btnRadio: [{ type: core.Input }],
  454. uncheckable: [{ type: core.Input }],
  455. value: [{ type: core.Input }],
  456. disabled: [{ type: core.Input }],
  457. isActive: [{ type: core.HostBinding, args: ['class.active',] }, { type: core.HostBinding, args: ['attr.aria-pressed',] }],
  458. onClick: [{ type: core.HostListener, args: ['click',] }]
  459. };
  460. return ButtonRadioDirective;
  461. }());
  462. /**
  463. * @fileoverview added by tsickle
  464. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  465. */
  466. var ButtonsModule = /** @class */ (function () {
  467. function ButtonsModule() {
  468. }
  469. /**
  470. * @return {?}
  471. */
  472. ButtonsModule.forRoot = /**
  473. * @return {?}
  474. */
  475. function () {
  476. return { ngModule: ButtonsModule, providers: [] };
  477. };
  478. ButtonsModule.decorators = [
  479. { type: core.NgModule, args: [{
  480. declarations: [ButtonCheckboxDirective, ButtonRadioDirective, ButtonRadioGroupDirective],
  481. exports: [ButtonCheckboxDirective, ButtonRadioDirective, ButtonRadioGroupDirective]
  482. },] }
  483. ];
  484. return ButtonsModule;
  485. }());
  486. exports.ButtonCheckboxDirective = ButtonCheckboxDirective;
  487. exports.ButtonRadioDirective = ButtonRadioDirective;
  488. exports.ButtonRadioGroupDirective = ButtonRadioGroupDirective;
  489. exports.ButtonsModule = ButtonsModule;
  490. exports.ɵa = CHECKBOX_CONTROL_VALUE_ACCESSOR;
  491. exports.ɵb = RADIO_CONTROL_VALUE_ACCESSOR;
  492. exports.ɵc = RADIO_CONTROL_VALUE_ACCESSOR$1;
  493. Object.defineProperty(exports, '__esModule', { value: true });
  494. }));
  495. //# sourceMappingURL=ngx-bootstrap-buttons.umd.js.map