1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | import { __assign, __extends, __read, __spreadArray } from "tslib";
|
24 | import { MDCComponent } from '@material/base/component';
|
25 | import { applyPassive } from '@material/dom/events';
|
26 | import { matches } from '@material/dom/ponyfill';
|
27 | import { MDCRipple } from '@material/ripple/component';
|
28 | import { MDCRippleFoundation } from '@material/ripple/foundation';
|
29 | import { MDCSwitchFoundation } from './foundation';
|
30 | var MDCSwitch = (function (_super) {
|
31 | __extends(MDCSwitch, _super);
|
32 | function MDCSwitch() {
|
33 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
34 | _this.rippleSurface = _this.createRipple();
|
35 | return _this;
|
36 | }
|
37 | MDCSwitch.attachTo = function (root) {
|
38 | return new MDCSwitch(root);
|
39 | };
|
40 | MDCSwitch.prototype.destroy = function () {
|
41 | _super.prototype.destroy.call(this);
|
42 | this.rippleSurface.destroy();
|
43 | this.nativeControl.removeEventListener('change', this.changeHandler);
|
44 | };
|
45 | MDCSwitch.prototype.initialSyncWithDOM = function () {
|
46 | var _this = this;
|
47 | this.changeHandler = function () {
|
48 | var _a;
|
49 | var args = [];
|
50 | for (var _i = 0; _i < arguments.length; _i++) {
|
51 | args[_i] = arguments[_i];
|
52 | }
|
53 | (_a = _this.foundation).handleChange.apply(_a, __spreadArray([], __read(args)));
|
54 | };
|
55 | this.nativeControl.addEventListener('change', this.changeHandler);
|
56 |
|
57 |
|
58 |
|
59 | this.checked = this.checked;
|
60 | };
|
61 | MDCSwitch.prototype.getDefaultFoundation = function () {
|
62 | var _this = this;
|
63 |
|
64 |
|
65 | var adapter = {
|
66 | addClass: function (className) { return _this.root.classList.add(className); },
|
67 | removeClass: function (className) { return _this.root.classList.remove(className); },
|
68 | setNativeControlChecked: function (checked) { return _this.nativeControl.checked =
|
69 | checked; },
|
70 | setNativeControlDisabled: function (disabled) { return _this.nativeControl.disabled =
|
71 | disabled; },
|
72 | setNativeControlAttr: function (attr, value) {
|
73 | _this.nativeControl.setAttribute(attr, value);
|
74 | },
|
75 | };
|
76 | return new MDCSwitchFoundation(adapter);
|
77 | };
|
78 | Object.defineProperty(MDCSwitch.prototype, "ripple", {
|
79 | get: function () {
|
80 | return this.rippleSurface;
|
81 | },
|
82 | enumerable: false,
|
83 | configurable: true
|
84 | });
|
85 | Object.defineProperty(MDCSwitch.prototype, "checked", {
|
86 | get: function () {
|
87 | return this.nativeControl.checked;
|
88 | },
|
89 | set: function (checked) {
|
90 | this.foundation.setChecked(checked);
|
91 | },
|
92 | enumerable: false,
|
93 | configurable: true
|
94 | });
|
95 | Object.defineProperty(MDCSwitch.prototype, "disabled", {
|
96 | get: function () {
|
97 | return this.nativeControl.disabled;
|
98 | },
|
99 | set: function (disabled) {
|
100 | this.foundation.setDisabled(disabled);
|
101 | },
|
102 | enumerable: false,
|
103 | configurable: true
|
104 | });
|
105 | MDCSwitch.prototype.createRipple = function () {
|
106 | var _this = this;
|
107 | var RIPPLE_SURFACE_SELECTOR = MDCSwitchFoundation.strings.RIPPLE_SURFACE_SELECTOR;
|
108 | var rippleSurface = this.root.querySelector(RIPPLE_SURFACE_SELECTOR);
|
109 |
|
110 |
|
111 | var adapter = __assign(__assign({}, MDCRipple.createAdapter(this)), { addClass: function (className) { return rippleSurface.classList.add(className); }, computeBoundingRect: function () { return rippleSurface.getBoundingClientRect(); }, deregisterInteractionHandler: function (evtType, handler) {
|
112 | _this.nativeControl.removeEventListener(evtType, handler, applyPassive());
|
113 | }, isSurfaceActive: function () { return matches(_this.nativeControl, ':active'); }, isUnbounded: function () { return true; }, registerInteractionHandler: function (evtType, handler) {
|
114 | _this.nativeControl.addEventListener(evtType, handler, applyPassive());
|
115 | }, removeClass: function (className) {
|
116 | rippleSurface.classList.remove(className);
|
117 | }, updateCssVariable: function (varName, value) {
|
118 | rippleSurface.style.setProperty(varName, value);
|
119 | } });
|
120 | return new MDCRipple(this.root, new MDCRippleFoundation(adapter));
|
121 | };
|
122 | Object.defineProperty(MDCSwitch.prototype, "nativeControl", {
|
123 | get: function () {
|
124 | var NATIVE_CONTROL_SELECTOR = MDCSwitchFoundation.strings.NATIVE_CONTROL_SELECTOR;
|
125 | return this.root.querySelector(NATIVE_CONTROL_SELECTOR);
|
126 | },
|
127 | enumerable: false,
|
128 | configurable: true
|
129 | });
|
130 | return MDCSwitch;
|
131 | }(MDCComponent));
|
132 | export { MDCSwitch };
|
133 |
|
\ | No newline at end of file |