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 } from "tslib";
|
24 | import { MDCFoundation } from '@material/base/foundation';
|
25 | import { cssClasses, strings } from './constants';
|
26 | var MDCSwitchFoundation = (function (_super) {
|
27 | __extends(MDCSwitchFoundation, _super);
|
28 | function MDCSwitchFoundation(adapter) {
|
29 | return _super.call(this, __assign(__assign({}, MDCSwitchFoundation.defaultAdapter), adapter)) || this;
|
30 | }
|
31 | Object.defineProperty(MDCSwitchFoundation, "strings", {
|
32 |
|
33 | get: function () {
|
34 | return strings;
|
35 | },
|
36 | enumerable: false,
|
37 | configurable: true
|
38 | });
|
39 | Object.defineProperty(MDCSwitchFoundation, "cssClasses", {
|
40 |
|
41 | get: function () {
|
42 | return cssClasses;
|
43 | },
|
44 | enumerable: false,
|
45 | configurable: true
|
46 | });
|
47 | Object.defineProperty(MDCSwitchFoundation, "defaultAdapter", {
|
48 |
|
49 | get: function () {
|
50 | return {
|
51 | addClass: function () { return undefined; },
|
52 | removeClass: function () { return undefined; },
|
53 | setNativeControlChecked: function () { return undefined; },
|
54 | setNativeControlDisabled: function () { return undefined; },
|
55 | setNativeControlAttr: function () { return undefined; },
|
56 | };
|
57 | },
|
58 | enumerable: false,
|
59 | configurable: true
|
60 | });
|
61 |
|
62 | MDCSwitchFoundation.prototype.setChecked = function (checked) {
|
63 | this.adapter.setNativeControlChecked(checked);
|
64 | this.updateAriaChecked(checked);
|
65 | this.updateCheckedStyling(checked);
|
66 | };
|
67 |
|
68 | MDCSwitchFoundation.prototype.setDisabled = function (disabled) {
|
69 | this.adapter.setNativeControlDisabled(disabled);
|
70 | if (disabled) {
|
71 | this.adapter.addClass(cssClasses.DISABLED);
|
72 | }
|
73 | else {
|
74 | this.adapter.removeClass(cssClasses.DISABLED);
|
75 | }
|
76 | };
|
77 |
|
78 | MDCSwitchFoundation.prototype.handleChange = function (evt) {
|
79 | var nativeControl = evt.target;
|
80 | this.updateAriaChecked(nativeControl.checked);
|
81 | this.updateCheckedStyling(nativeControl.checked);
|
82 | };
|
83 |
|
84 | MDCSwitchFoundation.prototype.updateCheckedStyling = function (checked) {
|
85 | if (checked) {
|
86 | this.adapter.addClass(cssClasses.CHECKED);
|
87 | }
|
88 | else {
|
89 | this.adapter.removeClass(cssClasses.CHECKED);
|
90 | }
|
91 | };
|
92 | MDCSwitchFoundation.prototype.updateAriaChecked = function (checked) {
|
93 | this.adapter.setNativeControlAttr(strings.ARIA_CHECKED_ATTR, "" + !!checked);
|
94 | };
|
95 | return MDCSwitchFoundation;
|
96 | }(MDCFoundation));
|
97 | export { MDCSwitchFoundation };
|
98 |
|
99 | export default MDCSwitchFoundation;
|
100 |
|
\ | No newline at end of file |