component.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * @license
  3. * Copyright 2020 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 { MDCCircularProgressFoundation } from './foundation';
  26. /** MDC Circular Progress */
  27. var MDCCircularProgress = /** @class */ (function (_super) {
  28. __extends(MDCCircularProgress, _super);
  29. function MDCCircularProgress() {
  30. return _super !== null && _super.apply(this, arguments) || this;
  31. }
  32. MDCCircularProgress.prototype.initialize = function () {
  33. this.determinateCircle = this.root.querySelector(MDCCircularProgressFoundation.strings.DETERMINATE_CIRCLE_SELECTOR);
  34. };
  35. MDCCircularProgress.attachTo = function (root) {
  36. return new MDCCircularProgress(root);
  37. };
  38. Object.defineProperty(MDCCircularProgress.prototype, "determinate", {
  39. /**
  40. * Sets whether the progress indicator is in determinate mode.
  41. * @param value Whether the indicator should be determinate.
  42. */
  43. set: function (value) {
  44. this.foundation.setDeterminate(value);
  45. },
  46. enumerable: false,
  47. configurable: true
  48. });
  49. Object.defineProperty(MDCCircularProgress.prototype, "progress", {
  50. /**
  51. * Sets the current progress value. In indeterminate mode, this has no
  52. * visual effect but will be reflected if the indicator is switched to
  53. * determinate mode.
  54. * @param value The current progress value, which must be between 0 and 1.
  55. */
  56. set: function (value) {
  57. this.foundation.setProgress(value);
  58. },
  59. enumerable: false,
  60. configurable: true
  61. });
  62. Object.defineProperty(MDCCircularProgress.prototype, "isClosed", {
  63. /**
  64. * Whether the progress indicator is hidden.
  65. */
  66. get: function () {
  67. return this.foundation.isClosed();
  68. },
  69. enumerable: false,
  70. configurable: true
  71. });
  72. /**
  73. * Shows the progress indicator.
  74. */
  75. MDCCircularProgress.prototype.open = function () {
  76. this.foundation.open();
  77. };
  78. /**
  79. * Hides the progress indicator.
  80. */
  81. MDCCircularProgress.prototype.close = function () {
  82. this.foundation.close();
  83. };
  84. MDCCircularProgress.prototype.getDefaultFoundation = function () {
  85. var _this = this;
  86. // DO NOT INLINE this variable. For backward compatibility, foundations take
  87. // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
  88. // methods, we need a separate, strongly typed adapter variable.
  89. var adapter = {
  90. addClass: function (className) {
  91. _this.root.classList.add(className);
  92. },
  93. getDeterminateCircleAttribute: function (attributeName) {
  94. return _this.determinateCircle.getAttribute(attributeName);
  95. },
  96. hasClass: function (className) { return _this.root.classList.contains(className); },
  97. removeClass: function (className) {
  98. _this.root.classList.remove(className);
  99. },
  100. removeAttribute: function (attributeName) {
  101. _this.root.removeAttribute(attributeName);
  102. },
  103. setAttribute: function (attributeName, value) {
  104. _this.safeSetAttribute(_this.root, attributeName, value);
  105. },
  106. setDeterminateCircleAttribute: function (attributeName, value) {
  107. _this.determinateCircle.setAttribute(attributeName, value);
  108. },
  109. };
  110. return new MDCCircularProgressFoundation(adapter);
  111. };
  112. return MDCCircularProgress;
  113. }(MDCComponent));
  114. export { MDCCircularProgress };
  115. //# sourceMappingURL=component.js.map