UNPKG

5.55 kBJavaScriptView Raw
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 */
23import { __assign, __extends } from "tslib";
24import { MDCComponent } from '@material/base/component';
25import { applyPassive } from '@material/dom/events';
26import { MDCRipple } from '@material/ripple/component';
27import { MDCRippleFoundation } from '@material/ripple/foundation';
28import { MDCRadioFoundation } from './foundation';
29var MDCRadio = /** @class */ (function (_super) {
30 __extends(MDCRadio, _super);
31 function MDCRadio() {
32 var _this = _super !== null && _super.apply(this, arguments) || this;
33 _this.rippleSurface = _this.createRipple();
34 return _this;
35 }
36 MDCRadio.attachTo = function (root) {
37 return new MDCRadio(root);
38 };
39 Object.defineProperty(MDCRadio.prototype, "checked", {
40 get: function () {
41 return this.nativeControl.checked;
42 },
43 set: function (checked) {
44 this.nativeControl.checked = checked;
45 },
46 enumerable: false,
47 configurable: true
48 });
49 Object.defineProperty(MDCRadio.prototype, "disabled", {
50 get: function () {
51 return this.nativeControl.disabled;
52 },
53 set: function (disabled) {
54 this.foundation.setDisabled(disabled);
55 },
56 enumerable: false,
57 configurable: true
58 });
59 Object.defineProperty(MDCRadio.prototype, "value", {
60 get: function () {
61 return this.nativeControl.value;
62 },
63 set: function (value) {
64 this.nativeControl.value = value;
65 },
66 enumerable: false,
67 configurable: true
68 });
69 Object.defineProperty(MDCRadio.prototype, "ripple", {
70 get: function () {
71 return this.rippleSurface;
72 },
73 enumerable: false,
74 configurable: true
75 });
76 MDCRadio.prototype.destroy = function () {
77 this.rippleSurface.destroy();
78 _super.prototype.destroy.call(this);
79 };
80 MDCRadio.prototype.getDefaultFoundation = function () {
81 var _this = this;
82 // DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
83 // To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable.
84 var adapter = {
85 addClass: function (className) { return _this.root.classList.add(className); },
86 removeClass: function (className) { return _this.root.classList.remove(className); },
87 setNativeControlDisabled: function (disabled) { return _this.nativeControl.disabled =
88 disabled; },
89 };
90 return new MDCRadioFoundation(adapter);
91 };
92 MDCRadio.prototype.createRipple = function () {
93 var _this = this;
94 // DO NOT INLINE this variable. For backward compatibility, foundations take a Partial<MDCFooAdapter>.
95 // To ensure we don't accidentally omit any methods, we need a separate, strongly typed adapter variable.
96 // tslint:disable:object-literal-sort-keys Methods should be in the same order as the adapter interface.
97 var adapter = __assign(__assign({}, MDCRipple.createAdapter(this)), { registerInteractionHandler: function (evtType, handler) {
98 _this.nativeControl.addEventListener(evtType, handler, applyPassive());
99 }, deregisterInteractionHandler: function (evtType, handler) {
100 _this.nativeControl.removeEventListener(evtType, handler, applyPassive());
101 },
102 // Radio buttons technically go "active" whenever there is *any* keyboard
103 // interaction. This is not the UI we desire.
104 isSurfaceActive: function () { return false; }, isUnbounded: function () { return true; } });
105 // tslint:enable:object-literal-sort-keys
106 return new MDCRipple(this.root, new MDCRippleFoundation(adapter));
107 };
108 Object.defineProperty(MDCRadio.prototype, "nativeControl", {
109 get: function () {
110 var NATIVE_CONTROL_SELECTOR = MDCRadioFoundation.strings.NATIVE_CONTROL_SELECTOR;
111 var el = this.root.querySelector(NATIVE_CONTROL_SELECTOR);
112 if (!el) {
113 throw new Error("Radio component requires a " + NATIVE_CONTROL_SELECTOR + " element");
114 }
115 return el;
116 },
117 enumerable: false,
118 configurable: true
119 });
120 return MDCRadio;
121}(MDCComponent));
122export { MDCRadio };
123//# sourceMappingURL=component.js.map
\No newline at end of file