UNPKG

3.94 kBJavaScriptView Raw
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 */
23import { __extends } from "tslib";
24import { MDCComponent } from '@material/base/component';
25import { MDCFloatingLabelFoundation } from '@material/floating-label/foundation';
26import { cssClasses, strings } from './constants';
27import { MDCNotchedOutlineFoundation } from './foundation';
28var MDCNotchedOutline = /** @class */ (function (_super) {
29 __extends(MDCNotchedOutline, _super);
30 function MDCNotchedOutline() {
31 return _super !== null && _super.apply(this, arguments) || this;
32 }
33 MDCNotchedOutline.attachTo = function (root) {
34 return new MDCNotchedOutline(root);
35 };
36 MDCNotchedOutline.prototype.initialSyncWithDOM = function () {
37 this.notchElement =
38 this.root.querySelector(strings.NOTCH_ELEMENT_SELECTOR);
39 var label = this.root.querySelector('.' + MDCFloatingLabelFoundation.cssClasses.ROOT);
40 if (label) {
41 label.style.transitionDuration = '0s';
42 this.root.classList.add(cssClasses.OUTLINE_UPGRADED);
43 requestAnimationFrame(function () {
44 label.style.transitionDuration = '';
45 });
46 }
47 else {
48 this.root.classList.add(cssClasses.NO_LABEL);
49 }
50 };
51 /**
52 * Updates classes and styles to open the notch to the specified width.
53 * @param notchWidth The notch width in the outline.
54 */
55 MDCNotchedOutline.prototype.notch = function (notchWidth) {
56 this.foundation.notch(notchWidth);
57 };
58 /**
59 * Updates classes and styles to close the notch.
60 */
61 MDCNotchedOutline.prototype.closeNotch = function () {
62 this.foundation.closeNotch();
63 };
64 MDCNotchedOutline.prototype.getDefaultFoundation = function () {
65 var _this = this;
66 // DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
67 // To ensure we don't accidentally omit any 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) { return _this.root.classList.add(className); },
71 removeClass: function (className) { return _this.root.classList.remove(className); },
72 setNotchWidthProperty: function (width) {
73 _this.notchElement.style.setProperty('width', width + 'px');
74 },
75 removeNotchWidthProperty: function () {
76 _this.notchElement.style.removeProperty('width');
77 },
78 };
79 // tslint:enable:object-literal-sort-keys
80 return new MDCNotchedOutlineFoundation(adapter);
81 };
82 return MDCNotchedOutline;
83}(MDCComponent));
84export { MDCNotchedOutline };
85//# sourceMappingURL=component.js.map
\No newline at end of file