component.js 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @license
  3. * Copyright 2016 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 { estimateScrollWidth } from '@material/dom/ponyfill';
  26. import { MDCFloatingLabelFoundation } from './foundation';
  27. /** MDC Floating Label */
  28. var MDCFloatingLabel = /** @class */ (function (_super) {
  29. __extends(MDCFloatingLabel, _super);
  30. function MDCFloatingLabel() {
  31. return _super !== null && _super.apply(this, arguments) || this;
  32. }
  33. MDCFloatingLabel.attachTo = function (root) {
  34. return new MDCFloatingLabel(root);
  35. };
  36. /**
  37. * Styles the label to produce the label shake for errors.
  38. * @param shouldShake If true, shakes the label by adding a CSS class;
  39. * otherwise, stops shaking by removing the class.
  40. */
  41. MDCFloatingLabel.prototype.shake = function (shouldShake) {
  42. this.foundation.shake(shouldShake);
  43. };
  44. /**
  45. * Styles the label to float/dock.
  46. * @param shouldFloat If true, floats the label by adding a CSS class;
  47. * otherwise, docks it by removing the class.
  48. */
  49. MDCFloatingLabel.prototype.float = function (shouldFloat) {
  50. this.foundation.float(shouldFloat);
  51. };
  52. /**
  53. * Styles the label as required.
  54. * @param isRequired If true, adds an asterisk to the label, indicating that
  55. * it is required.
  56. */
  57. MDCFloatingLabel.prototype.setRequired = function (isRequired) {
  58. this.foundation.setRequired(isRequired);
  59. };
  60. MDCFloatingLabel.prototype.getWidth = function () {
  61. return this.foundation.getWidth();
  62. };
  63. MDCFloatingLabel.prototype.getDefaultFoundation = function () {
  64. var _this = this;
  65. // DO NOT INLINE this variable. For backward compatibility, foundations take
  66. // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
  67. // methods, we need a separate, strongly typed adapter variable.
  68. // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
  69. var adapter = {
  70. addClass: function (className) {
  71. _this.root.classList.add(className);
  72. },
  73. removeClass: function (className) {
  74. _this.root.classList.remove(className);
  75. },
  76. hasClass: function (className) { return _this.root.classList.contains(className); },
  77. getWidth: function () { return estimateScrollWidth(_this.root); },
  78. registerInteractionHandler: function (evtType, handler) {
  79. _this.listen(evtType, handler);
  80. },
  81. deregisterInteractionHandler: function (evtType, handler) {
  82. _this.unlisten(evtType, handler);
  83. },
  84. };
  85. // tslint:enable:object-literal-sort-keys
  86. return new MDCFloatingLabelFoundation(adapter);
  87. };
  88. return MDCFloatingLabel;
  89. }(MDCComponent));
  90. export { MDCFloatingLabel };
  91. //# sourceMappingURL=component.js.map