UNPKG

4.87 kBJavaScriptView Raw
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 */
23import { __extends } from "tslib";
24import { MDCComponent } from '@material/base/component';
25import { MDCRipple } from '@material/ripple/component';
26import { MDCRippleFoundation } from '@material/ripple/foundation';
27import { strings } from './constants';
28import { MDCChipTrailingActionFoundation } from './foundation';
29var MDCChipTrailingAction = /** @class */ (function (_super) {
30 __extends(MDCChipTrailingAction, _super);
31 function MDCChipTrailingAction() {
32 return _super !== null && _super.apply(this, arguments) || this;
33 }
34 Object.defineProperty(MDCChipTrailingAction.prototype, "ripple", {
35 get: function () {
36 return this.rippleSurface;
37 },
38 enumerable: false,
39 configurable: true
40 });
41 MDCChipTrailingAction.attachTo = function (root) {
42 return new MDCChipTrailingAction(root);
43 };
44 MDCChipTrailingAction.prototype.initialize = function (rippleFactory) {
45 if (rippleFactory === void 0) { rippleFactory = function (el, foundation) {
46 return new MDCRipple(el, foundation);
47 }; }
48 // DO NOT INLINE this variable. For backward compatibility, foundations take
49 // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
50 // methods, we need a separate, strongly typed adapter variable.
51 var rippleAdapter = MDCRipple.createAdapter(this);
52 this.rippleSurface =
53 rippleFactory(this.root, new MDCRippleFoundation(rippleAdapter));
54 };
55 MDCChipTrailingAction.prototype.initialSyncWithDOM = function () {
56 var _this = this;
57 this.handleClick = function (evt) {
58 _this.foundation.handleClick(evt);
59 };
60 this.handleKeydown = function (evt) {
61 _this.foundation.handleKeydown(evt);
62 };
63 this.listen('click', this.handleClick);
64 this.listen('keydown', this.handleKeydown);
65 };
66 MDCChipTrailingAction.prototype.destroy = function () {
67 this.rippleSurface.destroy();
68 this.unlisten('click', this.handleClick);
69 this.unlisten('keydown', this.handleKeydown);
70 _super.prototype.destroy.call(this);
71 };
72 MDCChipTrailingAction.prototype.getDefaultFoundation = function () {
73 var _this = this;
74 // DO NOT INLINE this variable. For backward compatibility, foundations take
75 // a Partial<MDCFooAdapter>. To ensure we don't accidentally omit any
76 // methods, we need a separate, strongly typed adapter variable.
77 var adapter = {
78 focus: function () {
79 // TODO(b/157231863): Migate MDCComponent#root to HTMLElement
80 _this.root.focus();
81 },
82 getAttribute: function (attr) { return _this.root.getAttribute(attr); },
83 notifyInteraction: function (trigger) {
84 return _this.emit(strings.INTERACTION_EVENT, { trigger: trigger }, true /* shouldBubble */);
85 },
86 notifyNavigation: function (key) {
87 _this.emit(strings.NAVIGATION_EVENT, { key: key }, true /* shouldBubble */);
88 },
89 setAttribute: function (attr, value) {
90 _this.root.setAttribute(attr, value);
91 },
92 };
93 return new MDCChipTrailingActionFoundation(adapter);
94 };
95 MDCChipTrailingAction.prototype.isNavigable = function () {
96 return this.foundation.isNavigable();
97 };
98 MDCChipTrailingAction.prototype.focus = function () {
99 this.foundation.focus();
100 };
101 MDCChipTrailingAction.prototype.removeFocus = function () {
102 this.foundation.removeFocus();
103 };
104 return MDCChipTrailingAction;
105}(MDCComponent));
106export { MDCChipTrailingAction };
107//# sourceMappingURL=component.js.map
\No newline at end of file