ngx-bootstrap-buttons.js 13 KB

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