component.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @license
  3. * Copyright 2018 Google Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. import { __extends } from "tslib";
  24. import { MDCComponent } from '@material/base/component';
  25. import { MDCRipple } from '@material/ripple/component';
  26. import { MDCIconButtonToggleFoundation } from './foundation';
  27. var strings = MDCIconButtonToggleFoundation.strings;
  28. /** MDC Icon Button Toggle */
  29. var MDCIconButtonToggle = /** @class */ (function (_super) {
  30. __extends(MDCIconButtonToggle, _super);
  31. function MDCIconButtonToggle() {
  32. var _this = _super !== null && _super.apply(this, arguments) || this;
  33. _this.rippleComponent = _this.createRipple();
  34. return _this;
  35. }
  36. MDCIconButtonToggle.attachTo = function (root) {
  37. return new MDCIconButtonToggle(root);
  38. };
  39. MDCIconButtonToggle.prototype.initialSyncWithDOM = function () {
  40. var _this = this;
  41. this.handleClick = function () {
  42. _this.foundation.handleClick();
  43. };
  44. this.listen('click', this.handleClick);
  45. };
  46. MDCIconButtonToggle.prototype.destroy = function () {
  47. this.unlisten('click', this.handleClick);
  48. this.ripple.destroy();
  49. _super.prototype.destroy.call(this);
  50. };
  51. MDCIconButtonToggle.prototype.getDefaultFoundation = function () {
  52. var _this = this;
  53. // DO NOT INLINE this variable. For backward compatibility, foundations take
  54. // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
  55. // methods, we need a separate, strongly typed adapter variable.
  56. var adapter = {
  57. addClass: function (className) {
  58. _this.root.classList.add(className);
  59. },
  60. hasClass: function (className) { return _this.root.classList.contains(className); },
  61. notifyChange: function (evtData) {
  62. _this.emit(strings.CHANGE_EVENT, evtData);
  63. },
  64. removeClass: function (className) {
  65. _this.root.classList.remove(className);
  66. },
  67. getAttr: function (attrName) { return _this.root.getAttribute(attrName); },
  68. setAttr: function (attrName, attrValue) {
  69. _this.safeSetAttribute(_this.root, attrName, attrValue);
  70. },
  71. };
  72. return new MDCIconButtonToggleFoundation(adapter);
  73. };
  74. Object.defineProperty(MDCIconButtonToggle.prototype, "ripple", {
  75. get: function () {
  76. return this.rippleComponent;
  77. },
  78. enumerable: false,
  79. configurable: true
  80. });
  81. Object.defineProperty(MDCIconButtonToggle.prototype, "on", {
  82. get: function () {
  83. return this.foundation.isOn();
  84. },
  85. set: function (isOn) {
  86. this.foundation.toggle(isOn);
  87. },
  88. enumerable: false,
  89. configurable: true
  90. });
  91. MDCIconButtonToggle.prototype.createRipple = function () {
  92. var ripple = new MDCRipple(this.root);
  93. ripple.unbounded = true;
  94. return ripple;
  95. };
  96. return MDCIconButtonToggle;
  97. }(MDCComponent));
  98. export { MDCIconButtonToggle };
  99. //# sourceMappingURL=component.js.map