component.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * @license
  3. * Copyright 2017 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 { MDCLinearProgressFoundation } from './foundation';
  26. /** MDC Linear Progress */
  27. var MDCLinearProgress = /** @class */ (function (_super) {
  28. __extends(MDCLinearProgress, _super);
  29. function MDCLinearProgress() {
  30. return _super !== null && _super.apply(this, arguments) || this;
  31. }
  32. MDCLinearProgress.attachTo = function (root) {
  33. return new MDCLinearProgress(root);
  34. };
  35. Object.defineProperty(MDCLinearProgress.prototype, "determinate", {
  36. set: function (value) {
  37. this.foundation.setDeterminate(value);
  38. },
  39. enumerable: false,
  40. configurable: true
  41. });
  42. Object.defineProperty(MDCLinearProgress.prototype, "progress", {
  43. set: function (value) {
  44. this.foundation.setProgress(value);
  45. },
  46. enumerable: false,
  47. configurable: true
  48. });
  49. Object.defineProperty(MDCLinearProgress.prototype, "buffer", {
  50. set: function (value) {
  51. this.foundation.setBuffer(value);
  52. },
  53. enumerable: false,
  54. configurable: true
  55. });
  56. MDCLinearProgress.prototype.open = function () {
  57. this.foundation.open();
  58. };
  59. MDCLinearProgress.prototype.close = function () {
  60. this.foundation.close();
  61. };
  62. MDCLinearProgress.prototype.initialSyncWithDOM = function () {
  63. var _this = this;
  64. this.root.addEventListener('transitionend', function () {
  65. _this.foundation.handleTransitionEnd();
  66. });
  67. };
  68. MDCLinearProgress.prototype.getDefaultFoundation = function () {
  69. var _this = this;
  70. // DO NOT INLINE this variable. For backward compatibility, foundations take
  71. // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
  72. // methods, we need a separate, strongly typed adapter variable.
  73. var adapter = {
  74. addClass: function (className) {
  75. _this.root.classList.add(className);
  76. },
  77. forceLayout: function () {
  78. _this.root.getBoundingClientRect();
  79. },
  80. setBufferBarStyle: function (styleProperty, value) {
  81. var bufferBar = _this.root.querySelector(MDCLinearProgressFoundation.strings.BUFFER_BAR_SELECTOR);
  82. if (bufferBar) {
  83. bufferBar.style.setProperty(styleProperty, value);
  84. }
  85. },
  86. setPrimaryBarStyle: function (styleProperty, value) {
  87. var primaryBar = _this.root.querySelector(MDCLinearProgressFoundation.strings.PRIMARY_BAR_SELECTOR);
  88. if (primaryBar) {
  89. primaryBar.style.setProperty(styleProperty, value);
  90. }
  91. },
  92. hasClass: function (className) { return _this.root.classList.contains(className); },
  93. removeAttribute: function (attributeName) {
  94. _this.root.removeAttribute(attributeName);
  95. },
  96. removeClass: function (className) {
  97. _this.root.classList.remove(className);
  98. },
  99. setAttribute: function (attributeName, value) {
  100. _this.safeSetAttribute(_this.root, attributeName, value);
  101. },
  102. setStyle: function (name, value) {
  103. _this.root.style.setProperty(name, value);
  104. },
  105. attachResizeObserver: function (callback) {
  106. var RO = window.ResizeObserver;
  107. if (RO) {
  108. var ro = new RO(callback);
  109. ro.observe(_this.root);
  110. return ro;
  111. }
  112. return null;
  113. },
  114. getWidth: function () { return _this.root.offsetWidth; },
  115. };
  116. return new MDCLinearProgressFoundation(adapter);
  117. };
  118. return MDCLinearProgress;
  119. }(MDCComponent));
  120. export { MDCLinearProgress };
  121. //# sourceMappingURL=component.js.map